Skip to content

Commit

Permalink
Merge pull request #143 from Thorfusion/Personal-Dupe
Browse files Browse the repository at this point in the history
Patch Personal Chest dupe
  • Loading branch information
maggi373 committed Oct 15, 2023
2 parents 2df7cd9 + 12d5ad3 commit 6127ae6
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 62 deletions.
7 changes: 4 additions & 3 deletions src/main/java/mekanism/api/MekanismConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static class general

}
public static class mekce {
public static boolean enableBoPProgression = true;
public static boolean enableBoPProgression;
public static boolean EnableQuartzCompat;
public static boolean EnableDiamondCompat;
public static boolean EnablePoorOresCompat;
Expand All @@ -82,8 +82,9 @@ public static class mekce {
public static int IC2SourceTier;
public static int digitalMinerMaxRadius;
public static boolean enableSingleUseCardboxes;
public static boolean accurateHeavyWaterCapture = true;
public static int heavyWaterChance = 4;
public static boolean enablePersonalChestPocketAccess;
public static boolean accurateHeavyWaterCapture;
public static int heavyWaterChance;
}


Expand Down
30 changes: 17 additions & 13 deletions src/main/java/mekanism/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@

import java.io.File;

import static mekanism.api.MekanismConfig.mekce.enablePersonalChestPocketAccess;

/**
* Client proxy for the Mekanism mod.
* @author AidanBrady
Expand Down Expand Up @@ -117,13 +119,15 @@ public void openPersonalChest(EntityPlayer entityplayer, int id, int windowId, b
FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPersonalChest(entityplayer.inventory, tileEntity));
entityplayer.openContainer.windowId = windowId;
}
else {
else if (enablePersonalChestPocketAccess)
{
ItemStack stack = entityplayer.getCurrentEquippedItem();
int hotbarSlot = entityplayer.inventory.currentItem;

if(MachineType.get(stack) == MachineType.PERSONAL_CHEST)
{
InventoryPersonalChest inventory = new InventoryPersonalChest(entityplayer);
FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPersonalChest(entityplayer.inventory, inventory));
FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPersonalChest(entityplayer.inventory, inventory, hotbarSlot));
entityplayer.openContainer.windowId = windowId;
}
}
Expand Down Expand Up @@ -386,29 +390,29 @@ public GuiScreen getClientGui(int ID, EntityPlayer player, World world, int x, i
case 58:
return new GuiFuelwoodHeater(player.inventory, (TileEntityFuelwoodHeater)tileEntity);
}

return null;
}

@Override
public void handleTeleporterUpdate(PortableTeleporterMessage message)
{
GuiScreen screen = Minecraft.getMinecraft().currentScreen;

if(screen instanceof GuiTeleporter && ((GuiTeleporter)screen).itemStack != null)
{
GuiTeleporter teleporter = (GuiTeleporter)screen;

teleporter.clientStatus = message.status;
teleporter.clientFreq = message.frequency;
teleporter.clientPublicCache = message.publicCache;
teleporter.clientPrivateCache = message.privateCache;
teleporter.clientProtectedCache = message.protectedCache;

teleporter.updateButtons();
}
}

@Override
public void addHitEffects(Coord4D coord, MovingObjectPosition mop)
{
Expand All @@ -417,7 +421,7 @@ public void addHitEffects(Coord4D coord, MovingObjectPosition mop)
Minecraft.getMinecraft().effectRenderer.addBlockHitEffects(coord.xCoord, coord.yCoord, coord.zCoord, mop);
}
}

@Override
public void doGenericSparkle(TileEntity tileEntity, INodeChecker checker)
{
Expand All @@ -432,7 +436,7 @@ public void doMultiblockSparkle(final TileEntityMultiblock<?> tileEntity)
@Override
public boolean isNode(TileEntity tile)
{
return MultiblockManager.areEqual(tile, tileEntity);
return MultiblockManager.areEqual(tile, tileEntity);
}
}).run();
}
Expand All @@ -442,11 +446,11 @@ public boolean isNode(TileEntity tile)
public void loadUtilities()
{
super.loadUtilities();

FMLCommonHandler.instance().bus().register(new ClientPlayerTracker());
FMLCommonHandler.instance().bus().register(new ClientTickHandler());
FMLCommonHandler.instance().bus().register(new RenderTickHandler());

new MekanismKeyHandler();

HolidayManager.init();
Expand Down Expand Up @@ -522,7 +526,7 @@ public void renderLaser(World world, Pos3D from, Pos3D to, ForgeDirection direct
{
Minecraft.getMinecraft().effectRenderer.addEffect(new EntityLaser(world, from, to, direction, energy));
}

@Override
public FontRenderer getFontRenderer()
{
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mekanism/client/gui/GuiPersonalChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class GuiPersonalChest extends GuiMekanism

public GuiPersonalChest(InventoryPlayer inventory, TileEntityPersonalChest tentity)
{
super(tentity, new ContainerPersonalChest(inventory, tentity, null, true));
super(tentity, new ContainerPersonalChest(inventory, tentity, null, true, -1));

xSize+=26;
ySize+=64;
Expand All @@ -28,9 +28,9 @@ public GuiPersonalChest(InventoryPlayer inventory, TileEntityPersonalChest tenti
guiElements.add(new GuiSecurityTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiPersonalChest.png")));
}

public GuiPersonalChest(InventoryPlayer inventory, IInventory inv)
public GuiPersonalChest(InventoryPlayer inventory, IInventory inv, int hotbarSlot)
{
super(new ContainerPersonalChest(inventory, null, inv, false));
super(new ContainerPersonalChest(inventory, null, inv, false, hotbarSlot));

xSize+=26;
ySize+=64;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mekanism/common/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void loadConfiguration()
mekce.enableSiliconCompat = Mekanism.configurationce.get("mekce", "EnableSiliconCompat", true, "When a mod that adds silicon (galacticraft, enderio and projectred) is detected, recipe for control circuit is changed from using iron to silicon in the metalurgic infuser").getBoolean();
mekce.digitalMinerMaxRadius = Mekanism.configurationce.get("mekce", "DigitalMinerMaxRadius", 32, "Select range from 1 to 64, we do not recommend going over 32", 1, 64).getInt();
mekce.enableSingleUseCardboxes = Mekanism.configurationce.get("mekce", "EnableSingleUseCardboxes", true, "This allows to force single use on cardboxes or not").getBoolean();

mekce.enablePersonalChestPocketAccess = Mekanism.configurationce.get("mekce", "enablePersonalChestPocketAccess", true, "This allows opening Personal Chests from your inventory without having to place them").getBoolean();

mekce.IC2SinkTier = Mekanism.configurationce.get("mekce", "IC2SinkTier", 4, "Tier level for machines, we recommend setting it to tier 2 for ic2 classic", 1, 4).getInt();
mekce.IC2SourceTier = Mekanism.configurationce.get("mekce", "IC2SourceTier", 4, "Tier level for generators, we recommend setting it to tier 2 for ic2 classic", 1, 4).getInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import invtweaks.api.container.ChestContainer;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.inventory.InventoryPersonalChest;
import mekanism.common.inventory.slot.SlotPersonalChest;
import mekanism.common.tile.TileEntityPersonalChest;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -17,12 +18,14 @@ public class ContainerPersonalChest extends Container
private TileEntityPersonalChest tileEntity;
private IInventory itemInventory;
private boolean isBlock;
private int slot;

public ContainerPersonalChest(InventoryPlayer inventory, TileEntityPersonalChest tentity, IInventory inv, boolean b)
public ContainerPersonalChest(InventoryPlayer inventory, TileEntityPersonalChest tentity, IInventory inv, boolean b, int i)
{
tileEntity = tentity;
itemInventory = inv;
isBlock = b;
slot = i;

if(isBlock)
{
Expand Down Expand Up @@ -56,7 +59,6 @@ public ContainerPersonalChest(InventoryPlayer inventory, TileEntityPersonalChest
addSlotToContainer(new SlotPersonalChest(inventory, slotX, 8 + slotX * 18, 206));
}
}

public IInventory getInv()
{
if(isBlock)
Expand Down Expand Up @@ -86,12 +88,18 @@ public void onContainerClosed(EntityPlayer entityplayer)
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
if(isBlock)
{
if(isBlock) {
return tileEntity.isUseableByPlayer(entityplayer);
}
} else {
if (slot == entityplayer.inventory.currentItem && itemInventory instanceof InventoryPersonalChest) {
ItemStack currentHeldItem = entityplayer.getHeldItem();
ItemStack stack = ((InventoryPersonalChest) itemInventory).getStack();

return true;
if (stack != null)
return stack == currentHeldItem;
}
}
return false;
}

@Override
Expand Down Expand Up @@ -143,7 +151,7 @@ public ItemStack slotClick(int slotNumber, int destSlot, int modifier, EntityPla
{
ItemStack itemStack = player.inventory.getStackInSlot(destSlot);

if(MachineType.get(itemStack) == MachineType.PERSONAL_CHEST)
if(itemStack != null && MachineType.get(itemStack) == MachineType.PERSONAL_CHEST)
{
return null;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/mekanism/common/network/PacketConfigSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public void toBytes(ByteBuf dataStream)
dataStream.writeInt(mekce.IC2SourceTier);
dataStream.writeInt(mekce.digitalMinerMaxRadius);
dataStream.writeBoolean(mekce.enableSingleUseCardboxes);

dataStream.writeBoolean(mekce.enablePersonalChestPocketAccess);

for(MachineType type : MachineType.getValidMachines())
{
dataStream.writeBoolean(machines.isEnabled(type.name));
Expand Down Expand Up @@ -281,7 +282,8 @@ public void fromBytes(ByteBuf dataStream)
mekce.IC2SourceTier = dataStream.readInt();
mekce.digitalMinerMaxRadius = dataStream.readInt();
mekce.enableSingleUseCardboxes = dataStream.readBoolean();

mekce.enablePersonalChestPocketAccess = dataStream.readBoolean();

for(MachineType type : MachineType.getValidMachines())
{
machines.setEntry(type.name, dataStream.readBoolean());
Expand Down
61 changes: 32 additions & 29 deletions src/main/java/mekanism/common/network/PacketPersonalChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
public class PacketPersonalChest implements IMessageHandler<PersonalChestMessage, IMessage>
{
@Override
public IMessage onMessage(PersonalChestMessage message, MessageContext context)
public IMessage onMessage(PersonalChestMessage message, MessageContext context)
{
EntityPlayer player = PacketHandler.getPlayer(context);

if(message.packetType == PersonalChestPacketType.SERVER_OPEN)
{
try {
Expand Down Expand Up @@ -58,94 +58,97 @@ else if(message.packetType == PersonalChestPacketType.CLIENT_OPEN)
e.printStackTrace();
}
}

return null;
}

public static class PersonalChestMessage implements IMessage
{
public PersonalChestPacketType packetType;

public boolean isBlock;

public int guiType;
public int windowId;

public Coord4D coord4D;

public int hotbarSlot;

public PersonalChestMessage() {}

//This is a really messy implementation...
public PersonalChestMessage(PersonalChestPacketType type, boolean b1, int i1, int i2, Coord4D c1)
public PersonalChestMessage(PersonalChestPacketType type, boolean b1, int i1, int i2, Coord4D c1, int slot)
{
packetType = type;
switch(packetType)

switch (packetType)
{
case CLIENT_OPEN:
guiType = i1;
windowId = i2;
isBlock = b1;

if(isBlock)
{

if (isBlock) {
coord4D = c1;
} else {
hotbarSlot = slot;
}

break;
case SERVER_OPEN:
isBlock = b1;

if(isBlock)
{

if (isBlock) {
coord4D = c1;
} else {
hotbarSlot = slot;
}

break;
}
}

@Override
public void toBytes(ByteBuf dataStream)
{
dataStream.writeInt(packetType.ordinal());

switch(packetType)
{
case CLIENT_OPEN:
dataStream.writeInt(guiType);
dataStream.writeInt(windowId);
dataStream.writeBoolean(isBlock);

if(isBlock)
{
dataStream.writeInt(coord4D.xCoord);
dataStream.writeInt(coord4D.yCoord);
dataStream.writeInt(coord4D.zCoord);
dataStream.writeInt(coord4D.dimensionId);
}

break;
case SERVER_OPEN:
dataStream.writeBoolean(isBlock);

if(isBlock)
{
dataStream.writeInt(coord4D.xCoord);
dataStream.writeInt(coord4D.yCoord);
dataStream.writeInt(coord4D.zCoord);
dataStream.writeInt(coord4D.dimensionId);
}

break;
}
}

@Override
public void fromBytes(ByteBuf dataStream)
{
packetType = PersonalChestPacketType.values()[dataStream.readInt()];

if(packetType == PersonalChestPacketType.SERVER_OPEN)
{
isBlock = dataStream.readBoolean();
Expand All @@ -168,7 +171,7 @@ else if(packetType == PersonalChestPacketType.CLIENT_OPEN)
}
}
}

public static enum PersonalChestPacketType
{
CLIENT_OPEN,
Expand Down
Loading

0 comments on commit 6127ae6

Please sign in to comment.