-
Notifications
You must be signed in to change notification settings - Fork 15
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
1 parent
b237e76
commit dba8594
Showing
9 changed files
with
103 additions
and
59 deletions.
There are no files selected for viewing
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
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
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
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
14 changes: 9 additions & 5 deletions
14
src/main/java/dev/latvian/mods/kubejs/create/events/SpecialFluidHandlerEvent.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,18 +1,22 @@ | ||
package dev.latvian.mods.kubejs.create.events; | ||
|
||
import com.simibubi.create.content.fluids.OpenEndedPipe; | ||
import com.simibubi.create.api.effect.OpenPipeEffectHandler; | ||
import com.simibubi.create.foundation.fluid.FluidIngredient; | ||
import dev.latvian.mods.kubejs.create.platform.FluidIngredientHelper; | ||
import dev.latvian.mods.kubejs.event.EventJS; | ||
import dev.latvian.mods.kubejs.fluid.FluidStackJS; | ||
|
||
import java.util.function.BiConsumer; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.AABB; | ||
|
||
/** | ||
* @author Prunoideae | ||
*/ | ||
public class SpecialFluidHandlerEvent extends EventJS { | ||
public void add(FluidIngredient fluidIngredient, BiConsumer<OpenEndedPipe, FluidStackJS> handler) { | ||
OpenEndedPipe.registerEffectHandler(FluidIngredientHelper.createEffectHandler(fluidIngredient, handler)); | ||
public interface PipeHandler { | ||
void apply(Level level, AABB aabb, FluidStackJS fluid); | ||
} | ||
|
||
public void add(FluidIngredient fluidIngredient, PipeHandler handler) { | ||
OpenPipeEffectHandler.REGISTRY.registerProvider(FluidIngredientHelper.createEffectHandler(fluidIngredient, handler)); | ||
} | ||
} |
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
11 changes: 0 additions & 11 deletions
11
src/main/java/dev/latvian/mods/kubejs/create/platform/BoilerHeaterHelper.java
This file was deleted.
Oops, something went wrong.
74 changes: 54 additions & 20 deletions
74
src/main/java/dev/latvian/mods/kubejs/create/platform/FluidIngredientHelper.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,48 +1,82 @@ | ||
package dev.latvian.mods.kubejs.create.platform; | ||
|
||
import com.simibubi.create.api.behaviour.BlockSpoutingBehaviour; | ||
import com.simibubi.create.content.fluids.OpenEndedPipe; | ||
import com.simibubi.create.content.fluids.spout.SpoutBlockEntity; | ||
import com.simibubi.create.api.behaviour.spouting.BlockSpoutingBehaviour; | ||
import com.simibubi.create.api.effect.OpenPipeEffectHandler; | ||
import com.simibubi.create.api.registry.SimpleRegistry; | ||
import com.simibubi.create.foundation.fluid.FluidIngredient; | ||
import dev.architectury.hooks.fluid.forge.FluidStackHooksForge; | ||
import dev.latvian.mods.kubejs.block.state.BlockStatePredicate; | ||
import dev.latvian.mods.kubejs.create.events.SpecialFluidHandlerEvent; | ||
import dev.latvian.mods.kubejs.create.events.SpecialSpoutHandlerEvent; | ||
import dev.latvian.mods.kubejs.fluid.FluidStackJS; | ||
import dev.latvian.mods.kubejs.level.BlockContainerJS; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.event.TagsUpdatedEvent; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class FluidIngredientHelper { | ||
public static FluidIngredient toFluidIngredient(FluidStackJS fluidStack) { | ||
return FluidIngredient.fromFluidStack(FluidStackHooksForge.toForge(fluidStack.getFluidStack())); | ||
} | ||
|
||
public static OpenEndedPipe.IEffectHandler createEffectHandler(FluidIngredient fluidIngredient, BiConsumer<OpenEndedPipe, FluidStackJS> handler) { | ||
return new OpenEndedPipe.IEffectHandler() { | ||
public static SimpleRegistry.Provider<Fluid, OpenPipeEffectHandler> createEffectHandler(FluidIngredient fluidIngredient, SpecialFluidHandlerEvent.PipeHandler handler) { | ||
return new SimpleRegistry.Provider<>() { | ||
final FluidIngredient filter = fluidIngredient; | ||
Set<Fluid> validFluids = null; | ||
|
||
final OpenPipeEffectHandler internalHandler = (level, aabb, fluid) -> { | ||
if (filter.test(fluid)) { | ||
handler.apply(level, aabb, FluidStackJS.of(fluid)); | ||
} | ||
}; | ||
|
||
@Override | ||
public boolean canApplyEffects(OpenEndedPipe pipe, FluidStack fluid) { | ||
return fluidIngredient.test(fluid); | ||
public @Nullable OpenPipeEffectHandler get(Fluid fluidIn) { | ||
if (validFluids.contains(fluidIn)) { | ||
return internalHandler; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
private Set<Fluid> getValidFluids() { | ||
if (validFluids == null) { | ||
Set<Fluid> set = new HashSet<>(); | ||
for (FluidStack fluidStack : fluidIngredient.getMatchingFluidStacks()) { | ||
Fluid fluid = fluidStack.getFluid(); | ||
set.add(fluid); | ||
} | ||
validFluids = set; | ||
} | ||
return validFluids; | ||
} | ||
|
||
@Override | ||
public void applyEffects(OpenEndedPipe pipe, FluidStack fluid) { | ||
handler.accept(pipe, FluidStackJS.of(fluid)); | ||
public void onRegister(Runnable invalidate) { | ||
MinecraftForge.EVENT_BUS.addListener((TagsUpdatedEvent event) -> { | ||
if (event.shouldUpdateStaticData()) { | ||
invalidate.run(); | ||
filter.matchingFluidStacks = null; | ||
validFluids = null; | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
public static BlockSpoutingBehaviour createSpoutingHandler(BlockStatePredicate block, SpecialSpoutHandlerEvent.SpoutHandler handler) { | ||
return new BlockSpoutingBehaviour() { | ||
@Override | ||
public int fillBlock(Level world, BlockPos pos, SpoutBlockEntity spout, FluidStack availableFluid, boolean simulate) { | ||
if (!block.test(world.getBlockState(pos))) { | ||
return 0; | ||
} | ||
return (int) handler.fillBlock(new BlockContainerJS(world, pos), FluidStackJS.of(FluidStackHooksForge.fromForge(availableFluid)), simulate); | ||
public static SimpleRegistry.Provider<Block, BlockSpoutingBehaviour> createSpoutingHandler(BlockStatePredicate block, SpecialSpoutHandlerEvent.SpoutHandler handler) { | ||
final BlockSpoutingBehaviour internalHandler = (world, pos, spout, availableFluid, simulate) -> { | ||
if (!block.test(world.getBlockState(pos))) { | ||
return 0; | ||
} | ||
return (int) handler.fillBlock(new BlockContainerJS(world, pos), FluidStackJS.of(FluidStackHooksForge.fromForge(availableFluid)), simulate); | ||
}; | ||
return blockIn -> block.testBlock(blockIn) ? internalHandler : 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