color override API tests
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package com.seibel.distanthorizons.fabric;
|
package com.seibel.distanthorizons.fabric;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.DhApi;
|
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.abstractEvents.DhApiChunkProcessingEvent;
|
||||||
import com.seibel.distanthorizons.api.methods.events.DhApiEventRegister;
|
import com.seibel.distanthorizons.api.methods.events.DhApiEventRegister;
|
||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiLevelLoadEvent;
|
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.misc.IPluginPacketSender;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
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.TestChunkInputReplacerEvent;
|
||||||
|
import com.seibel.distanthorizons.fabric.testing.TestCustomColorEvent;
|
||||||
import com.seibel.distanthorizons.fabric.testing.TestWorldGenBindingEvent;
|
import com.seibel.distanthorizons.fabric.testing.TestWorldGenBindingEvent;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
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 */
|
/* Register the mod needed event callbacks */
|
||||||
|
|
||||||
// can be enabled to test overrides/events without having to build a separate API project
|
// can be enabled to test overrides/events without having to build a separate API project
|
||||||
if (false)
|
|
||||||
{
|
{
|
||||||
DhApiEventRegister.on(DhApiLevelLoadEvent.class, new TestWorldGenBindingEvent());
|
// test custom world gen
|
||||||
DhApi.events.bind(DhApiChunkProcessingEvent.class, new TestChunkInputReplacerEvent());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+43
@@ -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<EventParam> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+86
@@ -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<EventParam> 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user