Search in sources :

Example 1 with BlockPneumaticCraftCamo

use of me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo 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 2 with BlockPneumaticCraftCamo

use of me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo in project pnc-repressurized by TeamPneumatic.

the class CamoModel method handleBlockState.

private IBakedModel handleBlockState(IBlockState state) {
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState ext = (IExtendedBlockState) state;
        IBlockState camoState = ext.getValue(BlockPneumaticCraftCamo.CAMO_STATE);
        if (camoState != null && !(camoState.getBlock() instanceof BlockPneumaticCraftCamo)) {
            BlockModelShapes blockModelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
            return blockModelShapes.getModelForState(camoState);
        }
    }
    return originalModel;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPneumaticCraftCamo(me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo) BlockModelShapes(net.minecraft.client.renderer.BlockModelShapes)

Example 3 with BlockPneumaticCraftCamo

use of me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo in project pnc-repressurized by TeamPneumatic.

the class ClientEventHandler method onModelBaking.

@SubscribeEvent
public void onModelBaking(ModelBakeEvent event) {
    // set up camo models for camouflagable blocks
    for (Block block : Blockss.blocks) {
        if (block instanceof BlockPneumaticCraftCamo) {
            Map<IBlockState, ModelResourceLocation> map = event.getModelManager().getBlockModelShapes().getBlockStateMapper().getVariants(block);
            for (Map.Entry<IBlockState, ModelResourceLocation> entry : map.entrySet()) {
                Object object = event.getModelRegistry().getObject(entry.getValue());
                if (object != null) {
                    IBakedModel existing = (IBakedModel) object;
                    CamoModel customModel = new CamoModel(existing);
                    event.getModelRegistry().putObject(entry.getValue(), customModel);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) BlockPneumaticCraftCamo(me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

BlockPneumaticCraftCamo (me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo)3 IBlockState (net.minecraft.block.state.IBlockState)3 PacketPlaySound (me.desht.pneumaticcraft.common.network.PacketPlaySound)1 ICamouflageableTE (me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE)1 Block (net.minecraft.block.Block)1 BlockModelShapes (net.minecraft.client.renderer.BlockModelShapes)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1