Skip to content

Commit

Permalink
Adding rotate Inventory Relay (#15)
Browse files Browse the repository at this point in the history
* Adding rotate InventoryRelay

* Change modId & fix return method

* Fix return method wrenchCanSetFacing

* Apply spotless

* Update BuildScript

---------

Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
evgengoldwar and Dream-Master authored Jul 18, 2024
1 parent 72f2256 commit 8dd76ac
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
43 changes: 42 additions & 1 deletion src/main/java/vswe/stevesfactory/blocks/TileEntityRelay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -781,4 +784,42 @@ public void readContentFromNBT(NBTTagCompound nbtTagCompound) {
protected EnumSet<ClusterMethodRegistration> 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;
}
}

0 comments on commit 8dd76ac

Please sign in to comment.