Skip to content

Instantly share code, notes, and snippets.

@Keridos
Created December 2, 2016 16:40
Show Gist options
  • Save Keridos/510c33b9a73c7e88be947141d8bbd3a1 to your computer and use it in GitHub Desktop.
Save Keridos/510c33b9a73c7e88be947141d8bbd3a1 to your computer and use it in GitHub Desktop.
package omtteam.omlib.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 27/11/16.
* This Class
*/
public class TileEntityBase extends TileEntity {
@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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment