GT5-Unofficial/src/main/java/gregtech/common/blocks/GT_Packet_Ores.java

67 lines
2 KiB
Java
Raw Normal View History

2015-06-23 22:29:05 +00:00
package gregtech.common.blocks;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import gregtech.api.net.GT_Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
2015-06-23 22:29:05 +00:00
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class GT_Packet_Ores
2015-10-22 02:06:25 +00:00
extends GT_Packet {
private int mX;
private int mZ;
private int mY;
2015-10-22 02:06:25 +00:00
private short mMetaData;
public GT_Packet_Ores() {
super(true);
}
public GT_Packet_Ores(BlockPos blockPos, short aMetaData) {
2015-10-22 02:06:25 +00:00
super(false);
this.mX = blockPos.getX();
this.mY = blockPos.getY();
this.mZ = blockPos.getZ();
2015-10-22 02:06:25 +00:00
this.mMetaData = aMetaData;
}
@Override
2015-10-22 02:06:25 +00:00
public byte[] encode() {
ByteArrayDataOutput tOut = ByteStreams.newDataOutput(12);
tOut.writeInt(this.mX);
tOut.writeShort(this.mY);
tOut.writeInt(this.mZ);
tOut.writeShort(this.mMetaData);
return tOut.toByteArray();
}
@Override
2015-10-22 02:06:25 +00:00
public GT_Packet decode(ByteArrayDataInput aData) {
return new GT_Packet_Ores(new BlockPos(aData.readInt(), aData.readShort(), aData.readInt()), aData.readShort());
2015-10-22 02:06:25 +00:00
}
@Override
2015-10-22 02:06:25 +00:00
public void process(IBlockAccess aWorld) {
if (aWorld != null) {
BlockPos blockPos = new BlockPos(this.mX, this.mY, this.mZ);
TileEntity tTileEntity = aWorld.getTileEntity(blockPos);
2015-10-22 02:06:25 +00:00
if ((tTileEntity instanceof GT_TileEntity_Ores)) {
((GT_TileEntity_Ores) tTileEntity).mMetaData = this.mMetaData;
}
if (((aWorld instanceof World)) && (((World) aWorld).isRemote)) {
((World) aWorld).markBlockRangeForRenderUpdate(blockPos, blockPos);
2015-10-22 02:06:25 +00:00
}
}
}
@Override
2015-10-22 02:06:25 +00:00
public byte getPacketID() {
return 3;
2015-06-23 22:29:05 +00:00
}
}