Skip to content

Commit

Permalink
Add Block Bonk sound
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Sep 7, 2024
1 parent 76b27be commit d24810e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ protected void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) {
tag.put(INVENTORY, items.serializeNBT(provider));
}

// Load data from NBT
@Override
public void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) {
super.loadAdditional(tag, provider);
Expand All @@ -54,9 +53,8 @@ public void addItem(ItemStack stack) {

public boolean removeItems() {
ItemStack storedStack = items.getStackInSlot(0);
if (!storedStack.isEmpty() && storedStack.getCount() > 0) {
if (!storedStack.isEmpty() && storedStack.getCount() > 0)
return true;
}
return false;
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/wenxin2/marioverse/init/SoundRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.neoforged.neoforge.registries.DeferredHolder;

public class SoundRegistry {
public static final DeferredHolder<SoundEvent, SoundEvent> BLOCK_BONK;
public static final DeferredHolder<SoundEvent, SoundEvent> COIN_PICKUP;
public static final DeferredHolder<SoundEvent, SoundEvent> COIN_PLACE;
public static final DeferredHolder<SoundEvent, SoundEvent> PIPES_LINKED;
Expand All @@ -21,6 +22,8 @@ public class SoundRegistry {
public static final DeferredHolder<SoundEvent, SoundEvent> WRENCH_BOUND;

static {
BLOCK_BONK = Marioverse.SOUNDS.register("block.block_bonk",
() -> SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "block.block_bonk")));
COIN_PICKUP = Marioverse.SOUNDS.register("block.coin_pickup",
() -> SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "block.coin_pickup")));
COIN_PLACE = Marioverse.SOUNDS.register("block.coin_place",
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.wenxin2.marioverse.blocks.entities.QuestionBlockEntity;
import com.wenxin2.marioverse.blocks.entities.WarpPipeBlockEntity;
import com.wenxin2.marioverse.init.ConfigRegistry;
import com.wenxin2.marioverse.init.SoundRegistry;
import com.wenxin2.marioverse.init.TagRegistry;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -102,6 +103,9 @@ public void baseTick() {
if (currentState.getBlock() instanceof QuestionBlock)
world.setBlock(pos, currentState.setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3);
}

if (state.getValue(QuestionBlock.EMPTY))
world.playSound(null, pos, SoundRegistry.BLOCK_BONK.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/marioverse/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"item.marioverse.pipe_wrench.tooltip.right_click": "Right-click: Opens pipe GUI",
"item.marioverse.pipe_wrench.tooltip.shift_right_click": "Shift-right-click: Binds pipes",

"subtitles.marioverse.block.block_bonk": "Block bonked",
"subtitles.marioverse.block.coin_pickup": "Coin picked up",
"subtitles.marioverse.block.coin_place": "Coin placed",
"subtitles.marioverse.block.pipes_linked": "Pipes linked",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/marioverse/sounds.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"block.block_bonk": {"category": "block", "sounds": [{ "name": "marioverse:block/block_bonk", "stream": false }],
"subtitle": "subtitles.marioverse.block.block_bonk" },

"block.coin_pickup": {"category": "block", "sounds": [{ "name": "marioverse:block/coin_pickup", "stream": false }],
"subtitle": "subtitles.marioverse.block.coin_pickup" },

Expand Down
Binary file not shown.

0 comments on commit d24810e

Please sign in to comment.