2019-07-23 12:54:53 +02:00
|
|
|
package com.simibubi.create.foundation.block;
|
2019-07-11 19:55:11 +02:00
|
|
|
|
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
|
|
|
import net.minecraft.network.NetworkManager;
|
|
|
|
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.tileentity.TileEntityType;
|
|
|
|
|
2019-07-23 12:54:53 +02:00
|
|
|
public abstract class SyncedTileEntity extends TileEntity {
|
2019-07-11 19:55:11 +02:00
|
|
|
|
2019-07-23 12:54:53 +02:00
|
|
|
public SyncedTileEntity(TileEntityType<?> tileEntityTypeIn) {
|
2019-07-11 19:55:11 +02:00
|
|
|
super(tileEntityTypeIn);
|
|
|
|
}
|
2019-08-27 17:35:34 +02:00
|
|
|
|
2019-07-16 16:01:51 +02:00
|
|
|
@Override
|
|
|
|
public CompoundNBT getTileData() {
|
|
|
|
return super.getTileData();
|
|
|
|
}
|
2019-08-27 17:35:34 +02:00
|
|
|
|
2019-07-11 19:55:11 +02:00
|
|
|
@Override
|
|
|
|
public CompoundNBT getUpdateTag() {
|
|
|
|
return write(new CompoundNBT());
|
|
|
|
}
|
2019-08-27 17:35:34 +02:00
|
|
|
|
2019-07-11 19:55:11 +02:00
|
|
|
@Override
|
|
|
|
public void handleUpdateTag(CompoundNBT tag) {
|
|
|
|
read(tag);
|
|
|
|
}
|
2019-08-27 17:35:34 +02:00
|
|
|
|
|
|
|
public void sendData() {
|
2019-11-20 22:50:19 +01:00
|
|
|
world.notifyBlockUpdate(getPos(), getBlockState(), getBlockState(), 2 | 4 | 16);
|
2019-08-27 17:35:34 +02:00
|
|
|
}
|
2019-11-20 22:50:19 +01:00
|
|
|
|
2019-08-27 17:35:34 +02:00
|
|
|
public void causeBlockUpdate() {
|
|
|
|
world.notifyBlockUpdate(getPos(), getBlockState(), getBlockState(), 1);
|
|
|
|
}
|
|
|
|
|
2019-07-11 19:55:11 +02:00
|
|
|
@Override
|
2019-08-27 17:35:34 +02:00
|
|
|
public SUpdateTileEntityPacket getUpdatePacket() {
|
|
|
|
return new SUpdateTileEntityPacket(getPos(), 1, writeToClient(new CompoundNBT()));
|
2019-07-11 19:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-08-27 17:35:34 +02:00
|
|
|
public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
|
2019-07-16 16:01:51 +02:00
|
|
|
readClientUpdate(pkt.getNbtCompound());
|
|
|
|
}
|
2019-08-27 17:35:34 +02:00
|
|
|
|
2019-07-16 16:01:51 +02:00
|
|
|
// Special handling for client update packets
|
|
|
|
public void readClientUpdate(CompoundNBT tag) {
|
|
|
|
read(tag);
|
|
|
|
}
|
2019-08-27 17:35:34 +02:00
|
|
|
|
2019-07-16 16:01:51 +02:00
|
|
|
// Special handling for client update packets
|
|
|
|
public CompoundNBT writeToClient(CompoundNBT tag) {
|
|
|
|
return write(tag);
|
2019-07-11 19:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|