Mecblader Posted October 25, 2014 Posted October 25, 2014 Hello, I had made a pipe block that worked fine and I just had one thing left to do, convert it to a Forge Multipart. I got the block code to convert just fine, but I have been having issues with the Tile Entity code. My problem is that I can't seem to find a way to access the multi part itself when in the world. What I mean by accessing the multi part, I mean that I have code in other Tile Entities and in non converted Tile Entities of the pipe block that check to see if one of the adjacent blocks around them are instances of the Pipe Tile Entity. I use this information for rendering a transferring data. The issue that I am facing is that I can check if the adjacent blocks are instances of TileMultipart, but I cannot seem to figure out how to check if there is a pipe part in the block space. All help is appreciated, Thank You. Quote Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!
superninjaman45 Posted October 25, 2014 Posted October 25, 2014 What you are trying to do sounds very possible. However we are going to need some code to glance at to fully understand the situation. I'll be honest, I probably won't be a ton of help but the others will need code. Quote An average guy who mods Minecraft. If you need help and are willing to use your brain, don't be afraid to ask. Also, check out the Unofficial Minecraft Coder Pack (MCP) Prerelease Center for the latest from the MCP Team! Was I helpful? Leave some karma/thanks!
larsgerrits Posted October 25, 2014 Posted October 25, 2014 In the TileMultipart, there's a List/Seq ( partList for Scala, jPartList() for Java). You can iterate through it and check if the TMultipart is an instance of your pipe. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
Mecblader Posted October 25, 2014 Author Posted October 25, 2014 Does any one know of any open source mod that has a tile entity implemented with a forge multi part, so I can have a better understanding of how to efficiently do stuff. Quote Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!
gcewing Posted October 27, 2014 Posted October 27, 2014 Does any one know of any open source mod that has a tile entity implemented with a forge multi part, so I can have a better understanding of how to efficiently do stuff. Project Red makes extensive use of multiparts. Also Forge Multipart itself includes multipart versions of some vanilla items such as torches and levers. Finally, for what it's worth, here's some code of my own (incomplete) implementing a pipe part. The canConnectToTube() method contains an example of looking at a tile entity to see whether it contains another pipe part. It's a bit specialised, because my pipes are always centre parts and therefore can only appear in slot 6 of the part list. In the general case you would have to iterate over partMap. //------------------------------------------------------------------------------------------------ // // Project Blue - Pneumatic Tube Part // //------------------------------------------------------------------------------------------------ package gcewing.projectblue; import java.util.*; import net.minecraft.inventory.*; import net.minecraft.nbt.*; import net.minecraft.tileentity.*; import net.minecraft.util.*; import net.minecraftforge.common.util.*; import codechicken.microblock.*; import codechicken.multipart.*; import codechicken.multipart.MultiPartRegistry.IPartFactory; import codechicken.lib.data.*; import codechicken.lib.lighting.*; import codechicken.lib.raytracer.*; import codechicken.lib.vec.*; public class PneumaticTubePart extends JCenterPart implements IHollowConnect { final static int tubeWidth = 6; // sixteenths final static double h = 0.5 * (tubeWidth / 16.0); static Cuboid6 centerBox = new Cuboid6(0.5 - h, 0.5 - h, 0.5 - h, 0.5 + h, 0.5 + h, 0.5 + h); static Cuboid6[] sideBoxes = new Cuboid6[6]; static { for (int i = 0; i < 6; i++) { Transformation t = Rotation.sideRotations[i].at(codechicken.lib.vec.Vector3.center); sideBoxes[i] = new Cuboid6(0.5 - h, 0, 0.5 - h, 0.5 + h, 0.5 - h, 0.5 + h).apply(t); } } public int connections = 0; public Collection<TubePayload> payloads; public boolean isConnectedOnSide(int i) { return (connections & (1 << i)) != 0; } @Override public String getType() { return "pb_pneumatictube"; } @Override public int getHollowSize() { return tubeWidth; } @Override public Iterable<Cuboid6> getCollisionBoxes() { List<Cuboid6> result = new ArrayList<Cuboid6>(); result.add(centerBox); for (int i = 0; i < 6; i++) if (isConnectedOnSide(i)) result.add(sideBoxes[i]); return result; } @Override public Iterable<IndexedCuboid6> getSubParts() { List<IndexedCuboid6> result = new ArrayList<IndexedCuboid6>(); result.add(new IndexedCuboid6(6, centerBox)); for (int i = 0; i < 6; i++) if (isConnectedOnSide(i)) result.add(new IndexedCuboid6(i, sideBoxes[i])); return result; } @Override public void writeDesc(MCDataOutput data) { data.writeByte(connections & 0xff); } @Override public void readDesc(MCDataInput data) { connections = data.readByte(); } @Override public void save(NBTTagCompound nbt) { nbt.setInteger("connections", connections); } @Override public void load(NBTTagCompound nbt) { connections = nbt.getInteger("connections"); } @Override public void renderStatic(codechicken.lib.vec.Vector3 pos, LazyLightMatrix olm, int pass) { if (pass == 0) PneumaticTubeRenderer.renderStaticInWorld(this, pos.x, pos.y, pos.z); } // @Override // public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass) { // } // @Override // public void drawBreaking(RenderBlocks rb) { // } @Override public void onAdded() { if (!world().isRemote) updateConnections(); } @Override public void onPartChanged(TMultiPart part) { if (!world().isRemote) updateConnections(); } @Override public void onNeighborChanged() { if (!world().isRemote) updateConnections(); } void updateConnections() { int mask = 0; for (int i = 0; i < 6; i++) { ForgeDirection d = ForgeDirection.getOrientation(i); TileEntity te = world().getTileEntity(x() + d.offsetX, y() + d.offsetY, z() + d.offsetZ); if (canConnectToTube(te, i ^ 1)) { if (tubeCanConnect(this, i)) mask |= 1 << i; } } if (connections != mask) { connections = mask; tile().markDirty(); sendDescUpdate(); } } static boolean canConnectToTube(TileEntity te, int side) { if (te instanceof IInventory) return true; if (te instanceof TileMultipart) { TileMultipart tmp = (TileMultipart)te; TMultiPart part = tmp.partMap(6); if (part instanceof PneumaticTubePart) return tubeCanConnect(part, side); } return false; } static boolean tubeCanConnect(TMultiPart tube, int side) { TMultiPart part = tube.tile().partMap(side); if (part == null) return true; if (part instanceof TFacePart) { TFacePart f = (TFacePart)part; return (f.redstoneConductionMap() & (1 << side)) != 0; } return false; } //------------------------------------------------------------------------------------------------ public static class Factory implements IPartFactory { public TMultiPart createPart(String name, boolean client) { return new PneumaticTubePart(); } } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.