Done. End Stone Smelter.
This commit is contained in:
parent
9a1dc34927
commit
7f8f3fbda5
4 changed files with 107 additions and 21 deletions
|
@ -1,15 +1,15 @@
|
|||
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.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
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;
|
||||
|
@ -18,37 +18,29 @@ 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;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EndStoneSmelterRecipeBookScreen extends BlastFurnaceRecipeBookScreen {
|
||||
private Iterator<Item> fuelIterator;
|
||||
private Set<Item> fuels;
|
||||
private Slot fuelSlot;
|
||||
private Item currentItem;
|
||||
private float frameTime;
|
||||
|
||||
@Override
|
||||
protected Set<Item> getAllowedFuels() {
|
||||
return EndStoneSmelterBlockEntity.availableFuels().keySet();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void showGhostRecipe(Recipe<?> recipe, List<Slot> slots) {
|
||||
this.ghostSlots.reset();
|
||||
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()) {
|
||||
|
@ -60,5 +52,44 @@ public class EndStoneSmelterRecipeBookScreen extends BlastFurnaceRecipeBookScree
|
|||
this.ghostSlots.addSlot(ingredient, slot.x, slot.y);
|
||||
}
|
||||
}
|
||||
this.fuelSlot = slots.get(2);
|
||||
if (this.fuels == null) {
|
||||
this.fuels = this.getAllowedFuels();
|
||||
}
|
||||
|
||||
this.fuelIterator = this.fuels.iterator();
|
||||
this.currentItem = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGhostSlots(MatrixStack matrixStack, int x, int y, boolean bl, float f) {
|
||||
this.ghostSlots.draw(matrixStack, client, x, y, bl, f);
|
||||
if (fuelSlot != null) {
|
||||
if (!Screen.hasControlDown()) {
|
||||
this.frameTime += f;
|
||||
}
|
||||
|
||||
int slotX = this.fuelSlot.x + x;
|
||||
int slotY = this.fuelSlot.y + y;
|
||||
DrawableHelper.fill(matrixStack, slotX, slotY, slotX + 16, slotY + 16, 822018048);
|
||||
this.client.getItemRenderer().renderInGuiWithOverrides(client.player, this.getItem().getStackForRender(), slotX, slotY);
|
||||
RenderSystem.depthFunc(516);
|
||||
DrawableHelper.fill(matrixStack, slotX, slotY, slotX + 16, slotY + 16, 822083583);
|
||||
RenderSystem.depthFunc(515);
|
||||
}
|
||||
}
|
||||
|
||||
private Item getItem() {
|
||||
if (this.currentItem == null || this.frameTime > 30.0F) {
|
||||
this.frameTime = 0.0F;
|
||||
if (this.fuelIterator == null || !this.fuelIterator.hasNext()) {
|
||||
if (this.fuels == null) {
|
||||
this.fuels = this.getAllowedFuels();
|
||||
}
|
||||
this.fuelIterator = this.fuels.iterator();
|
||||
}
|
||||
this.currentItem = this.fuelIterator.next();
|
||||
}
|
||||
return this.currentItem;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package ru.betterend.client.gui;
|
|||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
|
||||
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
|
||||
|
@ -13,8 +16,10 @@ import net.minecraft.screen.slot.SlotActionType;
|
|||
import net.minecraft.text.StringVisitable;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EndStoneSmelterScreen extends HandledScreen<EndStoneSmelterScreenHandler> implements RecipeBookProvider {
|
||||
|
||||
private final static Identifier RECIPE_BUTTON_TEXTURE = new Identifier("textures/gui/recipe_button.png");
|
||||
|
|
|
@ -58,7 +58,7 @@ public class EndStoneSmelterScreenHandler extends AbstractRecipeScreenHandler<In
|
|||
}
|
||||
for(int i = 0; i < 9; ++i) {
|
||||
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -116,6 +116,54 @@ public class EndStoneSmelterScreenHandler extends AbstractRecipeScreenHandler<In
|
|||
return EndStoneSmelterBlockEntity.canUseAsFuel(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferSlot(PlayerEntity player, int index) {
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
Slot slot = this.slots.get(index);
|
||||
if (slot != null && slot.hasStack()) {
|
||||
ItemStack itemStack2 = slot.getStack();
|
||||
itemStack = itemStack2.copy();
|
||||
if (index == 3) {
|
||||
if (insertItem(itemStack2, 4, 40, true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
slot.onStackChanged(itemStack2, itemStack);
|
||||
} else if (index != 2 && index != 1 && index != 0) {
|
||||
if (isSmeltable(itemStack2)) {
|
||||
if (!insertItem(itemStack2, 0, 2, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (isFuel(itemStack2)) {
|
||||
if (!this.insertItem(itemStack2, 2, 3, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (index >= 4 && index < 31) {
|
||||
if (!insertItem(itemStack2, 31, 40, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (index >= 31 && index < 40 && !insertItem(itemStack2, 4, 31, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!insertItem(itemStack2, 4, 40, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemStack2.isEmpty()) {
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.markDirty();
|
||||
}
|
||||
|
||||
if (itemStack2.getCount() == itemStack.getCount()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
slot.onTakeItem(player, itemStack2);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public int getSmeltProgress() {
|
||||
int time = this.propertyDelegate.get(2);
|
||||
|
|
|
@ -28,6 +28,7 @@ public class AlloyingRecipe implements Recipe<Inventory> {
|
|||
protected final Ingredient primaryInput;
|
||||
protected final Ingredient secondaryInput;
|
||||
protected final ItemStack output;
|
||||
protected final String group;
|
||||
protected final float experience;
|
||||
protected final int smeltTime;
|
||||
|
||||
|
@ -35,6 +36,7 @@ public class AlloyingRecipe implements Recipe<Inventory> {
|
|||
public AlloyingRecipe(Identifier id, Ingredient primaryInput, Ingredient secondaryInput,
|
||||
ItemStack output, float experience, int smeltTime) {
|
||||
|
||||
this.group = String.format("%s:%s", GROUP, id.getPath());
|
||||
this.id = id;
|
||||
this.primaryInput = primaryInput;
|
||||
this.secondaryInput = secondaryInput;
|
||||
|
@ -98,7 +100,7 @@ public class AlloyingRecipe implements Recipe<Inventory> {
|
|||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public String getGroup() {
|
||||
return GROUP;
|
||||
return this.group;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue