Skip to content

Commit

Permalink
Add duration tooltip to Core GUI sustain
Browse files Browse the repository at this point in the history
  • Loading branch information
IONayrus committed Jan 25, 2025
1 parent 31b967c commit f5bc8ee
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod_name=Note Block Master
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GNU GPLv3
# The mod version. See https://semver.org/
mod_version=0.7.5.1
mod_version=0.7.5.2
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.world.phys.shapes.EntityCollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.nayrus.noteblockmaster.item.SpinningCore;
import net.nayrus.noteblockmaster.item.TunerItem;
import net.nayrus.noteblockmaster.screen.CoreScreen;
import net.nayrus.noteblockmaster.setup.NBMTags;
Expand Down Expand Up @@ -79,7 +80,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
if(!(context instanceof EntityCollisionContext eCon) || eCon.equals(CollisionContext.empty())) return COLLISION;
if(eCon.getEntity() instanceof Player player
&& FinalTuple.getHeldItems(player).contains(TunerItem.class)) return COLLISION;
&& FinalTuple.getHeldItems(player).contains(TunerItem.class, SpinningCore.class)) return COLLISION;
return Shapes.empty();
}

Expand Down Expand Up @@ -122,14 +123,15 @@ public static int getVolume(BlockState state){

@Override
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if(!stack.is(NBMTags.Items.TUNERS)) return super.useItemOn(stack, state, level, pos, player, hand, hitResult);
if(!(stack.is(NBMTags.Items.TUNERS) || (stack.is(NBMTags.Items.CORES)))) return super.useItemOn(stack, state, level, pos, player, hand, hitResult);
BlockState anb = level.getBlockState(pos.below());
if(!anb.is(Registry.ADVANCED_NOTEBLOCK)){
if(!level.isClientSide()) level.scheduleTick(pos, state.getBlock(), 0);
return ItemInteractionResult.SUCCESS;
}
if(level.isClientSide()){
Minecraft.getInstance().setScreen(new CoreScreen(state, pos, anb.getValue(AdvancedNoteBlock.INSTRUMENT).getSustains()));
Minecraft.getInstance().setScreen(new CoreScreen(state, pos, anb.getValue(AdvancedNoteBlock.INSTRUMENT),
AdvancedNoteBlock.getPitchFromNote(AdvancedNoteBlock.getNoteValue(anb))));
}
return ItemInteractionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ public InteractionResult addCoreToAdvancedNoteBlock(Level level, Player player,
return InteractionResult.CONSUME;
}
if(hand.equals(InteractionHand.OFF_HAND)) player.swing(hand);
return InteractionResult.PASS;
return InteractionResult.CONSUME;
}

public InteractionResult addCoreToTuningCore(Level level, Player player, BlockPos pos, BlockState state, ItemStack stack, InteractionHand hand, AdvancedInstrument instrument){
if(stack.is(Registry.SUSTAIN) ){
if(TuningCore.isSustaining(state)) return InteractionResult.PASS;
if(TuningCore.isSustaining(state)) return InteractionResult.SUCCESS;
if(level.isClientSide()) return Utils.swingHelper(player, hand, true);
level.setBlockAndUpdate(pos, state.setValue(TuningCore.SUSTAIN, instrument.getSustains()));
}else{
if(TuningCore.isMixing(state)) return InteractionResult.PASS;
if(TuningCore.isMixing(state)) return InteractionResult.SUCCESS;
if(level.isClientSide()) return Utils.swingHelper(player, hand, true);
level.setBlockAndUpdate(pos, state.setValue(TuningCore.VOLUME, 20));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public NBMRenderType(String name, VertexFormat format, VertexFormat.Mode mode, i
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setTextureState(NO_TEXTURE)
.setDepthTestState(NO_DEPTH_TEST)
.setCullState(NO_CULL)
.setCullState(CULL)
.setLightmapState(NO_LIGHTMAP)
.setWriteMaskState(COLOR_WRITE)
.createCompositeState(false));
Expand All @@ -30,7 +30,7 @@ public NBMRenderType(String name, VertexFormat format, VertexFormat.Mode mode, i
.setLayeringState(VIEW_OFFSET_Z_LAYERING)
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setTextureState(NO_TEXTURE)
.setCullState(NO_CULL)
.setCullState(CULL)
.setLightmapState(NO_LIGHTMAP)
.setWriteMaskState(COLOR_DEPTH_WRITE)
.createCompositeState(false));
Expand Down
30 changes: 23 additions & 7 deletions src/main/java/net/nayrus/noteblockmaster/screen/CoreScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.state.BlockState;
import net.nayrus.noteblockmaster.screen.base.BaseCoreScreen;
import net.nayrus.noteblockmaster.screen.widget.IntegerEditBox;
import net.nayrus.noteblockmaster.screen.widget.ValueSlider;
import net.nayrus.noteblockmaster.sound.AdvancedInstrument;

import java.awt.*;
import java.util.Locale;

public class CoreScreen extends BaseCoreScreen {

protected final AdvancedInstrument instrument;
protected final int maxSustain;
protected final float scale;

public CoreScreen(BlockState state, BlockPos pos, int maxSustain) {
public CoreScreen(BlockState state, BlockPos pos, AdvancedInstrument instrument, float pitch) {
super(state, pos);
this.maxSustain = maxSustain;
this.instrument = instrument;
this.maxSustain = instrument.getSustains();
this.scale = 1/pitch;
}

private static final int COMP_HEIGHT = 19;
Expand All @@ -39,16 +48,17 @@ protected void init() {
}
});

this.sustainBox = new IntegerEditBox(this.font, getRelX() + 138, getRelY() + 28, 27, COMP_HEIGHT, this.maxSustain,true);
this.sustainBox = new IntegerEditBox(this.font, getRelX() + 138, getRelY() + 28, 27, COMP_HEIGHT, maxSustain,true);
this.sustainBox.setEditable(isSustaining);
this.sustainBox.setValue(isSustaining ? Integer.toString(this.sustain) : Integer.toString(this.maxSustain));
this.sustainBox.setValue(isSustaining ? Integer.toString(this.sustain) : Integer.toString(maxSustain));
this.sustainBox.setMaxLength(3);
this.sustainBox.setResponder(s -> {
if(!s.isEmpty()) {
int _new = Integer.parseInt(s);
if(_new < 1) _new = 1;
this.sustain = _new;
this.sustainSlider.setValue((_new - 1)/ (this.maxSustain > 1 ? (this.maxSustain - 1.0F) : 1.0F));
this.sustainSlider.setValue((_new - 1)/ (maxSustain > 1 ? (maxSustain - 1.0F) : 1.0F));
this.sustainSlider.setTooltip(getTooltip());
}
});

Expand All @@ -67,12 +77,13 @@ protected void init() {
this.volSlider.setMessage(Component.literal("Volume"));

this.sustainSlider = new ValueSlider(getRelX() + 10, getRelY() + 28, 118, COMP_HEIGHT,
isSustaining ? (this.sustain - 1) / (this.maxSustain - 1.0) : 1.0, !isSustaining ? null : (val) -> {
this.sustain = (int) (val * (this.maxSustain - 1) + 1);
isSustaining ? (this.sustain - 1) / (maxSustain - 1.0) : 1.0, !isSustaining ? null : (val) -> {
this.sustain = (int) (val * (maxSustain - 1) + 1);
this.sustainBox.setValue(Integer.toString(this.sustain));
});
this.sustainSlider.active = isSustaining;
this.sustainSlider.setMessage(Component.literal("Sustain"));
this.sustainSlider.setTooltip(getTooltip());

addRenderableWidget(this.volBox);
addRenderableWidget(this.volSlider);
Expand All @@ -92,4 +103,9 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
this.onClose();
return super.keyPressed(keyCode, scanCode, modifiers);
}

public Tooltip getTooltip(){
return Tooltip.create(Component.literal(String.format(Locale.US,"%.2f",
this.instrument.getSustainTime(this.sustain != -1 ? this.sustain : 1) * this.scale) + " ms").withColor(Color.LIGHT_GRAY.getRGB()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ public boolean contains(Item item) {
return getA().is(item) || getB().is(item);
}

public boolean contains(Class<? extends Item> itemclass) {
return itemclass.isInstance(getA().getItem()) || itemclass.isInstance(getB().getItem());
@SafeVarargs
public final boolean contains(Class<? extends Item>... itemclasses) {
for(Class<? extends Item> itemclass : itemclasses){
if(itemclass.isInstance(getA().getItem()) || itemclass.isInstance(getB().getItem())) return true;
}
return false;
}

public ItemStack getFirst(Item item){
Expand Down

0 comments on commit f5bc8ee

Please sign in to comment.