Jump to content

Minothor

Members
  • Posts

    63
  • Joined

Converted

  • Gender
    Male
  • URL
    https://github.com/Minothor

Minothor's Achievements

Stone Miner

Stone Miner (3/8)

4

Reputation

  1. Ah, righto, I was assuming that it would feed back into either an animation or other visual cooldown indicator of some kind. Yeah, without that, it's less work for both the coder and the server!
  2. Yeah, you're going to have to store the items in the Tileentity and read the nbtdata from the Tileentity being rendered. I use something similar with directions on my pipes: https://github.com/Minothor/diagonalCabling/blob/master/src/main/java/diaCable/renderers/blocks/TileEntityFluxCableRenderer.java
  3. The wiki provides an excellent primer tut on NBT here: http://www.minecraftforge.net/wiki/Creating_NBT_for_items The two methods that have been suggested to you so far both involve the onUpdate function (called every tick by the game) Cool's has a variable stored per Itemstack that could be named "coolDownTicksToGo" which is the number of ticks left until the item can be reused. The update function just decreases the number if it's >=0. Using the item sets the variable to the number of ticks needed to count down. Sieben's provides a bit more accuracy since tick rate can be variable. He stores the date/time (a 'Long' type in Java) the item was last used in the Itemstack nbt tag and uses the update function to check if the time difference between that stored time and the current time is >= the cooldown period. Using the item just sets have var to the current time.
  4. Hi all, I'm having a really bizarre issue with setting up one of my mods since reinstalling this PC. setupDecompWorkspace, clean and eclipse are all accepted by gradle and gradlew.bat however, the eclipse command is not adding any of the required folders. Any ideas on why this might be happening would be welcome at this point, it's getting frustrating as hell. Project in Question: https://github.com/Minothor/diagonalCabling Intended behaviour: Restored ability to just clone and run quickstart.bat in order to resume coding
  5. Grey has an excellent breakdown on rendering here: http://greyminecraftcoder.blogspot.be/2013/08/rendering-items.html Basically, you need to write your custom renderer and bind the relevant item rendering perspects in to it. For example, this renderer responds to the EQUIPPED_FIRST_PERSON mode and displays the cards in the player's hand instead of the item: https://github.com/Minothor/EmeraldCasino/blob/master/src/main/java/EmeraldCasino/renderers/items/ I hope this helps and good luck, custom rendering can be a right pain at times!
  6. Currently the server is keeping the correct connections data and it's the client that's out of sync, I'm shunting all the connection making/breaking/checking code out of the tile entities now and into static methods in the MFHelper api class. Partly to centralize control so that one fix works for all, partly so that I'm not duplicating whole methods for each TE. I'll keep you guys posted if I manage to solve it or not. Cheers again to everyone for the suggestions, help and support!
  7. ipsq, getUnlocalisedName() will return the name that the mod or minecraft game assigns it, the names of items that have been renamed in-game are stored in a displayName string on the itemStack container. The contained item's unlocalised name will be a constant still. (unless I'm misunderstanding your requirements) If you really need to though, you could probably test the path of the resource referenced by IIcon and compare that but it's probably unnecessary. Also, Lars, with Cauldron, that's no longer strictly true, although it can cause all kinds of issues, it is at least theoretically feasible to write a mod that leverages both frameworks.
  8. Cheers for pointing that out Lars, I've cleaned that up and I'm wondering if I can force the client side to resync in any other way... I'll do some more research over the weekend. Cheers again to everyone for all the help and suggestions so far though! (these forums actually help keep me motivated and ambitious)
  9. Cheers for pointing out some of the points that I'd missed in the datapacket methods, I've also added in debug code to check the side that's desyncing and it is indeed the client-side that isn't updating it's connections list, server side it cleaning up just fine it would seem. I've added in your changes in the datapacket methods, but the desync is still rearing it's ugly head I'm afraid. Here's the TileEntity class as it stands currently: package net.RPower.RPowermod.machines.power.cable; import java.util.LinkedList; import java.util.List; import java.util.Queue; import RPower.api.power.block.I_MFSink; import RPower.api.power.block.cable.I_MFCable; import RPower.api.power.block.cable.I_PipeDirection; import RPower.api.power.core.E_MFPacketType; import RPower.api.power.core.MFHelper; import RPower.api.power.core.MFPacket; import net.RPower.RPowermod.core.RPCore; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityFluxCable extends TileEntity implements I_MFCable { //Connections are an array of [up, Down, North, East, West, South] public List<I_PipeDirection> connections; //whether or not the cable is lossy public boolean insulatedCable; //maximum limit the cable can carry public double packetSizeLimit; //Packets awaiting processing public Queue<MFPacket> internalBuffer; //automatically calculated. public double percentageLoss; //transfer mode, unbridged connections can only cross an intersection in straight lines (may be reserved for advanced cabling) public boolean bridgeConnections; private double distLimit; public TileEntityFluxCable() { this(32); } public TileEntityFluxCable(double packetSize) { this(packetSize,false); } public TileEntityFluxCable(double packetSize, boolean insulated) { this(packetSize,insulated,true); } public TileEntityFluxCable(double packetSize, boolean insulated,boolean bridged) { packetSizeLimit= packetSize; insulatedCable=insulated; bridgeConnections=bridged; connections=new LinkedList<I_PipeDirection>(); internalBuffer=new LinkedList<MFPacket>(); checkLoss(insulated); distLimit = insulatedCable?(4*packetSize):packetSize; } private void checkLoss(boolean insulated) { if(!insulated) { percentageLoss=(packetSizeLimit/MFPacket.POWERLIMIT); } } @Override public boolean takePacket(MFPacket packet) { double excess=0; if(!insulatedCable) { excess+=(percentageLoss*packet.getBuffer()); packet.setBuffer(packet.getBuffer()-excess); } if(packet.getBuffer()>packetSizeLimit) { excess += packet.getBuffer()-packetSizeLimit; packet.setBuffer(packetSizeLimit); } powerBleed(excess); boolean result=false; result=internalBuffer.add(packet); return result; } @Override public void writeToNBT(NBTTagCompound nbtTag) { byte[] connectionsArr = new byte[connections.size()]; int i =0; for (I_PipeDirection connection: connections) { connectionsArr[i] = connection.toByte(); i++; } nbtTag.setByteArray("connections", connectionsArr); nbtTag.setBoolean("insulated", insulatedCable); nbtTag.setBoolean("bridged", bridgeConnections); nbtTag.setDouble("packetLimit", packetSizeLimit); super.writeToNBT(nbtTag); }; @Override public void readFromNBT(NBTTagCompound nbtTag) { byte[] connectionsArr = nbtTag.getByteArray("connections"); for (byte b : connectionsArr) { I_PipeDirection temp = new PipeDirection(b); connections.add(temp); } insulatedCable=nbtTag.getBoolean("insulated"); bridgeConnections=nbtTag.getBoolean("bridged"); packetSizeLimit=nbtTag.getDouble("packetLimit"); checkLoss(insulatedCable); super.readFromNBT(nbtTag); } //Fixed by Whov @Override public Packet getDescriptionPacket() { Packet packet = super.getDescriptionPacket(); NBTTagCompound nbtTag = packet != null ? ((S35PacketUpdateTileEntity)packet).func_148857_g() : new NBTTagCompound(); writeToNBT(nbtTag); this.writeToNBT(nbtTag); //TODO: Get this damn working! return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } //Fixed by Whov @Override public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) { super.onDataPacket(networkManager, packet); readFromNBT(packet.func_148857_g()); } @Override public void updateEntity() { if(!internalBuffer.isEmpty()) { MFPacket packet = internalBuffer.remove(); boolean result=false; byte direction; for(int i=0; i<59;i++) { int posNeg = ((int)(Math.random()*%2==0)?1:-1; double randXvel=Math.random()*(2*posNeg); double randYvel=Math.random()*(2*posNeg); double randZvel=Math.random()*(2*posNeg); this.worldObj.spawnParticle("magicCrit", xCoord, yCoord, zCoord, randXvel, randYvel, randZvel); } switch(packet.getType()) { case RESPOND: direction = packet.getOrigin().peek(); result = (direction!=-1); result = pushPacket(packet); break; default: direction = packet.getOrigin().peek(); packet.getOrigin().add(randDir(direction).toByte()); result=pushPacket(packet); break; } } super.updateEntity(); } private I_PipeDirection randDir(byte initDirection) { I_PipeDirection origin = new PipeDirection(initDirection); origin.invert(); I_PipeDirection newDirection = origin; int attempt = 0; while (!connections.isEmpty()&&attempt<26&&newDirection.equals(origin)) { attempt++; int randNum=(int)(Math.random()*connections.size()); newDirection = connections.get(randNum); } return newDirection; } @Override public boolean checkConnections() { boolean result=false; int x,y,z,i=0; for(y=-1;y<2;y++) { //System.out.println("Y Level: "+y); for(x=-1;x<2;x++) { //System.out.println("X Position: "+x); for(z=-1;z<2;z++) { //System.out.println("Z Position: "+z); i++; Block target = worldObj.getBlock(xCoord+x, yCoord+y, zCoord+z); //System.out.print("Test["+i+"] Checking block at ["+(xCoord+x)+","+(yCoord+y)+","+(zCoord+z)+"]"); if(target.hasTileEntity(target.getDamageValue(worldObj, xCoord+x, yCoord+y, zCoord+z))&&MFHelper.checkConnectable(worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z))) { //System.out.print(" - Valid!"); boolean twoWay = (worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z))instanceof I_MFCable; formConnection(twoWay, x,y,z); } //System.out.print('\n'); } } //System.out.println("================================================================="); } return result; } @Override public synchronized void formConnection(boolean twoWay, int x, int y, int z) { if(!(x==0&&y==0&&z==0)) { connections.add(new PipeDirection(x, y, z)); if (twoWay) { ((I_MFCable)(worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z))).formConnection(false, -x, -y, -z); worldObj.markBlockForUpdate(xCoord+x, yCoord+y, zCoord+z); } //System.out.println("connection formed"); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } @Override public synchronized void breakConnection(boolean twoWay, int x, int y, int z) { I_PipeDirection targetConnector = new PipeDirection(x,y,z); if(connections.contains(targetConnector)) { System.out.println("Connector found..."); System.out.println("Remove operation was "+(connections.remove(targetConnector)?"":"un")+"successful."); } if (twoWay&&(worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z))instanceof I_MFCable) { I_MFCable targetTile = (I_MFCable)worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z); targetTile.breakConnection(false,-x, -y, -z); worldObj.markBlockForUpdate(xCoord+x, yCoord+y, zCoord+z); } worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } @Override public boolean pushPacket(MFPacket packet) { boolean result= false; if(packet.getType()==E_MFPacketType.RESPOND&&packet.getBuffer()<=0) { packet=null; } if(packet!=null&&packet.getOrigin().size()<=distLimit); { byte direction = packet.getOrigin().peek(); if(packet.getType()==E_MFPacketType.RESPOND) packet.getOrigin().pop(); int[]origin = {xCoord,yCoord,zCoord}; int[] target = new PipeDirection(direction).getTarget(); for(int i=0;i<3;i++) { target[i]+=origin[i]; } result = this.worldObj.getBlock(target[0], target[1], target[2]).hasTileEntity(0); if(result) result=this.worldObj.getTileEntity(target[0], target[1], target[2])instanceof I_MFSink; if(result) result=((I_MFSink)this.worldObj.getTileEntity(target[0], target[1], target[2])).takePacket(packet); if(!result) powerBleed(packet.getBuffer()); } return result; } @Override public boolean canUpdate() { return true; } @Override public double flowLimit() { return packetSizeLimit; } @Override public void powerBleed(double excess) { //add power bleed to chunk atmosphere -> own effects + taint if Thaumcraft installed if(excess>0) System.err.println(""+excess+" MF bled off into atmosphere!\n"); } @Override public double getPacketLimit() { return packetSizeLimit; } @Override public boolean isInsulated() { return insulatedCable; } @Override public boolean isBridged() { return bridgeConnections; } @Override public boolean canDeBridge() { return insulatedCable; } @Override public List<I_PipeDirection> getConnections() { System.out.println("Getting "+(worldObj.isRemote?"Client":"Server")+" connections"); return connections; } public String toJSON() { String result = "\n{"; result+=("\n\t\"tileX\":\""+xCoord+"\","); result+=("\n\t\"tileY\":\""+yCoord+"\","); result+=("\n\t\"tileZ\":\""+zCoord+"\","); result+=("\n\t\"connections\":[\n"); for (I_PipeDirection pipe : connections) { result+=(pipe.toJSON()+",\n"); } result+="]"; result+="\n}\n"; return result; } @Override public void breakAllConnections() { int conNum=connections.size(); for (int i= 0; i<conNum;i++) { int[] target = connections.get(0).getTarget(); breakConnection(true, target[0], target[1], target[2]); } } }
  10. I'm not really that good, to be honest, before this year I hadn't really touched Java since 2007.
  11. I haven't been able to test the single function yet, just the removal of a pipe with only one connection. As for the test, I overrode the equals function with a test that checks the results of each connection's toByte() method so I'm evaluating the direction rather than the object in memory. As far as I can tell, the server and client entities desync, but the server side maintains the correct number while meaning that the pipes client side can behave in unintended ways since packets are transient and don't sync. One solution will be to make packet handling server side only and sync the tile entities when the server ones receive a packet. Still left with the visual artifacts client side though.
  12. I catch the break block in the block class and tell the tileEntity to run the breakAllConnections() method before calling the superclass break method. Code: https://github.com/BackSpace47/main/blob/PowerSystem_V2/java/net/RPower/RPowermod/machines/power/cable/BlockFluxCable.java
  13. Ah, yeah, that's because the x value is the relative value from -1 to 1, so xCoord + (-1) is the same as xCoord -1. I'm thinking of adding a cleanUp() function that can be marked to run on block update, see if that helps.
  14. Please could you elaborate on that? I'm looking through the break connection code and I'm inverting the relative coords in all the right places as far as I can see.
  15. hitting a new bug now I'm afraid, remotely calling the breakConnection() function on adjacent pipes sometimes leaves open ended connections towards the removed pipe. package net.RPower.RPowermod.machines.power.cable; import java.util.LinkedList; import java.util.List; import java.util.Queue; import RPower.api.power.E_MFPacketType; import RPower.api.power.I_MFSink; import RPower.api.power.MFHelper; import RPower.api.power.MFPacket; import RPower.api.power.cable.I_MFCable; import RPower.api.power.cable.I_PipeDirection; import net.RPower.RPowermod.core.RPCore; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityFluxCable extends TileEntity implements I_MFCable { //Connections are an array of [up, Down, North, East, West, South] public List<I_PipeDirection> connections; //whether or not the cable is lossy public boolean insulatedCable; //maximum limit the cable can carry public double packetSizeLimit; //Packets awaiting processing public Queue<MFPacket> internalBuffer; //automatically calculated. public double percentageLoss; //transfer mode, unbridged connections can only cross an intersection in straight lines (may be reserved for advanced cabling) public boolean bridgeConnections; private double distLimit; public TileEntityFluxCable() { this(32); } public TileEntityFluxCable(double packetSize) { this(packetSize,false); } public TileEntityFluxCable(double packetSize, boolean insulated) { this(packetSize,insulated,true); } public TileEntityFluxCable(double packetSize, boolean insulated,boolean bridged) { packetSizeLimit= packetSize; insulatedCable=insulated; bridgeConnections=bridged; connections=new LinkedList<I_PipeDirection>(); internalBuffer=new LinkedList<MFPacket>(); checkLoss(insulated); distLimit = insulatedCable?(4*packetSize):packetSize; } private void checkLoss(boolean insulated) { if(!insulated) { percentageLoss=(packetSizeLimit/MFPacket.POWERLIMIT); } } @Override public boolean takePacket(MFPacket packet) { double excess=0; if(!insulatedCable) { excess+=(percentageLoss*packet.getBuffer()); packet.setBuffer(packet.getBuffer()-excess); } if(packet.getBuffer()>packetSizeLimit) { excess += packet.getBuffer()-packetSizeLimit; packet.setBuffer(packetSizeLimit); } powerBleed(excess); boolean result=false; result=internalBuffer.add(packet); return result; } @Override public void writeToNBT(NBTTagCompound nbtTag) { byte[] connectionsArr = new byte[connections.size()]; int i =0; for (I_PipeDirection connection: connections) { connectionsArr[i] = connection.toByte(); i++; } nbtTag.setByteArray("connections", connectionsArr); nbtTag.setBoolean("insulated", insulatedCable); nbtTag.setBoolean("bridged", bridgeConnections); nbtTag.setDouble("packetLimit", packetSizeLimit); super.writeToNBT(nbtTag); }; @Override public void readFromNBT(NBTTagCompound nbtTag) { byte[] connectionsArr = nbtTag.getByteArray("connections"); for (byte b : connectionsArr) { I_PipeDirection temp = new PipeDirection(b); connections.add(temp); } insulatedCable=nbtTag.getBoolean("insulated"); bridgeConnections=nbtTag.getBoolean("bridged"); packetSizeLimit=nbtTag.getDouble("packetLimit"); checkLoss(insulatedCable); super.readFromNBT(nbtTag); } @Override public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); //TODO: Get this damn working! return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } @Override public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } @Override public void updateEntity() { if(!internalBuffer.isEmpty()) { MFPacket packet = internalBuffer.remove(); boolean result=false; byte direction; for(int i=0; i<59;i++) { int posNeg = ((int)(Math.random()*%2==0)?1:-1; double randXvel=Math.random()*(2*posNeg); double randYvel=Math.random()*(2*posNeg); double randZvel=Math.random()*(2*posNeg); this.worldObj.spawnParticle("magicCrit", xCoord, yCoord, zCoord, randXvel, randYvel, randZvel); } switch(packet.getType()) { case RESPOND: direction = packet.getOrigin().peek(); result = (direction!=-1); result = pushPacket(packet); break; default: direction = packet.getOrigin().peek(); packet.getOrigin().add(randDir(direction).toByte()); result=pushPacket(packet); break; } } super.updateEntity(); } private I_PipeDirection randDir(byte initDirection) { I_PipeDirection origin = new PipeDirection(initDirection); origin.invert(); I_PipeDirection newDirection = origin; int attempt = 0; while (!connections.isEmpty()&&attempt<26&&newDirection.equals(origin)) { attempt++; int randNum=(int)(Math.random()*connections.size()); newDirection = connections.get(randNum); } return newDirection; } public boolean checkConnections() { boolean result=false; int x,y,z,i=0; for(y=-1;y<2;y++) { //System.out.println("Y Level: "+y); for(x=-1;x<2;x++) { //System.out.println("X Position: "+x); for(z=-1;z<2;z++) { //System.out.println("Z Position: "+z); i++; Block target = worldObj.getBlock(xCoord+x, yCoord+y, zCoord+z); //System.out.print("Test["+i+"] Checking block at ["+(xCoord+x)+","+(yCoord+y)+","+(zCoord+z)+"]"); if(target.hasTileEntity(target.getDamageValue(worldObj, xCoord+x, yCoord+y, zCoord+z))&&MFHelper.checkConnectable(worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z))) { //System.out.print(" - Valid!"); boolean twoWay = (worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z))instanceof I_MFCable; formConnection(twoWay, x,y,z); } //System.out.print('\n'); } } //System.out.println("================================================================="); } return result; } @Override public void formConnection(boolean twoWay, int x, int y, int z) { if(!(x==0&&y==0&&z==0)) { connections.add(new PipeDirection(x, y, z)); if (twoWay) { ((I_MFCable)(worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z))).formConnection(false, -x, -y, -z); worldObj.markBlockForUpdate(xCoord+x, yCoord+y, zCoord+z); } //System.out.println("connection formed"); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } @Override public void breakConnection(boolean twoWay, int x, int y, int z) { if (twoWay&&(worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z))instanceof I_MFCable) { I_MFCable targetTile = (I_MFCable)worldObj.getTileEntity(xCoord+x, yCoord+y, zCoord+z); targetTile.breakConnection(false,-x, -y, -z); worldObj.markBlockForUpdate(xCoord+x, yCoord+y, zCoord+z); } connections.remove(new PipeDirection(x,y,z)); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } @Override public boolean pushPacket(MFPacket packet) { boolean result= false; if(packet.getType()==E_MFPacketType.RESPOND&&packet.getBuffer()<=0) { packet=null; } if(packet!=null&&packet.getOrigin().size()<=distLimit); { byte direction = packet.getOrigin().peek(); if(packet.getType()==E_MFPacketType.RESPOND) packet.getOrigin().pop(); int[]origin = {xCoord,yCoord,zCoord}; int[] target = new PipeDirection(direction).getTarget(); for(int i=0;i<3;i++) { target[i]+=origin[i]; } result = this.worldObj.getBlock(target[0], target[1], target[2]).hasTileEntity(0); if(result) result=this.worldObj.getTileEntity(target[0], target[1], target[2])instanceof I_MFSink; if(result) result=((I_MFSink)this.worldObj.getTileEntity(target[0], target[1], target[2])).takePacket(packet); if(!result) powerBleed(packet.getBuffer()); } return result; } @Override public boolean canUpdate() { return true; } @Override public double flowLimit() { return packetSizeLimit; } @Override public void powerBleed(double excess) { //add power bleed to chunk atmosphere -> own effects + taint if Thaumcraft installed if(excess>0) System.err.println(""+excess+" MF bled off into atmosphere!\n"); } @Override public double getPacketLimit() { return packetSizeLimit; } @Override public boolean isInsulated() { return insulatedCable; } @Override public boolean isBridged() { return bridgeConnections; } @Override public boolean canDeBridge() { return insulatedCable; } @Override public List<I_PipeDirection> getConnections() { return connections; } public String toJSON() { String result = "\n{"; result+=("\n\t\"tileX\":\""+xCoord+"\","); result+=("\n\t\"tileY\":\""+yCoord+"\","); result+=("\n\t\"tileZ\":\""+zCoord+"\","); result+=("\n\t\"connections\":[\n"); for (I_PipeDirection pipe : connections) { result+=(pipe.toJSON()+",\n"); } result+="]"; result+="\n}\n"; return result; } @Override public void breakAllConnections() { for (I_PipeDirection direction : connections) { int[] target = direction.getTarget(); breakConnection(true, target[0], target[1], target[2]); } } } package RPower.api.power.cable; import net.RPower.RPowermod.machines.power.cable.PipeDirection; public abstract class A_PipeDirection implements I_PipeDirection { protected int[] target = {0,0,0}; public A_PipeDirection(int xOffset, int yOffset, int zOffset) { int[] targetArr= {xOffset,yOffset,zOffset}; setTarget(targetArr); } //TODO: Solve why connections of Y= 1, X&Z=0 evaluate to -89 instead of 111. public A_PipeDirection(byte b) { //System.out.println("["+b+"]"); //y = b/100 (nearest whole) int yOffset = (byte)b/100; //System.out.println(b+" yO:"+yOffset); //remove the processed value from the byte b-=(100*yOffset); //System.out.println(" "+b); if(b<0) b*=-1; //x = (b/10)-1 (again, nearest whole and convert 0-> -1, 1 -> 0, 2 -> 1) int xOffset = (b/10)-1; //System.out.println(b+" xO:"+xOffset); //remove the processed value from the byte b-= (10*(xOffset+1)); //System.out.println(" "+b); //z = b-1 (converting 0-> -1, 1 -> 0, 2 -> 1) int zOffset = b-1; //System.out.println(b+" zO:"+zOffset); int[] targetArr= {xOffset,yOffset,zOffset}; setTarget(targetArr); } @Override public void setTarget(int[] target) { this.target = target; } @Override public int[] getTarget() { return target; } @Override public byte toByte() { byte modifier = (byte) (target[1]<0?-1:1); //=(100*y)+(10*(x+1))+(z+1) byte xRef = (byte) ((modifier*10)*(1+target[0])); //System.out.println("Byte xRef:"+xRef); byte yRef = (byte) (100*target[1]); //System.out.println("Byte yRef:"+yRef); byte zRef = (byte)(modifier*(1+target[2])); //System.out.println("Byte zRef:"+zRef); byte result = (byte) (zRef+xRef+yRef); return result; } @Override public String toJSON() { String result = "\n{"; result+=("\n\t\"targetX\":\""+target[0]+"\","); result+=("\n\t\"targetY\":\""+target[1]+"\","); result+=("\n\t\"targetZ\":\""+target[2]+"\""); result+="\n}\n"; return result; } @Override public void invert() { int[] newTarget = {-target[0],-target[1],-target[2]}; target = newTarget; } @Override public boolean equals(Object obj) { if (obj==null||!(obj instanceof I_PipeDirection)) return false; return ((I_PipeDirection)obj).toByte()==this.toByte(); } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.