From 8dd76acf04802efcaf24548927c51f6fa858712f Mon Sep 17 00:00:00 2001 From: evgengoldwar <69961523+evgengoldwar@users.noreply.github.com> Date: Thu, 18 Jul 2024 20:12:31 +0400 Subject: [PATCH] Adding rotate Inventory Relay (#15) * Adding rotate InventoryRelay * Change modId & fix return method * Fix return method wrenchCanSetFacing * Apply spotless * Update BuildScript --------- Co-authored-by: Martin Robertz --- dependencies.gradle | 1 + .../blocks/BlockCableDirectionAdvanced.java | 6 +-- .../blocks/TileEntityClusterElement.java | 4 +- .../stevesfactory/blocks/TileEntityRelay.java | 43 ++++++++++++++++++- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 0783c522d..6792401d8 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,4 +2,5 @@ dependencies { compileOnly('com.github.GTNewHorizons:waila:1.8.1:api') + compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev') } diff --git a/src/main/java/vswe/stevesfactory/blocks/BlockCableDirectionAdvanced.java b/src/main/java/vswe/stevesfactory/blocks/BlockCableDirectionAdvanced.java index 3350410eb..a0430d0e1 100644 --- a/src/main/java/vswe/stevesfactory/blocks/BlockCableDirectionAdvanced.java +++ b/src/main/java/vswe/stevesfactory/blocks/BlockCableDirectionAdvanced.java @@ -96,15 +96,15 @@ public boolean isAdvanced(int meta) { return (meta & 8) != 0; } - public int getSideMeta(int meta) { + public static int getSideMeta(int meta) { return meta & 7; } - private int addAdvancedMeta(int meta, int advancedMeta) { + public static int addAdvancedMeta(int meta, int advancedMeta) { return meta | (advancedMeta & 8); } - private int getAdvancedMeta(int meta) { + public static int getAdvancedMeta(int meta) { return addAdvancedMeta(0, meta); } diff --git a/src/main/java/vswe/stevesfactory/blocks/TileEntityClusterElement.java b/src/main/java/vswe/stevesfactory/blocks/TileEntityClusterElement.java index 1e5f55953..a36bb6a83 100644 --- a/src/main/java/vswe/stevesfactory/blocks/TileEntityClusterElement.java +++ b/src/main/java/vswe/stevesfactory/blocks/TileEntityClusterElement.java @@ -10,7 +10,7 @@ public abstract class TileEntityClusterElement extends TileEntity { private ClusterRegistry registryElement; private boolean isPartOfCluster; - private int meta; + public int meta; protected TileEntityClusterElement() { registryElement = ClusterRegistry.get(this); @@ -48,12 +48,14 @@ public void setMetaData(int meta) { @Override public final void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); + tagCompound.setInteger("MetaData", this.meta); writeContentToNBT(tagCompound); } @Override public final void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); + this.meta = tagCompound.getInteger("MetaData"); readContentFromNBT(tagCompound); } diff --git a/src/main/java/vswe/stevesfactory/blocks/TileEntityRelay.java b/src/main/java/vswe/stevesfactory/blocks/TileEntityRelay.java index b22bc2fa2..aaf7329eb 100644 --- a/src/main/java/vswe/stevesfactory/blocks/TileEntityRelay.java +++ b/src/main/java/vswe/stevesfactory/blocks/TileEntityRelay.java @@ -25,8 +25,10 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; +import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import ic2.api.tile.IWrenchable; import vswe.stevesfactory.interfaces.ContainerRelay; import vswe.stevesfactory.interfaces.GuiRelay; import vswe.stevesfactory.network.DataBitHelper; @@ -38,8 +40,9 @@ import vswe.stevesfactory.wrappers.InventoryWrapperHorse; import vswe.stevesfactory.wrappers.InventoryWrapperPlayer; +@Optional.Interface(iface = "ic2.api.tile.IWrenchable", modid = "IC2") public class TileEntityRelay extends TileEntityClusterElement - implements IInventory, ISidedInventory, IFluidHandler, ITileEntityInterface { + implements IInventory, ISidedInventory, IFluidHandler, ITileEntityInterface, IWrenchable { private static final int MAX_CHAIN_LENGTH = 512; private int[] cachedAllSlots; @@ -781,4 +784,42 @@ public void readContentFromNBT(NBTTagCompound nbtTagCompound) { protected EnumSet getRegistrations() { return EnumSet.of(ClusterMethodRegistration.ON_BLOCK_PLACED_BY, ClusterMethodRegistration.ON_BLOCK_ACTIVATED); } + + @Optional.Method(modid = "IC2") + @Override + public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int facing) { + return this.getFacing() != facing; + } + + @Optional.Method(modid = "IC2") + @Override + public short getFacing() { + return (short) BlockCableDirectionAdvanced.getSideMeta(this.getBlockMetadata()); + } + + @Optional.Method(modid = "IC2") + @Override + public void setFacing(short facing) { + int advancedMeta = BlockCableDirectionAdvanced.getAdvancedMeta(this.getBlockMetadata()); + this.meta = BlockCableDirectionAdvanced.addAdvancedMeta(facing, advancedMeta); + this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, this.meta, 3); + } + + @Optional.Method(modid = "IC2") + @Override + public boolean wrenchCanRemove(EntityPlayer entityPlayer) { + return false; + } + + @Optional.Method(modid = "IC2") + @Override + public float getWrenchDropRate() { + return 0; + } + + @Optional.Method(modid = "IC2") + @Override + public ItemStack getWrenchDrop(EntityPlayer entityPlayer) { + return null; + } }