mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 07:27:15 +01:00
Move fallback behaviour back to FluidReactions
This commit is contained in:
parent
70e8bc8140
commit
332455a4a5
3 changed files with 73 additions and 62 deletions
|
@ -1,32 +1,36 @@
|
|||
package com.simibubi.create.api.event;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Event that is fired when a two fluids meet in a pipe ({@link Flow})<br>
|
||||
* or when a fluid in a pipe meets with a fluid in the world ({@link Spill}).<br>
|
||||
* This Event is fired when a two fluids meet in a pipe ({@link Flow})<br>
|
||||
* or when a fluid in a pipe meets with a fluid in the world
|
||||
* ({@link Spill}).<br>
|
||||
* <br>
|
||||
* If it is not null, the event's BlockState will be placed in world after firing.
|
||||
* If it is not null, the event's BlockState will be placed in world after
|
||||
* firing.
|
||||
*/
|
||||
public class PipeCollisionEvent extends Event {
|
||||
|
||||
private final Level level;
|
||||
private final BlockPos pos;
|
||||
protected final Fluid fluid0, fluid1;
|
||||
protected final Fluid firstFluid, secondFluid;
|
||||
|
||||
@Nullable
|
||||
private BlockState state;
|
||||
|
||||
protected PipeCollisionEvent(Level level, BlockPos pos, Fluid fluid0, Fluid fluid1, @Nullable BlockState defaultState) {
|
||||
protected PipeCollisionEvent(Level level, BlockPos pos, Fluid firstFluid, Fluid secondFluid,
|
||||
@Nullable BlockState defaultState) {
|
||||
this.level = level;
|
||||
this.pos = pos;
|
||||
this.fluid0 = fluid0;
|
||||
this.fluid1 =fluid1;
|
||||
this.firstFluid = firstFluid;
|
||||
this.secondFluid = secondFluid;
|
||||
this.state = defaultState;
|
||||
}
|
||||
|
||||
|
@ -54,11 +58,11 @@ public class PipeCollisionEvent extends Event {
|
|||
}
|
||||
|
||||
public Fluid getFirstFluid() {
|
||||
return fluid0;
|
||||
return firstFluid;
|
||||
}
|
||||
|
||||
public Fluid getSecondFluid() {
|
||||
return fluid1;
|
||||
return secondFluid;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,11 +73,11 @@ public class PipeCollisionEvent extends Event {
|
|||
}
|
||||
|
||||
public Fluid getWorldFluid() {
|
||||
return fluid0;
|
||||
return firstFluid;
|
||||
}
|
||||
|
||||
public Fluid getPipeFluid() {
|
||||
return fluid1;
|
||||
return secondFluid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simibubi.create.content.fluids;
|
||||
|
||||
import com.simibubi.create.AllFluids;
|
||||
import com.simibubi.create.api.event.PipeCollisionEvent;
|
||||
import com.simibubi.create.foundation.advancement.AdvancementBehaviour;
|
||||
import com.simibubi.create.foundation.advancement.AllAdvancements;
|
||||
|
@ -7,12 +8,19 @@ import com.simibubi.create.foundation.fluid.FluidHelper;
|
|||
import com.simibubi.create.foundation.utility.BlockHelper;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.tags.FluidTags;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
||||
@EventBusSubscriber
|
||||
public class FluidReactions {
|
||||
|
||||
public static void handlePipeFlowCollision(Level level, BlockPos pos, FluidStack fluid, FluidStack fluid2) {
|
||||
|
@ -24,8 +32,27 @@ public class FluidReactions {
|
|||
|
||||
PipeCollisionEvent.Flow event = new PipeCollisionEvent.Flow(level, pos, f1, f2, null);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
if (event.getState() != null) {
|
||||
if (event.getState() != null)
|
||||
level.setBlockAndUpdate(pos, event.getState());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handlePipeFlowCollisionFallback(PipeCollisionEvent.Flow event) {
|
||||
Fluid f1 = event.getFirstFluid();
|
||||
Fluid f2 = event.getSecondFluid();
|
||||
|
||||
if (f1 == Fluids.WATER && f2 == Fluids.LAVA || f2 == Fluids.WATER && f1 == Fluids.LAVA) {
|
||||
event.setState(Blocks.COBBLESTONE.defaultBlockState());
|
||||
} else if (f1 == Fluids.LAVA && FluidHelper.hasBlockState(f2)) {
|
||||
BlockState lavaInteraction = AllFluids.getLavaInteraction(FluidHelper.convertToFlowing(f2).defaultFluidState());
|
||||
if (lavaInteraction != null) {
|
||||
event.setState(lavaInteraction);
|
||||
}
|
||||
} else if (f2 == Fluids.LAVA && FluidHelper.hasBlockState(f1)) {
|
||||
BlockState lavaInteraction = AllFluids.getLavaInteraction(FluidHelper.convertToFlowing(f1).defaultFluidState());
|
||||
if (lavaInteraction != null) {
|
||||
event.setState(lavaInteraction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,5 +66,33 @@ public class FluidReactions {
|
|||
level.setBlockAndUpdate(pos, event.getState());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handlePipeSpillCollisionFallback(PipeCollisionEvent.Spill event) {
|
||||
Fluid pf = event.getPipeFluid();
|
||||
Fluid wf = event.getWorldFluid();
|
||||
|
||||
if (FluidHelper.isTag(pf, FluidTags.WATER) && wf == Fluids.LAVA) {
|
||||
event.setState(Blocks.OBSIDIAN.defaultBlockState());
|
||||
} else if (pf == Fluids.WATER && wf == Fluids.FLOWING_LAVA) {
|
||||
event.setState(Blocks.COBBLESTONE.defaultBlockState());
|
||||
} else if (pf == Fluids.LAVA && wf == Fluids.WATER) {
|
||||
event.setState(Blocks.STONE.defaultBlockState());
|
||||
} else if (pf == Fluids.LAVA && wf == Fluids.FLOWING_LAVA) {
|
||||
event.setState(Blocks.COBBLESTONE.defaultBlockState());
|
||||
}
|
||||
|
||||
if (pf == Fluids.LAVA) {
|
||||
BlockState lavaInteraction = AllFluids.getLavaInteraction(wf.defaultFluidState());
|
||||
if (lavaInteraction != null) {
|
||||
event.setState(lavaInteraction);
|
||||
}
|
||||
} else if (wf == Fluids.FLOWING_LAVA && FluidHelper.hasBlockState(pf)) {
|
||||
BlockState lavaInteraction = AllFluids.getLavaInteraction(FluidHelper.convertToFlowing(pf).defaultFluidState());
|
||||
if (lavaInteraction != null) {
|
||||
event.setState(lavaInteraction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -124,54 +124,6 @@ public class CommonEvents {
|
|||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void whenPipeFluidsMeet(PipeCollisionEvent.Flow event) {
|
||||
Fluid f1 = event.getFirstFluid();
|
||||
Fluid f2 = event.getSecondFluid();
|
||||
|
||||
if (f1 == Fluids.WATER && f2 == Fluids.LAVA || f2 == Fluids.WATER && f1 == Fluids.LAVA) {
|
||||
event.setState(Blocks.COBBLESTONE.defaultBlockState());
|
||||
} else if (f1 == Fluids.LAVA && FluidHelper.hasBlockState(f2)) {
|
||||
BlockState lavaInteraction = AllFluids.getLavaInteraction(FluidHelper.convertToFlowing(f2).defaultFluidState());
|
||||
if (lavaInteraction != null) {
|
||||
event.setState(lavaInteraction);
|
||||
}
|
||||
} else if (f2 == Fluids.LAVA && FluidHelper.hasBlockState(f1)) {
|
||||
BlockState lavaInteraction = AllFluids.getLavaInteraction(FluidHelper.convertToFlowing(f1).defaultFluidState());
|
||||
if (lavaInteraction != null) {
|
||||
event.setState(lavaInteraction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void whenPipeSpillsIntoWorld(PipeCollisionEvent.Spill event) {
|
||||
Fluid pf = event.getPipeFluid();
|
||||
Fluid wf = event.getWorldFluid();
|
||||
|
||||
if (FluidHelper.isTag(pf, FluidTags.WATER) && wf == Fluids.LAVA) {
|
||||
event.setState(Blocks.OBSIDIAN.defaultBlockState());
|
||||
} else if (pf == Fluids.WATER && wf == Fluids.FLOWING_LAVA) {
|
||||
event.setState(Blocks.COBBLESTONE.defaultBlockState());
|
||||
} else if (pf == Fluids.LAVA && wf == Fluids.WATER) {
|
||||
event.setState(Blocks.STONE.defaultBlockState());
|
||||
} else if (pf == Fluids.LAVA && wf == Fluids.FLOWING_LAVA) {
|
||||
event.setState(Blocks.COBBLESTONE.defaultBlockState());
|
||||
}
|
||||
|
||||
if (pf == Fluids.LAVA) {
|
||||
BlockState lavaInteraction = AllFluids.getLavaInteraction(wf.defaultFluidState());
|
||||
if (lavaInteraction != null) {
|
||||
event.setState(lavaInteraction);
|
||||
}
|
||||
} else if (wf == Fluids.FLOWING_LAVA && FluidHelper.hasBlockState(pf)) {
|
||||
BlockState lavaInteraction = AllFluids.getLavaInteraction(FluidHelper.convertToFlowing(pf).defaultFluidState());
|
||||
if (lavaInteraction != null) {
|
||||
event.setState(lavaInteraction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerWorldTick(WorldTickEvent event) {
|
||||
if (event.phase == Phase.START)
|
||||
|
|
Loading…
Reference in a new issue