Added Pouch Cleaning like Leather Armor
This commit is contained in:
parent
dbd4db3c79
commit
da73d6ddbc
2 changed files with 44 additions and 9 deletions
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.oitsjustjose.criss_cross.event;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.oitsjustjose.criss_cross.items.ItemPouch;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
|
public class PouchCleanEvent
|
||||||
|
{
|
||||||
|
@SubscribeEvent
|
||||||
|
public void registerEvent(PlayerInteractEvent event)
|
||||||
|
{
|
||||||
|
if (event.action != event.action.RIGHT_CLICK_BLOCK || event.world.getBlockState(event.pos) == null)
|
||||||
|
return;
|
||||||
|
if (event.entityPlayer.getHeldItem() == null || !(event.entityPlayer.getHeldItem().getItem() instanceof ItemPouch))
|
||||||
|
return;
|
||||||
|
|
||||||
|
EntityPlayer player = event.entityPlayer;
|
||||||
|
ItemPouch pouch = (ItemPouch) player.getHeldItem().getItem();
|
||||||
|
World world = event.world;
|
||||||
|
Random rand = world.rand;
|
||||||
|
|
||||||
|
if (world.getBlockState(event.pos).getBlock() != Blocks.cauldron || event.world.getBlockState(event.pos) == Blocks.cauldron.getStateFromMeta(0))
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (pouch.hasColor(player.getHeldItem()))
|
||||||
|
{
|
||||||
|
pouch.removeColor(player.getHeldItem());
|
||||||
|
world.setBlockState(event.pos, Blocks.cauldron.getStateFromMeta(Blocks.cauldron.getMetaFromState(world.getBlockState(event.pos)) - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,22 +1,16 @@
|
||||||
package com.oitsjustjose.criss_cross.items;
|
package com.oitsjustjose.criss_cross.items;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.oitsjustjose.criss_cross.CrissCross;
|
import com.oitsjustjose.criss_cross.CrissCross;
|
||||||
|
import com.oitsjustjose.criss_cross.event.PouchCleanEvent;
|
||||||
import com.oitsjustjose.criss_cross.gui.GUIHandler;
|
import com.oitsjustjose.criss_cross.gui.GUIHandler;
|
||||||
import com.oitsjustjose.criss_cross.lib.Lib;
|
import com.oitsjustjose.criss_cross.lib.Lib;
|
||||||
import com.oitsjustjose.criss_cross.util.ColorUtils;
|
|
||||||
|
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.EnumDyeColor;
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemArmor;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumChatFormatting;
|
|
||||||
import net.minecraft.util.StatCollector;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
@ -29,6 +23,7 @@ public class ItemPouch extends Item
|
||||||
this.setUnlocalizedName(Lib.modid + ".pouch");
|
this.setUnlocalizedName(Lib.modid + ".pouch");
|
||||||
this.setCreativeTab(CrissCross.CCTab);
|
this.setCreativeTab(CrissCross.CCTab);
|
||||||
GameRegistry.registerItem(this, this.getUnlocalizedName());
|
GameRegistry.registerItem(this, this.getUnlocalizedName());
|
||||||
|
MinecraftForge.EVENT_BUS.register(new PouchCleanEvent());
|
||||||
Lib.add(this);
|
Lib.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,7 +33,7 @@ public class ItemPouch extends Item
|
||||||
return (!stack.hasTagCompound() ? false : (!stack.getTagCompound().hasKey("display", 10) ? false : stack.getTagCompound().getCompoundTag("display").hasKey("color", 3)));
|
return (!stack.hasTagCompound() ? false : (!stack.getTagCompound().hasKey("display", 10) ? false : stack.getTagCompound().getCompoundTag("display").hasKey("color", 3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(ItemStack stack, int color)
|
public void setColor(ItemStack stack, int color)
|
||||||
{
|
{
|
||||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue