Java Code Examples for net.minecraft.item.ItemBlock

The following are top voted examples for showing how to use net.minecraft.item.ItemBlock. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Proyecto-DASI   File: MinecraftTypeHelper.java   Source Code and License 7 votes vote down vote up
/** Attempt to parse string as a Variation, allowing for block properties having different names to the enum values<br>
 * (eg blue_orchid vs orchidBlue etc.)
 * @param part the string (potentially in the 'wrong' format, eg 'orchidBlue')
 * @param is the ItemStack from which this string came (eg from is.getUnlocalisedName)
 * @return a Variation, if one exists, that matches the part string passed in, or one of the ItemStacks current property values.
 */
public static Variation attemptToGetAsVariant(String part, ItemStack is)
{
    if (is.getItem() instanceof ItemBlock)
    {
        // Unlocalised name doesn't always match the names we use in types.xsd
        // (which are the names displayed by Minecraft when using the F3 debug etc.)
        ItemBlock ib = (ItemBlock)(is.getItem());
        IBlockState bs = ib.block.getStateFromMeta(is.getMetadata());
        for (IProperty prop : (java.util.Set<IProperty>)bs.getProperties().keySet())
        { 
            Comparable<?> comp = bs.getValue(prop);
            Variation var = attemptToGetAsVariant(comp.toString());
            if (var != null)
                return var;
        }
        return null;
    }
    else
        return attemptToGetAsVariant(part);
}
 
Example 2
Project: Mods   File: TNTCannon.java   Source Code and License 6 votes vote down vote up
public int getSlotForUse(EntityPlayer player, ItemStack stack) {
	ItemStack stackToUse = player.inventory.getStackInSlot(player.inventory.currentItem + 1);
	if (stackToUse != null && stackToUse.getItem() instanceof ItemBlock
			&& this.allowBlock(stack,
					Block.getBlockFromItem(stackToUse.getItem()).getStateFromMeta(stackToUse.getMetadata()),
					player.world))
		return player.inventory.currentItem + 1;
	else
		for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
			stackToUse = player.inventory.getStackInSlot(i);
			if (stackToUse != null && stackToUse.getItem() instanceof ItemBlock
					&& this.allowBlock(stack,
							Block.getBlockFromItem(stackToUse.getItem()).getStateFromMeta(stackToUse.getMetadata()),
							player.world))
				return i;
		}
	return -1;
}
 
Example 3
Project: Firma   File: BaseLiquid.java   Source Code and License 6 votes vote down vote up
public BaseLiquid(String fluidName, Consumer<Fluid> f, int col) {
	super(fluidName, new ResourceLocation(FirmaMod.MODID + ":blocks/water_still"), new ResourceLocation(FirmaMod.MODID + ":blocks/water_flow"));
	this.setUnlocalizedName(FirmaMod.MODID + ":fluid." + fluidName);
	FluidRegistry.registerFluid(this);
	f.accept(this);
	block = new BaseBlockLiquid(this, Material.WATER);
	block.setRegistryName(FirmaMod.MODID + ":fluid." + fluidName);
	block.setUnlocalizedName(FirmaMod.MODID + ":fluid." + fluidName);
	block.setCreativeTab(FirmaMod.blockTab);
	block.setLightOpacity(3);
	block.setLightLevel(0);
	
	GameRegistry.register(block);
	i = new ItemBlock(block);
	i.setRegistryName(FirmaMod.MODID+":fluid."+fluidName);
	i.setUnlocalizedName(FirmaMod.MODID+":fluid."+fluidName);
	GameRegistry.register(i);
	FirmaMod.allFluids.add(this);
	this.col = col;
}
 
Example 4
Project: Soot   File: ClientProxy.java   Source Code and License 6 votes vote down vote up
@Override
public void registerItemModel(Item item) {
    if(item instanceof IItemColored)
        COLOR_ITEMS.add((IItemColored) item);
    if(item instanceof ItemBlock)
    {
        ItemBlock itemBlock = (ItemBlock) item;
        Block block = itemBlock.getBlock();
        ResourceLocation resloc = block.getRegistryName();
        if(block instanceof IBlockVariants) {
            for (IBlockState state : ((IBlockVariants) block).getValidStates()) {
                ModelLoader.setCustomModelResourceLocation(item, block.getMetaFromState(state), new ModelResourceLocation(resloc, ((IBlockVariants) block).getBlockStateName(state)));
            }
        }
        else
            ModelLoader.setCustomModelResourceLocation(item,0,new ModelResourceLocation(resloc, "inventory"));
    }
    else
        ModelLoader.setCustomModelResourceLocation(item,0,new ModelResourceLocation(item.getRegistryName(), "inventory"));

}
 
Example 5
Project: CustomWorldGen   File: GameData.java   Source Code and License 6 votes vote down vote up
public GameData()
{
    iBlockRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.BLOCKS, Block.class, new ResourceLocation("minecraft:air"), MIN_BLOCK_ID, MAX_BLOCK_ID, true, BlockCallbacks.INSTANCE, BlockCallbacks.INSTANCE, BlockCallbacks.INSTANCE, BlockCallbacks.INSTANCE);
    iItemRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.ITEMS, Item.class, null, MIN_ITEM_ID, MAX_ITEM_ID, true, ItemCallbacks.INSTANCE, ItemCallbacks.INSTANCE, ItemCallbacks.INSTANCE, ItemCallbacks.INSTANCE);
    iPotionRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.POTIONS, Potion.class, null, MIN_POTION_ID, MAX_POTION_ID, false, PotionCallbacks.INSTANCE, PotionCallbacks.INSTANCE, PotionCallbacks.INSTANCE, null);
    iBiomeRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.BIOMES, Biome.class, null, MIN_BIOME_ID, MAX_BIOME_ID, false, BiomeCallbacks.INSTANCE, BiomeCallbacks.INSTANCE, BiomeCallbacks.INSTANCE, null);
    iSoundEventRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.SOUNDEVENTS, SoundEvent.class, null, MIN_SOUND_ID, MAX_SOUND_ID, false, null, null, null, null);
    ResourceLocation WATER = new ResourceLocation("water");
    iPotionTypeRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.POTIONTYPES, PotionType.class, WATER, MIN_POTIONTYPE_ID, MAX_POTIONTYPE_ID, false, null, null, null, null);
    iEnchantmentRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.ENCHANTMENTS, Enchantment.class, null, MIN_ENCHANTMENT_ID, MAX_ENCHANTMENT_ID, false, null, null, null, null);

    try
    {
        blockField = FinalFieldHelper.makeWritable(ReflectionHelper.findField(ItemBlock.class, "block", "field_150939" + "_a"));
    }
    catch (Exception e)
    {
        FMLLog.log(Level.FATAL, e, "Cannot access the 'block' field from ItemBlock, this is fatal!");
        throw Throwables.propagate(e);
    }
}
 
Example 6
Project: harshencastle   File: HarshenUtils.java   Source Code and License 6 votes vote down vote up
public static ArrayList<Block> getBlocksFromString(String blockName)
{
	ArrayList<Block> blocks = new ArrayList<>();
	if(!HarshenUtils.toArray(Blocks.AIR, null).contains(Block.getBlockFromName(blockName)))
		blocks.add(Block.getBlockFromName(blockName));
	for(ItemStack oreStack : OreDictionary.getOres(blockName))
		if(oreStack.getItem() instanceof ItemBlock)
			blocks.add(((ItemBlock)oreStack.getItem()).getBlock());
	ArrayList<Block> finalBlocks = new ArrayList<>();
	for(Block b : blocks)
	{
		NonNullList<ItemStack> items = NonNullList.create();
		b.getSubBlocks(CreativeTabs.SEARCH, items);
		for(ItemStack stack : items)
			if(!stack.isEmpty())
				finalBlocks.add(Block.getBlockFromItem(stack.getItem()));
			else
				finalBlocks.add(b);
	}
	return finalBlocks;
}
 
Example 7
Project: harshencastle   File: HarshenBlocks.java   Source Code and License 6 votes vote down vote up
public static void register() {
	for(Block block : HarshenConfigs.BLOCKS.allComponants)
		if(HarshenConfigs.BLOCKS.isEnabled(block))
		{
			ForgeRegistries.BLOCKS.register(block);
			if(blocksWithItems.contains(block))
			{
				ItemBlock item = block instanceof IMetaItemBlock ? add(block) : new ItemBlock(block);
				item.setRegistryName(block.getRegistryName());
				item.setMaxStackSize(blockStackSize.get(block));
				ForgeRegistries.ITEMS.register(item);
			}
				
		}
			
}
 
Example 8
Project: Proyecto-DASI   File: MinecraftTypeHelper.java   Source Code and License 6 votes vote down vote up
/** Attempt to parse string as a Variation, allowing for block properties having different names to the enum values<br>
 * (eg blue_orchid vs orchidBlue etc.)
 * @param part the string (potentially in the 'wrong' format, eg 'orchidBlue')
 * @param is the ItemStack from which this string came (eg from is.getUnlocalisedName)
 * @return a Variation, if one exists, that matches the part string passed in, or one of the ItemStacks current property values.
 */
public static Variation attemptToGetAsVariant(String part, ItemStack is)
{
    if (is.getItem() instanceof ItemBlock)
    {
        // Unlocalised name doesn't always match the names we use in types.xsd
        // (which are the names displayed by Minecraft when using the F3 debug etc.)
        ItemBlock ib = (ItemBlock)(is.getItem());
        IBlockState bs = ib.block.getStateFromMeta(is.getMetadata());
        for (IProperty prop : (java.util.Set<IProperty>)bs.getProperties().keySet())
        { 
            Comparable<?> comp = bs.getValue(prop);
            Variation var = attemptToGetAsVariant(comp.toString());
            if (var != null)
                return var;
        }
        return null;
    }
    else
        return attemptToGetAsVariant(part);
}
 
Example 9
Project: BaseClient   File: ShadersRender.java   Source Code and License 6 votes vote down vote up
public static void renderHand0(EntityRenderer er, float par1, int par2)
{
    if (!Shaders.isShadowPass)
    {
        Item item = Shaders.itemToRender != null ? Shaders.itemToRender.getItem() : null;
        Block block = item instanceof ItemBlock ? ((ItemBlock)item).getBlock() : null;

        if (!(item instanceof ItemBlock) || !(block instanceof Block) || block.getBlockLayer() == EnumWorldBlockLayer.SOLID)
        {
            Shaders.readCenterDepth();
            Shaders.beginHand();
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            er.renderHand(par1, par2);
            Shaders.endHand();
            Shaders.isHandRendered = true;
        }
    }
}
 
Example 10
Project: craftsman   File: Turtle.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void track(PlayerTickEvent event) {
    EntityPlayer player = event.player;
    
    Item heldItem = player.getHeldItemMainhand().getItem();
    if (!(heldItem instanceof ItemBlock)) {
        return;
    }    
    
    IBlockState heldBlockState = Block.getBlockFromItem(heldItem).getDefaultState();
    BlockPos basePos = player.getPosition().add(0, -1, 0);
    IBlockState baseState = player.getEntityWorld().getBlockState(basePos);
    
    if (heldBlockState.equals(baseState)) {
        return;
    }

    player.getEntityWorld().setBlockState(basePos, heldBlockState);
}
 
Example 11
Project: DecompiledMinecraft   File: StatList.java   Source Code and License 6 votes vote down vote up
private static void initStats()
{
    for (Item item : Item.itemRegistry)
    {
        if (item != null)
        {
            int i = Item.getIdFromItem(item);
            String s = func_180204_a(item);

            if (s != null)
            {
                objectUseStats[i] = (new StatCrafting("stat.useItem.", s, new ChatComponentTranslation("stat.useItem", new Object[] {(new ItemStack(item)).getChatComponent()}), item)).registerStat();

                if (!(item instanceof ItemBlock))
                {
                    itemStats.add((StatCrafting)objectUseStats[i]);
                }
            }
        }
    }

    replaceAllSimilarBlocks(objectUseStats);
}
 
Example 12
Project: Clef   File: EventHandlerServer.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onRegisterItem(RegistryEvent.Register<Item> event)
{
    Clef.itemInstrument = (new ItemInstrument()).setFull3D().setRegistryName("clef", "instrument").setUnlocalizedName("clef.item.instrument");
    event.getRegistry().register(Clef.itemInstrument);

    Clef.creativeTabInstruments = new CreativeTabs("clef") {
        public final ItemStack iconItem = new ItemStack(Clef.itemInstrument);

        @Override
        public ItemStack getTabIconItem()
        {
            return iconItem;
        }
    };
    Clef.itemInstrument.setCreativeTab(Clef.creativeTabInstruments);
    Clef.blockInstrumentPlayer.setCreativeTab(Clef.creativeTabInstruments);

    event.getRegistry().register(new ItemBlock(Clef.blockInstrumentPlayer).setRegistryName(Clef.blockInstrumentPlayer.getRegistryName()));
}
 
Example 13
Project: BaseClient   File: BlockFlowerPot.java   Source Code and License 6 votes vote down vote up
public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
{
    TileEntity tileentity = worldIn.getTileEntity(pos);

    if (tileentity instanceof TileEntityFlowerPot)
    {
        Item item = ((TileEntityFlowerPot)tileentity).getFlowerPotItem();

        if (item instanceof ItemBlock)
        {
            return Block.getBlockFromItem(item).colorMultiplier(worldIn, pos, renderPass);
        }
    }

    return 16777215;
}
 
Example 14
Project: Technical   File: TileEntityMachine.java   Source Code and License 6 votes vote down vote up
public static int getItemBurnTimeElectrical(ItemStack itemStack) {
	if(itemStack == null) {
		return 0;
	} else {
		Item item = itemStack.getItem();

		if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {

			@SuppressWarnings("unused")
			Block block = Block.getBlockFromItem(item);

		}
		if(item == TechnicalItem.Battery1)
			return 2560;

		return 0;
	}
}
 
Example 15
Project: MeeCreeps   File: DigdownStairsActionWorker.java   Source Code and License 6 votes vote down vote up
private void placeStair(EnumFacing facing, BlockPos pos, EntityItem entityItem) {
    ItemStack blockStack = entityItem.getItem();
    ItemStack actual = blockStack.splitStack(32);
    numStairs += 32;
    if (blockStack.isEmpty()) {
        entityItem.setDead();
    }
    if (actual.isEmpty()) {
        return;
    }
    Item item = actual.getItem();
    if (!(item instanceof ItemBlock)) {
        // Safety
        return;
    }

    placeStair(facing, pos);
}
 
Example 16
Project: DankNull   File: ModCreativeTab.java   Source Code and License 6 votes vote down vote up
@Override
public void displayAllRelevantItems(NonNullList<ItemStack> items) {
	for (int i = 0; i < 6; i++) {
		items.add(new ItemStack(ModItems.DANK_NULL, 1, i));
	}
	for (Item item : ModItems.getList()) {
		if (!(item instanceof ItemDankNull) && !(item instanceof ItemDankNullHolder) && !(item instanceof ItemBlock) && !(item instanceof ItemDankNullPanel)) {
			items.add(new ItemStack(item));
		}
	}
	for (int i = 0; i < 6; i++) {
		items.add(new ItemStack(ModItems.DANK_NULL_PANEL, 1, i));
	}
	for (Block block : ModBlocks.getList()) {
		items.add(new ItemStack(block));
	}
}
 
Example 17
Project: BetterBeginningsReborn   File: RegisterModels.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <BBBlock extends Block & IBBName, BBItem extends Item & IBBName> void register()
{
	// blocks
	for (Block b : RegisterBlocks.allBlocks)
	{
		registerBlock((BBBlock)b);
	}

	// items
	for (Item i : RegisterItems.allItems)
	{
		//Skip ItemBlocks as their models are registered during the block model registration
		if(i instanceof ItemBlock && RegisterBlocks.allBlocks.contains(Block.getBlockFromItem(i))) continue;
		registerItem((BBItem)i);
	}
}
 
Example 18
Project: Randores2   File: RandoresForgeUpgradeRecipe.java   Source Code and License 6 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    double speed = 0;
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.getStackInSlot(i);
        if(stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock() instanceof CraftiniumForge) {
            speed += stack.getSubCompound("randores").getInteger("furnace_speed");
        } else {
            speed += this.upgrades.entrySet().stream().filter(e -> e.getKey().apply(stack)).map(Entry::getValue).findFirst().orElse(0d);
        }
    }

    int intSpeed = (int) speed;
    if(intSpeed > this.clamp) {
        intSpeed = this.clamp;
    }

    ItemStack res = new ItemStack(CraftingBlocks.forgeItem);
    res.getOrCreateSubCompound("randores").setInteger("furnace_speed", intSpeed);
    return res;
}
 
Example 19
Project: Never-Enough-Currency   File: ItemHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
	registry = event.getRegistry();

	wallet = register(new ItemWallet("wallet"));
	linkingCard = register(new ItemLinkingCard("linking_card"));

	penny = register(new ItemMoneyBase("penny", 0.01F));
	nickel = register(new ItemMoneyBase("nickel", 0.05F));
	dime = register(new ItemMoneyBase("dime", 0.10F));
	quarter = register(new ItemMoneyBase("quarter", 0.25F));

	dollarBill = register(new ItemMoneyBase("dollar_bill", 1F));
	fiveDollarBill = register(new ItemMoneyBase("five_dollar_bill", 5F));
	tenDollarBill = register(new ItemMoneyBase("ten_dollar_bill", 10F));
	twentyDollarBill = register(new ItemMoneyBase("twenty_dollar_bill", 20F));
	fiftyDollarBill = register(new ItemMoneyBase("fifty_dollar_bill", 50F));
	hundredDollarBill = register(new ItemMoneyBase("hundred_dollar_bill", 100F));

	for (ItemBlock ib : itemBlocks) {
		registry.register(ib);
		if (ib.getBlock() instanceof BlockBasic) {
			((BlockBasic) ib.getBlock()).registerItemModel(ib);
		}
	}
}
 
Example 20
Project: FoodCraft-Reloaded   File: BlockLoader.java   Source Code and License 6 votes vote down vote up
@Load
public void registerBlocks() {
    for (Field field : FCRBlocks.class.getFields()) {
        field.setAccessible(true);
        RegBlock anno = field.getAnnotation(RegBlock.class);
        if (anno==null) continue;

        try {
            Block block = (Block) field.get(null);
            ForgeRegistries.BLOCKS.register(block.setRegistryName(NameBuilder.buildRegistryName(anno.value())).setUnlocalizedName(NameBuilder.buildUnlocalizedName(anno.value())));

            //Register item block.
            Class<? extends ItemBlock> itemClass = anno.itemClass();
            Constructor<? extends ItemBlock> con = itemClass.getConstructor(Block.class);
            con.setAccessible(true);
            ForgeRegistries.ITEMS.register(con.newInstance(block).setRegistryName(block.getRegistryName()).setUnlocalizedName(block.getUnlocalizedName()));

            Arrays.asList(anno.oreDict()).forEach(s -> OreDictionary.registerOre(s, block));
        } catch (Exception e) {
            FoodCraftReloaded.getLogger().warn("Un-able to register block " + field.toGenericString(), e);
        }
    }
}
 
Example 21
Project: DecompiledMinecraft   File: StatList.java   Source Code and License 6 votes vote down vote up
private static void initStats()
{
    for (Item item : Item.itemRegistry)
    {
        if (item != null)
        {
            int i = Item.getIdFromItem(item);
            String s = func_180204_a(item);

            if (s != null)
            {
                objectUseStats[i] = (new StatCrafting("stat.useItem.", s, new ChatComponentTranslation("stat.useItem", new Object[] {(new ItemStack(item)).getChatComponent()}), item)).registerStat();

                if (!(item instanceof ItemBlock))
                {
                    itemStats.add((StatCrafting)objectUseStats[i]);
                }
            }
        }
    }

    replaceAllSimilarBlocks(objectUseStats);
}
 
Example 22
Project: rezolve   File: RezolveMod.java   Source Code and License 5 votes vote down vote up
public void registerItemBlock(BlockBase block) {
	this.registerBlock(block);

	ItemBlock item = new ItemBlock(block);
	item.setRegistryName(block.getRegistryName());
	GameRegistry.register(item);

	block.itemBlock = item;
}
 
Example 23
Project: ThermionicsWorld   File: BlockVarieties.java   Source Code and License 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
	if (tab!=this.getCreativeTabToDisplayOn()) return;
	
    for (int i=0; i<16; i++) {
        list.add(new ItemStack(ItemBlock.getItemFromBlock(this), 1, i));
    }
}
 
Example 24
Project: Solar   File: RenderHelper.java   Source Code and License 5 votes vote down vote up
public static void renderItemStack(ItemStack stack) {
	//Fix stack 'y' center
	if(stack.getItem() instanceof ItemBlock) {
		GlStateManager.translate(0F, -0.1F, 0F);
	}
	RenderItem render = Minecraft.getMinecraft().getRenderItem();
	GlStateManager.pushAttrib();
	net.minecraft.client.renderer.RenderHelper.enableStandardItemLighting();
	render.renderItem(stack, ItemCameraTransforms.TransformType.GROUND);
	net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
	GlStateManager.popAttrib();
}
 
Example 25
Project: FoodCraft-Reloaded   File: ItemVegetableCake.java   Source Code and License 5 votes vote down vote up
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();
    Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(vegetableType.toString(), "cake")));

    if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
        facing = EnumFacing.UP;
    else if (!block.isReplaceable(worldIn, pos))
        pos = pos.offset(facing);

    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
        IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);

        if (!worldIn.setBlockState(pos, blockState, 11))
            return EnumActionResult.FAIL;
        else {
            blockState = worldIn.getBlockState(pos);

            if (blockState.getBlock() == cake) {
                ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
                blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
            }

            SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
            worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            itemstack.shrink(1);
            return EnumActionResult.SUCCESS;
        }
    }
    else
        return EnumActionResult.FAIL;
}
 
Example 26
Project: pnc-repressurized   File: DroneAIPlace.java   Source Code and License 5 votes vote down vote up
@Override
protected boolean doBlockInteraction(BlockPos pos, double distToBlock) {
    if (drone.getPathNavigator().hasNoPath()) {
        EnumFacing side = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
        for (int i = 0; i < drone.getInv().getSlots(); i++) {
            ItemStack droneStack = drone.getInv().getStackInSlot(i);
            if (droneStack.getItem() instanceof ItemBlock && ((ItemBlock) droneStack.getItem()).getBlock().canPlaceBlockOnSide(drone.world(), pos, ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()))) {
                if (widget.isItemValidForFilters(droneStack)) {
                    ItemBlock itemBlock = (ItemBlock) droneStack.getItem();
                    Block block = itemBlock.getBlock();
                    if (drone.world().mayPlace(block, pos, false, side, drone instanceof EntityDrone ? (EntityDrone) drone : null)) {
                        int newMeta = itemBlock.getMetadata(droneStack.getMetadata());
                        setFakePlayerAccordingToDir();
                        IBlockState iblockstate1 = block.getStateForPlacement(drone.world(), pos, side, side.getFrontOffsetX(), side.getFrontOffsetY(), side.getFrontOffsetZ(), newMeta, drone.getFakePlayer(), EnumHand.MAIN_HAND);
                        if (itemBlock.placeBlockAt(droneStack, drone.getFakePlayer(), drone.world(), pos, side, side.getFrontOffsetX(), side.getFrontOffsetY(), side.getFrontOffsetZ(), iblockstate1)) {
                            drone.addAir(null, -PneumaticValues.DRONE_USAGE_PLACE);
                            SoundType soundType = block.getSoundType(iblockstate1, drone.world(), pos, drone.getFakePlayer());
                            drone.world().playSound(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F, false);
                            droneStack.shrink(1);
                            if (droneStack.getCount() <= 0) {
                                drone.getInv().setStackInSlot(i, ItemStack.EMPTY);
                            }
                        }
                        return false;
                    }
                }
            }
        }
        return false;
    } else {
        return true;
    }
}
 
Example 27
Project: Mods   File: TileEntityAmmoFurnace.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the number of ticks that the supplied fuel item will keep the
 * furnace burning, or 0 if the item isn't fuel
 */
public static int getItemBurnTime(ItemStack stack) {
	if (stack.isEmpty())
		return 0;
	else {
		Item item = stack.getItem();

		if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR) {
			Block block = Block.getBlockFromItem(item);

			if (block == Blocks.WOODEN_SLAB)
				return 150;

			if (block.getDefaultState().getMaterial() == Material.WOOD)
				return 300;

			if (block == Blocks.COAL_BLOCK)
				return 16000;
		}

		if (item instanceof ItemTool && "WOOD".equals(((ItemTool) item).getToolMaterialName()))
			return 200;
		if (item instanceof ItemSword && "WOOD".equals(((ItemSword) item).getToolMaterialName()))
			return 200;
		if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe) item).getMaterialName()))
			return 200;
		if (item == Items.STICK)
			return 100;
		if (item == Items.COAL)
			return 1600;
		if (item == Items.LAVA_BUCKET)
			return 20000;
		if (item == Item.getItemFromBlock(Blocks.SAPLING))
			return 100;
		if (item == Items.BLAZE_ROD)
			return 2400;
		return net.minecraftforge.fml.common.registry.GameRegistry.getFuelValue(stack);
	}
}
 
Example 28
Project: pnc-repressurized   File: Itemss.java   Source Code and License 5 votes vote down vote up
public static void registerItem(IForgeRegistry<Item> registry, Item item) {
    registry.register(item);
    ThirdPartyManager.instance().onItemRegistry(item);
    if (item instanceof ItemBlock) {
        all_itemblocks.add((ItemBlock) item);
    } else {
        items.add(item);
    }
}
 
Example 29
Project: uniquecrops   File: BlockOldGrass.java   Source Code and License 5 votes vote down vote up
public BlockOldGrass() {
	
	setRegistryName("oldgrass");
	setUnlocalizedName(UniqueCrops.MOD_ID + ".oldgrass");
	setCreativeTab(UniqueCrops.TAB);
	setSoundType(SoundType.PLANT);
	setHardness(0.6F);
	setTickRandomly(true);
	GameRegistry.register(this);
	GameRegistry.register(new ItemBlock(this), getRegistryName());
}
 
Example 30
Project: HeroUtils   File: DriverSidedBlock.java   Source Code and License 5 votes vote down vote up
protected boolean worksWith(final Block referenceBlock, final int referenceMetadata) {
    for (ItemStack stack : blocks) {
        if (stack != null && stack.getItem() instanceof ItemBlock) {
            final ItemBlock item = (ItemBlock) stack.getItem();
            final Block supportedBlock = item.getBlock();
            final int supportedMetadata = item.getMetadata(stack.getItemDamage());
            if (referenceBlock == supportedBlock && (referenceMetadata == supportedMetadata || stack.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 31
Project: uniquecrops   File: BlockDarkBlock.java   Source Code and License 5 votes vote down vote up
public BlockDarkBlock() {
	
	super("darkblock", Material.ROCK);
	setSoundType(SoundType.STONE);
	setHardness(10.0F);
	setResistance(6000000.0F);
	EntityEnderman.setCarriable(this, true);
	GameRegistry.register(new ItemBlock(this), getRegistryName());
}
 
Example 32
Project: rtap   File: ModBlocks.java   Source Code and License 5 votes vote down vote up
private static void registerBlock(Block block) {
	
	GameRegistry.register(block);
	ItemBlock item = new ItemBlock(block);
	item.setRegistryName(block.getRegistryName());
	GameRegistry.register(item);
	
}
 
Example 33
Project: MobBlocker   File: BlockChunkProtector.java   Source Code and License 5 votes vote down vote up
/**
 * Constructor for the BlockChunkProtector class
 *
 * This method handles initializing the block and adding it to the GameRegistry.
 * This contructor is only called once per game launch.
 */
public BlockChunkProtector() {
	super(Material.ROCK);
	setUnlocalizedName(MobBlocker.MODID + ".chunkprotector");
	setRegistryName("chunkprotector");

	// If the Chunk Protector is configured to never decay, block is breakable so that it won't cause clutter.
	// Otherwise, it is unbreakable, because it shouldn't last in the world for all that long, and I can't figure out how to get it to drop with metadata intact.
	if (Config.ticksToLive != -1) setBlockUnbreakable();
	else {
		setHardness(1.5F);
		setResistance(18000000);
	}

	// Register block to GameRegistry
	GameRegistry.register(this);

	// Create anonymous class for the item form of this block
	// This allows the addition of custom tooltips that show how long the block will last in world once placed.
	GameRegistry.register(new ItemBlock(this) {
		@Override
		public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean adv) {
			// Only add tooltips if decay is enabled
			if (Config.ticksToLive != -1) {
				BlockChunkProtector.addStringToTooltip("&5Good for: &4" + Config.ticksToLive + " &5ticks", list);
			}
			else {
				return;
			}
		}
	}.setRegistryName(this.getRegistryName()));
	// Registers TileEntity associated with this block
	GameRegistry.registerTileEntity(TileEntityChunkProtector.class, MobBlocker.MODID + "_chunkprotector");
}
 
Example 34
Project: uniquecrops   File: BlockOldGravel.java   Source Code and License 5 votes vote down vote up
public BlockOldGravel() {
	
	setRegistryName("oldgravel");
	setUnlocalizedName(UniqueCrops.MOD_ID + ".oldgravel");
	setCreativeTab(UniqueCrops.TAB);
	setHardness(0.6F);
	setSoundType(SoundType.GROUND);
	GameRegistry.register(this);
	GameRegistry.register(new ItemBlock(this), getRegistryName());
}
 
Example 35
Project: SimplyTea   File: SimplyTea.java   Source Code and License 5 votes vote down vote up
public BlockTeaSapling(String name, boolean addToTab) {
	super();
	this.setSoundType(SoundType.PLANT);
	setUnlocalizedName(name);
	setRegistryName(SimplyTea.MODID+":"+name);
	if (addToTab){
		setCreativeTab(SimplyTea.tab);
	}
       this.setTickRandomly(true);
       itemBlock = (new ItemBlock(this).setRegistryName(this.getRegistryName()));
}
 
Example 36
Project: SimplyTea   File: SimplyTea.java   Source Code and License 5 votes vote down vote up
public BlockTeaTrunk(String name, boolean addToTab) {
super(Material.WOOD);
this.setSoundType(SoundType.WOOD);
setHarvestLevel("axe",-1);
setHardness(1.8f);
setUnlocalizedName(name);
setRegistryName(SimplyTea.MODID+":"+name);
if (addToTab){
	setCreativeTab(SimplyTea.tab);
}
this.setTickRandomly(true);
      itemBlock = (new ItemBlock(this).setRegistryName(this.getRegistryName()));
  }
 
Example 37
Project: Machines-and-Stuff   File: MBlocks.java   Source Code and License 5 votes vote down vote up
private static void registerBlock(Block block, String key, String texture, Class tile, CreativeTabs tab) {
    block.setUnlocalizedName(key).setCreativeTab(TAB);
    if(DEVENV && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
        writeFile(key, texture);
    renderMap.put(texture, block);
    GameRegistry.register(block, new ResourceLocation(Reference.MODID + ":" + key));
    GameRegistry.register(new ItemBlock(block), new ResourceLocation(Reference.MODID + ":" + key));
    if(tile != null) {
        GameRegistry.registerTileEntity(tile, key);
    }
}
 
Example 38
Project: Backmemed   File: Shaders.java   Source Code and License 5 votes vote down vote up
private static boolean isTranslucentBlock(ItemStack stack)
{
    if (stack == null)
    {
        return false;
    }
    else
    {
        Item item = stack.getItem();

        if (item == null)
        {
            return false;
        }
        else if (!(item instanceof ItemBlock))
        {
            return false;
        }
        else
        {
            ItemBlock itemblock = (ItemBlock)item;
            Block block = itemblock.getBlock();

            if (block == null)
            {
                return false;
            }
            else
            {
                BlockRenderLayer blockrenderlayer = block.getBlockLayer();
                return blockrenderlayer == BlockRenderLayer.TRANSLUCENT;
            }
        }
    }
}
 
Example 39
Project: CustomWorldGen   File: GameRegistry.java   Source Code and License 5 votes vote down vote up
/**
 * Use {@link #register(IForgeRegistryEntry)} instead
 */
@Deprecated
public static Block registerBlock(Block block)
{
    register(block);
    register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
    return block;
}
 
Example 40
Project: ChatBomb   File: ModBlocks.java   Source Code and License 5 votes vote down vote up
private static void registerBlock(Block block, String registryName, ItemBlock itemBlock, boolean inCreativeTab) {
    // Set the registry name.
    block.setRegistryName(Reference.MOD_ID, registryName);
    block.setUnlocalizedName(Reference.MOD_ID + "." + registryName);
    // Add to the game registry.
    GameRegistry.register(block);
    GameRegistry.register(itemBlock, block.getRegistryName());

    if (inCreativeTab)
        block.setCreativeTab(ChatBomb.creativeTab);

    System.out.println("Registered block ~ "+block.getRegistryName());

}
 
Example 41
Project: GlobalXP   File: GlobalXP.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	ModMetadata meta = event.getModMetadata();

	meta.authorList = Arrays.asList(new String[]{"bl4ckscor3"});
	meta.autogenerated = false;
	meta.description = "Adds a fast way to store XP and share it with your friends!";
	meta.modId = MOD_ID;
	meta.name = NAME;
	meta.version = VERSION;
	MinecraftForge.EVENT_BUS.register(new bl4ckscor3.mod.globalxp.handlers.EventHandler());
	config = new Config(event.getSuggestedConfigurationFile());
	network = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID);
	network.registerMessage(new SPacketUpdateXPBlock.Handler(), SPacketUpdateXPBlock.class, 0, Side.CLIENT);
	network.registerMessage(new CPacketRequestXPBlockUpdate.Handler(), CPacketRequestXPBlockUpdate.class, 1, Side.SERVER);
	xp_block = new XPBlock(Material.IRON);
	GameData.register_impl(xp_block);
	GameData.register_impl(new ItemBlock(xp_block).setRegistryName(xp_block.getRegistryName().toString()));
	GameRegistry.registerTileEntity(TileEntityXPBlock.class, xp_block.getRegistryName().toString());
	serverProxy.loadModels();
	serverProxy.registerRenderers();
}
 
Example 42
Project: FoodCraft-Reloaded   File: ItemFruitCake.java   Source Code and License 5 votes vote down vote up
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();
    Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(fruitType.toString(), "cake")));

    if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
        facing = EnumFacing.UP;
    else if (!block.isReplaceable(worldIn, pos))
        pos = pos.offset(facing);

    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
        IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);

        if (!worldIn.setBlockState(pos, blockState, 11))
            return EnumActionResult.FAIL;
        else {
            blockState = worldIn.getBlockState(pos);

            if (blockState.getBlock() == cake) {
                ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
                blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
            }

            SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
            worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            itemstack.shrink(1);
            return EnumActionResult.SUCCESS;
        }
    }
    else
        return EnumActionResult.FAIL;
}
 
Example 43
Project: uniquecrops   File: BlockTotemhead.java   Source Code and License 5 votes vote down vote up
public BlockTotemhead() {
	
	super("totemhead", Material.WOOD);
	setHardness(2.0F);
	setResistance(20.0F);
	setTickRandomly(true);
	GameRegistry.register(new ItemBlock(this), getRegistryName());
}
 
Example 44
Project: Got-Wood   File: MasterRegistrar.java   Source Code and License 5 votes vote down vote up
public static void register(FMLPreInitializationEvent e, List<?> list) {
	Iterator<?> iterator = list.iterator();
	while (iterator.hasNext()) {
		Object k = iterator.next();
		if (k instanceof Block) {
			Block block = (Block) k;
			ForgeRegistries.BLOCKS.register(block);
			BlockRegistry.registry.put(block.getRegistryName().getResourcePath(), block);
			if (!(k instanceof BlockSpecialFire) && !(k instanceof BlockWoodDoor)) {
				((Block) k).setCreativeTab(GotWood.TREE_TAB);
			}
			block.setUnlocalizedName(GotWood.ID + "." + block.getRegistryName().getResourcePath());
			if (!(k instanceof BlockDoubleSlab) && !ForgeRegistries.ITEMS.containsKey(block.getRegistryName())) {
				ForgeRegistries.ITEMS.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
			}
		} else if (k instanceof Item) {
			Item item = (Item) k;
			ForgeRegistries.ITEMS.register((Item) k);
			ItemRegistry.registry.put(item.getRegistryName().getResourcePath(), item);
			((Item) k).setCreativeTab(GotWood.TREE_TAB);
			((Item) k).setUnlocalizedName(GotWood.ID + "." + ((Item) k).getRegistryName().getResourcePath());
		}
	}
	if (e.getSide() == Side.CLIENT) {
		registerModels(list);
	}
}
 
Example 45
Project: DankNull   File: BlockContainerBase.java   Source Code and License 5 votes vote down vote up
public BlockContainerBase(Material materialIn, String name, float hardness, float resistance) {
	super(materialIn);
	setUnlocalizedName(name);
	setRegistryName(name);
	setResistance(resistance);
	setHardness(hardness);
	GameRegistry.register(this);
	GameRegistry.register(new ItemBlock(this), getRegistryName());
}
 
Example 46
Project: ArcaneMagic   File: ArcaneTransfigurationTableTESR.java   Source Code and License 5 votes vote down vote up
private void renderItem(ItemStack stack, int slot)
{

	if (stack != null && !stack.isEmpty())
	{
		int slotX = slot;
		int slotY = 0;

		if (slot >= 6)
		{
			slotX = slot - 6;
			slotY = 2;
		} else if (slot >= 3)
		{
			slotX = slot - 3;
			slotY = 1;
		}
		RenderHelper.enableStandardItemLighting();
		GlStateManager.enableLighting();
		GlStateManager.pushMatrix();
		GlStateManager.translate((slotX / 5.35d) + 0.315, .675, (slotY / 5.35d) + 0.315);
		GlStateManager.scale(.1f, .1f, .1f);
		if (!(stack.getItem() instanceof ItemBlock))
		{
			GlStateManager.rotate(-90, 1, 0, 0);
			GlStateManager.translate(0, 0, -0.5);
		}
		Minecraft.getMinecraft().getRenderItem().renderItem(stack, ItemCameraTransforms.TransformType.NONE);
		GlStateManager.popMatrix();
	}
}
 
Example 47
Project: SerenityCE   File: CopsVsCrims.java   Source Code and License 5 votes vote down vote up
public boolean isOnEnemyTeam(EntityPlayer target) {
    boolean teamChecks = false;
    ChatColor myCol = null;
    ChatColor enemyCol = null;
    if (target != null) {
        for (ChatColor col : ChatColor.values()) {
            if (col == ChatColor.RESET)
                continue;
            if (mc.thePlayer.getDisplayName().getFormattedText().contains(col.toString()) && myCol == null) {
                myCol = col;
            }
            if (target.getDisplayName().getFormattedText().contains(col.toString()) && enemyCol == null) {
                enemyCol = col;
            }
        }
        try {
            if (myCol != null && enemyCol != null) {
                teamChecks = myCol != enemyCol;
            } else {
                if (mc.thePlayer.getTeam() != null) {
                    teamChecks = !mc.thePlayer.isOnSameTeam(target);
                } else {
                    if (mc.thePlayer.inventory.armorInventory[3].getItem() instanceof ItemBlock) {
                        teamChecks = !ItemStack.areItemStacksEqual(mc.thePlayer.inventory.armorInventory[3], target.inventory.armorInventory[3]);
                    }
                }
            }
        } catch (Exception e) {}
    }

    return teamChecks;
}
 
Example 48
Project: Melodium   File: BlockBase.java   Source Code and License 5 votes vote down vote up
public BlockBase(Material materialIn, String name, boolean addToTab) {
	super(materialIn);
	setUnlocalizedName(name);
	setRegistryName(Melodium.MODID+":"+name);
	if (addToTab){
		setCreativeTab(Melodium.tab);
	}
	GameRegistry.register(this);
       GameRegistry.register(itemBlock = (new ItemBlock(this).setRegistryName(this.getRegistryName())));
}
 
Example 49
Project: BaseClient   File: EntityLiving.java   Source Code and License 5 votes vote down vote up
public boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)
{
    int i;

    if (inventorySlot == 99)
    {
        i = 0;
    }
    else
    {
        i = inventorySlot - 100 + 1;

        if (i < 0 || i >= this.equipment.length)
        {
            return false;
        }
    }

    if (itemStackIn == null || getArmorPosition(itemStackIn) == i || i == 4 && itemStackIn.getItem() instanceof ItemBlock)
    {
        this.setCurrentItemOrArmor(i, itemStackIn);
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 50
Project: BaseClient   File: EntityArmorStand.java   Source Code and License 5 votes vote down vote up
public boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)
{
    int i;

    if (inventorySlot == 99)
    {
        i = 0;
    }
    else
    {
        i = inventorySlot - 100 + 1;

        if (i < 0 || i >= this.contents.length)
        {
            return false;
        }
    }

    if (itemStackIn != null && EntityLiving.getArmorPosition(itemStackIn) != i && (i != 4 || !(itemStackIn.getItem() instanceof ItemBlock)))
    {
        return false;
    }
    else
    {
        this.setCurrentItemOrArmor(i, itemStackIn);
        return true;
    }
}
 
Example 51
Project: Valkyrien-Warfare-Drivers-for-OpenComputers   File: ModBlocks.java   Source Code and License 5 votes vote down vote up
private static <T extends Block> T register(T block, ItemBlock itemBlock) {
	GameRegistry.register(block);
	GameRegistry.register(itemBlock);
	
	if (block instanceof BlockBase) {
		((BlockBase)block).registerItemModel(itemBlock);
	}
	if(block instanceof BlockTileEntity) {
		GameRegistry.registerTileEntity(((BlockTileEntity<?>)block).getTileEntityClass(), block.getRegistryName().toString());
	}
	
	return block;
}
 
Example 52
Project: ProjectEon   File: CommonProxy.java   Source Code and License 5 votes vote down vote up
protected void register(IForgeRegistryEntry item, String name) {
    ResourceLocation loc = getName(name);
    GameRegistry.register(item, loc);

    if(item instanceof Block) {
        GameRegistry.register(new ItemBlock((Block)item).setRegistryName(loc));
    }
}
 
Example 53
Project: uniquecrops   File: BlockCropsBase.java   Source Code and License 5 votes vote down vote up
public BlockCropsBase(EnumCrops type, boolean extra, boolean canPlant) {
	
	this.type = type;
	this.extra = extra;
	this.canPlant = canPlant;
	this.clickHarvest = true;
	setRegistryName("crop" + type.getName());
	setUnlocalizedName(UniqueCrops.MOD_ID + ".crop" + type.getName());
	GameRegistry.register(this);
	GameRegistry.register(new ItemBlock(this), getRegistryName());
}
 
Example 54
Project: CustomWorldGen   File: GameRegistry.java   Source Code and License 5 votes vote down vote up
/**
 * Use {@link #register(IForgeRegistryEntry)} instead
 */
@Deprecated
public static Block registerBlock(Block block, Class<? extends ItemBlock> itemclass, String name, Object... itemCtorArgs)
{
    if (Strings.isNullOrEmpty(name))
    {
        throw new IllegalArgumentException("Attempted to register a block with no name: " + block);
    }
    if (Loader.instance().isInState(LoaderState.CONSTRUCTING))
    {
        FMLLog.warning("The mod %s is attempting to register a block whilst it it being constructed. This is bad modding practice - please use a proper mod lifecycle event.", Loader.instance().activeModContainer());
    }
    try
    {
        assert block != null : "registerBlock: block cannot be null";
        if (block.getRegistryName() != null && !block.getRegistryName().toString().equals(name))
            throw new IllegalArgumentException("Attempted to register a Block with conflicting names. Old: " + block.getRegistryName() + " New: " + name);
        ItemBlock i = null;
        if (itemclass != null)
        {
            Class<?>[] ctorArgClasses = new Class<?>[itemCtorArgs.length + 1];
            ctorArgClasses[0] = Block.class;
            for (int idx = 1; idx < ctorArgClasses.length; idx++)
            {
                ctorArgClasses[idx] = itemCtorArgs[idx - 1].getClass();
            }
            Constructor<? extends ItemBlock> itemCtor = itemclass.getConstructor(ctorArgClasses);
            i = itemCtor.newInstance(ObjectArrays.concat(block, itemCtorArgs));
        }
        // block registration has to happen first
        register(block.getRegistryName() == null ? block.setRegistryName(name) : block);
        if (i != null)
            register(i.setRegistryName(name));
        return block;
    } catch (Exception e)
    {
        FMLLog.log(Level.ERROR, e, "Caught an exception during block registration");
        throw new LoaderException(e);
    }
}
 
Example 55
Project: DecompiledMinecraft   File: EntityLiving.java   Source Code and License 5 votes vote down vote up
public boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)
{
    int i;

    if (inventorySlot == 99)
    {
        i = 0;
    }
    else
    {
        i = inventorySlot - 100 + 1;

        if (i < 0 || i >= this.equipment.length)
        {
            return false;
        }
    }

    if (itemStackIn != null && getArmorPosition(itemStackIn) != i && (i != 4 || !(itemStackIn.getItem() instanceof ItemBlock)))
    {
        return false;
    }
    else
    {
        this.setCurrentItemOrArmor(i, itemStackIn);
        return true;
    }
}
 
Example 56
Project: Loot-Slash-Conquer   File: ModBlocks.java   Source Code and License 4 votes vote down vote up
@SubscribeEvent
public void registerItemBlocks(RegistryEvent.Register<Item> event)
{
	event.getRegistry().register(new ItemBlock(DUNGEON_BRICK).setRegistryName(DUNGEON_BRICK.getRegistryName()));
}
 
Example 57
Project: CharcoalPit   File: BlockBase.java   Source Code and License 4 votes vote down vote up
@Deprecated
public void register(){
	ForgeRegistries.BLOCKS.register(this);
	ForgeRegistries.ITEMS.register(new ItemBlock(this).setRegistryName(getRegistryName()));
}
 
Example 58
Project: BetterBeginningsReborn   File: RegisterHelper.java   Source Code and License 4 votes vote down vote up
public static <T extends Block & IBBName> void registerBlock(IForgeRegistry<Block> blockRegistry, T block)
{
    registerBlock(blockRegistry, block, block.getName());
    itemBlocks.add(setupItem(new ItemBlock(block), block.getName()));
}
 
Example 59
Project: MineCamera   File: BlockLoader.java   Source Code and License 4 votes vote down vote up
private static void register(Block block, ItemBlock itemBlock, String name) {
	GameRegistry.registerBlock(block.setRegistryName(name), (Class<? extends ItemBlock>) null);
	GameRegistry.registerItem(itemBlock.setRegistryName(name));
	GameData.getBlockItemMap().put(block, itemBlock);
}
 
Example 60
Project: BaseClient   File: LayerCustomHead.java   Source Code and License 4 votes vote down vote up
public void doRenderLayer(EntityLivingBase entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale)
{
    ItemStack itemstack = entitylivingbaseIn.getCurrentArmor(3);

    if (itemstack != null && itemstack.getItem() != null)
    {
        Item item = itemstack.getItem();
        Minecraft minecraft = Minecraft.getMinecraft();
        GlStateManager.pushMatrix();

        if (entitylivingbaseIn.isSneaking())
        {
            GlStateManager.translate(0.0F, 0.2F, 0.0F);
        }

        boolean flag = entitylivingbaseIn instanceof EntityVillager || entitylivingbaseIn instanceof EntityZombie && ((EntityZombie)entitylivingbaseIn).isVillager();

        if (!flag && entitylivingbaseIn.isChild())
        {
            float f = 2.0F;
            float f1 = 1.4F;
            GlStateManager.scale(f1 / f, f1 / f, f1 / f);
            GlStateManager.translate(0.0F, 16.0F * scale, 0.0F);
        }

        this.field_177209_a.postRender(0.0625F);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

        if (item instanceof ItemBlock)
        {
            float f2 = 0.625F;
            GlStateManager.translate(0.0F, -0.25F, 0.0F);
            GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
            GlStateManager.scale(f2, -f2, -f2);

            if (flag)
            {
                GlStateManager.translate(0.0F, 0.1875F, 0.0F);
            }

            minecraft.getItemRenderer().renderItem(entitylivingbaseIn, itemstack, ItemCameraTransforms.TransformType.HEAD);
        }
        else if (item == Items.skull)
        {
            float f3 = 1.1875F;
            GlStateManager.scale(f3, -f3, -f3);

            if (flag)
            {
                GlStateManager.translate(0.0F, 0.0625F, 0.0F);
            }

            GameProfile gameprofile = null;

            if (itemstack.hasTagCompound())
            {
                NBTTagCompound nbttagcompound = itemstack.getTagCompound();

                if (nbttagcompound.hasKey("SkullOwner", 10))
                {
                    gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
                }
                else if (nbttagcompound.hasKey("SkullOwner", 8))
                {
                    String s = nbttagcompound.getString("SkullOwner");

                    if (!StringUtils.isNullOrEmpty(s))
                    {
                        gameprofile = TileEntitySkull.updateGameprofile(new GameProfile((UUID)null, s));
                        nbttagcompound.setTag("SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile));
                    }
                }
            }

            TileEntitySkullRenderer.instance.renderSkull(-0.5F, 0.0F, -0.5F, EnumFacing.UP, 180.0F, itemstack.getMetadata(), gameprofile, -1);
        }

        GlStateManager.popMatrix();
    }
}