Make BOP dyes work on sheep and wolf collars

This commit is contained in:
Cheeserolls 2015-04-19 23:01:46 +01:00
parent f2b073fdb8
commit e9bba1cce6
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright 2014, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.handler;
import biomesoplenty.api.item.BOPItems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class DyeEventHandler
{
@SubscribeEvent
public void entityInteract(EntityInteractEvent event)
{
ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
if (stack == null) {return;}
Item item = stack.getItem();
EnumDyeColor dyeColor;
if (item == BOPItems.black_dye) {dyeColor = EnumDyeColor.BLACK;}
else if (item == BOPItems.blue_dye) {dyeColor = EnumDyeColor.BLUE;}
else if (item == BOPItems.brown_dye) {dyeColor = EnumDyeColor.BROWN;}
else if (item == BOPItems.green_dye) {dyeColor = EnumDyeColor.GREEN;}
else if (item == BOPItems.white_dye) {dyeColor = EnumDyeColor.WHITE;}
else {return;}
Entity target = event.target;
if (target instanceof EntityWolf)
{
EntityWolf wolf = (EntityWolf)target;
if (dyeColor != wolf.getCollarColor())
{
wolf.setCollarColor(dyeColor);
if (!event.entityPlayer.capabilities.isCreativeMode) {--stack.stackSize;}
event.setResult(Result.ALLOW);
}
}
else if (target instanceof EntitySheep)
{
EntitySheep sheep = (EntitySheep)target;
if (!sheep.getSheared() && dyeColor != sheep.getFleeceColor())
{
sheep.setFleeceColor(dyeColor);
if (!event.entityPlayer.capabilities.isCreativeMode) {--stack.stackSize;}
event.setResult(Result.ALLOW);
}
}
}
}

View File

@ -9,6 +9,7 @@
package biomesoplenty.common.init;
import net.minecraftforge.common.MinecraftForge;
import biomesoplenty.common.handler.DyeEventHandler;
import biomesoplenty.common.handler.GuiEventHandler;
import biomesoplenty.common.handler.decoration.DecorateBiomeEventHandler;
@ -20,5 +21,6 @@ public class ModHandlers
MinecraftForge.EVENT_BUS.register(decorateBiomeHandler);
MinecraftForge.TERRAIN_GEN_BUS.register(decorateBiomeHandler);
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
MinecraftForge.EVENT_BUS.register(new DyeEventHandler());
}
}