Advertisement
Guest User

TileEntityShaft.java

a guest
Jan 20th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package logico.geartech.gear.tileentities;
  2.  
  3. import ...
  4.  
  5. public class TileEntityShaft extends TileEntity {
  6.  
  7.     private int rotation = 0;
  8.     private float rotationSpeed = 0;
  9.  
  10.     private final Set<ForgeDirection> connectedSides = new HashSet<ForgeDirection>();
  11.  
  12.     private Orientation orientation = Orientation.UNKNOWN;
  13.  
  14.     public void setPosition (final int x, final int y, final int z) {
  15.  
  16.         xCoord = x;
  17.         yCoord = y;
  18.         zCoord = z;
  19.  
  20.     }
  21.  
  22.     protected void setConnectedOnSide (final ForgeDirection side) {
  23.  
  24.         if (side.ordinal() >= 0 && side.ordinal() <= 5) {
  25.  
  26.             connectedSides.add(side);
  27.             orientation = Orientation.fromDirection(side);
  28.  
  29.         }
  30.  
  31.     }
  32.  
  33.     public void updateConnections (final ForgeDirection side) {
  34.  
  35.         ... [ends up calling setConnectedOnSide]
  36.  
  37.     }
  38.  
  39.     public void updateConnections (final Orientation orientation) {
  40.  
  41.         updateConnections(orientation.defaultSide);
  42.  
  43.     }
  44.  
  45.     public void updateConnections () {
  46.  
  47.         updateConnections(orientation.defaultSide);
  48.  
  49.     }
  50.  
  51.     @Override public Packet getDescriptionPacket () {
  52.  
  53.         final NBTTagCompound tag = new NBTTagCompound();
  54.         writeToNBT(tag);
  55.         return new Packet132TileEntityData(xCoord, yCoord, zCoord, 1, tag);
  56.  
  57.     }
  58.  
  59.     @Override public void onDataPacket (final INetworkManager net, final Packet132TileEntityData packet) {
  60.  
  61.                 if (worldObj.isRemote) {
  62.                     final NBTTagCompound tag = packet.customParam1;
  63.                     readFromNBT(tag);
  64.                 }
  65.  
  66.     }
  67.  
  68.     @Override public void readFromNBT (final NBTTagCompound tagCompound) {
  69.  
  70.         super.readFromNBT(tagCompound);
  71.  
  72.         rotation = tagCompound.getInteger("Direction");
  73.         rotationSpeed = tagCompound.getFloat("RotationSpeed");
  74.         orientation = Orientation.values()[tagCompound.getInteger("Orientation")];
  75.                
  76.                 NBTTagCompound connections = tagCompound.getCompoundTag("Connections");
  77.                 if (connections.getBoolean("Forward")) {
  78.                     setConnectedOnSide(orientation.defaultSide);
  79.                 }
  80.                 if (connections.getBoolean("Backward")) {
  81.                     setConnectedOnSide(orientation.defaultSide.getOpposite());
  82.                 }
  83.  
  84.     }
  85.  
  86.     @Override public void writeToNBT (final NBTTagCompound tagCompound) {
  87.  
  88.         super.writeToNBT(tagCompound);
  89.  
  90.         tagCompound.setInteger("Direction", rotation);
  91.         tagCompound.setFloat("RotationSpeed", rotationSpeed);
  92.         tagCompound.setInteger("Orientation", orientation.ordinal());
  93.                
  94.                 NBTTagCompound connections = new NBTTagCompound();
  95.                 if (connectedSides.contains(orientation.defaultSide)) {
  96.                     connections.setBoolean("Forward", true);
  97.                 }
  98.                 if (connectedSides.contains(orientation.defaultSide.getOpposite())) {
  99.                     connections.setBoolean("Backward", true);
  100.                 }
  101.  
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement