Posted May 14, 201312 yr I have been using Universal Electricity to create an axle network to be able to use for things such as gates. I've been working on making the axles visually spin. The rotation of the axle is decided in updateEntity() off of the current rotation and the current RPS (revolutions per second). This seems to be working fine when I run debug in updateEntity(), but when I debug in the axle's renderer, it always shows rotation as 0. Does anyone have any idea what might be wrong or how to fix it. I'm kinda blanking on this one. Below is the code for TileEntityAxle, which is what all axles extend and contains that code, and the renderer for the wooden axle. package woggatemod.prefab.tile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.ForgeDirection; import org.bouncycastle.util.Arrays; import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.PacketManager; import universalelectricity.prefab.tile.TileEntityAdvanced; import woggatemod.core.block.IAxle; import woggatemod.core.block.IKineticNetworkProvider; import woggatemod.core.block.IWogConnector; import woggatemod.core.kineticenergy.IKineticNetwork; import woggatemod.core.kineticenergy.KineticNetwork; import woggatemod.core.vector.WogVectorHelper; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public abstract class TileEntityAxle extends TileEntityAdvanced implements IAxle, IPacketReceiver { private IKineticNetwork network; /** * Used client side to render. */ public boolean[] visuallyConnected = {false, false, false, false, false, false}; public TileEntity[] connectedBlocks = {null, null, null, null, null, null}; protected String channel = ""; protected float rotation = 0; protected double rps = 1; public void updateConnection(TileEntity tile, ForgeDirection side) { if (!worldObj.isRemote) { if (tile instanceof IWogConnector) { if (canConnectOnSide(side)) { if (((IWogConnector) tile).canConnectWog(side.getOpposite())) { connectedBlocks[side.ordinal()] = tile; visuallyConnected[side.ordinal()] = true; if (tile.getClass() == getClass() && tile instanceof IKineticNetworkProvider) { getNetwork().mergeConnection(((IKineticNetworkProvider) tile).getNetwork()); } return; } } } if (connectedBlocks[side.ordinal()] != null) { // TODO - add functions here. Check tileEntityConductor } connectedBlocks[side.ordinal()] = null; visuallyConnected[side.ordinal()] = false; } } @Override public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { if (worldObj.isRemote) { visuallyConnected[0] = dataStream.readBoolean(); visuallyConnected[1] = dataStream.readBoolean(); visuallyConnected[2] = dataStream.readBoolean(); visuallyConnected[3] = dataStream.readBoolean(); visuallyConnected[4] = dataStream.readBoolean(); visuallyConnected[5] = dataStream.readBoolean(); rotation = dataStream.readFloat(); } } @Override public void initiate() { updateAdjacentWogConnections(); } @Override public void invalidate() { if (!worldObj.isRemote) { getNetwork().splitNetwork(this); } super.invalidate(); } @Override public void updateEntity() { super.updateEntity(); if (!worldObj.isRemote) { if (ticks % 8 == 0) { updateAdjacentWogConnections(); } if (getRPS() > 0) { float addedRotation = (float) (360.0F * getRPS()) / 4; setRotation(rotation + addedRotation); } if (getRotation() > 359) { setRotation(rotation % 360); } } } @Override public void updateAdjacentWogConnections() { if (worldObj != null) { if (!worldObj.isRemote) { boolean[] previousConnections = visuallyConnected.clone(); for (byte i = 0; i < 6; i++) { updateConnection(WogVectorHelper.getConnectorFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i)); } if (!Arrays.areEqual(previousConnections, visuallyConnected)) { worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } } } @Override public Packet getDescriptionPacket() { return PacketManager.getPacket(channel, this, visuallyConnected[0], visuallyConnected[1], visuallyConnected[2], visuallyConnected[3], visuallyConnected[4], visuallyConnected[5], rotation); } @Override public IKineticNetwork getNetwork() { if (network == null) { setNetwork(new KineticNetwork(this)); } return network; } @Override public void setNetwork(IKineticNetwork network) { this.network = network; } @Override public TileEntity[] getAdjacentWogConnections() { return connectedBlocks; } @Override public boolean canConnectWog(ForgeDirection side) { return true; } @Override @SideOnly(Side.CLIENT) public AxisAlignedBB getRenderBoundingBox() { return AxisAlignedBB.getAABBPool().getAABB(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1); } public int getTotalConnections() { int connections = 0; for (int i = 0; i < visuallyConnected.length; i++) { connections += visuallyConnected ? 1 : 0; } return connections; } public int getFirstConnection() { for (int i = 0; i < visuallyConnected.length; i++) { if (visuallyConnected) { return i; } } return -1; } public boolean canConnectOnSide(ForgeDirection side) { return false; } public long getTicks() { return ticks; } @Override public float getRotation() { return rotation; } @Override public void setRotation(float rotate) { rotation = rotate; } @Override public double getRPS() { return rps; } } package woggatemod.components.client; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; import woggatemod.components.common.WogComponents; import woggatemod.components.common.tileentity.TileEntityWoodAxle; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderWoodAxle extends TileEntitySpecialRenderer { private ModelWoodAxle model; private long prevTick, tick = 0; public RenderWoodAxle() { model = new ModelWoodAxle(); } public void renderAModelAt(TileEntityWoodAxle tile, double d, double d1, double d2, float f) { bindTextureByName(WogComponents.MODEL_TEXTURE_DIRECTORY + "woodAxle.png"); GL11.glPushMatrix(); GL11.glTranslatef((float) d + 0.5F, (float) d1 - 0.5F, (float) d2 + 0.5F); if (tile.visuallyConnected[0]) { model.renderBottom(); } if (tile.visuallyConnected[1]) { model.renderTop(); } if (tile.visuallyConnected[2]) { model.renderFront(); } if (tile.visuallyConnected[3]) { model.renderBack(); } if (tile.visuallyConnected[4]) { model.renderLeft(); } if (tile.visuallyConnected[5]) { model.renderRight(); } model.renderMiddle(); if (tile.getTotalConnections() > 0) { int side = tile.getFirstConnection(); float rotateX = 0.0F, rotateY = 0.0F, rotateZ = 0.0F; if (side == 0 || side == 1) { rotateY = 1.0F; } else if (side == 2 || side == 3) { rotateZ = 1.0F; } else { rotateX = 1.0F; } float rotation = tile.getRotation(); GL11.glRotatef(rotation, rotateX, rotateY, rotateZ); } GL11.glPopMatrix(); } @Override public void renderTileEntityAt(TileEntity tile, double d, double d1, double d2, float f) { renderAModelAt((TileEntityWoodAxle) tile, d, d1, d2, f); } }
May 14, 201312 yr What value does rotate get at this line during debugg? float rotation = tile.getRotation(); Also all the renderAt methods ask for the TE as input, where do you call this from? During debug, what is the value for rotation inn the passed inn TE? If you guys dont get it.. then well ya.. try harder...
May 16, 201312 yr Author What value does rotate get at this line during debugg? float rotation = tile.getRotation(); Also all the renderAt methods ask for the TE as input, where do you call this from? During debug, what is the value for rotation inn the passed inn TE? float rotation = tile.getRotation() always comes out to 0. I have checked at the actual tile entity in debug though and it seems to be calculating it fine. I don't know where the tile entity is being passed for the renderAt method. I guess I always assumed it was fine since the visually connected part always works fine. I'm going to run a quick check to see if the tile entity being passed in the renderer is the tile entity for the axle. I believe if I check the id of the tile entity it should match the id of the one in the renderer. I'll post back in just a second. Update - The id's do not match, one is 63 the other is 109. This could be because I'm casting it though, I'm not sure. Also, thank you for the help.
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.