forked from DragonsPlusMinecraft/CreateDragonLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
23 deletions.
There are no files selected for viewing
40 changes: 18 additions & 22 deletions
40
src/main/java/plus/dragons/createdragonlib/fluid/FluidLavaReaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
package plus.dragons.createdragonlib.fluid; | ||
|
||
import java.util.IdentityHashMap; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; | ||
|
||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.material.FlowingFluid; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import java.util.IdentityHashMap; | ||
|
||
@SuppressWarnings("UnstableApiUsage") | ||
public record FluidLavaReaction(BlockState withLava, BlockState withFlowingLava, BlockState lavaOnSelf) { | ||
|
||
private static final IdentityHashMap<FluidVariant, FluidLavaReaction> REACTIONS = new IdentityHashMap<>(); | ||
|
||
public static void register(FluidVariant type, BlockState withLava, BlockState withFlowingLava, BlockState lavaOnSelf) { | ||
// TODO | ||
// FluidInteractionRegistry.addInteraction(ForgeMod.LAVA_TYPE.get(), new FluidInteractionRegistry.InteractionInformation( | ||
// type, fluidState -> fluidState.isSource() ? withLava : withFlowingLava | ||
// )); | ||
// FluidInteractionRegistry.addInteraction(type, new FluidInteractionRegistry.InteractionInformation( | ||
// ForgeMod.LAVA_TYPE.get(), lavaOnSelf | ||
// )); | ||
REACTIONS.put(type, new FluidLavaReaction(withLava, withFlowingLava, lavaOnSelf)); | ||
} | ||
|
||
@Nullable | ||
public static FluidLavaReaction get(FluidVariant fluid) { | ||
return REACTIONS.get(fluid); | ||
} | ||
|
||
|
||
private static final IdentityHashMap<FluidVariant, FluidLavaReaction> REACTIONS = new IdentityHashMap<>(); | ||
|
||
public static void register(FluidVariant type, BlockState withLava, BlockState withFlowingLava, BlockState lavaOnSelf) { | ||
REACTIONS.put(type, new FluidLavaReaction(withLava, withFlowingLava, lavaOnSelf)); | ||
} | ||
|
||
@Nullable | ||
public static FluidLavaReaction get(FlowingFluid fluid) { | ||
return REACTIONS.keySet().stream().anyMatch(variant -> variant.isOf(fluid.getSource())) ? REACTIONS.entrySet().stream().filter(p -> p.getKey().isOf(fluid.getSource())).findFirst().get().getValue() : null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/plus/dragons/createdragonlib/mixin/LavaFluidMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package plus.dragons.createdragonlib.mixin; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.tags.FluidTags; | ||
import net.minecraft.world.level.LevelAccessor; | ||
import net.minecraft.world.level.block.LiquidBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.material.FlowingFluid; | ||
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.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import plus.dragons.createdragonlib.fluid.FluidLavaReaction; | ||
|
||
@Mixin(LavaFluid.class) | ||
public class LavaFluidMixin { | ||
@Inject(method = "spreadTo", at = @At("HEAD"), cancellable = true) | ||
private void spread(LevelAccessor levelAccessor, BlockPos blockPos, BlockState blockState, Direction direction, FluidState fluidState, CallbackInfo ci) { | ||
if (direction == Direction.DOWN) { | ||
FluidState fluidState2 = levelAccessor.getFluidState(blockPos); | ||
if (fluidState.is(FluidTags.LAVA) && fluidState2.getType() instanceof FlowingFluid flow) { | ||
FluidLavaReaction reaction = FluidLavaReaction.get(flow); | ||
if (reaction == null) return; | ||
if (blockState.getBlock() instanceof LiquidBlock) | ||
levelAccessor.setBlock(blockPos, reaction.lavaOnSelf(), 3); | ||
levelAccessor.levelEvent(1501, blockPos, 0); | ||
ci.cancel(); | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/plus/dragons/createdragonlib/mixin/LiquidBlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package plus.dragons.createdragonlib.mixin; | ||
|
||
import static net.minecraft.world.level.block.LiquidBlock.POSSIBLE_FLOW_DIRECTIONS; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.tags.FluidTags; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.LiquidBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.material.FlowingFluid; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import plus.dragons.createdragonlib.fluid.FluidLavaReaction; | ||
|
||
@Mixin(LiquidBlock.class) | ||
public class LiquidBlockMixin { | ||
@Shadow | ||
@Final | ||
protected FlowingFluid fluid; | ||
|
||
@Inject(method = "shouldSpreadLiquid", at = @At("HEAD"), cancellable = true) | ||
@SuppressWarnings("deprecation") | ||
private void spread(Level level, BlockPos blockPos, BlockState blockState, CallbackInfoReturnable<Boolean> cir) { | ||
if (this.fluid.is(FluidTags.LAVA)) | ||
for (Direction direction : POSSIBLE_FLOW_DIRECTIONS) { | ||
BlockPos blockPos2 = blockPos.relative(direction.getOpposite()); | ||
FluidLavaReaction reaction = level.getFluidState(blockPos2).getType() instanceof FlowingFluid flow ? FluidLavaReaction.get(flow) : null; | ||
if (reaction != null) { | ||
BlockState state = level.getFluidState(blockPos).isSource() ? reaction.withLava() : reaction.withFlowingLava(); | ||
level.setBlockAndUpdate(blockPos, state); | ||
level.levelEvent(1501, blockPos, 0); | ||
cir.setReturnValue(false); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters