Search in sources :

Example 6 with ItemBlock

use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.

the class DroneAIPlace method isValidPosition.

@Override
protected boolean isValidPosition(ChunkPosition pos) {
    if (drone.getWorld().isAirBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
        boolean failedOnPlacement = false;
        for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
            ItemStack droneStack = drone.getInventory().getStackInSlot(i);
            if (droneStack != null && droneStack.getItem() instanceof ItemBlock) {
                if (widget.isItemValidForFilters(droneStack)) {
                    if (((ItemBlock) droneStack.getItem()).field_150939_a.canPlaceBlockOnSide(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()).ordinal())) {
                        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)) {
                            if (drone instanceof EntityDrone) {
                                EntityDrone entity = (EntityDrone) drone;
                                entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
                            }
                            return true;
                        } else {
                            if (drone instanceof EntityDrone) {
                                EntityDrone entity = (EntityDrone) drone;
                                entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
                            }
                            drone.addDebugEntry("gui.progWidget.place.debug.entityInWay", pos);
                            failedOnPlacement = true;
                        }
                    } else {
                        failedOnPlacement = true;
                        drone.addDebugEntry("gui.progWidget.place.debug.cantPlaceBlock", pos);
                    }
                }
            }
        }
        if (!failedOnPlacement)
            abort();
    }
    return false;
}
Also used : EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 7 with ItemBlock

use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.

the class BlockChargingStation method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
    if (!world.isRemote && player.isSneaking()) {
        TileEntityChargingStation station = (TileEntityChargingStation) world.getTileEntity(x, y, z);
        station.setCamoStack(player.getCurrentEquippedItem());
        return player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemBlock;
    } else
        return super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
}
Also used : TileEntityChargingStation(pneumaticCraft.common.tileentity.TileEntityChargingStation) ItemBlock(net.minecraft.item.ItemBlock)

Example 8 with ItemBlock

use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.

the class EventHandlerPneumaticCraft method onPlayerClick.

@SubscribeEvent
public void onPlayerClick(PlayerInteractEvent event) {
    Block interactedBlock = event.world.getBlock(event.x, event.y, event.z);
    if (!event.entityPlayer.capabilities.isCreativeMode || !event.entityPlayer.canCommandSenderUseCommand(2, "securityStation")) {
        if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_AIR && event.world != null && !event.world.isRemote) {
            if (interactedBlock != Blockss.securityStation || event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
                ItemStack heldItem = event.entityPlayer.getCurrentEquippedItem();
                boolean tryingToPlaceSecurityStation = heldItem != null && heldItem.getItem() instanceof ItemBlock && ((ItemBlock) heldItem.getItem()).field_150939_a == Blockss.securityStation;
                int blockingStations = PneumaticCraftUtils.getProtectingSecurityStations(event.entity.worldObj, event.x, event.y, event.z, event.entityPlayer, true, tryingToPlaceSecurityStation);
                if (blockingStations > 0) {
                    event.setCanceled(true);
                    event.entityPlayer.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocalFormatted(tryingToPlaceSecurityStation ? "message.securityStation.stationPlacementPrevented" : "message.securityStation.accessPrevented", blockingStations)));
                }
            }
        }
    }
    /**
         * Due to some weird quirk that causes Block#onBlockActivated not getting called on the server when the player is sneaking, this is a workaround.
         */
    if (!event.isCanceled() && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && !event.world.isRemote) {
        if (event.entityPlayer.isSneaking() && (interactedBlock == Blockss.elevatorCaller || interactedBlock == Blockss.chargingStation)) {
            event.setCanceled(interactedBlock.onBlockActivated(event.world, event.x, event.y, event.z, event.entityPlayer, event.face, 0, 0, 0));
        } else if (event.entityPlayer.getCurrentEquippedItem() != null && ModInteractionUtilImplementation.getInstance().isModdedWrench(event.entityPlayer.getCurrentEquippedItem().getItem())) {
            if (interactedBlock instanceof IPneumaticWrenchable) {
                ((IPneumaticWrenchable) interactedBlock).rotateBlock(event.world, event.entityPlayer, event.x, event.y, event.z, ForgeDirection.getOrientation(event.face));
            }
        }
    }
    if (!event.isCanceled() && interactedBlock == Blocks.cobblestone) {
        AchievementHandler.checkFor9x9(event.entityPlayer, event.x, event.y, event.z);
    }
}
Also used : Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) IPneumaticWrenchable(pneumaticCraft.api.block.IPneumaticWrenchable) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) ChatComponentText(net.minecraft.util.ChatComponentText) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 9 with ItemBlock

use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.

the class BlockPneumaticDoorBase method shouldSideBeRendered.

@Override
public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) {
    ForgeDirection d = ForgeDirection.getOrientation(side);
    TileEntityPneumaticDoorBase te = (TileEntityPneumaticDoorBase) world.getTileEntity(x - d.offsetX, y - d.offsetY, z - d.offsetZ);
    ItemStack camoStack = te.getStackInSlot(TileEntityPneumaticDoorBase.CAMO_SLOT);
    if (camoStack != null && camoStack.getItem() instanceof ItemBlock) {
        Block block = ((ItemBlock) camoStack.getItem()).field_150939_a;
        if (PneumaticCraftUtils.isRenderIDCamo(block.getRenderType())) {
            return true;
        }
    }
    return false;
}
Also used : TileEntityPneumaticDoorBase(pneumaticCraft.common.tileentity.TileEntityPneumaticDoorBase) 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 10 with ItemBlock

use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.

the class TileEntityElevatorCaller method onDescUpdate.

@Override
public void onDescUpdate() {
    Block newCamo = camoStack != null && camoStack.getItem() instanceof ItemBlock ? ((ItemBlock) camoStack.getItem()).field_150939_a : null;
    if (newCamo != camoBlock) {
        camoBlock = newCamo;
        rerenderChunk();
    }
}
Also used : Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemBlock(net.minecraft.item.ItemBlock)

Aggregations

ItemBlock (net.minecraft.item.ItemBlock)69 Block (net.minecraft.block.Block)36 ItemStack (net.minecraft.item.ItemStack)34 Item (net.minecraft.item.Item)14 IBlockState (net.minecraft.block.state.IBlockState)7 EntityItem (net.minecraft.entity.item.EntityItem)4 TileEntity (net.minecraft.tileentity.TileEntity)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 RenderItem (net.minecraft.client.renderer.entity.RenderItem)3 EnumFacing (net.minecraft.util.EnumFacing)3 BlockPos (net.minecraft.util.math.BlockPos)3 AMVector3 (am2.api.math.AMVector3)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CustomizableSCTE (net.geforcemods.securitycraft.api.CustomizableSCTE)2 IExplosive (net.geforcemods.securitycraft.api.IExplosive)2 IOwnable (net.geforcemods.securitycraft.api.IOwnable)2 Tessellator (net.minecraft.client.renderer.Tessellator)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ChatComponentText (net.minecraft.util.ChatComponentText)2