Search in sources :

Example 11 with ItemBlock

use of net.minecraft.item.ItemBlock in project MinecraftForge by MinecraftForge.

the class SubstitutionInjectionTest method testSubstitutionInjection.

@Test
public void testSubstitutionInjection() throws Exception {
    final FMLControlledNamespacedRegistry<Block> blockRegistry = (FMLControlledNamespacedRegistry<Block>) PersistentRegistryManager.findRegistryByType(Block.class);
    final FMLControlledNamespacedRegistry<Item> itemRegistry = (FMLControlledNamespacedRegistry<Item>) PersistentRegistryManager.findRegistryByType(Item.class);
    // Capture snapshot prior to registering the substitution - this is a world state "pre-substitute"
    final PersistentRegistryManager.GameDataSnapshot snapshot = PersistentRegistryManager.takeSnapshot();
    Block fnd = blockRegistry.getValue(myDirt);
    Block currDirt = Blocks.DIRT;
    // TEST 0: Verify that input state is correct
    assertEquals("Got vanilla dirt ", currDirt, fnd);
    // TEST 0a: Validate that the ItemBlock for Dirt points at vanilla dirt
    ItemBlock dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
    assertEquals("ItemBlock points at my block", currDirt, dirtitem.block);
    GameRegistry.addSubstitutionAlias("minecraft:dirt", GameRegistry.Type.BLOCK, toSub);
    PersistentRegistryManager.freezeData();
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();
    // This should not throw an exception
    try {
        StatList.reinit();
    } catch (Exception e) {
        fail("Caught exception");
    }
    // TEST 1: Does my substitute take effect? The substitute should be found in the registry
    fnd = blockRegistry.getValue(myDirt);
    currDirt = Blocks.DIRT;
    assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
    assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
    assertEquals("Got my dirt substitute - registry", toSub, fnd);
    // TEST 1a: Validate that the ItemBlock for Dirt now points at my dirt
    dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
    assertEquals("ItemBlock points at my block", toSub, dirtitem.block);
    // TEST 2: Does the substitute get injected when told by loading operation? The substitute should be found in the registry
    PersistentRegistryManager.injectSnapshot(snapshot, true, true);
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();
    fnd = blockRegistry.getValue(myDirt);
    currDirt = Blocks.DIRT;
    assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
    assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
    assertEquals("Got my dirt substitute - registry", toSub, fnd);
    dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
    assertEquals("ItemBlock points at my block", toSub, dirtitem.block);
    // TEST 3: Does the substitute get restored when reverting to frozen state? The substitute should be found in the registry again
    PersistentRegistryManager.revertToFrozen();
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();
    fnd = blockRegistry.getValue(myDirt);
    currDirt = Blocks.DIRT;
    assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
    assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
    assertEquals("Got my dirt substitute - registry", toSub, fnd);
    dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
    assertEquals("ItemBlock points at my block", toSub, dirtitem.block);
    // TEST 2 repeat: Does the substitute get injected when told by loading operation? The substitute should be found in the registry
    PersistentRegistryManager.injectSnapshot(snapshot, true, true);
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();
    fnd = blockRegistry.getValue(myDirt);
    currDirt = Blocks.DIRT;
    assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
    assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
    assertEquals("Got my dirt substitute - registry", toSub, fnd);
    dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
    assertEquals("ItemBlock points at my block", toSub, dirtitem.block);
    // TEST 3 repeat: Does the substitute get restored when reverting to frozen state? The substitute should be found in the registry again
    PersistentRegistryManager.revertToFrozen();
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();
    fnd = blockRegistry.getValue(myDirt);
    currDirt = Blocks.DIRT;
    assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
    assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
    assertEquals("Got my dirt substitute - registry", toSub, fnd);
    dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
    assertEquals("ItemBlock points at my block", toSub, dirtitem.block);
}
Also used : Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemBlock(net.minecraft.item.ItemBlock) Test(org.junit.Test)

Example 12 with ItemBlock

use of net.minecraft.item.ItemBlock in project MinecraftForge by MinecraftForge.

the class SubstitutionRemoveRestoreTest method testSubstitutionRemovalAndRestore.

@Test
public void testSubstitutionRemovalAndRestore() throws Exception {
    GameRegistry.addSubstitutionAlias("minecraft:dirt", GameRegistry.Type.BLOCK, toSub);
    PersistentRegistryManager.freezeData();
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();
    final FMLControlledNamespacedRegistry<Block> blockRegistry = (FMLControlledNamespacedRegistry<Block>) PersistentRegistryManager.findRegistryByType(Block.class);
    final FMLControlledNamespacedRegistry<Item> itemRegistry = (FMLControlledNamespacedRegistry<Item>) PersistentRegistryManager.findRegistryByType(Item.class);
    // TEST 1: Does my substitute take effect? The substitute should be found in the registry
    Block fnd = blockRegistry.getValue(myDirt);
    Block currDirt = Blocks.DIRT;
    assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
    assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
    assertEquals("Got my dirt substitute - registry", toSub, fnd);
    ItemBlock dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
    assertEquals("ItemBlock points at my block", toSub, dirtitem.block);
    // TEST 2: Does the substitute get removed when told by remote operation? The substitute should NOT be found in the registry
    final PersistentRegistryManager.GameDataSnapshot snapshot = PersistentRegistryManager.takeSnapshot();
    snapshot.entries.get(PersistentRegistryManager.BLOCKS).substitutions.clear();
    PersistentRegistryManager.injectSnapshot(snapshot, false, false);
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();
    fnd = blockRegistry.getValue(myDirt);
    currDirt = Blocks.DIRT;
    assertNotEquals("Got my dirt substitute - Blocks", toSub, currDirt);
    assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
    assertNotEquals("Got my dirt substitute - registry", toSub, fnd);
    dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
    assertEquals("ItemBlock points at vanilla block", currDirt, dirtitem.block);
    assertNotEquals("ItemBlock points at my block", toSub, dirtitem.block);
    // TEST 3: Does the substitute get restored when reverting to frozen state? The substitute should be found in the registry again
    PersistentRegistryManager.revertToFrozen();
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();
    fnd = blockRegistry.getValue(myDirt);
    currDirt = Blocks.DIRT;
    assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
    assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
    assertEquals("Got my dirt substitute - registry", toSub, fnd);
    dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
    assertEquals("ItemBlock points at my block", toSub, dirtitem.block);
}
Also used : Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemBlock(net.minecraft.item.ItemBlock) Test(org.junit.Test)

Example 13 with ItemBlock

use of net.minecraft.item.ItemBlock in project MineFactoryReloaded by powercrystals.

the class FactoryGlassPaneItemRenderer method renderItem.

@SuppressWarnings("deprecation")
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    RenderEngine renderEngine = Minecraft.getMinecraft().renderEngine;
    RenderBlocks renderer = (RenderBlocks) data[0];
    BlockFactoryGlassPane pane = (BlockFactoryGlassPane) Block.blocksList[((ItemBlock) item.getItem()).getBlockID()];
    GL11.glPushMatrix();
    GL11.glDisable(GL11.GL_CULL_FACE);
    Tessellator tessellator = Tessellator.instance;
    if (type == ItemRenderType.INVENTORY) {
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glScalef(16f, 16f, 16f);
        GL11.glTranslatef(0.5f, 0.5f, 0.5f);
        RenderingRegistry.instance().renderInventoryBlock(renderer, pane, item.getItemDamage(), MineFactoryReloadedCore.renderIdFactoryGlassPane);
        GL11.glTranslatef(-0.5f, -0.5f, -0.5f);
        GL11.glScalef(1 / 16f, 1 / 16f, 1 / 16f);
        if (item.hasEffect()) {
            GL11.glEnable(GL11.GL_CULL_FACE);
            GL11.glDepthFunc(GL11.GL_GREATER);
            GL11.glDepthMask(false);
            renderEngine.bindTexture("%blur%/misc/glint.png");
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_DST_COLOR);
            GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F);
            GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
            float f = 0.00390625F;
            float f1 = 0.00390625F;
            float f2 = Minecraft.getSystemTime() % (3000 + 0 * 1873) / (3000.0F + 0 * 1873) * 256.0F;
            float f3 = 0.0F;
            float f4 = 4.0F;
            tessellator.startDrawingQuads();
            tessellator.addVertexWithUV(0, 16, -50, (f2 + 16 * f4) * f, (f3 + 16) * f1);
            tessellator.addVertexWithUV(16, 16, -50, (f2 + 16 + 16 * f4) * f, (f3 + 16) * f1);
            tessellator.addVertexWithUV(16, 0, -50, (f2 + 16) * f, (f3 + 0.0F) * f1);
            tessellator.addVertexWithUV(0, 0, -50, (f2 + 0.0F) * f, (f3 + 0.0F) * f1);
            tessellator.draw();
            f2 = Minecraft.getSystemTime() % (3000 + 1 * 1873) / (3000.0F + 1 * 1873) * 256.0F;
            f4 = -1.0F;
            tessellator.startDrawingQuads();
            tessellator.addVertexWithUV(0, 16, -50, (f2 + 16 * f4) * f, (f3 + 16) * f1);
            tessellator.addVertexWithUV(16, 16, -50, (f2 + 16 + 16 * f4) * f, (f3 + 16) * f1);
            tessellator.addVertexWithUV(16, 0, -50, (f2 + 16) * f, (f3 + 0.0F) * f1);
            tessellator.addVertexWithUV(0, 0, -50, (f2 + 0.0F) * f, (f3 + 0.0F) * f1);
            tessellator.draw();
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glDepthMask(true);
            GL11.glDepthFunc(GL11.GL_LEQUAL);
        }
        GL11.glEnable(GL11.GL_LIGHTING);
    } else {
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        switch(type) {
            case EQUIPPED_FIRST_PERSON:
            case EQUIPPED:
                GL11.glTranslatef(10 / 16f, 7 / 16f, 0f);
                break;
            case ENTITY:
                GL11.glScalef(0.75f, 0.75f, 0.75f);
                GL11.glTranslatef(0f, 4 / 16f, 0f);
                break;
            default:
        }
        RenderingRegistry.instance().renderInventoryBlock(renderer, pane, item.getItemDamage(), MineFactoryReloadedCore.renderIdFactoryGlassPane);
        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    }
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glPopMatrix();
}
Also used : RenderBlocks(net.minecraft.client.renderer.RenderBlocks) Tessellator(net.minecraft.client.renderer.Tessellator) BlockFactoryGlassPane(powercrystals.minefactoryreloaded.block.BlockFactoryGlassPane) ItemBlock(net.minecraft.item.ItemBlock) RenderEngine(net.minecraft.client.renderer.RenderEngine)

Example 14 with ItemBlock

use of net.minecraft.item.ItemBlock in project RFToolsDimensions by McJty.

the class DimensionEditorTileEntity method update.

@Override
public void update() {
    if (getWorld().isRemote) {
        return;
    }
    ItemStack injectableItemStack = validateInjectableItemStack();
    if (ItemStackTools.isEmpty(injectableItemStack)) {
        return;
    }
    ItemStack dimensionItemStack = validateDimensionItemStack();
    if (ItemStackTools.isEmpty(dimensionItemStack)) {
        return;
    }
    if (ticksLeft == -1) {
        // We were not injecting. Start now.
        if (isMatterReceiver(injectableItemStack)) {
            ticksCost = DimletCosts.baseDimensionTickCost + 1000;
            ticksLeft = ticksCost;
            rfPerTick = DimletCosts.baseDimensionCreationCost + 200;
        } else if (isTNT(injectableItemStack)) {
            ticksCost = 600;
            ticksLeft = ticksCost;
            rfPerTick = 10;
        } else {
            DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
            Settings settings = KnownDimletConfiguration.getSettings(key);
            ticksCost = DimletCosts.baseDimensionTickCost + settings.getTickCost();
            ticksLeft = ticksCost;
            rfPerTick = DimletCosts.baseDimensionCreationCost + settings.getCreateCost();
        }
    } else {
        int rf = getEnergyStored(EnumFacing.DOWN);
        int rfpt = rfPerTick;
        rfpt = (int) (rfpt * (2.0f - getInfusedFactor()) / 2.0f);
        if (rf >= rfpt) {
            // Enough energy.
            consumeEnergy(rfpt);
            ticksLeft--;
            if (ticksLeft <= 0) {
                RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
                ItemStack dimensionTab = validateDimensionItemStack();
                NBTTagCompound tagCompound = dimensionTab.getTagCompound();
                int id = tagCompound.getInteger("id");
                injectableItemStack = validateInjectableItemStack();
                if (isMatterReceiver(injectableItemStack)) {
                    World dimWorld = dimensionManager.getWorldForDimension(getWorld(), id);
                    int y = findGoodReceiverLocation(dimWorld);
                    if (y == -1) {
                        y = dimWorld.getHeight() / 2;
                    }
                    Item item = injectableItemStack.getItem();
                    if (item instanceof ItemBlock) {
                        ItemBlock itemBlock = (ItemBlock) item;
                        IBlockState state = itemBlock.getBlock().getStateFromMeta(itemBlock.getMetadata(injectableItemStack));
                        BlockPos pos = new BlockPos(8, y, 8);
                        dimWorld.setBlockState(pos, state, 2);
                        Block block = dimWorld.getBlockState(pos).getBlock();
                        // @todo @@@@@@@@@@@@@@ check if right?
                        CompatBlock.activateBlock(block, dimWorld, pos, state, FakePlayerFactory.getMinecraft((WorldServer) dimWorld), EnumHand.MAIN_HAND, EnumFacing.DOWN, 0, 0, 0);
                        //                            block.onBlockPlaced(dimWorld, pos, EnumFacing.DOWN, 0, 0, 0, 0, null);
                        block.onBlockPlacedBy(dimWorld, pos, state, null, injectableItemStack);
                        dimWorld.setBlockToAir(pos.up());
                        dimWorld.setBlockToAir(pos.up(2));
                    }
                } else if (isTNT(injectableItemStack)) {
                    safeDeleteDimension(id, dimensionTab);
                } else {
                    DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
                    DimensionInformation information = dimensionManager.getDimensionInformation(id);
                    information.injectDimlet(key);
                    dimensionManager.save(getWorld());
                }
                inventoryHelper.decrStackSize(DimensionEditorContainer.SLOT_INJECTINPUT, 1);
                stopInjecting();
            }
        }
    }
    markDirty();
    setState();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) World(net.minecraft.world.World) ItemBlock(net.minecraft.item.ItemBlock) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) CompatBlock(mcjty.lib.compat.CompatBlock) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) Settings(mcjty.rftoolsdim.config.Settings)

Example 15 with ItemBlock

use of net.minecraft.item.ItemBlock in project ArsMagica2 by Mithion.

the class AMClientEventHandler method onItemTooltip.

@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.itemStack;
    if (stack != null && stack.getItem() instanceof ItemArmor) {
        double xp = 0;
        int armorLevel = 0;
        String[] effects = new String[0];
        if (stack.hasTagCompound()) {
            NBTTagCompound armorCompound = (NBTTagCompound) stack.stackTagCompound.getTag(AMArmor.NBT_KEY_AMPROPS);
            if (armorCompound != null) {
                xp = armorCompound.getDouble(AMArmor.NBT_KEY_TOTALXP);
                armorLevel = armorCompound.getInteger(AMArmor.NBT_KEY_ARMORLEVEL);
                String effectsList = armorCompound.getString(AMArmor.NBT_KEY_EFFECTS);
                if (effectsList != null && effectsList != "") {
                    effects = effectsList.split(AMArmor.INFUSION_DELIMITER);
                }
            }
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
            event.toolTip.add(StatCollector.translateToLocalFormatted("am2.tooltip.armorxp", String.format("%.2f", xp)));
            event.toolTip.add(String.format(StatCollector.translateToLocal("am2.tooltip.armorlevel"), armorLevel));
            for (String s : effects) {
                event.toolTip.add(StatCollector.translateToLocal("am2.tooltip." + s));
            }
        } else {
            event.toolTip.add(StatCollector.translateToLocal("am2.tooltip.shiftForDetails"));
        }
    } else if (stack.getItem() instanceof ItemBlock) {
        if (((ItemBlock) stack.getItem()).field_150939_a == BlocksCommonProxy.manaBattery) {
            if (stack.hasTagCompound()) {
                NBTTagList list = stack.stackTagCompound.getTagList("Lore", Constants.NBT.TAG_COMPOUND);
                if (list != null) {
                    for (int i = 0; i < list.tagCount(); ++i) {
                        NBTBase tag = list.getCompoundTagAt(i);
                        if (tag instanceof NBTTagString) {
                            event.toolTip.add((((NBTTagString) tag).func_150285_a_()));
                        }
                    }
                }
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTBase(net.minecraft.nbt.NBTBase) ItemArmor(net.minecraft.item.ItemArmor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

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