Spaces:
Build error
Build error
File size: 2,193 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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.LivingEntity;
import net.minecraft.world.entity.animal.Sheep;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import net.minecraft.world.level.block.entity.SignText;
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 p_41080_, Item.Properties p_41081_) {
super(p_41081_);
this.dyeColor = p_41080_;
ITEM_BY_COLOR.put(p_41080_, this);
}
@Override
public InteractionResult interactLivingEntity(ItemStack p_41085_, Player p_41086_, LivingEntity p_41087_, InteractionHand p_41088_) {
if (p_41087_ instanceof Sheep sheep && sheep.isAlive() && !sheep.isSheared() && sheep.getColor() != this.dyeColor) {
sheep.level().playSound(p_41086_, sheep, SoundEvents.DYE_USE, SoundSource.PLAYERS, 1.0F, 1.0F);
if (!p_41086_.level().isClientSide) {
sheep.setColor(this.dyeColor);
p_41085_.shrink(1);
}
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}
public DyeColor getDyeColor() {
return this.dyeColor;
}
public static DyeItem byColor(DyeColor p_41083_) {
return ITEM_BY_COLOR.get(p_41083_);
}
@Override
public boolean tryApplyToSign(Level p_277691_, SignBlockEntity p_277488_, boolean p_277951_, Player p_277932_) {
if (p_277488_.updateText(p_277649_ -> p_277649_.setColor(this.getDyeColor()), p_277951_)) {
p_277691_.playSound(null, p_277488_.getBlockPos(), SoundEvents.DYE_USE, SoundSource.BLOCKS, 1.0F, 1.0F);
return true;
} else {
return false;
}
}
} |