123 lines
4.9 KiB
Java
123 lines
4.9 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.item.Item;
|
|
import net.minecraft.world.item.RecordItem;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.item.ItemEntity;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.entity.JukeboxBlockEntity;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
|
|
public class JukeboxBlock extends BaseEntityBlock {
|
|
public static final BooleanProperty HAS_RECORD;
|
|
|
|
protected JukeboxBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Boolean>setValue((Property<Comparable>)JukeboxBlock.HAS_RECORD, false));
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
|
|
if (byg.<Boolean>getValue((Property<Boolean>)JukeboxBlock.HAS_RECORD)) {
|
|
this.dropRecording(bjt, fk);
|
|
byg = ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Boolean>setValue((Property<Comparable>)JukeboxBlock.HAS_RECORD, false);
|
|
bjt.setBlock(fk, byg, 2);
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
return InteractionResult.PASS;
|
|
}
|
|
|
|
public void setRecord(final LevelAccessor bju, final BlockPos fk, final BlockState byg, final ItemStack bek) {
|
|
final BlockEntity bwi6 = bju.getBlockEntity(fk);
|
|
if (!(bwi6 instanceof JukeboxBlockEntity)) {
|
|
return;
|
|
}
|
|
((JukeboxBlockEntity)bwi6).setRecord(bek.copy());
|
|
bju.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Boolean>setValue((Property<Comparable>)JukeboxBlock.HAS_RECORD, true), 2);
|
|
}
|
|
|
|
private void dropRecording(final Level bjt, final BlockPos fk) {
|
|
if (bjt.isClientSide) {
|
|
return;
|
|
}
|
|
final BlockEntity bwi4 = bjt.getBlockEntity(fk);
|
|
if (!(bwi4 instanceof JukeboxBlockEntity)) {
|
|
return;
|
|
}
|
|
final JukeboxBlockEntity bwz5 = (JukeboxBlockEntity)bwi4;
|
|
final ItemStack bek6 = bwz5.getRecord();
|
|
if (bek6.isEmpty()) {
|
|
return;
|
|
}
|
|
bjt.levelEvent(1010, fk, 0);
|
|
bwz5.clearContent();
|
|
final float float7 = 0.7f;
|
|
final double double8 = bjt.random.nextFloat() * 0.7f + 0.15000000596046448;
|
|
final double double9 = bjt.random.nextFloat() * 0.7f + 0.06000000238418579 + 0.6;
|
|
final double double10 = bjt.random.nextFloat() * 0.7f + 0.15000000596046448;
|
|
final ItemStack bek7 = bek6.copy();
|
|
final ItemEntity avy15 = new ItemEntity(bjt, fk.getX() + double8, fk.getY() + double9, fk.getZ() + double10, bek7);
|
|
avy15.setDefaultPickUpDelay();
|
|
bjt.addFreshEntity(avy15);
|
|
}
|
|
|
|
@Override
|
|
public void onRemove(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
|
|
if (byg1.getBlock() == byg4.getBlock()) {
|
|
return;
|
|
}
|
|
this.dropRecording(bjt, fk);
|
|
super.onRemove(byg1, bjt, fk, byg4, boolean5);
|
|
}
|
|
|
|
@Override
|
|
public BlockEntity newBlockEntity(final BlockGetter bjd) {
|
|
return new JukeboxBlockEntity();
|
|
}
|
|
|
|
@Override
|
|
public boolean hasAnalogOutputSignal(final BlockState byg) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getAnalogOutputSignal(final BlockState byg, final Level bjt, final BlockPos fk) {
|
|
final BlockEntity bwi5 = bjt.getBlockEntity(fk);
|
|
if (bwi5 instanceof JukeboxBlockEntity) {
|
|
final Item bef6 = ((JukeboxBlockEntity)bwi5).getRecord().getItem();
|
|
if (bef6 instanceof RecordItem) {
|
|
return ((RecordItem)bef6).getAnalogOutput();
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public RenderShape getRenderShape(final BlockState byg) {
|
|
return RenderShape.MODEL;
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(JukeboxBlock.HAS_RECORD);
|
|
}
|
|
|
|
static {
|
|
HAS_RECORD = BlockStateProperties.HAS_RECORD;
|
|
}
|
|
}
|