Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.railsofwar.row.track.tileentity;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.network.NetworkManager;
- import net.minecraft.network.play.server.SPacketUpdateTileEntity;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.ITickable;
- import net.railsofwar.row.track.enumeration.EnumTrackDirectionSWNE;
- import javax.annotation.Nullable;
- public class TilePointer extends TileEntity implements ITickable{
- public EnumTrackDirectionSWNE direction = EnumTrackDirectionSWNE.SOUTH;
- public boolean activated = false;
- public boolean prevActivated = false;
- public byte progress = 0;
- public TilePointer(){
- }
- @Override
- public void update(){
- if(this.activated){
- if(this.progress < 20){
- this.progress++;
- }else{
- this.progress = 20;
- }
- }else{
- if(this.progress > 0){
- this.progress--;
- }else{
- this.progress = 0;
- }
- }
- }
- @Override
- public NBTTagCompound writeToNBT(NBTTagCompound tag){
- tag.setByte("direction", (byte) direction.ordinal());
- tag.setBoolean("activated", activated);
- tag.setByte("progress", progress);
- return super.writeToNBT(tag);
- }
- @Override
- public void readFromNBT(NBTTagCompound tag){
- direction = EnumTrackDirectionSWNE.getFront(tag.getByte("direction"));
- this.activated = tag.getBoolean("activated");
- this.progress = tag.getByte("progress");
- super.readFromNBT(tag);
- }
- @Override
- public NBTTagCompound getUpdateTag(){
- return this.writeToNBT(new NBTTagCompound());
- }
- @Nullable
- public SPacketUpdateTileEntity getUpdatePacket(){
- return new SPacketUpdateTileEntity(this.pos, 0, this.getUpdateTag());
- }
- @Override
- public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
- readFromNBT(pkt.getNbtCompound());
- worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 3);
- }
- }
Add Comment
Please, Sign In to add comment