Skip to content

Commit

Permalink
Instrument is set on quick place, Fix info render layer, Fix double p…
Browse files Browse the repository at this point in the history
…layback on server
  • Loading branch information
IONayrus committed Feb 3, 2025
1 parent 00726ea commit c9c73c9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void loadPropertiesFromConfig(final NewRegistryEvent ignoredEvent)
TuningCore.loadSustainProperty();
}

private BlockState setInstrument(LevelReader reader, BlockPos pos, BlockState state) {
public BlockState setInstrument(LevelReader reader, BlockPos pos, BlockState state) {
NoteBlockInstrument noteblockinstrument = reader.getBlockState(pos.below()).instrument();
AdvancedInstrument instrument = noteblockinstrument.worksAboveNoteBlock() ? AdvancedInstrument.HARP : AdvancedInstrument.values()[noteblockinstrument.ordinal()];
BlockState above = reader.getBlockState(pos.above());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public InteractionResult addCoreToAdvancedNoteBlock(Level level, Player player,
return InteractionResult.CONSUME;
}
if(hand.equals(InteractionHand.OFF_HAND)) player.swing(hand);
return InteractionResult.CONSUME;
return InteractionResult.SUCCESS;
}

public InteractionResult addCoreToTuningCore(Level level, Player player, BlockPos pos, BlockState state, ItemStack stack, InteractionHand hand, AdvancedInstrument instrument){
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/net/nayrus/noteblockmaster/item/TunerItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.nayrus.noteblockmaster.block.AdvancedNoteBlock;
Expand Down Expand Up @@ -82,16 +81,16 @@ public InteractionResult useOn(UseOnContext context, boolean doOffHandSwing) {

private static void placeAdvancedNoteBlock(Level level, ItemStack tuner, BlockPos pos, TunerData data, ItemStack composer, Player player, Inventory inv) {
if(!level.isClientSide()){
Block block = Registry.ADVANCED_NOTEBLOCK.get();
AdvancedNoteBlock block = (AdvancedNoteBlock) Registry.ADVANCED_NOTEBLOCK.get();
if(tuner.is(Registry.NOTETUNER)) {
BlockState state = block.defaultBlockState().setValue(AdvancedNoteBlock.NOTE, data.value() + AdvancedNoteBlock.MIN_NOTE_VAL);
if(composer.is(Registry.TEMPOTUNER)) state = state.setValue(AdvancedNoteBlock.SUBTICK, getTunerData(composer).value());
level.setBlockAndUpdate(pos.above(), state);
level.setBlockAndUpdate(pos.above(), block.setInstrument(level, pos.above(), state));
}
else{
if(composer.is(Registry.COMPOSER)){
ComposeData cData = ComposeData.getComposeData(composer);
level.setBlockAndUpdate(pos.above(), block.defaultBlockState()
level.setBlockAndUpdate(pos.above(), block.setInstrument(level, pos.above(), block.defaultBlockState())
.setValue(AdvancedNoteBlock.SUBTICK, cData.subtick()));
if(!player.isShiftKeyDown()){
Tuple<Integer, Integer> next = ComposersNote.subtickAndPauseOnBeat(cData.beat() + 1, cData.bpm());
Expand All @@ -101,7 +100,7 @@ private static void placeAdvancedNoteBlock(Level level, ItemStack tuner, BlockPo
else{
BlockState state = block.defaultBlockState().setValue(AdvancedNoteBlock.SUBTICK, data.value());
if(composer.is(Registry.NOTETUNER)) state = state.setValue(AdvancedNoteBlock.NOTE, getTunerData(composer).value() + AdvancedNoteBlock.MIN_NOTE_VAL);
level.setBlockAndUpdate(pos.above(), state);
level.setBlockAndUpdate(pos.above(), block.setInstrument(level, pos.above(), state));
}
}
level.playSound(null, pos, SoundType.WOOD.getPlaceSound(), SoundSource.BLOCKS, 1.0F, 0.8F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public static void renderInfoLabel(MultiBufferSource.BufferSource buffer, PoseSt
matrix.pushPose();
matrix.translate(pos.getX() + 0.5, pos.getY() + 1.6F, pos.getZ() + 0.5);

renderInfoText(buffer, matrix, pos, text, RenderUtils.applyAlpha(RenderUtils.shiftColor(Color.LIGHT_GRAY, color, 0.8F), alpha), scale, new Vector3f(),0);
renderInfoText(buffer, matrix, pos, text, RenderUtils.applyAlpha(RenderUtils.shiftColor(color, Color.BLACK, 0.5F), alpha / 1.25F), scale, new Vector3f(-0.008F),0);
renderInfoText(buffer, matrix, pos, text, RenderUtils.applyAlpha(RenderUtils.shiftColor(Color.LIGHT_GRAY, color, 0.8F), alpha), scale, new Vector3f(),0);
renderInfoText(buffer, matrix, pos, " ".repeat(text.length() + 2), Color.BLACK, scale - 0.003F, new Vector3f(0.0F,0F,-0.02F), RenderUtils.applyAlpha(RenderUtils.shiftColor(Color.WHITE, color, 0.33F), alpha / 3.0F).getRGB());

matrix.popPose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,14 @@ public static void delayedNoteBlockEvent(BlockState state, Level level, BlockPos
}

public static void delayedCoredNoteBlockEvent(BlockState anb, BlockState core, Level level, BlockPos pos, AdvancedInstrument instrument){
if(!(level instanceof ServerLevel serverLevel)) {
delayedCoredNoteBlockEvent(
pos,
TuningCore.getSustain(core),
AdvancedNoteBlock.getNoteValue(anb),
(TuningCore.getVolume(core) / 20.0F),
instrument, TuningCore.isMixing(core),
anb.getValue(AdvancedNoteBlock.SUBTICK));
}else{
NetworkUtil.broadcastCoreSound(serverLevel, ScheduleCoreSound.of(
pos,
TuningCore.getSustain(core),
AdvancedNoteBlock.getNoteValue(anb),
(TuningCore.getVolume(core) / 20.0F),
instrument, TuningCore.isMixing(core),
anb.getValue(AdvancedNoteBlock.SUBTICK)));
}
if(!(level instanceof ServerLevel serverLevel)) return;
NetworkUtil.broadcastCoreSound(serverLevel, ScheduleCoreSound.of(
pos,
TuningCore.getSustain(core),
AdvancedNoteBlock.getNoteValue(anb),
(TuningCore.getVolume(core) / 20.0F),
instrument, TuningCore.isMixing(core),
anb.getValue(AdvancedNoteBlock.SUBTICK)));
}

@OnlyIn(Dist.CLIENT)
Expand Down

0 comments on commit c9c73c9

Please sign in to comment.