From 6766f8f0f890b1dcef46e11b5a65c0ae6a04b1ec Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Fri, 25 Jul 2014 20:16:00 -0500 Subject: [PATCH] Fixed #0681 - Cable Anchors Disappear when placed on Mekanism Cable --- fmp/FMPPlacementHelper.java | 233 +++++++++++++++++++++++++++++++++++ integration/modules/FMP.java | 40 +++--- 2 files changed, 253 insertions(+), 20 deletions(-) create mode 100644 fmp/FMPPlacementHelper.java diff --git a/fmp/FMPPlacementHelper.java b/fmp/FMPPlacementHelper.java new file mode 100644 index 000000000..88333544c --- /dev/null +++ b/fmp/FMPPlacementHelper.java @@ -0,0 +1,233 @@ +package appeng.fmp; + +import java.util.EnumSet; +import java.util.Set; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Vec3; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.parts.IFacadeContainer; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartHost; +import appeng.api.parts.LayerFlags; +import appeng.api.parts.SelectedPart; +import appeng.api.util.AEColor; +import appeng.api.util.DimensionalCoord; +import appeng.facade.FacadeContainer; +import appeng.util.Platform; +import codechicken.lib.vec.BlockCoord; +import codechicken.multipart.TileMultipart; + +public class FMPPlacementHelper implements IPartHost +{ + + private boolean hasPart = false; + private TileMultipart myMP; + private CableBusPart myPart; + + private CableBusPart getPart() + { + if ( myPart == null ) + myPart = (CableBusPart) PartRegistry.CableBusPart.construct( 0 ); + + BlockCoord loc = new BlockCoord( myMP.xCoord, myMP.yCoord, myMP.zCoord ); + + if ( myMP.canAddPart( myPart ) && Platform.isServer() ) + { + TileMultipart.addPart( myMP.getWorldObj(), loc, myPart ); + hasPart = true; + } + + return myPart; + } + + public void removePart() + { + if ( myPart.isEmpty() ) + { + if ( hasPart ) + { + myMP.remPart( myPart ); + hasPart = false; + } + myPart = null; + } + } + + public FMPPlacementHelper(TileMultipart mp) { + myMP = mp; + } + + @Override + public IFacadeContainer getFacadeContainer() + { + if ( myPart == null ) + return new FacadeContainer(); + return myPart.getFacadeContainer(); + } + + @Override + public boolean canAddPart(ItemStack part, ForgeDirection side) + { + CableBusPart myPart = getPart(); + + boolean returnValue = hasPart && myPart.canAddPart( part, side ); + + removePart(); + + return returnValue; + } + + @Override + public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer owner) + { + CableBusPart myPart = getPart(); + + ForgeDirection returnValue = hasPart ? myPart.addPart( is, side, owner ) : null; + + removePart(); + + return returnValue; + } + + @Override + public IPart getPart(ForgeDirection side) + { + if ( myPart == null ) + return null; + return myPart.getPart( side ); + } + + @Override + public void removePart(ForgeDirection side, boolean suppressUpdate) + { + if ( myPart == null ) + return; + myPart.removePart( side, suppressUpdate ); + } + + @Override + public void markForUpdate() + { + if ( myPart == null ) + return; + myPart.markForUpdate(); + } + + @Override + public DimensionalCoord getLocation() + { + if ( myPart == null ) + return new DimensionalCoord( myMP ); + return myPart.getLocation(); + } + + @Override + public TileEntity getTile() + { + return myMP; + } + + @Override + public AEColor getColor() + { + if ( myPart == null ) + return AEColor.Transparent; + return myPart.getColor(); + } + + @Override + public void clearContainer() + { + if ( myPart == null ) + return; + myPart.clearContainer(); + } + + @Override + public boolean isBlocked(ForgeDirection side) + { + getPart(); + + boolean returnValue = myPart.isBlocked( side ); + + removePart(); + + return returnValue; + } + + @Override + public SelectedPart selectPart(Vec3 pos) + { + if ( myPart == null ) + return new SelectedPart(); + return myPart.selectPart( pos ); + } + + @Override + public void markForSave() + { + if ( myPart == null ) + return; + myPart.markForSave(); + } + + @Override + public void partChanged() + { + if ( myPart == null ) + return; + myPart.partChanged(); + } + + @Override + public boolean hasRedstone(ForgeDirection side) + { + if ( myPart == null ) + return false; + return myPart.hasRedstone( side ); + } + + @Override + public boolean isEmpty() + { + if ( myPart == null ) + return true; + return myPart.isEmpty(); + } + + @Override + public Set getLayerFlags() + { + if ( myPart == null ) + return EnumSet.noneOf( LayerFlags.class ); + return myPart.getLayerFlags(); + } + + @Override + public void cleanup() + { + if ( myPart == null ) + return; + myPart.cleanup(); + } + + @Override + public void notifyNeighbors() + { + if ( myPart == null ) + return; + myPart.notifyNeighbors(); + } + + @Override + public boolean isInWorld() + { + if ( myPart == null ) + return myMP.getWorldObj() != null; + return myPart.isInWorld(); + } + +} diff --git a/integration/modules/FMP.java b/integration/modules/FMP.java index 6eac37969..dfe360c9f 100644 --- a/integration/modules/FMP.java +++ b/integration/modules/FMP.java @@ -13,12 +13,12 @@ import appeng.api.parts.IPartHost; import appeng.core.AELog; import appeng.fmp.CableBusPart; import appeng.fmp.FMPEvent; +import appeng.fmp.FMPPlacementHelper; import appeng.fmp.PartRegistry; import appeng.integration.IIntegrationModule; import appeng.integration.abstraction.IFMP; import appeng.integration.modules.helpers.FMPPacketEvent; import appeng.parts.CableBusContainer; -import appeng.util.Platform; import codechicken.lib.vec.BlockCoord; import codechicken.microblock.BlockMicroMaterial; import codechicken.multipart.MultiPartRegistry; @@ -45,7 +45,7 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF return null; } - + @Override public TMultiPart convert(World world, BlockCoord pos) { @@ -64,14 +64,14 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF @Override public void Init() throws Throwable - { - createAndRegister( AEApi.instance().blocks().blockQuartz.block(),0 ); - createAndRegister( AEApi.instance().blocks().blockQuartzPiller.block(),0 ); - createAndRegister( AEApi.instance().blocks().blockQuartzChiseled.block(),0 ); - createAndRegister( AEApi.instance().blocks().blockSkyStone.block(),0 ); - createAndRegister( AEApi.instance().blocks().blockSkyStone.block(),1 ); - createAndRegister( AEApi.instance().blocks().blockSkyStone.block(),2 ); - createAndRegister( AEApi.instance().blocks().blockSkyStone.block(),3 ); + { + createAndRegister( AEApi.instance().blocks().blockQuartz.block(), 0 ); + createAndRegister( AEApi.instance().blocks().blockQuartzPiller.block(), 0 ); + createAndRegister( AEApi.instance().blocks().blockQuartzChiseled.block(), 0 ); + createAndRegister( AEApi.instance().blocks().blockSkyStone.block(), 0 ); + createAndRegister( AEApi.instance().blocks().blockSkyStone.block(), 1 ); + createAndRegister( AEApi.instance().blocks().blockSkyStone.block(), 2 ); + createAndRegister( AEApi.instance().blocks().blockSkyStone.block(), 3 ); PartRegistry reg[] = PartRegistry.values(); @@ -85,9 +85,10 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF MultipartGenerator.registerPassThroughInterface( "appeng.helpers.AEMultiTile" ); } - private void createAndRegister(Block block, int i) { + private void createAndRegister(Block block, int i) + { if ( block != null ) - BlockMicroMaterial.createAndRegister(block, i); + BlockMicroMaterial.createAndRegister( block, i ); } @Override @@ -114,10 +115,7 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF return (IPartHost) p; } - TMultiPart part = PartRegistry.CableBusPart.construct( 0 ); - if ( mp.canAddPart( part ) && Platform.isServer() ) - TileMultipart.addPart( tile.getWorldObj(), loc, part ); - return (CableBusPart) part; + return new FMPPlacementHelper( mp ); } } catch (Throwable t) @@ -159,13 +157,15 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF } @Override - public Event newFMPPacketEvent(EntityPlayerMP sender) { - return new FMPPacketEvent(sender); + public Event newFMPPacketEvent(EntityPlayerMP sender) + { + return new FMPPacketEvent( sender ); } @Override - public Iterable blockTypes() { - Blocks def= AEApi.instance().blocks(); + public Iterable blockTypes() + { + Blocks def = AEApi.instance().blocks(); return Arrays.asList( def.blockMultiPart.block(), def.blockQuartzTorch.block() ); }