2025-11-24 22:52:51 +03:00

70 lines
2.4 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.google.common.collect.Maps
*/
package net.minecraft.world.item;
import com.google.common.collect.Maps;
import java.util.Map;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.sheep.Sheep;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SignApplicator;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.SignBlockEntity;
public class DyeItem
extends Item
implements SignApplicator {
private static final Map<DyeColor, DyeItem> ITEM_BY_COLOR = Maps.newEnumMap(DyeColor.class);
private final DyeColor dyeColor;
public DyeItem(DyeColor dyeColor, Item.Properties properties) {
super(properties);
this.dyeColor = dyeColor;
ITEM_BY_COLOR.put(dyeColor, this);
}
@Override
public InteractionResult interactLivingEntity(ItemStack itemStack, Player player, LivingEntity target, InteractionHand type) {
Sheep sheep;
if (target instanceof Sheep && (sheep = (Sheep)target).isAlive() && !sheep.isSheared() && sheep.getColor() != this.dyeColor) {
sheep.level().playSound((Entity)player, sheep, SoundEvents.DYE_USE, SoundSource.PLAYERS, 1.0f, 1.0f);
if (!player.level().isClientSide()) {
sheep.setColor(this.dyeColor);
itemStack.shrink(1);
}
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}
public DyeColor getDyeColor() {
return this.dyeColor;
}
public static DyeItem byColor(DyeColor color) {
return ITEM_BY_COLOR.get(color);
}
@Override
public boolean tryApplyToSign(Level level, SignBlockEntity sign, boolean isFrontText, Player player) {
if (sign.updateText(text -> text.setColor(this.getDyeColor()), isFrontText)) {
level.playSound(null, sign.getBlockPos(), SoundEvents.DYE_USE, SoundSource.BLOCKS, 1.0f, 1.0f);
return true;
}
return false;
}
}