Skip to content

Instantly share code, notes, and snippets.

@Keridos
Created November 25, 2016 14:27
Show Gist options
  • Save Keridos/f9f88c7ab3f91027e169b2c7bd610dba to your computer and use it in GitHub Desktop.
Save Keridos/f9f88c7ab3f91027e169b2c7bd610dba to your computer and use it in GitHub Desktop.
package openmodularturrets.tileentity;
import net.minecraft.block.state.IBlockState;
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.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nullable;
/**
* Created by Keridos on 05/12/2015.
* This Class
*/
public abstract class TileEntityOMT extends TileEntity {
protected int tier;
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound) {
super.writeToNBT(nbtTagCompound);
nbtTagCompound.setInteger("tier", tier);
return nbtTagCompound;
}
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound) {
super.readFromNBT(nbtTagCompound);
tier = nbtTagCompound.getInteger("tier");
}
@Nullable
@Override
public SPacketUpdateTileEntity getUpdatePacket() {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
this.writeToNBT(nbtTagCompound);
return new SPacketUpdateTileEntity(this.pos, 2, nbtTagCompound);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
this.readFromNBT(pkt.getNbtCompound());
}
@Override
public NBTTagCompound getUpdateTag() {
return this.writeToNBT(super.getUpdateTag());
}
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
return oldState.getBlock() != newState.getBlock();
}
public int getTier() {
return tier;
}
public void setTier(int tier) {
this.tier = tier;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment