Search in sources :

Example 1 with IDyeableItem

use of pl.asie.charset.lib.item.IDyeableItem in project Charset by CharsetMC.

the class DyeableItemWashHandler method onBlockInteract.

@SubscribeEvent
public void onBlockInteract(PlayerInteractEvent.RightClickBlock event) {
    if (!event.getWorld().isRemote && !event.getEntityPlayer().isSneaking()) {
        ItemStack stack = event.getEntityPlayer().getHeldItem(event.getHand());
        if (!stack.isEmpty() && stack.getItem() instanceof IDyeableItem) {
            IBlockState state = event.getWorld().getBlockState(event.getPos());
            if (state.getBlock() instanceof BlockCauldron && state.getPropertyKeys().contains(BlockCauldron.LEVEL)) {
                event.setCanceled(true);
                int level = state.getValue(BlockCauldron.LEVEL);
                if (level > 0 && ((IDyeableItem) stack.getItem()).hasColor(stack)) {
                    if (((IDyeableItem) stack.getItem()).removeColor(stack)) {
                        event.getWorld().setBlockState(event.getPos(), state.withProperty(BlockCauldron.LEVEL, level - 1));
                        event.getEntityPlayer().addStat(StatList.ARMOR_CLEANED);
                    }
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IDyeableItem(pl.asie.charset.lib.item.IDyeableItem) BlockCauldron(net.minecraft.block.BlockCauldron) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IDyeableItem

use of pl.asie.charset.lib.item.IDyeableItem in project Charset by CharsetMC.

the class JEIRecipeDyeableItem method getIngredients.

@Override
public void getIngredients(IIngredients ingredients) {
    ingredients.setInputLists(ItemStack.class, JEIPluginCharset.STACKS.expandRecipeItemStackInputs(Lists.newArrayList(recipe.input, recipe.DYE)));
    ArrayList<ItemStack> stacks = new ArrayList<>();
    for (ItemStack stack : recipe.input.getMatchingStacks()) {
        IDyeableItem item = (IDyeableItem) stack.getItem();
        for (EnumDyeColor color : EnumDyeColor.values()) {
            ItemStack stackColored = stack.copy();
            item.setColor(stackColored, ColorUtils.toIntColor(color));
            stacks.add(stackColored);
        }
    }
    ingredients.setOutputLists(ItemStack.class, Collections.singletonList(stacks));
}
Also used : IDyeableItem(pl.asie.charset.lib.item.IDyeableItem) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) EnumDyeColor(net.minecraft.item.EnumDyeColor)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2 IDyeableItem (pl.asie.charset.lib.item.IDyeableItem)2 ArrayList (java.util.ArrayList)1 BlockCauldron (net.minecraft.block.BlockCauldron)1 IBlockState (net.minecraft.block.state.IBlockState)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1