Skip to content

Commit

Permalink
feat: make lava fluid destroy certain malignant flesh blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Aug 11, 2024
1 parent 24e8e54 commit 543d55f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ protected void addTags(HolderLookup.Provider provider) {
.add(Blocks.MOSS_BLOCK, Blocks.VINE)
.addTag(BlockTags.FLOWERS);

tag(ModBlockTags.LAVA_DESTRUCTIBLE).add(
ModBlocks.MALIGNANT_FLESH_VEINS.get(),
ModBlocks.MALIGNANT_FLESH_SLAB.get(),
ModBlocks.MALIGNANT_FLESH_STAIRS.get(),
ModBlocks.MALIGNANT_FLESH_WALL.get(),
ModBlocks.PRIMAL_BLOOM.get(),
ModBlocks.PRIMAL_PERMEABLE_MEMBRANE.get(),
ModBlocks.PRIMAL_PERMEABLE_MEMBRANE_PANE.get()
);

tag(BlockTags.DOORS).add(ModBlocks.FLESH_DOOR.get()).add(ModBlocks.FULL_FLESH_DOOR.get());
tag(BlockTags.TRAPDOORS).add(ModBlocks.FLESH_IRIS_DOOR.get());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"values": [
"biomancy:malignant_flesh_veins",
"biomancy:malignant_flesh_slab",
"biomancy:malignant_flesh_stairs",
"biomancy:malignant_flesh_wall",
"biomancy:primal_bloom",
"biomancy:primal_permeable_membrane",
"biomancy:primal_permeable_membrane_pane"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public final class ModBlockTags {
public static final TagKey<Block> ALLOW_VEINS_TO_ATTACH = tag("allow_veins_to_attach");
public static final TagKey<Block> DISALLOW_VEINS_TO_ATTACH = tag("disallow_veins_to_attach");
public static final TagKey<Block> ACID_DESTRUCTIBLE = tag("acid_destructible");
public static final TagKey<Block> LAVA_DESTRUCTIBLE = tag("lava_destructible");

private ModBlockTags() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.github.elenterius.biomancy.mixin;

import com.github.elenterius.biomancy.init.tags.ModBlockTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FlowingFluid;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.LavaFluid;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(FlowingFluid.class)
public abstract class FlowingFluidMixin extends Fluid {

@Unique
private boolean biomancy$isLavaFluid() {
FlowingFluid fluid = (FlowingFluid) (Object) this;
return fluid instanceof LavaFluid;
}

@Inject(method = "canPassThrough", at = @At(value = "HEAD"), cancellable = true)
private void onCanPassThrough(BlockGetter level, Fluid fluid, BlockPos fromPos, BlockState fromBlockState, Direction direction, BlockPos toPos, BlockState toBlockState, FluidState toFluidState, CallbackInfoReturnable<Boolean> cir) {
if (biomancy$isLavaFluid() && toBlockState.is(ModBlockTags.LAVA_DESTRUCTIBLE)) {
cir.setReturnValue(true);
}
}

@Inject(method = "canSpreadTo", at = @At(value = "HEAD"), cancellable = true)
private void onCanSpreadTo(BlockGetter level, BlockPos fromPos, BlockState fromBlockState, Direction direction, BlockPos toPos, BlockState toBlockState, FluidState toFluidState, Fluid fluid, CallbackInfoReturnable<Boolean> cir) {
if (biomancy$isLavaFluid() && toBlockState.is(ModBlockTags.LAVA_DESTRUCTIBLE)) {
cir.setReturnValue(true);
}
}

@Inject(method = "spreadTo", at = @At(value = "HEAD"), cancellable = true)
private void onSpreadTo(LevelAccessor level, BlockPos pos, BlockState state, Direction direction, FluidState fluidState, CallbackInfo ci) {
if (biomancy$isLavaFluid() && state.is(ModBlockTags.LAVA_DESTRUCTIBLE)) {
level.setBlock(pos, fluidState.createLegacyBlock(), Block.UPDATE_ALL);
ci.cancel();
}
}

}
8 changes: 4 additions & 4 deletions src/main/resources/mixins.biomancy.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
},
"mixins": [
"AgeableMobAccessor", "AnimalMixin", "AreaEffectCloudMixin", "ArmorStandAccessor", "ArrowMixin", "BiomeAccessor", "ChickenMixin", "CowMixin",
"DamageSourceAccessor", "EntityAccessor", "IntegerPropertyAccessor", "LivingEntityAccessor", "LivingEntityMixin", "MobEffectInstanceAccessor",
"MobEffectInstanceMixin", "MobEntityAccessor", "PhantomMixin", "PigMixin", "PlayerMixin", "ServerLevelAccessor", "ServerLevelMixin", "SheepAccessor",
"SheepMixin", "SlimeAccessor", "SuspiciousStewItemAccessor", "SwordItemMixinAccessor", "TadpoleAccessor", "TextureSlotAccessor", "ThrownPotionMixin",
"UnbreakingEnchantmentMixin", "WallBlockMixin", "ZombieVillagerMixinAccessor"
"DamageSourceAccessor", "EntityAccessor", "FlowingFluidMixin", "IntegerPropertyAccessor", "LivingEntityAccessor", "LivingEntityMixin",
"MobEffectInstanceAccessor", "MobEffectInstanceMixin", "MobEntityAccessor", "PhantomMixin", "PigMixin", "PlayerMixin", "ServerLevelAccessor",
"ServerLevelMixin", "SheepAccessor", "SheepMixin", "SlimeAccessor", "SuspiciousStewItemAccessor", "SwordItemMixinAccessor", "TadpoleAccessor",
"TextureSlotAccessor", "ThrownPotionMixin", "UnbreakingEnchantmentMixin", "WallBlockMixin", "ZombieVillagerMixinAccessor"
],
"client": [
"client.ClientPackListenerMixin", "client.ClientRecipeBookMixin", "client.GuiGraphicsMixin", "client.PlayerRendererMixin", "client.RecipeCollectionAccessor"
Expand Down

0 comments on commit 543d55f

Please sign in to comment.