This commit is contained in:
Aleksey 2020-09-29 17:57:46 +03:00
parent 7d311ca3d7
commit 43993d13bc
5 changed files with 86 additions and 18 deletions

View file

@ -1,21 +1,64 @@
package ru.betterend.client.gui;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.recipebook.AbstractFurnaceRecipeBookScreen;
import net.minecraft.client.gui.screen.recipebook.BlastFurnaceRecipeBookScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Item;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.Recipe;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.collection.DefaultedList;
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
public class EndStoneSmelterRecipeBookScreen extends BlastFurnaceRecipeBookScreen {
private static final Text TITLE = new TranslatableText("gui.recipebook.toggleRecipes.blastable");
protected Text getToggleCraftableButtonText() {
return TITLE;
}
@Override
protected Set<Item> getAllowedFuels() {
return EndStoneSmelterBlockEntity.availableFuels().keySet();
}
@SuppressWarnings("unchecked")
@Override
public void showGhostRecipe(Recipe<?> recipe, List<Slot> slots) {
ItemStack result = recipe.getOutput();
this.ghostSlots.setRecipe(recipe);
this.ghostSlots.addSlot(Ingredient.ofStacks(result), (slots.get(3)).x, (slots.get(3)).y);
DefaultedList<Ingredient> inputs = recipe.getPreviewInputs();
try {
Field outputSlot = super.getClass().getDeclaredField("outputSlot");
outputSlot.setAccessible(true);
outputSlot.set(Slot.class, slots.get(3));
Field fuels = super.getClass().getDeclaredField("fuels");
fuels.setAccessible(true);
if (fuels.get(Set.class) == null) {
fuels.set(Set.class, this.getAllowedFuels());
}
Field fuelIterator = super.getClass().getDeclaredField("fuelIterator");
fuelIterator.setAccessible(true);
fuelIterator.set(Iterator.class, ((Set<Item>) fuels.get(Set.class)).iterator());
} catch (Exception ex) {
ex.printStackTrace();
}
Iterator<Ingredient> iterator = inputs.iterator();
for(int i = 0; i < 2; i++) {
if (!iterator.hasNext()) {
return;
}
Ingredient ingredient = iterator.next();
if (!ingredient.isEmpty()) {
Slot slot = slots.get(i);
this.ghostSlots.addSlot(ingredient, slot.x, slot.y);
}
}
}
}

View file

@ -37,7 +37,7 @@ public class EndStoneSmelterScreen extends HandledScreen<EndStoneSmelterScreenHa
this.recipeBook.reset(narrow);
this.recipeBook.toggleOpen();
this.x = this.recipeBook.findLeftEdge(narrow, width, backgroundWidth);
((TexturedButtonWidget)buttonWidget).setPos(this.x + 20, height / 2 - 49);
((TexturedButtonWidget) buttonWidget).setPos(this.x + 20, height / 2 - 49);
}));
this.titleX = (this.backgroundWidth - this.textRenderer.getWidth((StringVisitable)this.title)) / 2;
}