TechReborn/src/main/java/techreborn/tiles/TileMachineBase.java

68 lines
2 KiB
Java
Raw Normal View History

package techreborn.tiles;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import techreborn.packets.PacketHandler;
import java.util.List;
public abstract class TileMachineBase extends TileEntity {
2015-09-19 10:31:24 +02:00
int rotation;
2015-09-05 10:17:58 +02:00
public void syncWithAll() {
if (!worldObj.isRemote) {
PacketHandler.sendPacketToAllPlayers(getDescriptionPacket(),
worldObj);
}
}
2015-05-12 20:26:23 +02:00
@SideOnly(Side.CLIENT)
public void addWailaInfo(List<String> info) {
}
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord,
this.zCoord, 1, nbtTag);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
2015-05-12 20:26:23 +02:00
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord,
yCoord, zCoord);
readFromNBT(packet.func_148857_g());
2015-05-12 20:26:23 +02:00
}
2015-09-19 10:31:24 +02:00
public int getRotation() {
return rotation;
2015-09-05 10:17:58 +02:00
}
2015-09-19 10:31:24 +02:00
public void setRotation(int rotation) {
this.rotation = rotation;
2015-09-05 10:17:58 +02:00
syncWithAll();
worldObj.notifyBlockChange(xCoord, yCoord, zCoord, blockType);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
2015-09-19 10:31:24 +02:00
rotation = tagCompound.getInteger("rotation");
2015-09-05 10:17:58 +02:00
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
2015-09-19 10:31:24 +02:00
tagCompound.setInteger("rotation", rotation);
2015-09-05 10:17:58 +02:00
}
}