use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class PacketShowArea method toBytes.
@Override
public void toBytes(ByteBuf buffer) {
super.toBytes(buffer);
buffer.writeInt(area.length);
for (ChunkPosition pos : area) {
buffer.writeInt(pos.chunkPosX);
buffer.writeInt(pos.chunkPosY);
buffer.writeInt(pos.chunkPosZ);
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class PacketShowArea method fromBytes.
@Override
public void fromBytes(ByteBuf buffer) {
super.fromBytes(buffer);
area = new ChunkPosition[buffer.readInt()];
for (int i = 0; i < area.length; i++) {
area[i] = new ChunkPosition(buffer.readInt(), buffer.readInt(), buffer.readInt());
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class ProgWidgetRFCondition method getEvaluator.
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {
@Override
protected boolean evaluate(ChunkPosition pos) {
TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
int energy = 0;
if (te instanceof IEnergyReceiver) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (getSides()[d.ordinal()]) {
energy = Math.max(((IEnergyReceiver) te).getEnergyStored(d), energy);
}
}
}
if (te instanceof IEnergyProvider) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (getSides()[d.ordinal()]) {
energy = Math.max(((IEnergyProvider) te).getEnergyStored(d), energy);
}
}
}
return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? energy == ((ICondition) widget).getRequiredCount() : energy >= ((ICondition) widget).getRequiredCount();
}
};
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method onChunkLoad.
@SubscribeEvent
public void onChunkLoad(ChunkDataEvent.Load event) {
try {
if (!event.world.isRemote) {
if (event.getData().hasKey("SemiBlocks")) {
Map<ChunkPosition, ISemiBlock> map = getOrCreateMap(event.getChunk());
map.clear();
NBTTagList tagList = event.getData().getTagList("SemiBlocks", 10);
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound t = tagList.getCompoundTagAt(i);
ISemiBlock semiBlock = getSemiBlockForKey(t.getString("type"));
if (semiBlock != null) {
semiBlock.readFromNBT(t);
setSemiBlock(event.world, t.getInteger("x"), t.getInteger("y"), t.getInteger("z"), semiBlock, event.getChunk());
}
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method onServerTick.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
for (ISemiBlock semiBlock : addingBlocks) {
Chunk chunk = semiBlock.getWorld().getChunkFromBlockCoords(semiBlock.getPos().chunkPosX, semiBlock.getPos().chunkPosZ);
getOrCreateMap(chunk).put(semiBlock.getPos(), semiBlock);
chunk.setChunkModified();
for (EntityPlayerMP player : syncList.get(chunk)) {
NetworkHandler.sendTo(new PacketSetSemiBlock(semiBlock), player);
PacketDescription descPacket = semiBlock.getDescriptionPacket();
if (descPacket != null)
NetworkHandler.sendTo(descPacket, player);
}
}
addingBlocks.clear();
for (Chunk removingChunk : chunksMarkedForRemoval) {
if (!removingChunk.isChunkLoaded) {
semiBlocks.remove(removingChunk);
syncList.remove(removingChunk);
}
}
chunksMarkedForRemoval.clear();
for (Map<ChunkPosition, ISemiBlock> map : semiBlocks.values()) {
for (ISemiBlock semiBlock : map.values()) {
if (!semiBlock.isInvalid())
semiBlock.update();
}
Iterator<ISemiBlock> iterator = map.values().iterator();
while (iterator.hasNext()) {
if (iterator.next().isInvalid()) {
iterator.remove();
}
}
}
}
Aggregations