Search in sources :

Example 71 with ItemBlock

use of net.minecraft.item.ItemBlock in project BetterWithAddons by DaedalusGame.

the class ItemSpade method isItemDirt.

public static boolean isItemDirt(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    Item item = stack.getItem();
    if (item instanceof ItemBlock) {
        Block block = ((ItemBlock) item).getBlock();
        IBlockState state = block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, stack.getMetadata(), player, hand);
        return isDirt(stack, state);
    }
    return false;
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemBlock(net.minecraft.item.ItemBlock)

Example 72 with ItemBlock

use of net.minecraft.item.ItemBlock in project BetterWithAddons by DaedalusGame.

the class Packing method add.

@ZenMethod
public static void add(IItemStack output, IIngredient input) {
    ItemStack stack = CraftTweakerMC.getItemStack(output);
    if (stack.getItem() instanceof ItemBlock) {
        Block block = ((ItemBlock) stack.getItem()).getBlock();
        PackingRecipe r = new PackingRecipe(new IngredientCraftTweaker(input), block.getStateFromMeta(stack.getMetadata()));
        r.setJeiOutput(stack);
        CraftTweaker.LATE_ACTIONS.add(new Add(r));
    }
}
Also used : PackingRecipe(betterwithaddons.crafting.recipes.PackingRecipe) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) IngredientCraftTweaker(betterwithaddons.util.IngredientCraftTweaker) ItemStack(net.minecraft.item.ItemStack) IItemStack(crafttweaker.api.item.IItemStack) ItemBlock(net.minecraft.item.ItemBlock) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 73 with ItemBlock

use of net.minecraft.item.ItemBlock in project malmo by Microsoft.

the class MinecraftTypeHelper method attemptToGetAsVariant.

/**
 * 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 : bs.getProperties().keySet()) {
            Comparable<?> comp = bs.getValue(prop);
            Variation var = attemptToGetAsVariant(comp.toString());
            if (var != null)
                return var;
        }
        return null;
    } else
        return attemptToGetAsVariant(part);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ItemBlock(net.minecraft.item.ItemBlock) Variation(com.microsoft.Malmo.Schemas.Variation)

Example 74 with ItemBlock

use of net.minecraft.item.ItemBlock in project malmo by Microsoft.

the class CraftingHelper method dumpItemProperties.

/**
 * Little utility method for dumping out a list of all the Minecraft items, plus as many useful attributes as
 * we can find for them. This is primarily used by decision_tree_test.py but might be useful for real-world applications too.
 * @param filename location to save the dumped list.
 * @throws IOException
 */
public static void dumpItemProperties(String filename) throws IOException {
    FileOutputStream fos = new FileOutputStream("..//..//build//install//Python_Examples//item_database.json");
    OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
    BufferedWriter writer = new BufferedWriter(osw);
    JsonArray itemTypes = new JsonArray();
    for (ResourceLocation i : Item.REGISTRY.getKeys()) {
        Item item = Item.REGISTRY.getObject(i);
        if (item != null) {
            JsonObject json = new JsonObject();
            json.addProperty("type", Item.REGISTRY.getNameForObject(item).toString().replace("minecraft:", ""));
            json.addProperty("damageable", item.isDamageable());
            json.addProperty("rendersIn3D", item.isFull3D());
            json.addProperty("repairable", item.isRepairable());
            CreativeTabs tab = item.getCreativeTab();
            json.addProperty("tab", ((tab != null) ? item.getCreativeTab().getTabLabel() : "none"));
            ItemStack is = item.getDefaultInstance();
            json.addProperty("stackable", is.isStackable());
            json.addProperty("enchantable", is.isItemEnchantable());
            // Enum has four types, but only two (COMMON and RARE) appear to be used.
            json.addProperty("rare", (is.getRarity() == EnumRarity.RARE));
            json.addProperty("action", is.getItemUseAction().toString());
            json.addProperty("hasSubtypes", item.getHasSubtypes());
            json.addProperty("maxDamage", is.getMaxDamage());
            json.addProperty("maxUseDuration", is.getMaxItemUseDuration());
            json.addProperty("block", item instanceof ItemBlock);
            json.addProperty("hasContainerItem", item.hasContainerItem());
            if (item instanceof ItemBlock) {
                ItemBlock ib = (ItemBlock) item;
                Block b = ib.getBlock();
                IBlockState bs = b.getDefaultState();
                json.addProperty("slipperiness", b.slipperiness);
                json.addProperty("hardness", bs.getBlockHardness(null, null));
                json.addProperty("causesSuffocation", bs.causesSuffocation());
                json.addProperty("canProvidePower", bs.canProvidePower());
                json.addProperty("translucent", bs.isTranslucent());
                Material mat = bs.getMaterial();
                if (mat != null) {
                    json.addProperty("canBurn", mat.getCanBurn());
                    json.addProperty("isLiquid", mat.isLiquid());
                    json.addProperty("blocksMovement", mat.blocksMovement());
                    json.addProperty("needsNoTool", mat.isToolNotRequired());
                    json.addProperty("isReplaceable", mat.isReplaceable());
                    json.addProperty("pistonPushable", mat.getMobilityFlag() == EnumPushReaction.NORMAL);
                    json.addProperty("woodenMaterial", mat == Material.WOOD);
                    json.addProperty("ironMaterial", mat == Material.IRON);
                    json.addProperty("glassyMaterial", mat == Material.GLASS);
                    json.addProperty("clothMaterial", mat == Material.CLOTH);
                }
                boolean hasDirection = false;
                boolean hasColour = false;
                boolean hasVariant = false;
                for (IProperty prop : bs.getProperties().keySet()) {
                    System.out.println(Item.REGISTRY.getNameForObject(item).toString() + " -- " + prop);
                    if (prop instanceof PropertyDirection)
                        hasDirection = true;
                    if (prop instanceof PropertyEnum && prop.getName().equals("color"))
                        hasColour = true;
                    if (prop instanceof PropertyEnum && prop.getName().equals("variant")) {
                        hasVariant = true;
                        json.addProperty("variant", bs.getValue(prop).toString());
                    }
                }
                json.addProperty("hasDirection", hasDirection);
                json.addProperty("hasColour", hasColour);
                json.addProperty("hasVariant", hasVariant);
            }
            itemTypes.add(json);
        }
    }
    writer.write(itemTypes.toString());
    writer.close();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) PropertyDirection(net.minecraft.block.properties.PropertyDirection) JsonObject(com.google.gson.JsonObject) Material(net.minecraft.block.material.Material) CreativeTabs(net.minecraft.creativetab.CreativeTabs) PropertyEnum(net.minecraft.block.properties.PropertyEnum) ItemBlock(net.minecraft.item.ItemBlock) BufferedWriter(java.io.BufferedWriter) JsonArray(com.google.gson.JsonArray) Item(net.minecraft.item.Item) IProperty(net.minecraft.block.properties.IProperty) FileOutputStream(java.io.FileOutputStream) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) OutputStreamWriter(java.io.OutputStreamWriter) ItemStack(net.minecraft.item.ItemStack)

Example 75 with ItemBlock

use of net.minecraft.item.ItemBlock in project Almura by AlmuraDev.

the class CacheFeature method onPlayerCraftedItem.

@Listener
public void onPlayerCraftedItem(CraftItemEvent.Preview event) {
    final ItemStack result = ItemStackUtil.toNative(event.getPreview().getFinal().createStack());
    ;
    final Item resultItemType = result.getItem();
    // We only care about caches
    if (!(resultItemType instanceof ItemBlock) || !(((ItemBlock) resultItemType).getBlock() instanceof CacheBlock)) {
        return;
    }
    final CacheBlock resultCacheBlock = (CacheBlock) ((ItemBlock) resultItemType).getBlock();
    final ItemStack cacheStack = ItemStackUtil.toNative(event.getCraftingInventory().getCraftingGrid().query(QueryOperationTypes.ITEM_STACK_CUSTOM.of(stack -> ((Block) stack.getType().getBlock().orElse(null)) instanceof CacheBlock)).peek().orElse(org.spongepowered.api.item.inventory.ItemStack.empty()));
    // Safety check to ensure the cache stack is in the middle
    if (cacheStack.isEmpty() || !(cacheStack.getItem() instanceof ItemBlock) || !(((ItemBlock) cacheStack.getItem()).getBlock() instanceof CacheBlock)) {
        return;
    }
    final NBTTagCompound compound = cacheStack.getSubCompound("tag");
    if (compound == null) {
        return;
    }
    if (!compound.hasKey("Cache")) {
        return;
    }
    final NBTTagCompound cacheCompound = compound.getCompoundTag("Cache");
    if (!cacheCompound.hasKey(Almura.ID + ":single_slot")) {
        return;
    }
    final NBTTagCompound slotCompound = cacheCompound.getCompoundTag(Almura.ID + ":single_slot");
    if (!slotCompound.hasKey("Slot")) {
        return;
    }
    // Phew, we made it...
    // Set the new slot limit
    final int newSlotLimit = resultCacheBlock.getSlotLimit();
    final NBTTagCompound newSlotCompound = slotCompound.copy();
    newSlotCompound.setInteger("SlotLimit", newSlotLimit);
    // Copy the old compound and set the new single slot compound
    final NBTTagCompound newCompound = cacheStack.getTagCompound().copy();
    // Really not clean but its late and I'll make it better later..
    newCompound.getCompoundTag("tag").getCompoundTag("Cache").setTag(Almura.ID + ":single_slot", newSlotCompound);
    result.setTagCompound(newCompound);
    event.getPreview().setCustom(ItemStackUtil.fromNative(result));
}
Also used : Item(net.minecraft.item.Item) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CacheBlock(com.almuradev.almura.feature.cache.block.CacheBlock) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) Listener(org.spongepowered.api.event.Listener)

Aggregations

ItemBlock (net.minecraft.item.ItemBlock)78 Block (net.minecraft.block.Block)41 ItemStack (net.minecraft.item.ItemStack)37 Item (net.minecraft.item.Item)20 IBlockState (net.minecraft.block.state.IBlockState)11 EntityItem (net.minecraft.entity.item.EntityItem)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 TileEntity (net.minecraft.tileentity.TileEntity)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 IProperty (net.minecraft.block.properties.IProperty)3 RenderItem (net.minecraft.client.renderer.entity.RenderItem)3 EnumFacing (net.minecraft.util.EnumFacing)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 BlockPos (net.minecraft.util.math.BlockPos)3 AMVector3 (am2.api.math.AMVector3)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Tessellator (net.minecraft.client.renderer.Tessellator)2 ChatComponentText (net.minecraft.util.ChatComponentText)2