45 lines
1.3 KiB
Java
45 lines
1.3 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import com.google.common.collect.Maps;
|
|
import net.minecraft.world.entity.animal.Sheep;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import java.util.Map;
|
|
|
|
public class DyeItem extends Item {
|
|
private static final Map<DyeColor, DyeItem> ITEM_BY_COLOR;
|
|
private final DyeColor dyeColor;
|
|
|
|
public DyeItem(final DyeColor bdg, final Properties a) {
|
|
super(a);
|
|
this.dyeColor = bdg;
|
|
DyeItem.ITEM_BY_COLOR.put(bdg, this);
|
|
}
|
|
|
|
@Override
|
|
public boolean interactEnemy(final ItemStack bek, final Player ayg, final LivingEntity akw, final InteractionHand ajh) {
|
|
if (akw instanceof Sheep) {
|
|
final Sheep ats6 = (Sheep)akw;
|
|
if (ats6.isAlive() && !ats6.isSheared() && ats6.getColor() != this.dyeColor) {
|
|
ats6.setColor(this.dyeColor);
|
|
bek.shrink(1);
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public DyeColor getDyeColor() {
|
|
return this.dyeColor;
|
|
}
|
|
|
|
public static DyeItem byColor(final DyeColor bdg) {
|
|
return DyeItem.ITEM_BY_COLOR.get(bdg);
|
|
}
|
|
|
|
static {
|
|
ITEM_BY_COLOR = Maps.<DyeColor, Object>newEnumMap(DyeColor.class);
|
|
}
|
|
}
|