Fix shift-click bypass of slot filters + Remade ChargeBench and ChunkLoader with ContainerBuilder
This commit is contained in:
parent
b70d9b41c6
commit
19cdb5b4eb
11 changed files with 58 additions and 94 deletions
|
@ -98,10 +98,11 @@ public class GuiHandler implements IGuiHandler {
|
|||
} else if (ID == matterfabID) {
|
||||
return new ContainerMatterFabricator((TileMatterFabricator) world.getTileEntity(new BlockPos(x, y, z)),
|
||||
player);
|
||||
} else if (ID == chunkloaderID) {
|
||||
return new ContainerChunkloader((TileChunkLoader) world.getTileEntity(new BlockPos(x, y, z)), player);
|
||||
} else if (ID == assemblingmachineID) {
|
||||
container = new ContainerAssemblingMachine(player, (TileAssemblingMachine) world.getTileEntity(new BlockPos(x, y, z)));
|
||||
} else if (ID == GuiHandler.chunkloaderID) {
|
||||
return new ContainerBuilder().player(player.inventory).inventory().hotbar().addInventory()
|
||||
.create();
|
||||
} else if (ID == dieselGeneratorID) {
|
||||
return new ContainerDieselGenerator((TileDieselGenerator) world.getTileEntity(new BlockPos(x, y, z)),
|
||||
player);
|
||||
|
@ -126,11 +127,14 @@ public class GuiHandler implements IGuiHandler {
|
|||
return new ContainerLESU((TileLesu) world.getTileEntity(new BlockPos(x, y, z)), player);
|
||||
} else if (ID == idsuID) {
|
||||
return new ContainerIDSU((TileIDSU) world.getTileEntity(new BlockPos(x, y, z)), player);
|
||||
} else if (ID == chargeBench) {
|
||||
return new ContainerChargeBench((TileChargeBench) world.getTileEntity(new BlockPos(x, y, z)), player);
|
||||
} else if (ID == fusionID) {
|
||||
return new ContainerFusionReactor((TileEntityFusionController) world.getTileEntity(new BlockPos(x, y, z)),
|
||||
player);
|
||||
player);
|
||||
} else if (ID == GuiHandler.chargeBench) {
|
||||
return new ContainerBuilder().player(player.inventory).inventory().hotbar().addInventory()
|
||||
.tile((IInventory) world.getTileEntity(new BlockPos(x, y, z)))
|
||||
.energy(0, 62, 21).energy(1, 80, 21).energy(2, 98, 21).energy(3, 62, 39).energy(4, 80, 39)
|
||||
.energy(5, 98, 39).addInventory().create();
|
||||
} else if (ID == vacuumFreezerID) {
|
||||
return new ContainerVacuumFreezer((TileVacuumFreezer) world.getTileEntity(new BlockPos(x, y, z)), player);
|
||||
} else if (ID == grinderID) {
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
package techreborn.client.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import reborncore.client.gui.slots.BaseSlot;
|
||||
import reborncore.common.container.RebornContainer;
|
||||
import techreborn.tiles.TileChargeBench;
|
||||
|
||||
//import reborncore.client.gui.slots.BaseSlot;
|
||||
|
||||
public class ContainerChargeBench extends RebornContainer {
|
||||
|
||||
public int tickTime;
|
||||
EntityPlayer player;
|
||||
TileChargeBench tile;
|
||||
|
||||
public ContainerChargeBench(TileChargeBench tileChargeBench, EntityPlayer player) {
|
||||
tile = tileChargeBench;
|
||||
this.player = player;
|
||||
|
||||
this.addSlotToContainer(new BaseSlot(tileChargeBench.inventory, 0, 62, 21));
|
||||
this.addSlotToContainer(new BaseSlot(tileChargeBench.inventory, 1, 80, 21));
|
||||
this.addSlotToContainer(new BaseSlot(tileChargeBench.inventory, 2, 98, 21));
|
||||
this.addSlotToContainer(new BaseSlot(tileChargeBench.inventory, 3, 62, 39));
|
||||
this.addSlotToContainer(new BaseSlot(tileChargeBench.inventory, 4, 80, 39));
|
||||
this.addSlotToContainer(new BaseSlot(tileChargeBench.inventory, 5, 98, 39));
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
this.addSlotToContainer(new BaseSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 9; ++i) {
|
||||
this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package techreborn.client.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import reborncore.client.gui.slots.BaseSlot;
|
||||
import reborncore.common.container.RebornContainer;
|
||||
import techreborn.tiles.TileChunkLoader;
|
||||
|
||||
public class ContainerChunkloader extends RebornContainer {
|
||||
|
||||
EntityPlayer player;
|
||||
|
||||
public ContainerChunkloader(TileChunkLoader tilechunkloader, EntityPlayer player) {
|
||||
this.player = player;
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
this.addSlotToContainer(new BaseSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 9; ++i) {
|
||||
this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 142));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer p_75145_1_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -104,7 +104,7 @@ final class BuiltContainer extends Container {
|
|||
for (int slotIndex = start; stackToShift.getCount() > 0 && slotIndex < end; slotIndex++) {
|
||||
final Slot slot = this.inventorySlots.get(slotIndex);
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
if (stackInSlot == ItemStack.EMPTY) {
|
||||
if (stackInSlot == ItemStack.EMPTY && slot.isItemValid(stackToShift)) {
|
||||
final int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
stackInSlot = stackToShift.copy();
|
||||
stackInSlot.setCount(Math.min(stackToShift.getCount(), max));
|
||||
|
|
|
@ -7,6 +7,8 @@ import net.minecraft.inventory.EntityEquipmentSlot;
|
|||
|
||||
import reborncore.client.gui.slots.BaseSlot;
|
||||
|
||||
import techreborn.client.container.builder.slot.ArmorSlot;
|
||||
|
||||
public final class ContainerPlayerInventoryBuilder {
|
||||
|
||||
private final InventoryPlayer player;
|
||||
|
|
|
@ -8,6 +8,8 @@ import reborncore.client.gui.slots.BaseSlot;
|
|||
import reborncore.client.gui.slots.SlotFake;
|
||||
import reborncore.client.gui.slots.SlotOutput;
|
||||
|
||||
import techreborn.client.container.builder.slot.EnergyChargeSlot;
|
||||
|
||||
public class ContainerTileInventoryBuilder {
|
||||
|
||||
private final IInventory tile;
|
||||
|
@ -35,6 +37,11 @@ public class ContainerTileInventoryBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ContainerTileInventoryBuilder energy(final int index, final int x, final int y) {
|
||||
this.parent.slots.add(new EnergyChargeSlot(this.tile, index, x, y));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContainerBuilder addInventory() {
|
||||
this.parent.tileInventoryRanges.add(Range.between(this.rangeStart, this.parent.slots.size() - 1));
|
||||
return this.parent;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package techreborn.client.container.builder;
|
||||
package techreborn.client.container.builder.slot;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
|
@ -16,7 +16,7 @@ public class ArmorSlot extends FilteredSlot {
|
|||
this.setFilter(stack -> stack != null && stack.getItem().isValidArmor(stack, armorType, inventory.player));
|
||||
|
||||
this.setBackgroundLocation(
|
||||
new ResourceLocation(ModInfo.MOD_ID, "textures/gui/armor_" + armorType.getName() + ".png"));
|
||||
new ResourceLocation(ModInfo.MOD_ID, "textures/gui/slots/armor_" + armorType.getName() + ".png"));
|
||||
}
|
||||
|
||||
@Override
|
|
@ -0,0 +1,26 @@
|
|||
package techreborn.client.container.builder.slot;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
|
||||
import reborncore.api.power.IEnergyInterfaceItem;
|
||||
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
public class EnergyChargeSlot extends FilteredSlot {
|
||||
|
||||
private static final ResourceLocation TEX = new ResourceLocation(ModInfo.MOD_ID,
|
||||
"textures/gui/slots/energy_charge.png");
|
||||
|
||||
@SuppressWarnings("null")
|
||||
public EnergyChargeSlot(final IInventory inventory, final int index, final int xPosition, final int yPosition) {
|
||||
super(inventory, index, xPosition, yPosition);
|
||||
|
||||
this.setFilter(stack -> stack.hasCapability(CapabilityEnergy.ENERGY, EnumFacing.UP)
|
||||
|| stack.getItem() instanceof IEnergyInterfaceItem);
|
||||
this.setBackgroundLocation(EnergyChargeSlot.TEX);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package techreborn.client.container.builder;
|
||||
package techreborn.client.container.builder.slot;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
|
@ -5,7 +5,8 @@ import net.minecraft.client.renderer.GlStateManager;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import techreborn.client.container.ContainerChargeBench;
|
||||
|
||||
import techreborn.client.container.builder.ContainerBuilder;
|
||||
import techreborn.tiles.TileChargeBench;
|
||||
|
||||
public class GuiChargeBench extends GuiContainer {
|
||||
|
@ -14,8 +15,10 @@ public class GuiChargeBench extends GuiContainer {
|
|||
|
||||
TileChargeBench chargebench;
|
||||
|
||||
public GuiChargeBench(EntityPlayer player, TileChargeBench tile) {
|
||||
super(new ContainerChargeBench(tile, player));
|
||||
public GuiChargeBench(final EntityPlayer player, final TileChargeBench tile) {
|
||||
super(new ContainerBuilder().player(player.inventory).inventory().hotbar().addInventory().tile(tile)
|
||||
.energy(0, 62, 21).energy(1, 80, 21).energy(2, 98, 21).energy(3, 62, 39).energy(4, 80, 39)
|
||||
.energy(5, 98, 39).addInventory().create());
|
||||
this.xSize = 176;
|
||||
this.ySize = 167;
|
||||
chargebench = tile;
|
||||
|
|
|
@ -6,7 +6,8 @@ import net.minecraft.client.renderer.GlStateManager;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import techreborn.client.container.ContainerChunkloader;
|
||||
|
||||
import techreborn.client.container.builder.ContainerBuilder;
|
||||
import techreborn.tiles.TileChunkLoader;
|
||||
|
||||
public class GuiChunkLoader extends GuiContainer {
|
||||
|
@ -19,8 +20,8 @@ public class GuiChunkLoader extends GuiContainer {
|
|||
private GuiButton minusOneButton;
|
||||
private GuiButton minusTenButton;
|
||||
|
||||
public GuiChunkLoader(EntityPlayer player, TileChunkLoader tilechunkloader) {
|
||||
super(new ContainerChunkloader(tilechunkloader, player));
|
||||
public GuiChunkLoader(final EntityPlayer player, final TileChunkLoader tilechunkloader) {
|
||||
super(new ContainerBuilder().player(player.inventory).inventory().hotbar().addInventory().create());
|
||||
this.xSize = 176;
|
||||
this.ySize = 167;
|
||||
chunkloader = tilechunkloader;
|
||||
|
|
Loading…
Reference in a new issue