Search in sources :

Example 6 with BlockFrame

use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCEu.

the class CommandRecipeCheck method prettyPrintItemStack.

public String prettyPrintItemStack(ItemStack stack) {
    if (stack.getItem() instanceof MetaItem) {
        MetaItem<?> metaItem = (MetaItem<?>) stack.getItem();
        MetaValueItem metaValueItem = metaItem.getItem(stack);
        if (metaValueItem == null) {
            if (metaItem instanceof MetaPrefixItem) {
                Material material = ((MetaPrefixItem) metaItem).getMaterial(stack);
                OrePrefix orePrefix = ((MetaPrefixItem) metaItem).getOrePrefix();
                return "(MetaItem) OrePrefix: " + orePrefix.name + ", Material: " + material + " * " + stack.getCount();
            }
        } else {
            if (MetaItems.INTEGRATED_CIRCUIT.isItemEqual(stack)) {
                return "Config circuit #" + IntCircuitIngredient.getCircuitConfiguration(stack);
            }
            return "(MetaItem) " + metaValueItem.unlocalizedName + " * " + stack.getCount();
        }
    } else if (stack.getItem() instanceof MachineItemBlock) {
        MetaTileEntity mte = MachineItemBlock.getMetaTileEntity(stack);
        if (mte != null) {
            String id = mte.metaTileEntityId.toString();
            if (mte.metaTileEntityId.getNamespace().equals("gregtech"))
                id = mte.metaTileEntityId.getPath();
            return "(MetaTileEntity) " + id + " * " + stack.getCount();
        }
    } else {
        Block block = Block.getBlockFromItem(stack.getItem());
        String id = null;
        if (block instanceof BlockCompressed) {
            id = "block" + ((BlockCompressed) block).getGtMaterial(stack.getMetadata()).toCamelCaseString();
        } else if (block instanceof BlockFrame) {
            id = "frame" + ((BlockFrame) block).getGtMaterial(stack.getMetadata()).toCamelCaseString();
        } else if (block instanceof BlockMaterialPipe) {
            id = ((BlockMaterialPipe<?, ?, ?>) block).getPrefix().name + ((BlockMaterialPipe<?, ?, ?>) block).getItemMaterial(stack).toCamelCaseString();
        }
        if (id != null) {
            return "(MetaBlock) " + id + " * " + stack.getCount();
        }
    }
    // noinspection ConstantConditions
    return stack.getItem().getRegistryName().toString() + " * " + stack.getCount() + " (Meta " + stack.getItemDamage() + ")";
}
Also used : MetaValueItem(gregtech.api.items.metaitem.MetaItem.MetaValueItem) MetaItem(gregtech.api.items.metaitem.MetaItem) BlockCompressed(gregtech.common.blocks.BlockCompressed) OrePrefix(gregtech.api.unification.ore.OrePrefix) MachineItemBlock(gregtech.api.block.machines.MachineItemBlock) Material(gregtech.api.unification.material.Material) BlockMaterialPipe(gregtech.api.pipenet.block.material.BlockMaterialPipe) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) Block(net.minecraft.block.Block) MachineItemBlock(gregtech.api.block.machines.MachineItemBlock) MetaPrefixItem(gregtech.api.items.materialitem.MetaPrefixItem) BlockFrame(gregtech.common.blocks.BlockFrame)

Example 7 with BlockFrame

use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCEu.

the class FoamSprayerBehavior method onItemUse.

@Override
public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack itemStack = player.getHeldItem(hand);
    IFluidHandlerItem fluidHandlerItem = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
    FluidStack fluidStack = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
    if (fluidStack != null && fluidStack.amount >= FLUID_PER_BLOCK) {
        BlockPos offsetPos = pos.offset(facing);
        IBlockState initialBlockState = world.getBlockState(pos);
        IBlockState offsetState = world.getBlockState(offsetPos);
        if (initialBlockState.getBlock() instanceof BlockFrame) {
            int blocksToFoam = fluidStack.amount / FLUID_PER_BLOCK;
            int blocksFoamed = foamAllFrameBlocks(world, pos, blocksToFoam, player.isSneaking());
            if (!player.capabilities.isCreativeMode) {
                fluidHandlerItem.drain(FLUID_PER_BLOCK * blocksFoamed, true);
            }
            return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
        } else if (offsetState.getBlock().isReplaceable(world, offsetPos)) {
            int blocksToFoam = fluidStack.amount / FLUID_PER_BLOCK;
            int blocksFoamed = foamReplacableBlocks(world, offsetPos, blocksToFoam);
            if (!player.capabilities.isCreativeMode) {
                fluidHandlerItem.drain(FLUID_PER_BLOCK * blocksFoamed, true);
            }
            return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
        }
    }
    return ActionResult.newResult(EnumActionResult.PASS, itemStack);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) ItemStack(net.minecraft.item.ItemStack) BlockFrame(gregtech.common.blocks.BlockFrame)

Aggregations

BlockFrame (gregtech.common.blocks.BlockFrame)7 IBlockState (net.minecraft.block.state.IBlockState)6 ItemStack (net.minecraft.item.ItemStack)5 BlockPos (net.minecraft.util.math.BlockPos)5 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)5 FluidStack (net.minecraftforge.fluids.FluidStack)4 IFluidHandlerItem (net.minecraftforge.fluids.capability.IFluidHandlerItem)4 FluidHandlerItemStack (net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack)4 EnumFacing (net.minecraft.util.EnumFacing)3 IItemBehaviour (gregtech.api.items.metaitem.stats.IItemBehaviour)2 IItemCapabilityProvider (gregtech.api.items.metaitem.stats.IItemCapabilityProvider)2 IItemDurabilityManager (gregtech.api.items.metaitem.stats.IItemDurabilityManager)2 ModHandler (gregtech.api.recipes.ModHandler)2 Material (gregtech.api.unification.material.Material)2 Materials (gregtech.api.unification.material.Materials)2 MetaBlocks (gregtech.common.blocks.MetaBlocks)2 java.util (java.util)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ActionResult (net.minecraft.util.ActionResult)2 EnumActionResult (net.minecraft.util.EnumActionResult)2