2018-10-13 20:35:18 +02:00
|
|
|
package de.ellpeck.naturesaura.blocks.tiles;
|
|
|
|
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.NetworkManager;
|
|
|
|
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
|
|
|
import net.minecraft.server.management.PlayerChunkMapEntry;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
|
|
|
|
public class TileEntityImpl extends TileEntity {
|
|
|
|
@Override
|
|
|
|
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
|
|
|
|
return oldState.getBlock() != newState.getBlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-10-13 20:45:32 +02:00
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
2018-10-13 20:35:18 +02:00
|
|
|
this.writeNBT(compound, false);
|
2018-10-13 20:45:32 +02:00
|
|
|
return super.writeToNBT(compound);
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-10-13 20:45:32 +02:00
|
|
|
public void readFromNBT(NBTTagCompound compound) {
|
2018-10-13 20:35:18 +02:00
|
|
|
this.readNBT(compound, false);
|
2018-10-13 20:45:32 +02:00
|
|
|
super.readFromNBT(compound);
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void writeNBT(NBTTagCompound compound, boolean syncing) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void readNBT(NBTTagCompound compound, boolean syncing) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final SPacketUpdateTileEntity getUpdatePacket() {
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
this.writeNBT(compound, true);
|
|
|
|
return new SPacketUpdateTileEntity(this.pos, 0, compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final NBTTagCompound getUpdateTag() {
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
this.writeNBT(compound, true);
|
|
|
|
return compound;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleUpdateTag(NBTTagCompound tag) {
|
|
|
|
this.readNBT(tag, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
|
|
|
|
super.onDataPacket(net, packet);
|
|
|
|
this.readNBT(packet.getNbtCompound(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendToClients() {
|
|
|
|
WorldServer world = (WorldServer) this.getWorld();
|
|
|
|
PlayerChunkMapEntry entry = world.getPlayerChunkMap().getEntry(this.getPos().getX() >> 4, this.getPos().getZ() >> 4);
|
|
|
|
if (entry != null) {
|
|
|
|
for (EntityPlayerMP player : entry.getWatchingPlayers()) {
|
|
|
|
player.connection.sendPacket(this.getUpdatePacket());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|