2015-04-12 12:39:06 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
2015-05-22 22:15:19 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-04-13 21:36:16 +02:00
|
|
|
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;
|
2015-05-22 22:15:19 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
2015-04-12 12:39:06 +02:00
|
|
|
|
2015-06-01 22:29:39 +02:00
|
|
|
public abstract class TileMachineBase extends TileEntity {
|
|
|
|
|
2015-09-19 10:31:24 +02:00
|
|
|
int rotation;
|
2015-09-05 10:17:58 +02:00
|
|
|
|
2015-08-09 12:05:32 +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
|
2015-05-21 00:35:04 +02:00
|
|
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
2015-05-12 20:26:23 +02:00
|
|
|
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord,
|
|
|
|
yCoord, zCoord);
|
2015-08-09 12:05:32 +02:00
|
|
|
readFromNBT(packet.func_148857_g());
|
2015-05-12 20:26:23 +02:00
|
|
|
}
|
2015-05-09 21:29:26 +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:38:19 +02:00
|
|
|
if(tagCompound.hasKey("meta") && !tagCompound.hasKey("rotation")){
|
|
|
|
rotation = tagCompound.getInteger("meta");
|
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
2015-04-12 12:39:06 +02:00
|
|
|
}
|