Search in sources :

Example 1 with ICamouflageableTE

use of me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE in project pnc-repressurized by TeamPneumatic.

the class WailaCamoHandler method getWailaBody.

@Nonnull
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
    TileEntity te = accessor.getTileEntity();
    if (te instanceof ICamouflageableTE && ((ICamouflageableTE) te).getCamouflage() != null) {
        String str = ItemCamoApplicator.getCamoStateDisplayName(((ICamouflageableTE) te).getCamouflage());
        currenttip.add(TextFormatting.YELLOW + "[ Camo: " + str + "]");
    }
    return currenttip;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ICamouflageableTE(me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE) Nonnull(javax.annotation.Nonnull)

Example 2 with ICamouflageableTE

use of me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE in project pnc-repressurized by TeamPneumatic.

the class ItemCamoApplicator method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote) {
        if (player.isSneaking()) {
            // copy blockstate of clicked block
            IBlockState state = world.getBlockState(pos);
            if (state.getBlock() instanceof BlockPneumaticCraftCamo) {
                NetworkHandler.sendToAllAround(new PacketPlaySound(SoundEvents.BLOCK_COMPARATOR_CLICK, SoundCategory.PLAYERS, pos, 1.0F, 2.0F, false), world);
                player.sendStatusMessage(new TextComponentTranslation("message.camo.invalidBlock", getCamoStateDisplayName(state)), true);
            } else {
                setCamoState(stack, state);
            }
        } else {
            // either apply saved camo, or remove current camo from block
            TileEntity te = world.getTileEntity(pos);
            if (!(te instanceof ICamouflageableTE)) {
                return EnumActionResult.PASS;
            }
            IBlockState camoState = getCamoState(stack);
            float pressure = getPressure(stack);
            if (pressure < 0.1 && !player.capabilities.isCreativeMode) {
                // not enough pressure
                return EnumActionResult.FAIL;
            }
            // make sure player has enough of the camo item
            if (camoState != null && !player.capabilities.isCreativeMode) {
                ItemStack camoStack = ICamouflageableTE.getStackForState(camoState);
                if (!PneumaticCraftUtils.consumeInventoryItem(player.inventory, camoStack)) {
                    String name = camoStack.getDisplayName();
                    player.sendStatusMessage(new TextComponentTranslation("message.camo.notEnoughBlocks", name), true);
                    NetworkHandler.sendToAllAround(new PacketPlaySound(SoundEvents.BLOCK_COMPARATOR_CLICK, SoundCategory.PLAYERS, pos, 1.0F, 2.0F, false), world);
                    return EnumActionResult.FAIL;
                }
            }
            // return any existing camouflage on the block/TE
            IBlockState existingCamo = ((ICamouflageableTE) te).getCamouflage();
            if (existingCamo != null && !player.capabilities.isCreativeMode) {
                ItemStack camoStack = ICamouflageableTE.getStackForState(existingCamo);
                EntityItem entity = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, camoStack);
                world.spawnEntity(entity);
                entity.onCollideWithPlayer(player);
            }
            // and apply the new camouflage
            addAir(stack, -PneumaticValues.USAGE_CAMO_APPLICATOR);
            ((ICamouflageableTE) te).setCamouflage(camoState);
            NetworkHandler.sendToAllAround(new PacketPlaySound(Sounds.SHORT_HISS, SoundCategory.PLAYERS, pos, 1.0F, 1.0F, false), world);
            return EnumActionResult.SUCCESS;
        }
    } else {
        return EnumActionResult.SUCCESS;
    }
    return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) PacketPlaySound(me.desht.pneumaticcraft.common.network.PacketPlaySound) ItemStack(net.minecraft.item.ItemStack) ICamouflageableTE(me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE) BlockPneumaticCraftCamo(me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo) EntityItem(net.minecraft.entity.item.EntityItem)

Example 3 with ICamouflageableTE

use of me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE in project pnc-repressurized by TeamPneumatic.

the class BlockPneumaticCraftCamo method getCamoState.

protected IBlockState getCamoState(IBlockAccess blockAccess, BlockPos pos) {
    TileEntity te = PneumaticCraftUtils.getTileEntitySafely(blockAccess, pos);
    if (!(te instanceof ICamouflageableTE))
        return null;
    // must not use a camouflageable block as camouflage!
    IBlockState camoState = ((ICamouflageableTE) te).getCamouflage();
    return camoState == null || camoState.getBlock() instanceof BlockPneumaticCraftCamo ? null : camoState;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ICamouflageableTE(me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE)

Example 4 with ICamouflageableTE

use of me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE in project pnc-repressurized by TeamPneumatic.

the class BlockColorHandler method registerColorHandlers.

public static void registerColorHandlers() {
    final IBlockColor heatColor = (state, blockAccess, pos, tintIndex) -> {
        if (blockAccess != null && pos != null) {
            TileEntity te = blockAccess.getTileEntity(pos);
            int heatLevel = 10;
            if (te instanceof TileEntityCompressedIronBlock) {
                heatLevel = ((TileEntityCompressedIronBlock) te).getHeatLevel();
            } else if (te instanceof TileEntityVortexTube) {
                switch(tintIndex) {
                    case 0:
                        heatLevel = ((TileEntityVortexTube) te).getHotHeatLevel();
                        break;
                    case 1:
                        heatLevel = ((TileEntityVortexTube) te).getColdHeatLevel();
                        break;
                }
            }
            double[] color = TileEntityCompressedIronBlock.getColorForHeatLevel(heatLevel);
            return 0xFF000000 + ((int) (color[0] * 255) << 16) + ((int) (color[1] * 255) << 8) + (int) (color[2] * 255);
        }
        return 0xFFFFFFFF;
    };
    Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(heatColor, Blockss.COMPRESSED_IRON, Blockss.HEAT_SINK, Blockss.VORTEX_TUBE);
    final IBlockColor uvLightBoxLampColor = (state, blockAccess, pos, tintIndex) -> {
        if (blockAccess != null && pos != null) {
            TileEntity te = blockAccess.getTileEntity(pos);
            if (te instanceof TileEntityUVLightBox) {
                return ((TileEntityUVLightBox) te).areLightsOn ? 0xFF4000FF : 0xFFAFAFE4;
            }
        }
        return 0xFFAFAFE4;
    };
    Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(uvLightBoxLampColor, Blockss.UV_LIGHT_BOX);
    final IBlockColor camoColor = (state, worldIn, pos, tintIndex) -> {
        if (pos == null || worldIn == null)
            return 0xffffff;
        TileEntity te = worldIn.getTileEntity(pos);
        if (te instanceof ICamouflageableTE && ((ICamouflageableTE) te).getCamouflage() != null) {
            return Minecraft.getMinecraft().getBlockColors().colorMultiplier(((ICamouflageableTE) te).getCamouflage(), te.getWorld(), pos, tintIndex);
        } else {
            return 0xffffff;
        }
    };
    for (Block b : Blockss.blocks) {
        if (b instanceof BlockPneumaticCraftCamo) {
            Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(camoColor, b);
        }
    }
}
Also used : ICamouflageableTE(me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE) TileEntityVortexTube(me.desht.pneumaticcraft.common.tileentity.TileEntityVortexTube) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) IBlockColor(net.minecraft.client.renderer.color.IBlockColor) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityCompressedIronBlock(me.desht.pneumaticcraft.common.tileentity.TileEntityCompressedIronBlock) TileEntityUVLightBox(me.desht.pneumaticcraft.common.tileentity.TileEntityUVLightBox) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityCompressedIronBlock(me.desht.pneumaticcraft.common.tileentity.TileEntityCompressedIronBlock) IBlockColor(net.minecraft.client.renderer.color.IBlockColor) TileEntityUVLightBox(me.desht.pneumaticcraft.common.tileentity.TileEntityUVLightBox) TileEntityVortexTube(me.desht.pneumaticcraft.common.tileentity.TileEntityVortexTube) Block(net.minecraft.block.Block) TileEntityCompressedIronBlock(me.desht.pneumaticcraft.common.tileentity.TileEntityCompressedIronBlock) ICamouflageableTE(me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE)

Aggregations

ICamouflageableTE (me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE)4 TileEntity (net.minecraft.tileentity.TileEntity)4 IBlockState (net.minecraft.block.state.IBlockState)2 Nonnull (javax.annotation.Nonnull)1 BlockPneumaticCraftCamo (me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo)1 PacketPlaySound (me.desht.pneumaticcraft.common.network.PacketPlaySound)1 TileEntityCompressedIronBlock (me.desht.pneumaticcraft.common.tileentity.TileEntityCompressedIronBlock)1 TileEntityUVLightBox (me.desht.pneumaticcraft.common.tileentity.TileEntityUVLightBox)1 TileEntityVortexTube (me.desht.pneumaticcraft.common.tileentity.TileEntityVortexTube)1 Block (net.minecraft.block.Block)1 Minecraft (net.minecraft.client.Minecraft)1 IBlockColor (net.minecraft.client.renderer.color.IBlockColor)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 Side (net.minecraftforge.fml.relauncher.Side)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1