Search in sources :

Example 16 with EntityDrone

use of pneumaticCraft.common.entity.living.EntityDrone in project PneumaticCraft by MineMaarten.

the class RenderProgrammableController method renderTileEntityAt.

/*
     * TileEntitySpecialRenderer part
     */
@Override
public void renderTileEntityAt(TileEntity tileentity, double d0, double d1, double d2, float f) {
    if (renderDrone == null) {
        renderDrone = new RenderDrone(false);
        renderDrone.setRenderManager(RenderManager.instance);
        drone = new EntityDrone(tileentity.getWorldObj());
    }
    TileEntityProgrammableController te = (TileEntityProgrammableController) tileentity;
    double droneX = te.oldCurX + (te.getPosition().xCoord - te.oldCurX) * f - te.xCoord + 0.5 + d0;
    double droneY = te.oldCurY + (te.getPosition().yCoord - te.oldCurY) * f - te.yCoord - 0.2 + d1;
    double droneZ = te.oldCurZ + (te.getPosition().zCoord - te.oldCurZ) * f - te.zCoord + 0.5 + d2;
    renderDrone.doRender((Entity) drone, droneX, droneY, droneZ, 0, f);
}
Also used : TileEntityProgrammableController(pneumaticCraft.common.tileentity.TileEntityProgrammableController) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) RenderDrone(pneumaticCraft.client.render.entity.RenderDrone)

Example 17 with EntityDrone

use of pneumaticCraft.common.entity.living.EntityDrone in project PneumaticCraft by MineMaarten.

the class EventHandlerPneumaticCraft method onDroneSuicide.

@SubscribeEvent
public void onDroneSuicide(DroneSuicideEvent event) {
    if (event.drone instanceof EntityDrone) {
        EntityDrone drone = (EntityDrone) event.drone;
        AmadronOffer offer = drone.getHandlingOffer();
        if (offer != null) {
            int times = drone.getOfferTimes();
            if (offer.getInput() instanceof ItemStack) {
                int requiredCount = ((ItemStack) offer.getInput()).stackSize * times;
                for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
                    if (drone.getInventory().getStackInSlot(i) != null) {
                        requiredCount -= drone.getInventory().getStackInSlot(i).stackSize;
                    }
                }
                if (requiredCount <= 0) {
                    for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
                        drone.getInventory().setInventorySlotContents(i, null);
                    }
                    MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
                }
            } else {
                int requiredCount = ((FluidStack) offer.getInput()).amount * times;
                if (drone.getTank().getFluidAmount() >= requiredCount) {
                    MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
                }
            }
        }
    }
}
Also used : EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) AmadronRetrievalEvent(pneumaticCraft.api.drone.AmadronRetrievalEvent) AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 18 with EntityDrone

use of pneumaticCraft.common.entity.living.EntityDrone in project PneumaticCraft by MineMaarten.

the class EventHandlerPneumaticCraft method onAmadronSuccess.

@SubscribeEvent
public void onAmadronSuccess(AmadronRetrievalEvent event) {
    EntityDrone drone = (EntityDrone) event.drone;
    AmadronOffer offer = drone.getHandlingOffer();
    boolean shouldDeliver = false;
    if (offer instanceof AmadronOfferCustom) {
        AmadronOffer realOffer = AmadronOfferManager.getInstance().get(offer);
        if (realOffer != null) {
            //If we find the non-inverted offer, that means the Drone just has completed trading with a different player.
            ((AmadronOfferCustom) realOffer).addPayment(drone.getOfferTimes());
            ((AmadronOfferCustom) realOffer).addStock(-drone.getOfferTimes());
            realOffer.onTrade(drone.getOfferTimes(), drone.getBuyingPlayer());
            shouldDeliver = true;
        }
        realOffer = AmadronOfferManager.getInstance().get(((AmadronOfferCustom) offer).copy().invert());
        if (realOffer != null) {
            //If we find the inverted offer, that means the Drone has just restocked.
            ((AmadronOfferCustom) realOffer).addStock(drone.getOfferTimes());
        }
    } else {
        shouldDeliver = true;
    }
    if (shouldDeliver) {
        ItemStack usedTablet = drone.getUsedTablet();
        if (offer.getOutput() instanceof ItemStack) {
            ItemStack offeringItems = (ItemStack) offer.getOutput();
            int producedItems = offeringItems.stackSize * drone.getOfferTimes();
            List<ItemStack> stacks = new ArrayList<ItemStack>();
            while (producedItems > 0) {
                ItemStack stack = offeringItems.copy();
                stack.stackSize = Math.min(producedItems, stack.getMaxStackSize());
                stacks.add(stack);
                producedItems -= stack.stackSize;
            }
            ChunkPosition pos = ItemAmadronTablet.getItemProvidingLocation(usedTablet);
            if (pos != null) {
                World world = PneumaticCraftUtils.getWorldForDimension(ItemAmadronTablet.getItemProvidingDimension(usedTablet));
                PneumaticRegistry.getInstance().deliverItemsAmazonStyle(world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, stacks.toArray(new ItemStack[stacks.size()]));
            }
        } else {
            FluidStack offeringFluid = ((FluidStack) offer.getOutput()).copy();
            offeringFluid.amount *= drone.getOfferTimes();
            ChunkPosition pos = ItemAmadronTablet.getLiquidProvidingLocation(usedTablet);
            if (pos != null) {
                World world = PneumaticCraftUtils.getWorldForDimension(ItemAmadronTablet.getLiquidProvidingDimension(usedTablet));
                PneumaticRegistry.getInstance().deliverFluidAmazonStyle(world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, offeringFluid);
            }
        }
    }
}
Also used : EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) FluidStack(net.minecraftforge.fluids.FluidStack) ChunkPosition(net.minecraft.world.ChunkPosition) AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) AmadronOfferCustom(pneumaticCraft.common.recipes.AmadronOfferCustom) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 19 with EntityDrone

use of pneumaticCraft.common.entity.living.EntityDrone in project PneumaticCraft by MineMaarten.

the class DroneAIPlace method doBlockInteraction.

@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
    if (drone.getPathNavigator().hasNoPath()) {
        ForgeDirection side = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
        for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
            ItemStack droneStack = drone.getInventory().getStackInSlot(i);
            if (droneStack != null && droneStack.getItem() instanceof ItemBlock && ((ItemBlock) droneStack.getItem()).field_150939_a.canPlaceBlockOnSide(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()).ordinal())) {
                if (widget.isItemValidForFilters(droneStack)) {
                    if (drone instanceof EntityDrone) {
                        EntityDrone entity = (EntityDrone) drone;
                        //Teleport the drone to make sure it isn't in the way of placing a block.
                        entity.setPosition(entity.posX, entity.posY + 200, entity.posZ);
                    }
                    if (drone.getWorld().canPlaceEntityOnSide(((ItemBlock) droneStack.getItem()).field_150939_a, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, false, 0, null, droneStack)) {
                        Block block = Block.getBlockFromItem(droneStack.getItem());
                        int meta = droneStack.getItem().getMetadata(droneStack.getItemDamage());
                        int newMeta = block.onBlockPlaced(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, side.ordinal(), side.offsetX, side.offsetY, side.offsetZ, meta);
                        setFakePlayerAccordingToDir();
                        if (placeBlockAt(droneStack, drone.getFakePlayer(), drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, side.ordinal(), 0, 0, 0, newMeta)) {
                            drone.addAir(null, -PneumaticValues.DRONE_USAGE_PLACE);
                            drone.getWorld().playSoundEffect(pos.chunkPosX + 0.5F, pos.chunkPosY + 0.5F, pos.chunkPosZ + 0.5F, block.stepSound.func_150496_b(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
                            if (--droneStack.stackSize <= 0) {
                                drone.getInventory().setInventorySlotContents(i, null);
                            }
                        }
                        if (drone instanceof EntityDrone) {
                            EntityDrone entity = (EntityDrone) drone;
                            entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
                        }
                        return false;
                    }
                    if (drone instanceof EntityDrone) {
                        EntityDrone entity = (EntityDrone) drone;
                        entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
                    }
                }
            }
        }
        return false;
    } else {
        return true;
    }
}
Also used : ISidedWidget(pneumaticCraft.common.progwidgets.ISidedWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 20 with EntityDrone

use of pneumaticCraft.common.entity.living.EntityDrone in project PneumaticCraft by MineMaarten.

the class BlockDroneRedstoneEmitter method isProvidingWeakPower.

/**
     * Returns true if the block is emitting indirect/weak redstone power on the
     * specified side. If isBlockNormalCube returns true, standard redstone
     * propagation rules will apply instead and this will not be called. Args:
     * World, X, Y, Z, side. Note that the side is reversed - eg it is 1 (up)
     * when checking the bottom of the block.
     */
@Override
public int isProvidingWeakPower(IBlockAccess blockAccess, int x, int y, int z, int side) {
    if (blockAccess instanceof World) {
        World world = (World) blockAccess;
        List<EntityDrone> drones = world.getEntitiesWithinAABB(EntityDrone.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1));
        int signal = 0;
        for (EntityDrone drone : drones) {
            signal = Math.max(signal, drone.getEmittingRedstone(ForgeDirection.getOrientation(side).getOpposite()));
        }
        return signal;
    } else {
        return 0;
    }
}
Also used : EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) World(net.minecraft.world.World)

Aggregations

EntityDrone (pneumaticCraft.common.entity.living.EntityDrone)25 ItemStack (net.minecraft.item.ItemStack)10 IProgWidget (pneumaticCraft.common.progwidgets.IProgWidget)6 Entity (net.minecraft.entity.Entity)5 ProgWidgetStart (pneumaticCraft.common.progwidgets.ProgWidgetStart)5 World (net.minecraft.world.World)4 ProgWidgetArea (pneumaticCraft.common.progwidgets.ProgWidgetArea)4 ProgWidgetGoToLocation (pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation)4 ProgWidgetSuicide (pneumaticCraft.common.progwidgets.ProgWidgetSuicide)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ChunkPosition (net.minecraft.world.ChunkPosition)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 AmadronOffer (pneumaticCraft.common.recipes.AmadronOffer)3 ArrayList (java.util.ArrayList)2 ItemBlock (net.minecraft.item.ItemBlock)2 TileEntity (net.minecraft.tileentity.TileEntity)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 Block (net.minecraft.block.Block)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1