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

68 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;
2016-09-12 11:07:17 +00:00
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
2015-06-23 22:29:05 +00:00
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;
2016-09-12 11:07:17 +00:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-06-23 22:29:05 +00:00
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);
2016-09-12 11:07:17 +00:00
GT_TileEntity_Ores tileEntity_ores = (GT_TileEntity_Ores) aWorld.getTileEntity(blockPos);
if(tileEntity_ores != null) {
tileEntity_ores.mMetaData = mMetaData;
tileEntity_ores.causeChunkUpdate();
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
}
}