Guest User

TileEntityShaft.java

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