[Fix] EndStone Smelter destroys result item when recipe is clicked in book
This commit is contained in:
parent
3694bf1eee
commit
f6df2a2504
5 changed files with 83 additions and 64 deletions
|
@ -2,7 +2,7 @@ package org.betterx.betterend.blocks.entities;
|
|||
|
||||
import org.betterx.betterend.BetterEnd;
|
||||
import org.betterx.betterend.blocks.EndStoneSmelter;
|
||||
import org.betterx.betterend.client.gui.EndStoneSmelterScreenHandler;
|
||||
import org.betterx.betterend.client.gui.EndStoneSmelterMenu;
|
||||
import org.betterx.betterend.recipe.builders.AlloyingRecipe;
|
||||
import org.betterx.betterend.registry.EndBlockEntities;
|
||||
|
||||
|
@ -49,9 +49,15 @@ import java.util.Map;
|
|||
|
||||
public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder, StackedContentsCompatible {
|
||||
|
||||
private static final int[] TOP_SLOTS = new int[]{0, 1};
|
||||
private static final int[] BOTTOM_SLOTS = new int[]{2, 3};
|
||||
private static final int[] SIDE_SLOTS = new int[]{1, 2};
|
||||
private static final int[] TOP_SLOTS = new int[]{
|
||||
EndStoneSmelterMenu.INGREDIENT_SLOT_A,
|
||||
EndStoneSmelterMenu.INGREDIENT_SLOT_B
|
||||
};
|
||||
private static final int[] BOTTOM_SLOTS = new int[]{EndStoneSmelterMenu.FUEL_SLOT, EndStoneSmelterMenu.RESULT_SLOT};
|
||||
private static final int[] SIDE_SLOTS = new int[]{
|
||||
EndStoneSmelterMenu.INGREDIENT_SLOT_B,
|
||||
EndStoneSmelterMenu.FUEL_SLOT
|
||||
};
|
||||
private static final Map<Item, Integer> AVAILABLE_FUELS = Maps.newHashMap();
|
||||
|
||||
private final Object2IntOpenHashMap<ResourceLocation> recipesUsed;
|
||||
|
@ -65,7 +71,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
|
||||
public EndStoneSmelterBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
super(EndBlockEntities.END_STONE_SMELTER, blockPos, blockState);
|
||||
this.inventory = NonNullList.withSize(4, ItemStack.EMPTY);
|
||||
this.inventory = NonNullList.withSize(EndStoneSmelterMenu.SLOT_COUNT, ItemStack.EMPTY);
|
||||
this.recipesUsed = new Object2IntOpenHashMap<>();
|
||||
this.propertyDelegate = new ContainerData() {
|
||||
public int get(int index) {
|
||||
|
@ -151,7 +157,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
if (stack.getCount() > getMaxStackSize()) {
|
||||
stack.setCount(getMaxStackSize());
|
||||
}
|
||||
if ((slot == 0 || slot == 1) && !stackValid) {
|
||||
if ((slot == EndStoneSmelterMenu.INGREDIENT_SLOT_A || slot == EndStoneSmelterMenu.INGREDIENT_SLOT_B) && !stackValid) {
|
||||
smeltTimeTotal = getSmeltTime();
|
||||
smeltTime = 0;
|
||||
setChanged();
|
||||
|
@ -231,7 +237,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
|
||||
@Override
|
||||
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
|
||||
return new EndStoneSmelterScreenHandler(syncId, playerInventory, this, propertyDelegate);
|
||||
return new EndStoneSmelterMenu(syncId, playerInventory, this, propertyDelegate);
|
||||
}
|
||||
|
||||
public static void tick(
|
||||
|
@ -249,9 +255,11 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
|
||||
boolean burning = initialBurning;
|
||||
if (!tickLevel.isClientSide) {
|
||||
ItemStack fuel = blockEntity.inventory.get(2);
|
||||
if (!burning && (fuel.isEmpty() || blockEntity.inventory.get(0).isEmpty() && blockEntity.inventory.get(1)
|
||||
.isEmpty())) {
|
||||
ItemStack fuel = blockEntity.inventory.get(EndStoneSmelterMenu.FUEL_SLOT);
|
||||
if (!burning && (fuel.isEmpty()
|
||||
|| blockEntity.inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_A).isEmpty()
|
||||
&& blockEntity.inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_B).isEmpty())
|
||||
) {
|
||||
if (blockEntity.smeltTime > 0) {
|
||||
blockEntity.smeltTime = Mth.clamp(blockEntity.smeltTime - 2, 0, blockEntity.smeltTimeTotal);
|
||||
}
|
||||
|
@ -276,7 +284,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
if (fuel.isEmpty()) {
|
||||
Item remainFuel = item.getCraftingRemainingItem();
|
||||
blockEntity.inventory.set(
|
||||
2,
|
||||
EndStoneSmelterMenu.FUEL_SLOT,
|
||||
remainFuel == null ? ItemStack.EMPTY : new ItemStack(remainFuel)
|
||||
);
|
||||
}
|
||||
|
@ -309,16 +317,18 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
if (recipe == null) return false;
|
||||
boolean validInput;
|
||||
if (recipe instanceof AlloyingRecipe) {
|
||||
validInput = !inventory.get(0).isEmpty() && !inventory.get(1).isEmpty();
|
||||
validInput = !inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_A).isEmpty()
|
||||
&& !inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_B).isEmpty();
|
||||
} else {
|
||||
validInput = !inventory.get(0).isEmpty() || !inventory.get(1).isEmpty();
|
||||
validInput = !inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_A).isEmpty()
|
||||
|| !inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_B).isEmpty();
|
||||
}
|
||||
if (validInput) {
|
||||
ItemStack result = recipe.getResultItem();
|
||||
if (result.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
ItemStack output = this.inventory.get(3);
|
||||
ItemStack output = this.inventory.get(EndStoneSmelterMenu.RESULT_SLOT);
|
||||
int outCount = output.getCount();
|
||||
int total = outCount + result.getCount();
|
||||
if (output.isEmpty()) {
|
||||
|
@ -339,9 +349,9 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
if (recipe == null || !canAcceptRecipeOutput(recipe)) return;
|
||||
|
||||
ItemStack result = recipe.getResultItem();
|
||||
ItemStack output = inventory.get(3);
|
||||
ItemStack output = inventory.get(EndStoneSmelterMenu.RESULT_SLOT);
|
||||
if (output.isEmpty()) {
|
||||
inventory.set(3, result.copy());
|
||||
inventory.set(EndStoneSmelterMenu.RESULT_SLOT, result.copy());
|
||||
} else if (output.getItem() == result.getItem()) {
|
||||
output.grow(result.getCount());
|
||||
}
|
||||
|
@ -352,13 +362,13 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
}
|
||||
|
||||
if (recipe instanceof AlloyingRecipe) {
|
||||
inventory.get(0).shrink(1);
|
||||
inventory.get(1).shrink(1);
|
||||
inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_A).shrink(1);
|
||||
inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_B).shrink(1);
|
||||
} else {
|
||||
if (!inventory.get(0).isEmpty()) {
|
||||
inventory.get(0).shrink(1);
|
||||
if (!inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_A).isEmpty()) {
|
||||
inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_A).shrink(1);
|
||||
} else {
|
||||
inventory.get(1).shrink(1);
|
||||
inventory.get(EndStoneSmelterMenu.INGREDIENT_SLOT_B).shrink(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -399,7 +409,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
|
||||
@Override
|
||||
public boolean canTakeItemThroughFace(int slot, ItemStack stack, Direction dir) {
|
||||
if (dir == Direction.DOWN && slot == 2) {
|
||||
if (dir == Direction.DOWN && slot == EndStoneSmelterMenu.FUEL_SLOT) {
|
||||
return stack.getItem() == Items.BUCKET;
|
||||
}
|
||||
return true;
|
||||
|
@ -443,12 +453,12 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
}
|
||||
|
||||
public boolean canPlaceItem(int slot, ItemStack stack) {
|
||||
if (slot == 3) {
|
||||
if (slot == EndStoneSmelterMenu.RESULT_SLOT) {
|
||||
return false;
|
||||
} else if (slot != 2) {
|
||||
} else if (slot != EndStoneSmelterMenu.FUEL_SLOT) {
|
||||
return true;
|
||||
}
|
||||
ItemStack itemStack = this.inventory.get(2);
|
||||
ItemStack itemStack = this.inventory.get(EndStoneSmelterMenu.FUEL_SLOT);
|
||||
return canUseAsFuel(stack) || stack.getItem() == Items.BUCKET && itemStack.getItem() != Items.BUCKET;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.betterx.bclib.BCLib;
|
|||
import org.betterx.bclib.util.TranslationHelper;
|
||||
import org.betterx.betterend.BetterEnd;
|
||||
import org.betterx.betterend.blocks.EndStoneSmelter;
|
||||
import org.betterx.betterend.client.gui.EndStoneSmelterScreenHandler;
|
||||
import org.betterx.betterend.client.gui.EndStoneSmelterMenu;
|
||||
import org.betterx.betterend.client.render.BetterEndSkyRenderer;
|
||||
import org.betterx.betterend.events.ItemTooltipCallback;
|
||||
import org.betterx.betterend.interfaces.MultiModelItem;
|
||||
|
@ -26,9 +26,9 @@ import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry;
|
|||
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
|
||||
|
||||
public class BetterEndClient implements ClientModInitializer {
|
||||
public final static MenuType<EndStoneSmelterScreenHandler> HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(
|
||||
public final static MenuType<EndStoneSmelterMenu> HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(
|
||||
BetterEnd.makeID(EndStoneSmelter.ID),
|
||||
EndStoneSmelterScreenHandler::new
|
||||
EndStoneSmelterMenu::new
|
||||
);
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,17 +23,27 @@ import org.anti_ad.mc.ipn.api.IPNIgnore;
|
|||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@IPNIgnore
|
||||
public class EndStoneSmelterScreenHandler extends RecipeBookMenu<Container> {
|
||||
public class EndStoneSmelterMenu extends RecipeBookMenu<Container> {
|
||||
public static final int INGREDIENT_SLOT_A = 0;
|
||||
public static final int INGREDIENT_SLOT_B = 1;
|
||||
public static final int FUEL_SLOT = 2;
|
||||
public static final int RESULT_SLOT = 3;
|
||||
|
||||
public static final int SLOT_COUNT = 4;
|
||||
private static final int INV_SLOT_START = SLOT_COUNT;
|
||||
private static final int INV_SLOT_END = INV_SLOT_START + 3 * 9;
|
||||
private static final int USE_ROW_SLOT_START = INV_SLOT_END;
|
||||
private static final int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9;
|
||||
|
||||
private final Container inventory;
|
||||
private final ContainerData propertyDelegate;
|
||||
protected final Level world;
|
||||
|
||||
public EndStoneSmelterScreenHandler(int syncId, Inventory playerInventory) {
|
||||
this(syncId, playerInventory, new SimpleContainer(4), new SimpleContainerData(4));
|
||||
public EndStoneSmelterMenu(int syncId, Inventory playerInventory) {
|
||||
this(syncId, playerInventory, new SimpleContainer(SLOT_COUNT), new SimpleContainerData(4));
|
||||
}
|
||||
|
||||
public EndStoneSmelterScreenHandler(
|
||||
public EndStoneSmelterMenu(
|
||||
int syncId,
|
||||
Inventory playerInventory,
|
||||
Container inventory,
|
||||
|
@ -45,10 +55,10 @@ public class EndStoneSmelterScreenHandler extends RecipeBookMenu<Container> {
|
|||
this.world = playerInventory.player.level;
|
||||
|
||||
addDataSlots(propertyDelegate);
|
||||
addSlot(new Slot(inventory, 0, 45, 17));
|
||||
addSlot(new Slot(inventory, 1, 67, 17));
|
||||
addSlot(new SmelterFuelSlot(this, inventory, 2, 56, 53));
|
||||
addSlot(new SmelterOutputSlot(playerInventory.player, inventory, 3, 129, 35));
|
||||
addSlot(new Slot(inventory, INGREDIENT_SLOT_A, 45, 17));
|
||||
addSlot(new Slot(inventory, INGREDIENT_SLOT_B, 67, 17));
|
||||
addSlot(new SmelterFuelSlot(this, inventory, FUEL_SLOT, 56, 53));
|
||||
addSlot(new SmelterOutputSlot(playerInventory.player, inventory, RESULT_SLOT, 129, 35));
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
|
@ -74,7 +84,9 @@ public class EndStoneSmelterScreenHandler extends RecipeBookMenu<Container> {
|
|||
|
||||
@Override
|
||||
public void clearCraftingContent() {
|
||||
inventory.clearContent();
|
||||
this.getSlot(INGREDIENT_SLOT_A).set(ItemStack.EMPTY);
|
||||
this.getSlot(INGREDIENT_SLOT_B).set(ItemStack.EMPTY);
|
||||
this.getSlot(RESULT_SLOT).set(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,7 +96,7 @@ public class EndStoneSmelterScreenHandler extends RecipeBookMenu<Container> {
|
|||
|
||||
@Override
|
||||
public int getResultSlotIndex() {
|
||||
return 3;
|
||||
return RESULT_SLOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,7 +111,7 @@ public class EndStoneSmelterScreenHandler extends RecipeBookMenu<Container> {
|
|||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 4;
|
||||
return SLOT_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,7 +121,7 @@ public class EndStoneSmelterScreenHandler extends RecipeBookMenu<Container> {
|
|||
|
||||
@Override
|
||||
public boolean shouldMoveToInventory(int i) {
|
||||
return i != this.getResultSlotIndex();
|
||||
return i != FUEL_SLOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,28 +146,25 @@ public class EndStoneSmelterScreenHandler extends RecipeBookMenu<Container> {
|
|||
|
||||
ItemStack slotStack = slot.getItem();
|
||||
ItemStack itemStack = slotStack.copy();
|
||||
if (index == 3) {
|
||||
if (!moveItemStackTo(slotStack, 4, 40, true)) {
|
||||
if (index == RESULT_SLOT) {
|
||||
if (!moveItemStackTo(slotStack, INV_SLOT_START, USE_ROW_SLOT_END, true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
slot.onQuickCraft(slotStack, itemStack);
|
||||
} else if (index != 2 && index != 1 && index != 0) {
|
||||
if (isSmeltable(slotStack)) {
|
||||
if (!moveItemStackTo(slotStack, 0, 2, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (isFuel(slotStack)) {
|
||||
if (!moveItemStackTo(slotStack, 2, 3, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (index < 31) {
|
||||
if (!moveItemStackTo(slotStack, 31, 40, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (index < 40 && !moveItemStackTo(slotStack, 4, 31, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!moveItemStackTo(slotStack, 4, 40, false)) {
|
||||
} else if (((index == FUEL_SLOT) || (index == INGREDIENT_SLOT_A) || (index == INGREDIENT_SLOT_B))
|
||||
? !this.moveItemStackTo(slotStack, USE_ROW_SLOT_START, USE_ROW_SLOT_END, false)
|
||||
: (this.isSmeltable(slotStack)
|
||||
? !this.moveItemStackTo(slotStack, INGREDIENT_SLOT_A, FUEL_SLOT, false)
|
||||
: (this.isFuel(slotStack)
|
||||
? !this.moveItemStackTo(slotStack, FUEL_SLOT, RESULT_SLOT, false)
|
||||
: (((index >= INV_SLOT_START) && (index < INV_SLOT_END))
|
||||
? !this.moveItemStackTo(slotStack, USE_ROW_SLOT_START, USE_ROW_SLOT_END, false)
|
||||
: ((index >= USE_ROW_SLOT_START) && (index < USE_ROW_SLOT_END) && !this.moveItemStackTo(
|
||||
slotStack,
|
||||
INV_SLOT_START,
|
||||
INV_SLOT_END,
|
||||
false
|
||||
)))))) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ import net.fabricmc.api.EnvType;
|
|||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EndStoneSmelterScreen extends AbstractContainerScreen<EndStoneSmelterScreenHandler> implements RecipeUpdateListener {
|
||||
public class EndStoneSmelterScreen extends AbstractContainerScreen<EndStoneSmelterMenu> implements RecipeUpdateListener {
|
||||
|
||||
private final static ResourceLocation RECIPE_BUTTON_TEXTURE = new ResourceLocation("textures/gui/recipe_button.png");
|
||||
private final static ResourceLocation BACKGROUND_TEXTURE = BetterEnd.makeID("textures/gui/smelter_gui.png");
|
||||
|
@ -26,7 +26,7 @@ public class EndStoneSmelterScreen extends AbstractContainerScreen<EndStoneSmelt
|
|||
public final EndStoneSmelterRecipeBookScreen recipeBook;
|
||||
private boolean narrow;
|
||||
|
||||
public EndStoneSmelterScreen(EndStoneSmelterScreenHandler handler, Inventory inventory, Component title) {
|
||||
public EndStoneSmelterScreen(EndStoneSmelterMenu handler, Inventory inventory, Component title) {
|
||||
super(handler, inventory, title);
|
||||
recipeBook = new EndStoneSmelterRecipeBookScreen();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.betterx.betterend.client.gui.slot;
|
||||
|
||||
import org.betterx.betterend.client.gui.EndStoneSmelterScreenHandler;
|
||||
import org.betterx.betterend.client.gui.EndStoneSmelterMenu;
|
||||
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.inventory.FurnaceFuelSlot;
|
||||
|
@ -9,9 +9,9 @@ import net.minecraft.world.item.ItemStack;
|
|||
|
||||
public class SmelterFuelSlot extends Slot {
|
||||
|
||||
private final EndStoneSmelterScreenHandler handler;
|
||||
private final EndStoneSmelterMenu handler;
|
||||
|
||||
public SmelterFuelSlot(EndStoneSmelterScreenHandler handler, Container inventory, int index, int x, int y) {
|
||||
public SmelterFuelSlot(EndStoneSmelterMenu handler, Container inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue