From 0848ab38e80011aa45692c5287b95a4056634867 Mon Sep 17 00:00:00 2001 From: Roelymole Date: Sat, 1 Feb 2025 15:08:20 +0000 Subject: [PATCH 1/2] fix: prevented candles from being lit when there is no oxygen and also extinguish soul torches/lanterns --- .../mod/mixin/AbstractCandleBlockMixin.java | 56 +++++++++++++++++++ .../mod/mixin/FireChargeItemMixin.java | 50 +++++++++++++++++ .../mod/mixin/FlintAndSteelItemMixin.java | 50 +++++++++++++++++ .../mod/mixin/LanternBlockMixin.java | 2 +- .../mod/mixin/TorchBlockMixin.java | 4 +- src/main/resources/galacticraft.mixins.json | 3 + 6 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 src/main/java/dev/galacticraft/mod/mixin/AbstractCandleBlockMixin.java create mode 100644 src/main/java/dev/galacticraft/mod/mixin/FireChargeItemMixin.java create mode 100644 src/main/java/dev/galacticraft/mod/mixin/FlintAndSteelItemMixin.java diff --git a/src/main/java/dev/galacticraft/mod/mixin/AbstractCandleBlockMixin.java b/src/main/java/dev/galacticraft/mod/mixin/AbstractCandleBlockMixin.java new file mode 100644 index 000000000..337ae15e5 --- /dev/null +++ b/src/main/java/dev/galacticraft/mod/mixin/AbstractCandleBlockMixin.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.mod.mixin; + +import dev.galacticraft.api.universe.celestialbody.CelestialBody; +import dev.galacticraft.mod.content.GCBlocks; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.AbstractCandleBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; + +@Mixin(AbstractCandleBlock.class) +public abstract class AbstractCandleBlockMixin extends Block { + public AbstractCandleBlockMixin(Properties settings) { + super(settings); + } + + @ModifyArgs(method = "onProjectileHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/AbstractCandleBlock;setLit(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Z)V")) + protected void onProjectileHit(Args args) { + Level level = args.get(0); + boolean original = args.get(3); + Holder> holder = level.galacticraft$getCelestialBody(); + args.set(3, original && (holder == null || holder.value().atmosphere().breathable())); + } +} diff --git a/src/main/java/dev/galacticraft/mod/mixin/FireChargeItemMixin.java b/src/main/java/dev/galacticraft/mod/mixin/FireChargeItemMixin.java new file mode 100644 index 000000000..13c64f0a6 --- /dev/null +++ b/src/main/java/dev/galacticraft/mod/mixin/FireChargeItemMixin.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.mod.mixin; + +import dev.galacticraft.api.universe.celestialbody.CelestialBody; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.world.item.FireChargeItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(FireChargeItem.class) +public abstract class FireChargeItemMixin extends Item { + FireChargeItemMixin() { + super(null); + } + + @Redirect(method = "useOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + public boolean useOn(Level level, BlockPos blockPos, BlockState blockState) { + Holder> holder = level.galacticraft$getCelestialBody(); + if (holder != null && !holder.value().atmosphere().breathable()) { + return false; + } + return level.setBlockAndUpdate(blockPos, blockState); + } +} \ No newline at end of file diff --git a/src/main/java/dev/galacticraft/mod/mixin/FlintAndSteelItemMixin.java b/src/main/java/dev/galacticraft/mod/mixin/FlintAndSteelItemMixin.java new file mode 100644 index 000000000..9818ecbe6 --- /dev/null +++ b/src/main/java/dev/galacticraft/mod/mixin/FlintAndSteelItemMixin.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.mod.mixin; + +import dev.galacticraft.api.universe.celestialbody.CelestialBody; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.world.item.FlintAndSteelItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(FlintAndSteelItem.class) +public abstract class FlintAndSteelItemMixin extends Item { + FlintAndSteelItemMixin() { + super(null); + } + + @Redirect(method = "useOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean useOn(Level level, BlockPos blockPos, BlockState blockState, int n) { + Holder> holder = level.galacticraft$getCelestialBody(); + if (holder != null && !holder.value().atmosphere().breathable()) { + return false; + } + return level.setBlock(blockPos, blockState, n); + } +} \ No newline at end of file diff --git a/src/main/java/dev/galacticraft/mod/mixin/LanternBlockMixin.java b/src/main/java/dev/galacticraft/mod/mixin/LanternBlockMixin.java index f37702e65..c8f88b0df 100644 --- a/src/main/java/dev/galacticraft/mod/mixin/LanternBlockMixin.java +++ b/src/main/java/dev/galacticraft/mod/mixin/LanternBlockMixin.java @@ -48,7 +48,7 @@ public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldS super.onPlace(state, world, pos, oldState, moved); Holder> holder = world.galacticraft$getCelestialBody(); if (holder != null && !holder.value().atmosphere().breathable()) { - if (state.getBlock() == Blocks.LANTERN) { + if (state.getBlock() instanceof LanternBlock lantern && lantern != GCBlocks.GLOWSTONE_LANTERN) { world.setBlockAndUpdate(pos, GCBlocks.UNLIT_LANTERN.defaultBlockState().setValue(LanternBlock.HANGING, state.getValue(LanternBlock.HANGING)).setValue(LanternBlock.WATERLOGGED, state.getValue(LanternBlock.WATERLOGGED))); } world.addParticle(ParticleTypes.SMOKE, pos.getX(), pos.getY(), pos.getZ(), 0.0D, 0.0D, 0.0D); diff --git a/src/main/java/dev/galacticraft/mod/mixin/TorchBlockMixin.java b/src/main/java/dev/galacticraft/mod/mixin/TorchBlockMixin.java index 5792b00ce..8c78eb81e 100644 --- a/src/main/java/dev/galacticraft/mod/mixin/TorchBlockMixin.java +++ b/src/main/java/dev/galacticraft/mod/mixin/TorchBlockMixin.java @@ -49,9 +49,9 @@ public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldS super.onPlace(state, world, pos, oldState, moved); Holder> body = world.galacticraft$getCelestialBody(); if (body != null && !body.value().atmosphere().breathable()) { - if (state.getBlock() == Blocks.TORCH) { + if (state.getBlock() instanceof TorchBlock torch && torch != GCBlocks.GLOWSTONE_TORCH) { world.setBlockAndUpdate(pos, GCBlocks.UNLIT_TORCH.defaultBlockState()); - } else if (state.getBlock() == Blocks.WALL_TORCH) { + } else if (state.getBlock() instanceof WallTorchBlock torch && torch != GCBlocks.GLOWSTONE_TORCH) { world.setBlockAndUpdate(pos, GCBlocks.UNLIT_WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, state.getValue(WallTorchBlock.FACING))); } world.addParticle(ParticleTypes.SMOKE, pos.getX(), pos.getY(), pos.getZ(), 0.0D, 0.0D, 0.0D); diff --git a/src/main/resources/galacticraft.mixins.json b/src/main/resources/galacticraft.mixins.json index 7532bf2f6..4a35d8cc6 100644 --- a/src/main/resources/galacticraft.mixins.json +++ b/src/main/resources/galacticraft.mixins.json @@ -4,6 +4,7 @@ "plugin": "dev.galacticraft.mod.GalacticraftMixinPlugin", "compatibilityLevel": "JAVA_21", "mixins": [ + "AbstractCandleBlockMixin", "AbstractContainerMenuAccessor", "AbstractSkeletonEntityAccessor", "BlockBehaviourMixin", @@ -11,6 +12,8 @@ "BucketItemMixin", "DimensionTypeMixin", "EntityMixin", + "FireChargeItemMixin", + "FlintAndSteelItemMixin", "FlowingFluidMixin", "GiveCommandMixin", "ItemEntityMixin", From 799913e67379ade685e12c9e6aea141526e0ed1d Mon Sep 17 00:00:00 2001 From: Roelymole Date: Mon, 3 Feb 2025 14:37:03 +0000 Subject: [PATCH 2/2] fix: extinguish campfires when they are placed in a non-breathable atmosphere and remove unused imports from AbstractCandleBlockMixin --- .../mod/mixin/AbstractCandleBlockMixin.java | 8 --- .../mod/mixin/CampfireBlockMixin.java | 55 +++++++++++++++++++ src/main/resources/galacticraft.mixins.json | 1 + 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 src/main/java/dev/galacticraft/mod/mixin/CampfireBlockMixin.java diff --git a/src/main/java/dev/galacticraft/mod/mixin/AbstractCandleBlockMixin.java b/src/main/java/dev/galacticraft/mod/mixin/AbstractCandleBlockMixin.java index 337ae15e5..5b033751a 100644 --- a/src/main/java/dev/galacticraft/mod/mixin/AbstractCandleBlockMixin.java +++ b/src/main/java/dev/galacticraft/mod/mixin/AbstractCandleBlockMixin.java @@ -23,18 +23,10 @@ package dev.galacticraft.mod.mixin; import dev.galacticraft.api.universe.celestialbody.CelestialBody; -import dev.galacticraft.mod.content.GCBlocks; -import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.sounds.SoundSource; import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.AbstractCandleBlock; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; diff --git a/src/main/java/dev/galacticraft/mod/mixin/CampfireBlockMixin.java b/src/main/java/dev/galacticraft/mod/mixin/CampfireBlockMixin.java new file mode 100644 index 000000000..62026b243 --- /dev/null +++ b/src/main/java/dev/galacticraft/mod/mixin/CampfireBlockMixin.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.mod.mixin; + +import dev.galacticraft.api.universe.celestialbody.CelestialBody; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.CampfireBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(CampfireBlock.class) +public abstract class CampfireBlockMixin extends Block { + public CampfireBlockMixin(Properties settings) { + super(settings); + } + + @Override + @Deprecated + public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean moved) { + super.onPlace(state, world, pos, oldState, moved); + Holder> body = world.galacticraft$getCelestialBody(); + if (body != null && !body.value().atmosphere().breathable()) { + world.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.LIT, false)); + world.addParticle(ParticleTypes.SMOKE, pos.getX(), pos.getY(), pos.getZ(), 0.0D, 0.0D, 0.0D); + world.playLocalSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.GENERIC_EXTINGUISH_FIRE, SoundSource.BLOCKS, 1.0F, 0.9F, false); + } + } +} diff --git a/src/main/resources/galacticraft.mixins.json b/src/main/resources/galacticraft.mixins.json index 4a35d8cc6..25ee013a8 100644 --- a/src/main/resources/galacticraft.mixins.json +++ b/src/main/resources/galacticraft.mixins.json @@ -10,6 +10,7 @@ "BlockBehaviourMixin", "BucketItemAccessor", "BucketItemMixin", + "CampfireBlockMixin", "DimensionTypeMixin", "EntityMixin", "FireChargeItemMixin",