From ef98dbd5fd6a5c69dcb1b53998800b4255e1e5a1 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 2 May 2026 21:26:33 -0500 Subject: [PATCH] color override API tests --- .../fabric/FabricServerProxy.java | 22 ++++- .../testing/TestBlockWrapperCreatedEvent.java | 43 ++++++++++ .../fabric/testing/TestCustomColorEvent.java | 86 +++++++++++++++++++ 3 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestBlockWrapperCreatedEvent.java create mode 100644 fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestCustomColorEvent.java diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java index cf0568fb5..3781fd8c8 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java @@ -1,6 +1,8 @@ package com.seibel.distanthorizons.fabric; import com.seibel.distanthorizons.api.DhApi; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBlockColorOverrideEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBlockStateWrapperCreatedEvent; import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiChunkProcessingEvent; import com.seibel.distanthorizons.api.methods.events.DhApiEventRegister; import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiLevelLoadEvent; @@ -16,7 +18,9 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; +import com.seibel.distanthorizons.fabric.testing.TestBlockWrapperCreatedEvent; import com.seibel.distanthorizons.fabric.testing.TestChunkInputReplacerEvent; +import com.seibel.distanthorizons.fabric.testing.TestCustomColorEvent; import com.seibel.distanthorizons.fabric.testing.TestWorldGenBindingEvent; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -87,11 +91,21 @@ public class FabricServerProxy implements AbstractModInitializer.IEventProxy /* Register the mod needed event callbacks */ - // can be enabled to test overrides/events without having to build a separate API project - if (false) + // can be enabled to test overrides/events without having to build a separate API project { - DhApiEventRegister.on(DhApiLevelLoadEvent.class, new TestWorldGenBindingEvent()); - DhApi.events.bind(DhApiChunkProcessingEvent.class, new TestChunkInputReplacerEvent()); + // test custom world gen + if (false) + { + DhApiEventRegister.on(DhApiLevelLoadEvent.class, new TestWorldGenBindingEvent()); + DhApi.events.bind(DhApiChunkProcessingEvent.class, new TestChunkInputReplacerEvent()); + } + + // test custom colors + if (false) + { + DhApi.events.bind(DhApiBlockColorOverrideEvent.class, new TestCustomColorEvent()); + DhApi.events.bind(DhApiBlockStateWrapperCreatedEvent.class, new TestBlockWrapperCreatedEvent()); + } } diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestBlockWrapperCreatedEvent.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestBlockWrapperCreatedEvent.java new file mode 100644 index 000000000..d703fff5b --- /dev/null +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestBlockWrapperCreatedEvent.java @@ -0,0 +1,43 @@ +package com.seibel.distanthorizons.fabric.testing; + +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBlockStateWrapperCreatedEvent; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiEventParam; +import com.seibel.distanthorizons.core.logging.DhLogger; +import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; +import com.seibel.distanthorizons.core.util.LodUtil; + +import java.util.Random; + +/** + * @see TestCustomColorEvent + */ +public class TestBlockWrapperCreatedEvent extends DhApiBlockStateWrapperCreatedEvent +{ + private static final DhLogger LOGGER = new DhLoggerBuilder().build(); + + + + + @Override + public void blockStateWrapperCreated(DhApiEventParam event) + { + EventParam eventParam = event.value; + + // can be enabled to flip the opacity of transparent/opaque blocks + if (false) + { + if (eventParam.getBlockStateWrapper().getOpacity() == LodUtil.BLOCK_FULLY_OPAQUE) + { + eventParam.setOpacity(LodUtil.BLOCK_FULLY_TRANSPARENT); + } + else + { + eventParam.setOpacity(LodUtil.BLOCK_FULLY_OPAQUE); + } + } + + // needed for TestCustomColorEvent + eventParam.setAllowApiColorOverride(true); + } + +} diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestCustomColorEvent.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestCustomColorEvent.java new file mode 100644 index 000000000..7c08334ff --- /dev/null +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestCustomColorEvent.java @@ -0,0 +1,86 @@ +package com.seibel.distanthorizons.fabric.testing; + +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBlockColorOverrideEvent; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiEventParam; +import com.seibel.distanthorizons.core.logging.DhLogger; +import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; +import com.seibel.distanthorizons.core.util.LodUtil; +import com.seibel.distanthorizons.coreapi.util.ColorUtil; + +import java.awt.*; + +/** + * @see TestBlockWrapperCreatedEvent + */ +public class TestCustomColorEvent extends DhApiBlockColorOverrideEvent +{ + private static final DhLogger LOGGER = new DhLoggerBuilder().build(); + + + + @Override + public void blockStateWrapperCreated(DhApiEventParam event) + { + EventParam eventParam = event.value; + + //randomDatapointColors(eventParam); + //randomPerBlockColors(eventParam); + //blackWhitePositionStripe(eventParam); + positionRainbow(eventParam); + } + + /** each datapoint has a random color */ + private void randomDatapointColors(EventParam eventParam) + { + // random colors for each datapoint + int a = eventParam.getAlpha(); + int r = eventParam.getRed(); + int g = eventParam.getGreen(); + int b = eventParam.getBlue(); + + if (eventParam.getBlockStateWrapper().getOpacity() == LodUtil.BLOCK_FULLY_OPAQUE) + { + eventParam.setColor(255,r,g,b); + } + else + { + eventParam.setColor(60,r,g,b); + } + } + + /** each block has a different color */ + private void randomPerBlockColors(EventParam eventParam) + { + // random colors per block + int r = Math.abs(eventParam.getBlockStateWrapper().hashCode() % 255); + int g = Math.abs((eventParam.getBlockStateWrapper().hashCode() << 4) % 255); + int b = Math.abs((eventParam.getBlockStateWrapper().hashCode() << 8) % 255); + eventParam.setColor(r,g,b); + } + + private void blackWhitePositionStripe(EventParam eventParam) + { + // black-white stripes + int r = Math.abs(eventParam.getBlockPosX() % 255); + int g = r; + int b = r; + eventParam.setColor(r,g,b); + } + + /** rainbow along the X axis repeating every 255 blocks */ + private void positionRainbow(EventParam eventParam) + { + float[] ahsv = ColorUtil.argbToAhsv(ColorUtil.RED); + float a = ahsv[0]; + + int xModPos = Math.abs(eventParam.getBlockPosX() % 510); + float h = xModPos < 255 ? xModPos : 510 - xModPos; + float s = ahsv[2]; + float v = ahsv[3]; + int colorInt = ColorUtil.ahsvToArgb(a,h,s,v); + eventParam.setColor(ColorUtil.getRed(colorInt),ColorUtil.getGreen(colorInt),ColorUtil.getBlue(colorInt)); + } + + + +}