Naitenne

TilePointer

Jan 25th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. package net.railsofwar.row.track.tileentity;
  2.  
  3. import net.minecraft.nbt.NBTTagCompound;
  4. import net.minecraft.network.NetworkManager;
  5. import net.minecraft.network.play.server.SPacketUpdateTileEntity;
  6. import net.minecraft.tileentity.TileEntity;
  7. import net.minecraft.util.ITickable;
  8. import net.railsofwar.row.track.enumeration.EnumTrackDirectionSWNE;
  9.  
  10. import javax.annotation.Nullable;
  11.  
  12. public class TilePointer extends TileEntity implements ITickable{
  13.     public EnumTrackDirectionSWNE direction = EnumTrackDirectionSWNE.SOUTH;
  14.     public boolean activated = false;
  15.     public boolean prevActivated = false;
  16.     public byte progress = 0;
  17.  
  18.     public TilePointer(){
  19.     }
  20.  
  21.     @Override
  22.     public void update(){
  23.         if(this.activated){
  24.             if(this.progress < 20){
  25.                 this.progress++;
  26.             }else{
  27.                 this.progress = 20;
  28.             }
  29.         }else{
  30.             if(this.progress > 0){
  31.                 this.progress--;
  32.             }else{
  33.                 this.progress = 0;
  34.             }
  35.         }
  36.     }
  37.  
  38.     @Override
  39.     public NBTTagCompound writeToNBT(NBTTagCompound tag){
  40.         tag.setByte("direction", (byte) direction.ordinal());
  41.         tag.setBoolean("activated", activated);
  42.         tag.setByte("progress", progress);
  43.         return super.writeToNBT(tag);
  44.     }
  45.  
  46.     @Override
  47.     public void readFromNBT(NBTTagCompound tag){
  48.         direction = EnumTrackDirectionSWNE.getFront(tag.getByte("direction"));
  49.         this.activated = tag.getBoolean("activated");
  50.         this.progress = tag.getByte("progress");
  51.         super.readFromNBT(tag);
  52.     }
  53.  
  54.     @Override
  55.     public NBTTagCompound getUpdateTag(){
  56.         return this.writeToNBT(new NBTTagCompound());
  57.     }
  58.  
  59.     @Nullable
  60.     public SPacketUpdateTileEntity getUpdatePacket(){
  61.         return new SPacketUpdateTileEntity(this.pos, 0, this.getUpdateTag());
  62.     }
  63.  
  64.     @Override
  65.     public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
  66.         readFromNBT(pkt.getNbtCompound());
  67.         worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 3);
  68.     }
  69. }
Add Comment
Please, Sign In to add comment