Skip to content

Commit

Permalink
Allow dyeing sheep using dyed bottles (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Mar 9, 2019
1 parent 13707a0 commit 9885038
Showing 1 changed file with 31 additions and 0 deletions.
Expand Up @@ -2,12 +2,18 @@

import knightminer.inspirations.library.Util;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.ItemHandlerHelper;

public class ItemDyedWaterBottle extends Item {

Expand Down Expand Up @@ -82,4 +88,29 @@ public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems) {
}
}
}

/** Dye sheep on right click with a bottle */
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase target, EnumHand hand) {
int meta = stack.getMetadata();
if (meta <= 15 && target instanceof EntitySheep) {
EntitySheep sheep = (EntitySheep)target;
EnumDyeColor color = EnumDyeColor.byDyeDamage(meta);
if (!sheep.getSheared() && sheep.getFleeceColor() != color) {
sheep.setFleeceColor(color);
player.playSound(SoundEvents.ITEM_BOTTLE_EMPTY, 1.0F, 1.0F);

// give back bottle;
ItemStack bottle = new ItemStack(getContainerItem());
if (stack.getCount() == 1) {
player.setHeldItem(hand, bottle);
} else {
stack.shrink(1);
ItemHandlerHelper.giveItemToPlayer(player, bottle);
}
}
return true;
}
return false;
}
}

0 comments on commit 9885038

Please sign in to comment.