Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package logico.geartech.gear.tileentities;
- import ...
- public class TileEntityShaft extends TileEntity {
- private int rotation = 0;
- private float rotationSpeed = 0;
- private final Set<ForgeDirection> connectedSides = new HashSet<ForgeDirection>();
- private Orientation orientation = Orientation.UNKNOWN;
- public void setPosition (final int x, final int y, final int z) {
- xCoord = x;
- yCoord = y;
- zCoord = z;
- }
- protected void setConnectedOnSide (final ForgeDirection side) {
- if (side.ordinal() >= 0 && side.ordinal() <= 5) {
- connectedSides.add(side);
- orientation = Orientation.fromDirection(side);
- }
- }
- public void updateConnections (final ForgeDirection side) {
- ... [ends up calling setConnectedOnSide]
- }
- public void updateConnections (final Orientation orientation) {
- updateConnections(orientation.defaultSide);
- }
- public void updateConnections () {
- updateConnections(orientation.defaultSide);
- }
- @Override public Packet getDescriptionPacket () {
- final NBTTagCompound tag = new NBTTagCompound();
- writeToNBT(tag);
- return new Packet132TileEntityData(xCoord, yCoord, zCoord, 1, tag);
- }
- @Override public void onDataPacket (final INetworkManager net, final Packet132TileEntityData packet) {
- if (worldObj.isRemote) {
- final NBTTagCompound tag = packet.customParam1;
- readFromNBT(tag);
- }
- }
- @Override public void readFromNBT (final NBTTagCompound tagCompound) {
- super.readFromNBT(tagCompound);
- rotation = tagCompound.getInteger("Direction");
- rotationSpeed = tagCompound.getFloat("RotationSpeed");
- orientation = Orientation.values()[tagCompound.getInteger("Orientation")];
- NBTTagCompound connections = tagCompound.getCompoundTag("Connections");
- if (connections.getBoolean("Forward")) {
- setConnectedOnSide(orientation.defaultSide);
- }
- if (connections.getBoolean("Backward")) {
- setConnectedOnSide(orientation.defaultSide.getOpposite());
- }
- }
- @Override public void writeToNBT (final NBTTagCompound tagCompound) {
- super.writeToNBT(tagCompound);
- tagCompound.setInteger("Direction", rotation);
- tagCompound.setFloat("RotationSpeed", rotationSpeed);
- tagCompound.setInteger("Orientation", orientation.ordinal());
- NBTTagCompound connections = new NBTTagCompound();
- if (connectedSides.contains(orientation.defaultSide)) {
- connections.setBoolean("Forward", true);
- }
- if (connectedSides.contains(orientation.defaultSide.getOpposite())) {
- connections.setBoolean("Backward", true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement