Search in sources :

Example 26 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ProgWidgetArea method getAreaPoints.

private ChunkPosition[] getAreaPoints() {
    ChunkPosition c1;
    if (coord1Variable.equals("")) {
        c1 = x1 != 0 || y1 != 0 || z1 != 0 ? new ChunkPosition(x1, y1, z1) : null;
    } else {
        c1 = aiManager != null ? aiManager.getCoordinate(coord1Variable) : null;
    }
    ChunkPosition c2;
    if (coord2Variable.equals("")) {
        c2 = x2 != 0 || y2 != 0 || z2 != 0 ? new ChunkPosition(x2, y2, z2) : null;
    } else {
        c2 = aiManager != null ? aiManager.getCoordinate(coord2Variable) : null;
    }
    if (c1 == null && c2 == null) {
        return new ChunkPosition[] { null, null };
    } else if (c1 == null) {
        return new ChunkPosition[] { c2, null };
    } else if (c2 == null) {
        return new ChunkPosition[] { c1, null };
    } else {
        return new ChunkPosition[] { c1, c2 };
    }
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition)

Example 27 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class SemiBlockManager method onChunkSave.

@SubscribeEvent
public void onChunkSave(ChunkDataEvent.Save event) {
    Map<ChunkPosition, ISemiBlock> map = semiBlocks.get(event.getChunk());
    if (map != null && map.size() > 0) {
        NBTTagList tagList = new NBTTagList();
        for (Map.Entry<ChunkPosition, ISemiBlock> entry : map.entrySet()) {
            NBTTagCompound t = new NBTTagCompound();
            entry.getValue().writeToNBT(t);
            t.setInteger("x", entry.getKey().chunkPosX);
            t.setInteger("y", entry.getKey().chunkPosY);
            t.setInteger("z", entry.getKey().chunkPosZ);
            t.setString("type", getKeyForSemiBlock(entry.getValue()));
            tagList.appendTag(t);
        }
        event.getData().setTag("SemiBlocks", tagList);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ChunkPosition(net.minecraft.world.ChunkPosition) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) HashMap(java.util.HashMap) Map(java.util.Map) HashBiMap(com.google.common.collect.HashBiMap) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 28 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class SemiBlockManager method onClientTick.

@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
    if (this == getServerInstance())
        getClientOldInstance().onClientTick(event);
    else {
        EntityPlayer player = PneumaticCraft.proxy.getPlayer();
        if (player != null) {
            for (ISemiBlock semiBlock : addingBlocks) {
                Chunk chunk = semiBlock.getWorld().getChunkFromBlockCoords(semiBlock.getPos().chunkPosX, semiBlock.getPos().chunkPosZ);
                getOrCreateMap(chunk).put(semiBlock.getPos(), semiBlock);
            }
            addingBlocks.clear();
            Iterator<Map.Entry<Chunk, Map<ChunkPosition, ISemiBlock>>> iterator = semiBlocks.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<Chunk, Map<ChunkPosition, ISemiBlock>> entry = iterator.next();
                if (PneumaticCraftUtils.distBetween(player.posX, 0, player.posZ, entry.getKey().xPosition * 16 - 8, 0, entry.getKey().zPosition * 16 - 8) > SYNC_DISTANCE + 10) {
                    iterator.remove();
                } else {
                    for (ISemiBlock semiBlock : entry.getValue().values()) {
                        if (!semiBlock.isInvalid())
                            semiBlock.update();
                    }
                    Iterator<ISemiBlock> it = entry.getValue().values().iterator();
                    while (it.hasNext()) {
                        if (it.next().isInvalid()) {
                            it.remove();
                        }
                    }
                }
            }
        } else {
            semiBlocks.clear();
        }
    }
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Chunk(net.minecraft.world.chunk.Chunk) HashMap(java.util.HashMap) Map(java.util.Map) HashBiMap(com.google.common.collect.HashBiMap) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 29 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class SemiBlockManager method onInteraction.

@SubscribeEvent
public void onInteraction(PlayerInteractEvent event) {
    if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
        ItemStack curItem = event.entityPlayer.getCurrentEquippedItem();
        if (curItem != null && curItem.getItem() instanceof ISemiBlockItem) {
            if (getSemiBlock(event.world, event.x, event.y, event.z) != null) {
                if (event.entityPlayer.capabilities.isCreativeMode) {
                    setSemiBlock(event.world, event.x, event.y, event.z, null);
                } else {
                    breakSemiBlock(event.world, event.x, event.y, event.z, event.entityPlayer);
                }
                event.setCanceled(true);
            } else {
                ISemiBlock newBlock = ((ISemiBlockItem) curItem.getItem()).getSemiBlock(event.world, event.x, event.y, event.z, curItem);
                newBlock.initialize(event.world, new ChunkPosition(event.x, event.y, event.z));
                if (newBlock.canPlace()) {
                    setSemiBlock(event.world, event.x, event.y, event.z, newBlock);
                    newBlock.onPlaced(event.entityPlayer, curItem);
                    event.world.playSoundEffect(event.x + 0.5, event.y + 0.5, event.z + 0.5, Block.soundTypeGlass.func_150496_b(), (Block.soundTypeGlass.getVolume() + 1.0F) / 2.0F, Block.soundTypeGlass.getPitch() * 0.8F);
                    if (!event.entityPlayer.capabilities.isCreativeMode) {
                        curItem.stackSize--;
                        if (curItem.stackSize <= 0)
                            event.entityPlayer.setCurrentItemOrArmor(0, null);
                    }
                    event.setCanceled(true);
                }
            }
        }
    }
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 30 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ProgWidgetItemInventoryCondition method getEvaluator.

@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
    return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {

        @Override
        protected boolean evaluate(ChunkPosition pos) {
            IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
            if (inv != null) {
                int count = 0;
                Set<Integer> accessibleSlots = PneumaticCraftUtils.getAccessibleSlotsForInventoryAndSides(inv, ((ISidedWidget) widget).getSides());
                for (Integer i : accessibleSlots) {
                    ItemStack stack = inv.getStackInSlot(i);
                    if (stack != null && widget.isItemValidForFilters(stack)) {
                        count += stack.stackSize;
                    }
                }
                return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? count == ((ICondition) widget).getRequiredCount() : count >= ((ICondition) widget).getRequiredCount();
            }
            return false;
        }
    };
}
Also used : IInventory(net.minecraft.inventory.IInventory) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) ChunkPosition(net.minecraft.world.ChunkPosition) ItemStack(net.minecraft.item.ItemStack)

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