minecraft-source/src/net/minecraft/world/item/FireChargeItem.java

54 lines
2.2 KiB
Java

package net.minecraft.world.item;
import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.FireBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.InteractionResult;
public class FireChargeItem extends Item {
public FireChargeItem(final Properties a) {
super(a);
}
@Override
public InteractionResult useOn(final UseOnContext bfw) {
final Level bjt3 = bfw.getLevel();
BlockPos fk4 = bfw.getClickedPos();
final BlockState byg5 = bjt3.getBlockState(fk4);
boolean boolean6 = false;
if (byg5.getBlock() == Blocks.CAMPFIRE) {
if (!byg5.<Boolean>getValue((Property<Boolean>)CampfireBlock.LIT) && !byg5.<Boolean>getValue((Property<Boolean>)CampfireBlock.WATERLOGGED)) {
this.playSound(bjt3, fk4);
bjt3.setBlockAndUpdate(fk4, ((AbstractStateHolder<O, BlockState>)byg5).<Comparable, Boolean>setValue((Property<Comparable>)CampfireBlock.LIT, true));
boolean6 = true;
}
}
else {
fk4 = fk4.relative(bfw.getClickedFace());
if (bjt3.getBlockState(fk4).isAir()) {
this.playSound(bjt3, fk4);
bjt3.setBlockAndUpdate(fk4, ((FireBlock)Blocks.FIRE).getStateForPlacement(bjt3, fk4));
boolean6 = true;
}
}
if (boolean6) {
bfw.getItemInHand().shrink(1);
return InteractionResult.SUCCESS;
}
return InteractionResult.FAIL;
}
private void playSound(final Level bjt, final BlockPos fk) {
bjt.playSound(null, fk, SoundEvents.FIRECHARGE_USE, SoundSource.BLOCKS, 1.0f, (FireChargeItem.random.nextFloat() - FireChargeItem.random.nextFloat()) * 0.2f + 1.0f);
}
}