Search in sources :

Example 71 with ChunkPosition

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);
    }
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition)

Example 72 with ChunkPosition

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());
    }
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition)

Example 73 with ChunkPosition

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();
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEnergyProvider(cofh.api.energy.IEnergyProvider) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) ChunkPosition(net.minecraft.world.ChunkPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IEnergyReceiver(cofh.api.energy.IEnergyReceiver) ICondition(pneumaticCraft.common.progwidgets.ICondition)

Example 74 with ChunkPosition

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();
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ChunkPosition(net.minecraft.world.ChunkPosition) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 75 with ChunkPosition

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();
            }
        }
    }
}
Also used : PacketDescription(pneumaticCraft.common.network.PacketDescription) ChunkPosition(net.minecraft.world.ChunkPosition) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Chunk(net.minecraft.world.chunk.Chunk) PacketSetSemiBlock(pneumaticCraft.common.network.PacketSetSemiBlock) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

ChunkPosition (net.minecraft.world.ChunkPosition)94 ItemStack (net.minecraft.item.ItemStack)16 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 NBTTagList (net.minecraft.nbt.NBTTagList)10 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)9 TileEntity (net.minecraft.tileentity.TileEntity)9 ArrayList (java.util.ArrayList)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 Chunk (net.minecraft.world.chunk.Chunk)4 FluidStack (net.minecraftforge.fluids.FluidStack)4 Stack (java.util.Stack)3 Block (net.minecraft.block.Block)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 IInventory (net.minecraft.inventory.IInventory)3 PathPoint (net.minecraft.pathfinding.PathPoint)3 Vec3 (net.minecraft.util.Vec3)3