diff --git a/src/main/java/de/dafuqs/spectrum/blocks/decoration/GemstoneChimeBlock.java b/src/main/java/de/dafuqs/spectrum/blocks/decoration/GemstoneChimeBlock.java index db0608fc11..a9d54715b4 100644 --- a/src/main/java/de/dafuqs/spectrum/blocks/decoration/GemstoneChimeBlock.java +++ b/src/main/java/de/dafuqs/spectrum/blocks/decoration/GemstoneChimeBlock.java @@ -1,15 +1,29 @@ package de.dafuqs.spectrum.blocks.decoration; import com.mojang.serialization.*; +import de.dafuqs.spectrum.registries.*; import net.minecraft.core.*; import net.minecraft.core.particles.*; +import net.minecraft.core.registries.*; +import net.minecraft.resources.*; +import net.minecraft.server.level.*; import net.minecraft.sounds.*; +import net.minecraft.tags.*; import net.minecraft.util.*; +import net.minecraft.world.*; +import net.minecraft.world.entity.player.*; +import net.minecraft.world.item.*; +import net.minecraft.world.item.context.*; import net.minecraft.world.level.*; import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.state.*; +import net.minecraft.world.level.block.state.properties.*; import net.minecraft.world.level.pathfinder.*; +import net.minecraft.world.phys.*; import net.minecraft.world.phys.shapes.*; +import net.neoforged.bus.api.*; +import net.neoforged.neoforge.common.*; +import net.neoforged.neoforge.event.entity.player.*; import org.jspecify.annotations.*; public class GemstoneChimeBlock extends Block { @@ -21,11 +35,14 @@ public class GemstoneChimeBlock extends Block { protected final SoundEvent soundEvent; protected final ParticleOptions particleEffect; + //Is Muted holder + public static final BooleanProperty IS_MUTED = BooleanProperty.create("is_muted"); public GemstoneChimeBlock(Properties settings, SoundEvent soundEvent, ParticleOptions particleEffect) { super(settings); this.soundEvent = soundEvent; this.particleEffect = particleEffect; + registerDefaultState(stateDefinition.any().setValue(IS_MUTED, false)); } @Override @@ -36,16 +53,19 @@ public GemstoneChimeBlock(Properties settings, SoundEvent soundEvent, ParticleOp @Override public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource random) { - super.animateTick(state, world, pos, random); - - world.addParticle(particleEffect, - pos.getX() + 0.25 + random.nextDouble() * 0.5, - pos.getY() + 0.15 + random.nextDouble() * 0.5, - pos.getZ() + 0.25 + random.nextDouble() * 0.5, - 0, -0.02 - random.nextDouble() * 0.025, 0); - - if (random.nextFloat() < 0.2) { - world.playLocalSound(pos.getX(), pos.getY(), pos.getZ(), soundEvent, SoundSource.BLOCKS, 0.7F + random.nextFloat() * 0.4F, 0.75F + random.nextFloat() * 0.5F, true); + //Check if it's muted before running the following code. + boolean muteState = state.getValue(IS_MUTED); + if (!muteState) { + super.animateTick(state, world, pos, random); + world.addParticle(particleEffect, + pos.getX() + 0.25 + random.nextDouble() * 0.5, + pos.getY() + 0.15 + random.nextDouble() * 0.5, + pos.getZ() + 0.25 + random.nextDouble() * 0.5, + 0, -0.02 - random.nextDouble() * 0.025, 0); + + if (random.nextFloat() < 0.2) { + world.playLocalSound(pos.getX(), pos.getY(), pos.getZ(), soundEvent, SoundSource.BLOCKS, 0.7F + random.nextFloat() * 0.4F, 0.75F + random.nextFloat() * 0.5F, true); + } } } @@ -74,4 +94,37 @@ public ParticleOptions getParticleEffect() { return this.particleEffect; } + @Override + protected void createBlockStateDefinition(StateDefinition.Builder pBuilder){ + pBuilder.add(IS_MUTED); + } + + //Mute with wool, Unmute with Empty + @Override + public ItemInteractionResult useItemOn(ItemStack handStack, BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + //If the hand contains an item version of what is in the block tag #c:wools, switch block state to the muted variant and set isMuted to true + + if (handStack.is(SpectrumItemTags.WOOLS)){ + setMuted(state.setValue(IS_MUTED, true), world, pos); + return ItemInteractionResult.SUCCESS; + }else if (handStack.isEmpty()){ + setMuted(state.setValue(IS_MUTED, false), world, pos); + return ItemInteractionResult.SUCCESS; + } + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + + } + // + static void setMuted(BlockState state, Level world, BlockPos pos){ + world.setBlockAndUpdate(pos, state); + } + + //Additional Helper for BlockStates + @Override + @Nullable + public BlockState getStateForPlacement(BlockPlaceContext pContext) { + // code that determines which state will be used when + // placing down this block, depending on the BlockPlaceContext + return defaultBlockState(); + } } diff --git a/src/main/java/de/dafuqs/spectrum/registries/SpectrumItemTags.java b/src/main/java/de/dafuqs/spectrum/registries/SpectrumItemTags.java index 3b42f36f09..f7d5e72735 100644 --- a/src/main/java/de/dafuqs/spectrum/registries/SpectrumItemTags.java +++ b/src/main/java/de/dafuqs/spectrum/registries/SpectrumItemTags.java @@ -11,6 +11,7 @@ public class SpectrumItemTags { // "c" namespace public static final TagKey SKULLS = conventional("skulls"); public static final TagKey FRUITS = conventional("foods/fruit"); + public static final TagKey WOOLS = conventional("wools"); // "spectrum" namespace public static final TagKey FISHING_RODS = spectrum("fishing_rods"); diff --git a/src/main/resources/assets/spectrum/lang/en_us.json b/src/main/resources/assets/spectrum/lang/en_us.json index 02925d14c7..cc6e3d041d 100644 --- a/src/main/resources/assets/spectrum/lang/en_us.json +++ b/src/main/resources/assets/spectrum/lang/en_us.json @@ -2698,6 +2698,8 @@ "book.spectrum.guidebook.gemstone_armor.page5.text": "Gives me a short burst of Speed and Invisibility when hit, allowing me to retreat. Perfect for ranged combat.", "book.spectrum.guidebook.gemstone_chimes.name": "Gemstone Chimes", "book.spectrum.guidebook.gemstone_chimes.page0.text": "Having tinkered with the gems long enough, I find myself able to shape these fragile resources in the finest of ways. Slowly swaying in the breeze, the chimes' sounds remind me of the beginning of my journey – the first time I set foot in a geode. I remember it well. What a time it was!\\\nEach chime emits the soothing sound of its corresponding gemstone.", + "book.spectrum.guidebook.gemstone_chimes.muting.name": "Chime Muting", + "book.spectrum.guidebook.gemstone_chimes.page1.text": "If for some reason it's getting on my nerves, I can silence them by interacting with a little bit of wool, and I can undo this with bare hands.", "book.spectrum.guidebook.gemstone_glass.name": "Gemstone Glass", "book.spectrum.guidebook.gemstone_glass.page0.text": "Gemstones are already slightly transparent by nature. What could be more natural than using them to make a kind of glass?\\\nI can also make matching Glass Panes from them.", "book.spectrum.guidebook.gemstone_glass.page1.text": "I can build them out of every gemstone I found.", diff --git a/src/main/resources/data/c/tags/item/wools.json b/src/main/resources/data/c/tags/item/wools.json new file mode 100644 index 0000000000..0cf3103c27 --- /dev/null +++ b/src/main/resources/data/c/tags/item/wools.json @@ -0,0 +1,20 @@ +{ + "values": [ + "minecraft:black_wool", + "minecraft:blue_wool", + "minecraft:brown_wool", + "minecraft:cyan_wool", + "minecraft:gray_wool", + "minecraft:green_wool", + "minecraft:light_blue_wool", + "minecraft:light_gray_wool", + "minecraft:lime_wool", + "minecraft:magenta_wool", + "minecraft:orange_wool", + "minecraft:pink_wool", + "minecraft:purple_wool", + "minecraft:red_wool", + "minecraft:white_wool", + "minecraft:yellow_wool" + ] +} \ No newline at end of file diff --git a/src/main/resources/data/spectrum/modonomicon/books/guidebook/entries/decoration/gemstone_chimes.json b/src/main/resources/data/spectrum/modonomicon/books/guidebook/entries/decoration/gemstone_chimes.json index bf0f3c0178..7bc348416f 100644 --- a/src/main/resources/data/spectrum/modonomicon/books/guidebook/entries/decoration/gemstone_chimes.json +++ b/src/main/resources/data/spectrum/modonomicon/books/guidebook/entries/decoration/gemstone_chimes.json @@ -27,6 +27,11 @@ "title": "book.spectrum.guidebook.gemstone_chimes.name", "text": "book.spectrum.guidebook.gemstone_chimes.page0.text" }, + { + "type": "modonomicon:text", + "title": "book.spectrum.guidebook.gemstone_chimes.muting.name", + "text": "book.spectrum.guidebook.gemstone_chimes.page1.text" + }, { "type": "spectrum:pedestal_crafting", "title": "container.spectrum.rei.pedestal_recipe",