From 383461d1f33245ae7b69bf1fa8c2f3d7ce78a58f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 22 Aug 2015 19:47:20 +0200 Subject: [PATCH] Generified the Phantom Connector --- .../items/ItemPhantomConnector.java | 27 +++++-------------- .../actuallyadditions/tile/IPhantomTile.java | 2 ++ .../tile/TileEntityPhantomPlacer.java | 5 ++++ .../tile/TileEntityPhantomface.java | 5 ++++ 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemPhantomConnector.java b/src/main/java/ellpeck/actuallyadditions/items/ItemPhantomConnector.java index 948b174d2..3cb8801df 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemPhantomConnector.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemPhantomConnector.java @@ -2,8 +2,7 @@ package ellpeck.actuallyadditions.items; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import ellpeck.actuallyadditions.tile.TileEntityPhantomPlacer; -import ellpeck.actuallyadditions.tile.TileEntityPhantomface; +import ellpeck.actuallyadditions.tile.IPhantomTile; import ellpeck.actuallyadditions.util.*; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; @@ -32,21 +31,10 @@ public class ItemPhantomConnector extends Item implements INameableItem{ //Passing Data to Phantoms TileEntity tile = world.getTileEntity(x, y, z); if(tile != null){ - //Passing to Face - if(tile instanceof TileEntityPhantomface){ + //Passing to Phantom + if(tile instanceof IPhantomTile){ if(this.checkHasConnection(stack, player, tile)){ - ((TileEntityPhantomface)tile).boundPosition = this.getStoredPosition(stack); - this.clearStorage(stack); - player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.connected.desc"))); - return true; - } - return false; - } - //Passing to Placer - else if(tile instanceof TileEntityPhantomPlacer){ - if(this.checkHasConnection(stack, player, tile)){ - ((TileEntityPhantomPlacer)tile).boundPosition = this.getStoredPosition(stack); - tile.markDirty(); + ((IPhantomTile)tile).setBoundPosition(this.getStoredPosition(stack)); this.clearStorage(stack); player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.connected.desc"))); return true; @@ -66,11 +54,8 @@ public class ItemPhantomConnector extends Item implements INameableItem{ return true; } else{ - if(tile instanceof TileEntityPhantomPlacer){ - ((TileEntityPhantomPlacer)tile).boundPosition = null; - } - if(tile instanceof TileEntityPhantomface){ - ((TileEntityPhantomface)tile).boundPosition = null; + if(tile instanceof IPhantomTile){ + ((IPhantomTile)tile).setBoundPosition(null); } player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.unbound.desc"))); return false; diff --git a/src/main/java/ellpeck/actuallyadditions/tile/IPhantomTile.java b/src/main/java/ellpeck/actuallyadditions/tile/IPhantomTile.java index 965d08845..bab4966f0 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/IPhantomTile.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/IPhantomTile.java @@ -28,4 +28,6 @@ public interface IPhantomTile{ * @return The range the tile currently has */ int getRange(); + + void setBoundPosition(WorldPos pos); } diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomPlacer.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomPlacer.java index 30ff2cff4..2df200907 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomPlacer.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomPlacer.java @@ -129,6 +129,11 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements return this.range; } + @Override + public void setBoundPosition(WorldPos pos){ + this.boundPosition = pos == null ? null : pos.copy(); + } + @Override public void writeToNBT(NBTTagCompound compound){ super.writeToNBT(compound); diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java index a6f3dfd30..aa2e5ae46 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java @@ -145,6 +145,11 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP return this.range; } + @Override + public void setBoundPosition(WorldPos pos){ + this.boundPosition = pos == null ? null : pos.copy(); + } + public static class TileEntityPhantomLiquiface extends TileEntityPhantomface implements IFluidHandler{ public TileEntityPhantomLiquiface(){