From cb9a9d7784768450b48dc784fb9fb2f8a6e1d840 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sat, 29 Jan 2022 19:18:15 -0800 Subject: [PATCH 01/10] Fluid Flow API --- library/fluid/build.gradle | 8 ++ library/fluid/fluid-flow/build.gradle | 12 ++ .../qsl/fluidflow/api/FluidFlowEvents.java | 118 ++++++++++++++++++ .../qsl/fluidflow/mixin/FluidBlockMixin.java | 53 ++++++++ .../assets/quilt_fluid_flow/icon.png | Bin 0 -> 261 bytes .../src/main/resources/fabric.mod.json | 41 ++++++ .../resources/quilt_fluid_flow.mixins.json | 13 ++ .../qsl/fluidflow/FluidFlowEventTests.java | 37 ++++++ .../src/testmod/resources/fabric.mod.json | 16 +++ settings.gradle | 1 + 10 files changed, 299 insertions(+) create mode 100644 library/fluid/build.gradle create mode 100644 library/fluid/fluid-flow/build.gradle create mode 100644 library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/api/FluidFlowEvents.java create mode 100644 library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/mixin/FluidBlockMixin.java create mode 100644 library/fluid/fluid-flow/src/main/resources/assets/quilt_fluid_flow/icon.png create mode 100644 library/fluid/fluid-flow/src/main/resources/fabric.mod.json create mode 100644 library/fluid/fluid-flow/src/main/resources/quilt_fluid_flow.mixins.json create mode 100644 library/fluid/fluid-flow/src/testmod/java/org/quiltmc/qsl/fluidflow/FluidFlowEventTests.java create mode 100644 library/fluid/fluid-flow/src/testmod/resources/fabric.mod.json diff --git a/library/fluid/build.gradle b/library/fluid/build.gradle new file mode 100644 index 0000000000..9203188952 --- /dev/null +++ b/library/fluid/build.gradle @@ -0,0 +1,8 @@ +plugins { + id("qsl.library") +} + +qslLibrary { + libraryName = "fluid" + version = "1.0.0" +} diff --git a/library/fluid/fluid-flow/build.gradle b/library/fluid/fluid-flow/build.gradle new file mode 100644 index 0000000000..417cce5902 --- /dev/null +++ b/library/fluid/fluid-flow/build.gradle @@ -0,0 +1,12 @@ +plugins { + id("qsl.module") +} + +qslModule { + moduleName = "fluid-flow" + version = "1.0.0" + library = "fluid" + coreDependencies([ + "qsl_base" + ]) +} diff --git a/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/api/FluidFlowEvents.java b/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/api/FluidFlowEvents.java new file mode 100644 index 0000000000..decf264991 --- /dev/null +++ b/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/api/FluidFlowEvents.java @@ -0,0 +1,118 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.fluidflow.api; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jetbrains.annotations.Nullable; +import org.quiltmc.qsl.base.api.event.Event; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.util.Pair; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; + + +public final class FluidFlowEvents { + private FluidFlowEvents() { + } + + // Flowing Block to Interacting Block to Direction to Event + private static final Map>>> EVENT_MAP = new HashMap<>(); + + /** + * Registers a new event on a fluid flow. The same two blocks can register a different event for different directions, but the same directions will run the event that was registered first. + * + * @param flowingBlock The fluid block that flowed. + * @param interactionBlock The block in one of the {@code interactionDirections}. + * @param interactionDirections The direction to search for {@code interactionBlock}. + * @param interactionEvent The event to run when the conditions are met. + */ + public static void register(Block flowingBlock, Block interactionBlock, Direction[] interactionDirections, FluidFlowInteractionCallback interactionEvent) { + Map>> flowBlockEvents = EVENT_MAP.computeIfAbsent(flowingBlock, flowing -> new HashMap<>()); + Map> interactionEvents = flowBlockEvents.computeIfAbsent(interactionBlock, interacting -> new HashMap<>()); + + // Create events for all the different directions for the specified blocks + if (interactionEvents.isEmpty()) { + for (Direction direction : Direction.values()) { + interactionEvents.put(direction, Event.create(FluidFlowInteractionCallback.class, fluidFlowInteractionEvents -> (flowingBlockState, interactingBlockState, flowPos, world) -> { + for (FluidFlowInteractionCallback event : fluidFlowInteractionEvents) { + if (!event.onFlow(flowingBlockState, interactingBlockState, flowPos, world)) { + return false; + } + } + + return true; + })); + } + } + + // Register the new event callbacks + for (Map.Entry> pair : interactionEvents.entrySet()) { + for (Direction direction : interactionDirections) { + if (pair.getKey() == direction) { + pair.getValue().register(interactionEvent); + } + } + } + } + + /** + * Gets the event from the following blocks and direction. + * + * @param flowingBlock The fluid block that flowed. + * @param interactionBlock The block it interacts with. + * @param interactionDirection The interaction direction + * @return An event if the conditions are met, otherwise {@code null} + */ + public static @Nullable Event getEvent(Block flowingBlock, Block interactionBlock, Direction interactionDirection) { + if (EVENT_MAP.containsKey(flowingBlock)) { + Map>> flowBlockEvents = EVENT_MAP.get(flowingBlock); + + if (flowBlockEvents.containsKey(interactionBlock)) { + Map> interactionEvents = flowBlockEvents.get(interactionBlock); + + for (Map.Entry> pair : interactionEvents.entrySet()) { + if (pair.getKey() == interactionDirection) { + return pair.getValue(); + } + } + } + } + + return null; + } + + public interface FluidFlowInteractionCallback { + + /** + * An event run when a fluid flows next to a block. + * + * @param flowingBlockState The block state of the fluid block. + * @param interactingBlockState The block state of the interacting block. + * @param flowPos The position in the world that the fluid flowed into. + * @param world The world the event took place in. + * @return {@code false} if the event was successful, and {@code true} if it was unsuccessful (don't blame us its minecraft that does this). + */ + boolean onFlow(BlockState flowingBlockState, BlockState interactingBlockState, BlockPos flowPos, World world); + } +} diff --git a/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/mixin/FluidBlockMixin.java b/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/mixin/FluidBlockMixin.java new file mode 100644 index 0000000000..421365be2b --- /dev/null +++ b/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/mixin/FluidBlockMixin.java @@ -0,0 +1,53 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.fluidflow.mixin; + +import org.quiltmc.qsl.base.api.event.Event; +import org.quiltmc.qsl.fluidflow.api.FluidFlowEvents; +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.CallbackInfoReturnable; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.FluidBlock; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; + + +@Mixin(FluidBlock.class) +public class FluidBlockMixin extends Block { + public FluidBlockMixin(Settings settings) { + super(settings); + } + + @Inject(method = "receiveNeighborFluids", at = @At("HEAD"), cancellable = true) + private void receiveNeighborFluids(World world, BlockPos pos, BlockState state, CallbackInfoReturnable cir) { + for (Direction direction : Direction.values()) { + Event event = FluidFlowEvents.getEvent(this, world.getBlockState(pos.offset(direction)).getBlock(), direction); + + if (event != null) { + if (!event.invoker().onFlow(state, world.getBlockState(pos.offset(direction)), pos, world)) { + cir.setReturnValue(false); + return; + } + } + } + } +} diff --git a/library/fluid/fluid-flow/src/main/resources/assets/quilt_fluid_flow/icon.png b/library/fluid/fluid-flow/src/main/resources/assets/quilt_fluid_flow/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8d54ad0021bbf0258acfe2ba452ccc0e6f36f566 GIT binary patch literal 261 zcmV+g0s8)lP)O|2F_@TM=AcYyV#WxOBw)fQtW(8;_SF|EJmfx^Vx~qyO1! z+uE1g+$r5#A>8-?004nWL_t(I%jJ{V3V=0.12", + "minecraft": ">=1.18.2-alpha.22.3.a" + }, + "description": "Events for flowing fluids.", + "mixins": [ + "quilt_fluid_flow.mixins.json" + ], + "custom": { + "modmenu": { + "badges": [ + "library" + ], + "parent": { + "id": "qsl", + "name": "Quilt Standard Libraries", + "description": "A set of libraries to assist in making Quilt mods.", + "icon": "assets/quilt_fluid_flow/icon.png", + "badges": [ + "library" + ] + } + } + } +} diff --git a/library/fluid/fluid-flow/src/main/resources/quilt_fluid_flow.mixins.json b/library/fluid/fluid-flow/src/main/resources/quilt_fluid_flow.mixins.json new file mode 100644 index 0000000000..019c1d395b --- /dev/null +++ b/library/fluid/fluid-flow/src/main/resources/quilt_fluid_flow.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "org.quiltmc.qsl.fluidflow.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "FluidBlockMixin" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/library/fluid/fluid-flow/src/testmod/java/org/quiltmc/qsl/fluidflow/FluidFlowEventTests.java b/library/fluid/fluid-flow/src/testmod/java/org/quiltmc/qsl/fluidflow/FluidFlowEventTests.java new file mode 100644 index 0000000000..6ae07f4c82 --- /dev/null +++ b/library/fluid/fluid-flow/src/testmod/java/org/quiltmc/qsl/fluidflow/FluidFlowEventTests.java @@ -0,0 +1,37 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.fluidflow; + +import org.quiltmc.qsl.fluidflow.api.FluidFlowEvents; + +import net.minecraft.block.Blocks; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.math.Direction; + +import net.fabricmc.api.ModInitializer; + +public class FluidFlowEventTests implements ModInitializer { + @Override + public void onInitialize() { + FluidFlowEvents.register(Blocks.WATER, Blocks.BLUE_ICE, new Direction[]{Direction.DOWN}, (flowingBlockState, interactingBlockState, flowPos, world) -> { + world.setBlockState(flowPos, Blocks.ICE.getDefaultState()); + world.playSound(null, flowPos, SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 1, 1); + return false; + }); + } +} diff --git a/library/fluid/fluid-flow/src/testmod/resources/fabric.mod.json b/library/fluid/fluid-flow/src/testmod/resources/fabric.mod.json new file mode 100644 index 0000000000..84afca4161 --- /dev/null +++ b/library/fluid/fluid-flow/src/testmod/resources/fabric.mod.json @@ -0,0 +1,16 @@ +{ + "schemaVersion": 1, + "id": "quilt_fluid_flow_testmod", + "name": "Quilt Fluid Flow API Test Mod", + "version": "1.0.0", + "environment": "*", + "license": "Apache-2.0", + "depends": { + "quilt_fluid_flow": "*" + }, + "entrypoints": { + "main": [ + "org.quiltmc.qsl.fluidflow.FluidFlowEventTests" + ] + } +} diff --git a/settings.gradle b/settings.gradle index d0c72220e9..2e7bdaa3de 100644 --- a/settings.gradle +++ b/settings.gradle @@ -31,6 +31,7 @@ library("core") library("block") library("data") library("item") +library("fluid") library("command") def library(String library) { From d8cd6f72f5708b737fe77d4d52f34a22f7d2b974 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Fri, 18 Feb 2022 14:36:04 -0800 Subject: [PATCH 02/10] Merge in 1.18 --- library/fluid/fluid-flow/build.gradle | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/fluid/fluid-flow/build.gradle b/library/fluid/fluid-flow/build.gradle index 417cce5902..ce629202e7 100644 --- a/library/fluid/fluid-flow/build.gradle +++ b/library/fluid/fluid-flow/build.gradle @@ -6,7 +6,9 @@ qslModule { moduleName = "fluid-flow" version = "1.0.0" library = "fluid" - coreDependencies([ - "qsl_base" - ]) + moduleDependencies { + core { + api("qsl_base") + } + } } From f143c61c5b9cac5660d35b978f710f106e86df57 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Tue, 22 Feb 2022 17:21:52 -0800 Subject: [PATCH 03/10] Fix some issues + actually merge --- .../fluid/{fluid-flow => fluid_flow}/build.gradle | 2 +- .../qsl/fluid/flow}/api/FluidFlowEvents.java | 10 ++++------ .../qsl/fluid/flow}/mixin/FluidBlockMixin.java | 4 ++-- .../main/resources/assets/quilt_fluid_flow/icon.png | Bin .../src/main/resources/fabric.mod.json | 2 +- .../src/main/resources/quilt_fluid_flow.mixins.json | 2 +- .../qsl/fluid/flow}/FluidFlowEventTests.java | 9 +++++---- .../src/testmod/resources/fabric.mod.json | 2 +- 8 files changed, 15 insertions(+), 16 deletions(-) rename library/fluid/{fluid-flow => fluid_flow}/build.gradle (83%) rename library/fluid/{fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow => fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow}/api/FluidFlowEvents.java (96%) rename library/fluid/{fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow => fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow}/mixin/FluidBlockMixin.java (94%) rename library/fluid/{fluid-flow => fluid_flow}/src/main/resources/assets/quilt_fluid_flow/icon.png (100%) rename library/fluid/{fluid-flow => fluid_flow}/src/main/resources/fabric.mod.json (96%) rename library/fluid/{fluid-flow => fluid_flow}/src/main/resources/quilt_fluid_flow.mixins.json (76%) rename library/fluid/{fluid-flow/src/testmod/java/org/quiltmc/qsl/fluidflow => fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow}/FluidFlowEventTests.java (82%) rename library/fluid/{fluid-flow => fluid_flow}/src/testmod/resources/fabric.mod.json (82%) diff --git a/library/fluid/fluid-flow/build.gradle b/library/fluid/fluid_flow/build.gradle similarity index 83% rename from library/fluid/fluid-flow/build.gradle rename to library/fluid/fluid_flow/build.gradle index ce629202e7..e18627f1f3 100644 --- a/library/fluid/fluid-flow/build.gradle +++ b/library/fluid/fluid_flow/build.gradle @@ -3,7 +3,7 @@ plugins { } qslModule { - moduleName = "fluid-flow" + moduleName = "fluid_flow" version = "1.0.0" library = "fluid" moduleDependencies { diff --git a/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/api/FluidFlowEvents.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java similarity index 96% rename from library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/api/FluidFlowEvents.java rename to library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java index decf264991..f657d3d56e 100644 --- a/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/api/FluidFlowEvents.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java @@ -14,19 +14,17 @@ * limitations under the License. */ -package org.quiltmc.qsl.fluidflow.api; +package org.quiltmc.qsl.fluid.flow.api; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.Nullable; import org.quiltmc.qsl.base.api.event.Event; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; @@ -48,8 +46,8 @@ private FluidFlowEvents() { * @param interactionEvent The event to run when the conditions are met. */ public static void register(Block flowingBlock, Block interactionBlock, Direction[] interactionDirections, FluidFlowInteractionCallback interactionEvent) { - Map>> flowBlockEvents = EVENT_MAP.computeIfAbsent(flowingBlock, flowing -> new HashMap<>()); - Map> interactionEvents = flowBlockEvents.computeIfAbsent(interactionBlock, interacting -> new HashMap<>()); + Map>> flowBlockEvents = EVENT_MAP.computeIfAbsent(flowingBlock, flowing -> new Object2ObjectOpenHashMap<>()); + Map> interactionEvents = flowBlockEvents.computeIfAbsent(interactionBlock, interacting -> new Object2ObjectOpenHashMap<>()); // Create events for all the different directions for the specified blocks if (interactionEvents.isEmpty()) { diff --git a/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/mixin/FluidBlockMixin.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java similarity index 94% rename from library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/mixin/FluidBlockMixin.java rename to library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java index 421365be2b..fba7c2c45c 100644 --- a/library/fluid/fluid-flow/src/main/java/org/quiltmc/qsl/fluidflow/mixin/FluidBlockMixin.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package org.quiltmc.qsl.fluidflow.mixin; +package org.quiltmc.qsl.fluid.flow.mixin; import org.quiltmc.qsl.base.api.event.Event; -import org.quiltmc.qsl.fluidflow.api.FluidFlowEvents; +import org.quiltmc.qsl.fluid.flow.api.FluidFlowEvents; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; diff --git a/library/fluid/fluid-flow/src/main/resources/assets/quilt_fluid_flow/icon.png b/library/fluid/fluid_flow/src/main/resources/assets/quilt_fluid_flow/icon.png similarity index 100% rename from library/fluid/fluid-flow/src/main/resources/assets/quilt_fluid_flow/icon.png rename to library/fluid/fluid_flow/src/main/resources/assets/quilt_fluid_flow/icon.png diff --git a/library/fluid/fluid-flow/src/main/resources/fabric.mod.json b/library/fluid/fluid_flow/src/main/resources/fabric.mod.json similarity index 96% rename from library/fluid/fluid-flow/src/main/resources/fabric.mod.json rename to library/fluid/fluid_flow/src/main/resources/fabric.mod.json index 733e60c5ac..9013f17df4 100644 --- a/library/fluid/fluid-flow/src/main/resources/fabric.mod.json +++ b/library/fluid/fluid_flow/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "quilt_fluid_flow", - "name": "Quilt Tags API", + "name": "Quilt Fluid Flow API", "version": "${version}", "environment": "*", "license": "Apache-2.0", diff --git a/library/fluid/fluid-flow/src/main/resources/quilt_fluid_flow.mixins.json b/library/fluid/fluid_flow/src/main/resources/quilt_fluid_flow.mixins.json similarity index 76% rename from library/fluid/fluid-flow/src/main/resources/quilt_fluid_flow.mixins.json rename to library/fluid/fluid_flow/src/main/resources/quilt_fluid_flow.mixins.json index 019c1d395b..299c740d7e 100644 --- a/library/fluid/fluid-flow/src/main/resources/quilt_fluid_flow.mixins.json +++ b/library/fluid/fluid_flow/src/main/resources/quilt_fluid_flow.mixins.json @@ -1,6 +1,6 @@ { "required": true, - "package": "org.quiltmc.qsl.fluidflow.mixin", + "package": "org.quiltmc.qsl.fluid.flow.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ "FluidBlockMixin" diff --git a/library/fluid/fluid-flow/src/testmod/java/org/quiltmc/qsl/fluidflow/FluidFlowEventTests.java b/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java similarity index 82% rename from library/fluid/fluid-flow/src/testmod/java/org/quiltmc/qsl/fluidflow/FluidFlowEventTests.java rename to library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java index 6ae07f4c82..c6dcf35cfa 100644 --- a/library/fluid/fluid-flow/src/testmod/java/org/quiltmc/qsl/fluidflow/FluidFlowEventTests.java +++ b/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java @@ -14,20 +14,21 @@ * limitations under the License. */ -package org.quiltmc.qsl.fluidflow; +package org.quiltmc.qsl.fluid.flow; -import org.quiltmc.qsl.fluidflow.api.FluidFlowEvents; +import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; +import org.quiltmc.qsl.fluid.flow.api.FluidFlowEvents; import net.minecraft.block.Blocks; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.Direction; -import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.ModContainer; public class FluidFlowEventTests implements ModInitializer { @Override - public void onInitialize() { + public void onInitialize(ModContainer container) { FluidFlowEvents.register(Blocks.WATER, Blocks.BLUE_ICE, new Direction[]{Direction.DOWN}, (flowingBlockState, interactingBlockState, flowPos, world) -> { world.setBlockState(flowPos, Blocks.ICE.getDefaultState()); world.playSound(null, flowPos, SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 1, 1); diff --git a/library/fluid/fluid-flow/src/testmod/resources/fabric.mod.json b/library/fluid/fluid_flow/src/testmod/resources/fabric.mod.json similarity index 82% rename from library/fluid/fluid-flow/src/testmod/resources/fabric.mod.json rename to library/fluid/fluid_flow/src/testmod/resources/fabric.mod.json index 84afca4161..0952dec00e 100644 --- a/library/fluid/fluid-flow/src/testmod/resources/fabric.mod.json +++ b/library/fluid/fluid_flow/src/testmod/resources/fabric.mod.json @@ -10,7 +10,7 @@ }, "entrypoints": { "main": [ - "org.quiltmc.qsl.fluidflow.FluidFlowEventTests" + "org.quiltmc.qsl.fluid.flow.FluidFlowEventTests" ] } } From 7069a89f51c10f618b19b05aac7929d091c086f7 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Mon, 20 Jun 2022 12:53:44 -0700 Subject: [PATCH 04/10] Apply suggestions from code review Co-authored-by: LambdAurora --- .../qsl/fluid/flow/api/FluidFlowEvents.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java index f657d3d56e..c7616a9df2 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java @@ -40,10 +40,10 @@ private FluidFlowEvents() { /** * Registers a new event on a fluid flow. The same two blocks can register a different event for different directions, but the same directions will run the event that was registered first. * - * @param flowingBlock The fluid block that flowed. - * @param interactionBlock The block in one of the {@code interactionDirections}. - * @param interactionDirections The direction to search for {@code interactionBlock}. - * @param interactionEvent The event to run when the conditions are met. + * @param flowingBlock the fluid block that flowed + * @param interactionBlock the block in one of the {@code interactionDirections} + * @param interactionDirections the direction to search for {@code interactionBlock} + * @param interactionEvent the event to run when the conditions are met */ public static void register(Block flowingBlock, Block interactionBlock, Direction[] interactionDirections, FluidFlowInteractionCallback interactionEvent) { Map>> flowBlockEvents = EVENT_MAP.computeIfAbsent(flowingBlock, flowing -> new Object2ObjectOpenHashMap<>()); @@ -77,10 +77,10 @@ public static void register(Block flowingBlock, Block interactionBlock, Directio /** * Gets the event from the following blocks and direction. * - * @param flowingBlock The fluid block that flowed. - * @param interactionBlock The block it interacts with. - * @param interactionDirection The interaction direction - * @return An event if the conditions are met, otherwise {@code null} + * @param flowingBlock the fluid block that flowed + * @param interactionBlock the block it interacts with + * @param interactionDirection the interaction direction + * @return an event if the conditions are met, otherwise {@code null} */ public static @Nullable Event getEvent(Block flowingBlock, Block interactionBlock, Direction interactionDirection) { if (EVENT_MAP.containsKey(flowingBlock)) { From 977d2cad2924652ea2810d3d8e5a80f6b637f7e0 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Mon, 20 Jun 2022 13:31:19 -0700 Subject: [PATCH 05/10] Remove direction event system and just use a parameter --- library/fluid/build.gradle | 1 - library/fluid/fluid_flow/build.gradle | 4 +- .../qsl/fluid/flow/api/FluidFlowEvents.java | 73 ++++++------------- .../qsl/fluid/flow/mixin/FluidBlockMixin.java | 8 +- .../src/main/resources/fabric.mod.json | 41 ----------- .../qsl/fluid/flow/FluidFlowEventTests.java | 14 ++-- .../src/testmod/resources/fabric.mod.json | 16 ---- .../src/testmod/resources/quilt.mod.json | 14 ++++ .../src/testmod/resources/quilt.mod.json | 23 ++++++ .../src/testmod/resources/quilt.mod.json | 4 +- 10 files changed, 79 insertions(+), 119 deletions(-) delete mode 100644 library/fluid/fluid_flow/src/main/resources/fabric.mod.json delete mode 100644 library/fluid/fluid_flow/src/testmod/resources/fabric.mod.json create mode 100644 library/fluid/fluid_flow/src/testmod/resources/quilt.mod.json create mode 100644 library/fluid/src/testmod/resources/quilt.mod.json diff --git a/library/fluid/build.gradle b/library/fluid/build.gradle index 9203188952..0a57269639 100644 --- a/library/fluid/build.gradle +++ b/library/fluid/build.gradle @@ -4,5 +4,4 @@ plugins { qslLibrary { libraryName = "fluid" - version = "1.0.0" } diff --git a/library/fluid/fluid_flow/build.gradle b/library/fluid/fluid_flow/build.gradle index e18627f1f3..51467556ae 100644 --- a/library/fluid/fluid_flow/build.gradle +++ b/library/fluid/fluid_flow/build.gradle @@ -3,8 +3,10 @@ plugins { } qslModule { + name = "Quilt Fluid Flow Event API" moduleName = "fluid_flow" - version = "1.0.0" + id = "quilt_fluid_flow" + description = "Adds events for when fluids flow around other blocks." library = "fluid" moduleDependencies { core { diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java index c7616a9df2..a50003702f 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java @@ -16,7 +16,6 @@ package org.quiltmc.qsl.fluid.flow.api; -import java.util.HashMap; import java.util.Map; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -34,44 +33,27 @@ public final class FluidFlowEvents { private FluidFlowEvents() { } - // Flowing Block to Interacting Block to Direction to Event - private static final Map>>> EVENT_MAP = new HashMap<>(); + // Flowing Block to Interacting Block to Event + private static final Map>> EVENT_MAP = new Object2ObjectOpenHashMap<>(); /** - * Registers a new event on a fluid flow. The same two blocks can register a different event for different directions, but the same directions will run the event that was registered first. + * Registers a new event on a fluid flow. * * @param flowingBlock the fluid block that flowed * @param interactionBlock the block in one of the {@code interactionDirections} - * @param interactionDirections the direction to search for {@code interactionBlock} * @param interactionEvent the event to run when the conditions are met */ - public static void register(Block flowingBlock, Block interactionBlock, Direction[] interactionDirections, FluidFlowInteractionCallback interactionEvent) { - Map>> flowBlockEvents = EVENT_MAP.computeIfAbsent(flowingBlock, flowing -> new Object2ObjectOpenHashMap<>()); - Map> interactionEvents = flowBlockEvents.computeIfAbsent(interactionBlock, interacting -> new Object2ObjectOpenHashMap<>()); - - // Create events for all the different directions for the specified blocks - if (interactionEvents.isEmpty()) { - for (Direction direction : Direction.values()) { - interactionEvents.put(direction, Event.create(FluidFlowInteractionCallback.class, fluidFlowInteractionEvents -> (flowingBlockState, interactingBlockState, flowPos, world) -> { - for (FluidFlowInteractionCallback event : fluidFlowInteractionEvents) { - if (!event.onFlow(flowingBlockState, interactingBlockState, flowPos, world)) { - return false; - } - } - - return true; - })); - } - } - - // Register the new event callbacks - for (Map.Entry> pair : interactionEvents.entrySet()) { - for (Direction direction : interactionDirections) { - if (pair.getKey() == direction) { - pair.getValue().register(interactionEvent); + public static void register(Block flowingBlock, Block interactionBlock, FluidFlowInteractionCallback interactionEvent) { + Map> flowBlockEvents = EVENT_MAP.computeIfAbsent(flowingBlock, flowing -> new Object2ObjectOpenHashMap<>()); + flowBlockEvents.computeIfAbsent(interactionBlock, (block) -> Event.create(FluidFlowInteractionCallback.class, fluidFlowInteractionEvents -> (flowingBlockState, interactingBlockState, interactionDirection, flowPos, world) -> { + for (FluidFlowInteractionCallback event : fluidFlowInteractionEvents) { + if (!event.onFlow(flowingBlockState, interactingBlockState, interactionDirection, flowPos, world)) { + return false; } } - } + + return true; + })).register(interactionEvent); } /** @@ -79,22 +61,12 @@ public static void register(Block flowingBlock, Block interactionBlock, Directio * * @param flowingBlock the fluid block that flowed * @param interactionBlock the block it interacts with - * @param interactionDirection the interaction direction * @return an event if the conditions are met, otherwise {@code null} */ - public static @Nullable Event getEvent(Block flowingBlock, Block interactionBlock, Direction interactionDirection) { - if (EVENT_MAP.containsKey(flowingBlock)) { - Map>> flowBlockEvents = EVENT_MAP.get(flowingBlock); - - if (flowBlockEvents.containsKey(interactionBlock)) { - Map> interactionEvents = flowBlockEvents.get(interactionBlock); - - for (Map.Entry> pair : interactionEvents.entrySet()) { - if (pair.getKey() == interactionDirection) { - return pair.getValue(); - } - } - } + public static @Nullable Event getEvent(Block flowingBlock, Block interactionBlock) { + Map> flowBlockEvents = EVENT_MAP.get(flowingBlock); + if (flowBlockEvents != null) { + return flowBlockEvents.get(interactionBlock); } return null; @@ -105,12 +77,13 @@ public interface FluidFlowInteractionCallback { /** * An event run when a fluid flows next to a block. * - * @param flowingBlockState The block state of the fluid block. - * @param interactingBlockState The block state of the interacting block. - * @param flowPos The position in the world that the fluid flowed into. - * @param world The world the event took place in. - * @return {@code false} if the event was successful, and {@code true} if it was unsuccessful (don't blame us its minecraft that does this). + * @param flowingBlockState The block state of the fluid block. + * @param interactingBlockState The block state of the interacting block. + * @param fluidToInteractingBlockDirection The direction from the flowingBlockState to the interactingBlockState. + * @param flowPos The position in the world that the fluid flowed into. + * @param world The world the event took place in. + * @return {@code false} if the event successfully ran, and {@code true} if it was unsuccessful or did not run. */ - boolean onFlow(BlockState flowingBlockState, BlockState interactingBlockState, BlockPos flowPos, World world); + boolean onFlow(BlockState flowingBlockState, BlockState interactingBlockState, Direction fluidToInteractingBlockDirection, BlockPos flowPos, World world); } } diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java index fba7c2c45c..3087c3d5ed 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java @@ -33,17 +33,19 @@ @Mixin(FluidBlock.class) public class FluidBlockMixin extends Block { + private static final Direction[] DIRECTIONS = Direction.values(); + public FluidBlockMixin(Settings settings) { super(settings); } @Inject(method = "receiveNeighborFluids", at = @At("HEAD"), cancellable = true) private void receiveNeighborFluids(World world, BlockPos pos, BlockState state, CallbackInfoReturnable cir) { - for (Direction direction : Direction.values()) { - Event event = FluidFlowEvents.getEvent(this, world.getBlockState(pos.offset(direction)).getBlock(), direction); + for (Direction direction : DIRECTIONS) { + Event event = FluidFlowEvents.getEvent(this, world.getBlockState(pos.offset(direction)).getBlock()); if (event != null) { - if (!event.invoker().onFlow(state, world.getBlockState(pos.offset(direction)), pos, world)) { + if (!event.invoker().onFlow(state, world.getBlockState(pos.offset(direction)), direction, pos, world)) { cir.setReturnValue(false); return; } diff --git a/library/fluid/fluid_flow/src/main/resources/fabric.mod.json b/library/fluid/fluid_flow/src/main/resources/fabric.mod.json deleted file mode 100644 index 9013f17df4..0000000000 --- a/library/fluid/fluid_flow/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "schemaVersion": 1, - "id": "quilt_fluid_flow", - "name": "Quilt Fluid Flow API", - "version": "${version}", - "environment": "*", - "license": "Apache-2.0", - "icon": "assets/quilt_fluid_flow/icon.png", - "contact": { - "homepage": "https://quiltmc.org", - "issues": "https://github.com/QuiltMC/quilt-standard-libraries/issues", - "sources": "https://github.com/QuiltMC/quilt-standard-libraries" - }, - "authors": [ - "QuiltMC" - ], - "depends": { - "fabricloader": ">=0.12", - "minecraft": ">=1.18.2-alpha.22.3.a" - }, - "description": "Events for flowing fluids.", - "mixins": [ - "quilt_fluid_flow.mixins.json" - ], - "custom": { - "modmenu": { - "badges": [ - "library" - ], - "parent": { - "id": "qsl", - "name": "Quilt Standard Libraries", - "description": "A set of libraries to assist in making Quilt mods.", - "icon": "assets/quilt_fluid_flow/icon.png", - "badges": [ - "library" - ] - } - } - } -} diff --git a/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java b/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java index c6dcf35cfa..4059eb5024 100644 --- a/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java +++ b/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java @@ -16,6 +16,7 @@ package org.quiltmc.qsl.fluid.flow; +import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.fluid.flow.api.FluidFlowEvents; @@ -24,15 +25,18 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.Direction; -import net.fabricmc.loader.api.ModContainer; public class FluidFlowEventTests implements ModInitializer { @Override public void onInitialize(ModContainer container) { - FluidFlowEvents.register(Blocks.WATER, Blocks.BLUE_ICE, new Direction[]{Direction.DOWN}, (flowingBlockState, interactingBlockState, flowPos, world) -> { - world.setBlockState(flowPos, Blocks.ICE.getDefaultState()); - world.playSound(null, flowPos, SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 1, 1); - return false; + FluidFlowEvents.register(Blocks.WATER, Blocks.BLUE_ICE, (flowingBlockState, interactingBlockState, interactionDirection, flowPos, world) -> { + if (interactionDirection == Direction.DOWN) { + world.setBlockState(flowPos, Blocks.ICE.getDefaultState()); + world.playSound(null, flowPos, SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 1, 1); + return false; + } + + return true; }); } } diff --git a/library/fluid/fluid_flow/src/testmod/resources/fabric.mod.json b/library/fluid/fluid_flow/src/testmod/resources/fabric.mod.json deleted file mode 100644 index 0952dec00e..0000000000 --- a/library/fluid/fluid_flow/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "schemaVersion": 1, - "id": "quilt_fluid_flow_testmod", - "name": "Quilt Fluid Flow API Test Mod", - "version": "1.0.0", - "environment": "*", - "license": "Apache-2.0", - "depends": { - "quilt_fluid_flow": "*" - }, - "entrypoints": { - "main": [ - "org.quiltmc.qsl.fluid.flow.FluidFlowEventTests" - ] - } -} diff --git a/library/fluid/fluid_flow/src/testmod/resources/quilt.mod.json b/library/fluid/fluid_flow/src/testmod/resources/quilt.mod.json new file mode 100644 index 0000000000..9d550cb8a9 --- /dev/null +++ b/library/fluid/fluid_flow/src/testmod/resources/quilt.mod.json @@ -0,0 +1,14 @@ +{ + "schema_version": 1, + "quilt_loader": { + "group": "org.quiltmc.qsl", + "id": "quilt_fluid_flow_testmod", + "version": "1.0.0", + "metadata": { + "name": "Quilt Flow Flow Event Test Mod", + "license": "Apache-2.0" + }, + "intermediate_mappings": "net.fabricmc:intermediary", + "load_type": "always" + } +} diff --git a/library/fluid/src/testmod/resources/quilt.mod.json b/library/fluid/src/testmod/resources/quilt.mod.json new file mode 100644 index 0000000000..61172e7da2 --- /dev/null +++ b/library/fluid/src/testmod/resources/quilt.mod.json @@ -0,0 +1,23 @@ +{ + "schema_version": 1, + "quilt_loader": { + "group": "org.quiltmc.qsl", + "id": "quilt_fluid_testmod", + "version": "1.0.0", + "metadata": { + "name": "Quilt Fluid Library Test Mod", + "license": "Apache-2.0" + }, + "intermediate_mappings": "net.fabricmc:intermediary", + "load_type": "always", + "entrypoints": { + "init": [ + "org.quiltmc.qsl.fluid.flow.FluidFlowEventTests" + ] + }, + "depends": [ + "quilt_loader", + "quilt_fluid_flow" + ] + } +} diff --git a/library/worldgen/src/testmod/resources/quilt.mod.json b/library/worldgen/src/testmod/resources/quilt.mod.json index 893adb3353..0d6fc89fdf 100644 --- a/library/worldgen/src/testmod/resources/quilt.mod.json +++ b/library/worldgen/src/testmod/resources/quilt.mod.json @@ -2,10 +2,10 @@ "schema_version": 1, "quilt_loader": { "group": "org.quiltmc.qsl", - "id": "quilt_data_testmod", + "id": "quilt_worldgen_testmod", "version": "1.0.0", "metadata": { - "name": "Quilt Data Library Test Mod", + "name": "Quilt Worldgen Library Test Mod", "license": "Apache-2.0" }, "intermediate_mappings": "net.fabricmc:intermediary", From 9a16e651aa230c98131cccd17942d3d94027065f Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Mon, 20 Jun 2022 15:34:11 -0700 Subject: [PATCH 06/10] Apply suggestions from code review Co-authored-by: Ennui Langeweile <85590273+EnnuiL@users.noreply.github.com> --- .../java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java | 4 ++-- .../org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java | 2 +- .../src/main/resources/quilt_fluid_flow.mixins.json | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java index a50003702f..86488fdc4a 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java @@ -44,7 +44,7 @@ private FluidFlowEvents() { * @param interactionEvent the event to run when the conditions are met */ public static void register(Block flowingBlock, Block interactionBlock, FluidFlowInteractionCallback interactionEvent) { - Map> flowBlockEvents = EVENT_MAP.computeIfAbsent(flowingBlock, flowing -> new Object2ObjectOpenHashMap<>()); + var flowBlockEvents = EVENT_MAP.computeIfAbsent(flowingBlock, flowing -> new Object2ObjectOpenHashMap<>()); flowBlockEvents.computeIfAbsent(interactionBlock, (block) -> Event.create(FluidFlowInteractionCallback.class, fluidFlowInteractionEvents -> (flowingBlockState, interactingBlockState, interactionDirection, flowPos, world) -> { for (FluidFlowInteractionCallback event : fluidFlowInteractionEvents) { if (!event.onFlow(flowingBlockState, interactingBlockState, interactionDirection, flowPos, world)) { @@ -64,7 +64,7 @@ public static void register(Block flowingBlock, Block interactionBlock, FluidFlo * @return an event if the conditions are met, otherwise {@code null} */ public static @Nullable Event getEvent(Block flowingBlock, Block interactionBlock) { - Map> flowBlockEvents = EVENT_MAP.get(flowingBlock); + var flowBlockEvents = EVENT_MAP.get(flowingBlock); if (flowBlockEvents != null) { return flowBlockEvents.get(interactionBlock); } diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java index 3087c3d5ed..1276e4f5ab 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java @@ -42,7 +42,7 @@ public FluidBlockMixin(Settings settings) { @Inject(method = "receiveNeighborFluids", at = @At("HEAD"), cancellable = true) private void receiveNeighborFluids(World world, BlockPos pos, BlockState state, CallbackInfoReturnable cir) { for (Direction direction : DIRECTIONS) { - Event event = FluidFlowEvents.getEvent(this, world.getBlockState(pos.offset(direction)).getBlock()); + var event = FluidFlowEvents.getEvent(this, world.getBlockState(pos.offset(direction)).getBlock()); if (event != null) { if (!event.invoker().onFlow(state, world.getBlockState(pos.offset(direction)), direction, pos, world)) { diff --git a/library/fluid/fluid_flow/src/main/resources/quilt_fluid_flow.mixins.json b/library/fluid/fluid_flow/src/main/resources/quilt_fluid_flow.mixins.json index 299c740d7e..c990eb2941 100644 --- a/library/fluid/fluid_flow/src/main/resources/quilt_fluid_flow.mixins.json +++ b/library/fluid/fluid_flow/src/main/resources/quilt_fluid_flow.mixins.json @@ -5,8 +5,6 @@ "mixins": [ "FluidBlockMixin" ], - "client": [ - ], "injectors": { "defaultRequire": 1 } From 5f14754796b36c159d081c786dde24a879c41d36 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Wed, 22 Jun 2022 20:11:52 -0500 Subject: [PATCH 07/10] Make the test actually work --- .../qsl/fluid/flow/api/FluidFlowEvents.java | 22 +++++++++---------- .../src/testmod/resources/quilt.mod.json | 7 +++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java index 86488fdc4a..b3a0d0639d 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java @@ -39,9 +39,9 @@ private FluidFlowEvents() { /** * Registers a new event on a fluid flow. * - * @param flowingBlock the fluid block that flowed - * @param interactionBlock the block in one of the {@code interactionDirections} - * @param interactionEvent the event to run when the conditions are met + * @param flowingBlock the fluid block that flowed + * @param interactionBlock the block in one of the {@code interactionDirections} + * @param interactionEvent the event to run when the conditions are met */ public static void register(Block flowingBlock, Block interactionBlock, FluidFlowInteractionCallback interactionEvent) { var flowBlockEvents = EVENT_MAP.computeIfAbsent(flowingBlock, flowing -> new Object2ObjectOpenHashMap<>()); @@ -59,8 +59,8 @@ public static void register(Block flowingBlock, Block interactionBlock, FluidFlo /** * Gets the event from the following blocks and direction. * - * @param flowingBlock the fluid block that flowed - * @param interactionBlock the block it interacts with + * @param flowingBlock the fluid block that flowed + * @param interactionBlock the block it interacts with * @return an event if the conditions are met, otherwise {@code null} */ public static @Nullable Event getEvent(Block flowingBlock, Block interactionBlock) { @@ -77,13 +77,13 @@ public interface FluidFlowInteractionCallback { /** * An event run when a fluid flows next to a block. * - * @param flowingBlockState The block state of the fluid block. - * @param interactingBlockState The block state of the interacting block. - * @param fluidToInteractingBlockDirection The direction from the flowingBlockState to the interactingBlockState. - * @param flowPos The position in the world that the fluid flowed into. - * @param world The world the event took place in. + * @param flowingBlockState The block state of the fluid block. + * @param interactingBlockState The block state of the interacting block. + * @param interactionDirection The direction from the flowingBlockState to the interactingBlockState. + * @param flowPos The position in the world that the fluid flowed into. + * @param world The world the event took place in. * @return {@code false} if the event successfully ran, and {@code true} if it was unsuccessful or did not run. */ - boolean onFlow(BlockState flowingBlockState, BlockState interactingBlockState, Direction fluidToInteractingBlockDirection, BlockPos flowPos, World world); + boolean onFlow(BlockState flowingBlockState, BlockState interactingBlockState, Direction interactionDirection, BlockPos flowPos, World world); } } diff --git a/library/fluid/fluid_flow/src/testmod/resources/quilt.mod.json b/library/fluid/fluid_flow/src/testmod/resources/quilt.mod.json index 9d550cb8a9..b1d9d9e14c 100644 --- a/library/fluid/fluid_flow/src/testmod/resources/quilt.mod.json +++ b/library/fluid/fluid_flow/src/testmod/resources/quilt.mod.json @@ -9,6 +9,11 @@ "license": "Apache-2.0" }, "intermediate_mappings": "net.fabricmc:intermediary", - "load_type": "always" + "load_type": "always", + "entrypoints": { + "init": [ + "org.quiltmc.qsl.fluid.flow.FluidFlowEventTests" + ] + } } } From 9ddf88c4d4c2b9ca7732a5102eb43f51821a9c87 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sat, 6 Aug 2022 08:40:14 -0700 Subject: [PATCH 08/10] Apply suggestions from code review Co-authored-by: Ennui Langeweile <85590273+EnnuiL@users.noreply.github.com> --- .../java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java | 1 - library/worldgen/src/testmod/resources/quilt.mod.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java index b3a0d0639d..b68ed25e2b 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java @@ -73,7 +73,6 @@ public static void register(Block flowingBlock, Block interactionBlock, FluidFlo } public interface FluidFlowInteractionCallback { - /** * An event run when a fluid flows next to a block. * diff --git a/library/worldgen/src/testmod/resources/quilt.mod.json b/library/worldgen/src/testmod/resources/quilt.mod.json index 7e658f185a..79f704b455 100644 --- a/library/worldgen/src/testmod/resources/quilt.mod.json +++ b/library/worldgen/src/testmod/resources/quilt.mod.json @@ -5,7 +5,7 @@ "id": "quilt_worldgen_testmod", "version": "1.0.0", "metadata": { - "name": "Quilt Worldgen Test Mod", + "name": "Quilt Worldgen Test Mod", "license": "Apache-2.0" }, "intermediate_mappings": "net.fabricmc:intermediary", From a2b52d8cce208bc3275cad68e23c76737f031856 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sat, 6 Aug 2022 08:40:37 -0700 Subject: [PATCH 09/10] Update library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java --- .../java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java index b68ed25e2b..f1ba754904 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java @@ -30,8 +30,7 @@ public final class FluidFlowEvents { - private FluidFlowEvents() { - } + private FluidFlowEvents() {} // Flowing Block to Interacting Block to Event private static final Map>> EVENT_MAP = new Object2ObjectOpenHashMap<>(); From a9b0480a09eb38acfcd7472ed80a8c7ed4954d09 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Mon, 5 Jun 2023 22:30:24 -0700 Subject: [PATCH 10/10] Update to 1.20 --- library/fluid/fluid_flow/build.gradle | 1 - .../org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java | 2 +- .../org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java | 3 +-- .../org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java | 7 +++---- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/library/fluid/fluid_flow/build.gradle b/library/fluid/fluid_flow/build.gradle index 51467556ae..a01c49be08 100644 --- a/library/fluid/fluid_flow/build.gradle +++ b/library/fluid/fluid_flow/build.gradle @@ -7,7 +7,6 @@ qslModule { moduleName = "fluid_flow" id = "quilt_fluid_flow" description = "Adds events for when fluids flow around other blocks." - library = "fluid" moduleDependencies { core { api("qsl_base") diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java index f1ba754904..d2dbef315c 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/api/FluidFlowEvents.java @@ -20,7 +20,6 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.Nullable; -import org.quiltmc.qsl.base.api.event.Event; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -28,6 +27,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.world.World; +import org.quiltmc.qsl.base.api.event.Event; public final class FluidFlowEvents { private FluidFlowEvents() {} diff --git a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java index 1276e4f5ab..c9625c44e3 100644 --- a/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java +++ b/library/fluid/fluid_flow/src/main/java/org/quiltmc/qsl/fluid/flow/mixin/FluidBlockMixin.java @@ -16,8 +16,6 @@ package org.quiltmc.qsl.fluid.flow.mixin; -import org.quiltmc.qsl.base.api.event.Event; -import org.quiltmc.qsl.fluid.flow.api.FluidFlowEvents; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -30,6 +28,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.world.World; +import org.quiltmc.qsl.fluid.flow.api.FluidFlowEvents; @Mixin(FluidBlock.class) public class FluidBlockMixin extends Block { diff --git a/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java b/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java index 4059eb5024..51341baad1 100644 --- a/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java +++ b/library/fluid/fluid_flow/src/testmod/java/org/quiltmc/qsl/fluid/flow/FluidFlowEventTests.java @@ -16,15 +16,14 @@ package org.quiltmc.qsl.fluid.flow; -import org.quiltmc.loader.api.ModContainer; -import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; -import org.quiltmc.qsl.fluid.flow.api.FluidFlowEvents; - import net.minecraft.block.Blocks; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.Direction; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; +import org.quiltmc.qsl.fluid.flow.api.FluidFlowEvents; public class FluidFlowEventTests implements ModInitializer { @Override