Refactor and extend Stalinium Press functionality
This commit is contained in:
+28
-19
@@ -17,6 +17,7 @@ import net.minecraft.world.entity.player.Player;
|
|||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.inventory.ContainerData;
|
import net.minecraft.world.inventory.ContainerData;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
@@ -26,7 +27,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import javax.swing.plaf.basic.BasicComboBoxUI;
|
import javax.swing.plaf.basic.BasicComboBoxUI;
|
||||||
|
|
||||||
public class StaliniumPressBlockEntity extends BlockEntity implements MenuProvider {
|
public class StaliniumPressBlockEntity extends BlockEntity implements MenuProvider {
|
||||||
public final ItemStackHandler itemHandler = new ItemStackHandler(2) {
|
public final ItemStackHandler itemHandler = new ItemStackHandler(4) {
|
||||||
@Override
|
@Override
|
||||||
protected void onContentsChanged(int slot) {
|
protected void onContentsChanged(int slot) {
|
||||||
setChanged();
|
setChanged();
|
||||||
@@ -36,8 +37,10 @@ public class StaliniumPressBlockEntity extends BlockEntity implements MenuProvid
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final int INPUT_SLOT = 0;
|
public static final int INPUT_SLOT = 0;
|
||||||
private static final int OUTPUT_SLOT = 1;
|
public static final int REDSTONE_FUEL_SLOT = 1;
|
||||||
|
public static final int LAVA_FUEL_SLOT = 2;
|
||||||
|
public static final int OUTPUT_SLOT = 3;
|
||||||
|
|
||||||
protected final ContainerData data;
|
protected final ContainerData data;
|
||||||
private int progress = 0;
|
private int progress = 0;
|
||||||
@@ -110,11 +113,10 @@ public class StaliniumPressBlockEntity extends BlockEntity implements MenuProvid
|
|||||||
maxProgress = pTag.getInt("growth_chamber.max_progress");
|
maxProgress = pTag.getInt("growth_chamber.max_progress");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick(Level level, BlockPos blockPos, BlockState blockState) {
|
public void tick(Level level, BlockPos pos, BlockState state) {
|
||||||
if (hasRecipe()) {
|
if (hasRecipe()) {
|
||||||
increaseCraftingProgress();
|
increaseCraftingProgress();
|
||||||
setChanged(level, blockPos, blockState);
|
setChanged(level, pos, state);
|
||||||
|
|
||||||
if (hasCraftingFinished()) {
|
if (hasCraftingFinished()) {
|
||||||
craftItem();
|
craftItem();
|
||||||
resetProgress();
|
resetProgress();
|
||||||
@@ -125,11 +127,18 @@ public class StaliniumPressBlockEntity extends BlockEntity implements MenuProvid
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void craftItem() {
|
private void craftItem() {
|
||||||
if (itemHandler.getStackInSlot(INPUT_SLOT).getCount() < 9) return;
|
|
||||||
ItemStack output = new ItemStack(ModItems.STALINIUM_INGOT.get(), 1);
|
|
||||||
itemHandler.extractItem(INPUT_SLOT, 9, false);
|
itemHandler.extractItem(INPUT_SLOT, 9, false);
|
||||||
itemHandler.setStackInSlot(OUTPUT_SLOT, new ItemStack(output.getItem(),
|
itemHandler.extractItem(REDSTONE_FUEL_SLOT, 1, false);
|
||||||
itemHandler.getStackInSlot(OUTPUT_SLOT).getCount() + output.getCount()));
|
itemHandler.extractItem(LAVA_FUEL_SLOT, 1, false);
|
||||||
|
itemHandler.setStackInSlot(LAVA_FUEL_SLOT, new ItemStack(Items.BUCKET, 1));
|
||||||
|
ItemStack out = new ItemStack(ModItems.STALINIUM_INGOT.get(), 1);
|
||||||
|
itemHandler.setStackInSlot(
|
||||||
|
OUTPUT_SLOT,
|
||||||
|
new ItemStack(
|
||||||
|
out.getItem(),
|
||||||
|
itemHandler.getStackInSlot(OUTPUT_SLOT).getCount() + 1
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetProgress() {
|
private void resetProgress() {
|
||||||
@@ -146,15 +155,15 @@ public class StaliniumPressBlockEntity extends BlockEntity implements MenuProvid
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasRecipe() {
|
private boolean hasRecipe() {
|
||||||
if (itemHandler.getStackInSlot(INPUT_SLOT).getCount() < 9) {
|
ItemStack in = itemHandler.getStackInSlot(INPUT_SLOT);
|
||||||
return false;
|
ItemStack red = itemHandler.getStackInSlot(REDSTONE_FUEL_SLOT);
|
||||||
}
|
ItemStack lava = itemHandler.getStackInSlot(LAVA_FUEL_SLOT);
|
||||||
if (itemHandler.getStackInSlot(INPUT_SLOT).getItem() != ModItems.STALINIUM_NUGGET.get()) {
|
|
||||||
return false;
|
if (in.getItem() != ModItems.STALINIUM_NUGGET.get() || in.getCount() < 9) return false;
|
||||||
}
|
if (red.getItem() != Items.REDSTONE_BLOCK || red.getCount() < 1) return false;
|
||||||
ItemStack result = new ItemStack(ModItems.STALINIUM_INGOT.get(), 1);
|
if (lava.getItem()!= Items.LAVA_BUCKET || lava.getCount()< 1) return false;
|
||||||
return canInsertItemIntoOutputSlot(result) &&
|
ItemStack out = new ItemStack(ModItems.STALINIUM_INGOT.get(), 1);
|
||||||
canInsertAmountIntoOutputSlot(result.getCount());
|
return canInsertItemIntoOutputSlot(out) && canInsertAmountIntoOutputSlot(out.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canInsertItemIntoOutputSlot(ItemStack output) {
|
private boolean canInsertItemIntoOutputSlot(ItemStack output) {
|
||||||
|
|||||||
@@ -13,27 +13,34 @@ import net.minecraft.world.level.Level;
|
|||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.neoforged.neoforge.items.SlotItemHandler;
|
import net.neoforged.neoforge.items.SlotItemHandler;
|
||||||
|
|
||||||
|
import static net.krituximon.stalinium.block.entity.StaliniumPressBlockEntity.*;
|
||||||
|
|
||||||
public class StaliniumPressMenu extends AbstractContainerMenu {
|
public class StaliniumPressMenu extends AbstractContainerMenu {
|
||||||
public final StaliniumPressBlockEntity blockEntity;
|
public final StaliniumPressBlockEntity blockEntity;
|
||||||
private final Level level;
|
private final Level level;
|
||||||
private final ContainerData data;
|
private final ContainerData data;
|
||||||
|
|
||||||
public StaliniumPressMenu(int pContainerId, Inventory inv, FriendlyByteBuf extraData) {
|
public StaliniumPressMenu(int pContainerId, Inventory inv, FriendlyByteBuf extraData) {
|
||||||
this(pContainerId, inv, inv.player.level().getBlockEntity(extraData.readBlockPos()), new SimpleContainerData(2));
|
this(pContainerId, inv, (StaliniumPressBlockEntity) inv.player.level().getBlockEntity(extraData.readBlockPos()), new SimpleContainerData(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public StaliniumPressMenu(int pContainerId, Inventory inv, BlockEntity entity, ContainerData data) {
|
public StaliniumPressMenu(int id, Inventory inv, StaliniumPressBlockEntity be, ContainerData data) {
|
||||||
super(ModMenuTypes.STALINIUM_PRESS_MENU.get(), pContainerId);
|
super(ModMenuTypes.STALINIUM_PRESS_MENU.get(), id);
|
||||||
this.blockEntity = ((StaliniumPressBlockEntity) entity);
|
this.blockEntity = be;
|
||||||
this.level = inv.player.level();
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
this.level = inv.player.level();
|
||||||
|
|
||||||
|
// INPUT
|
||||||
|
this.addSlot(new SlotItemHandler(be.itemHandler, INPUT_SLOT, 54, 34));
|
||||||
|
// REDSTONE FUEL
|
||||||
|
this.addSlot(new SlotItemHandler(be.itemHandler, REDSTONE_FUEL_SLOT,54, 14));
|
||||||
|
// LAVA FUEL
|
||||||
|
this.addSlot(new SlotItemHandler(be.itemHandler, LAVA_FUEL_SLOT, 54, 54));
|
||||||
|
// OUTPUT
|
||||||
|
this.addSlot(new SlotItemHandler(be.itemHandler, OUTPUT_SLOT, 104, 34));
|
||||||
|
|
||||||
addPlayerInventory(inv);
|
addPlayerInventory(inv);
|
||||||
addPlayerHotbar(inv);
|
addPlayerHotbar(inv);
|
||||||
|
|
||||||
this.addSlot(new SlotItemHandler(blockEntity.itemHandler, 0, 54, 34));
|
|
||||||
this.addSlot(new SlotItemHandler(blockEntity.itemHandler, 1, 104, 34));
|
|
||||||
|
|
||||||
addDataSlots(data);
|
addDataSlots(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 1.2 KiB |
Reference in New Issue
Block a user