This commit is contained in:
SD 2022-03-15 15:50:20 +05:30
commit a91c5c5471
17 changed files with 545 additions and 529 deletions

View file

@ -151,8 +151,8 @@ dependencies {
modCompileOnly "curse.maven:worldedit-225608:3559499"
testImplementation("junit:junit:4.13.2")
testImplementation("net.devtech:PotatoUnit:1.0.2")
// testImplementation("junit:junit:4.13.2")
// testImplementation("net.devtech:PotatoUnit:1.0.2")
}
version = computeVersion(project.mod_version)
@ -213,15 +213,15 @@ curseforge {
}
}
test {
workingDir = file("test")
systemProperty("fabric.dli.config", file(".gradle/loom-cache/launch.cfg").getAbsolutePath())
//useJUnitPlatform()
}
tasks.test.doFirst {test ->
if (!test.workingDir.exists()) {
test.workingDir.mkdirs();
}
}
//test {
// workingDir = file("test")
//
// systemProperty("fabric.dli.config", file(".gradle/loom-cache/launch.cfg").getAbsolutePath())
// //useJUnitPlatform()
//}
//
//tasks.test.doFirst {test ->
// if (!test.workingDir.exists()) {
// test.workingDir.mkdirs();
// }
//}

View file

@ -3,6 +3,11 @@ package org.dimdev.dimdoors.client;
import java.util.Objects;
import com.flowpowered.math.TrigMath;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
@ -17,6 +22,8 @@ import net.minecraft.util.Identifier;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.dimdev.dimdoors.item.ModItems;
import org.dimdev.dimdoors.rift.targets.IdMarker;
@Environment(EnvType.CLIENT)
public class DetachedRiftBlockEntityRenderer implements BlockEntityRenderer<DetachedRiftBlockEntity> {
@ -28,6 +35,15 @@ public class DetachedRiftBlockEntityRenderer implements BlockEntityRenderer<Deta
@Override
public void render(DetachedRiftBlockEntity rift, float tickDelta, MatrixStack matrices, VertexConsumerProvider vcs, int breakProgress, int alpha) {
if(MinecraftClient.getInstance().player != null && MinecraftClient.getInstance().player.getStackInHand(Hand.MAIN_HAND).isOf(ModItems.RIFT_CONFIGURATION_TOOL) && rift.getData().getDestination() instanceof IdMarker idMarker) {
matrices.push();
matrices.translate(0.5, 0.5, 0.5);
MinecraftClient.getInstance().textRenderer.draw(Text.of(String.valueOf(idMarker.getId())), 0f,0f, 0xffffffff, false, matrices.peek().getPositionMatrix(), vcs, true, 0x000000, LightmapTextureManager.MAX_LIGHT_COORDINATE);
matrices.pop();
}
if (DimensionalDoorsInitializer.getConfig().getGraphicsConfig().showRiftCore) {
this.renderTesseract(vcs.getBuffer(MyRenderLayer.TESSERACT), rift, matrices, tickDelta);
} else {

View file

@ -1,5 +1,9 @@
package org.dimdev.dimdoors.client;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import org.dimdev.dimdoors.api.client.DimensionalPortalRenderer;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
@ -9,11 +13,24 @@ import net.minecraft.client.util.math.MatrixStack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.dimdev.dimdoors.item.ModItems;
import org.dimdev.dimdoors.rift.targets.IdMarker;
@Environment(EnvType.CLIENT)
public class EntranceRiftBlockEntityRenderer implements BlockEntityRenderer<EntranceRiftBlockEntity> {
@Override
public void render(EntranceRiftBlockEntity blockEntity, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, int overlay) {
if (MinecraftClient.getInstance().player != null)
if (MinecraftClient.getInstance().player.getStackInHand(Hand.MAIN_HAND).isOf(ModItems.RIFT_CONFIGURATION_TOOL))
if (blockEntity.getData().getDestination() instanceof IdMarker idMarker) {
matrixStack.push();
matrixStack.translate(0.5, 0.5, 0.5);
MinecraftClient.getInstance().textRenderer.draw(Text.of(String.valueOf(idMarker.getId())), 0f, 0f, 0xffffffff, false, matrixStack.peek().getPositionMatrix(), vertexConsumerProvider, true, 0x000000, LightmapTextureManager.MAX_LIGHT_COORDINATE);
matrixStack.pop();
}
DimensionalPortalRenderer.renderDimensionalPortal(matrixStack, vertexConsumerProvider, blockEntity.getTransformer(), tickDelta, light, overlay, blockEntity.isTall());
}
}

View file

@ -1,24 +1,8 @@
{
"type": {
"ultrawarm": false,
"natural": false,
"piglin_safe": false,
"respawn_anchor_works": false,
"bed_works": false,
"has_raids": false,
"has_skylight": false,
"has_ceiling": false,
"coordinate_scale": 1,
"ambient_light": 0,
"logical_height": 256,
"infiniburn": "#minecraft:infiniburn_overworld",
"effects":"dimdoor:limbo",
"min_y": 0,
"height": 256
},
"type": "dimdoors:limbo",
"generator": {
"type": "minecraft:noise",
"seed": 42,
"seed": 0,
"settings": "dimdoors:limbo",
"biome_source": {
"type": "minecraft:fixed",

View file

@ -5,7 +5,6 @@ accessible class net/minecraft/client/render/RenderLayer$MultiPhase
accessible class net/minecraft/client/render/RenderLayer$MultiPhaseParameters
accessible class net/minecraft/client/render/RenderPhase$Shader
accessible class net/minecraft/client/render/RenderPhase$Textures
accessible class net/minecraft/world/gen/feature/ConfiguredFeatures$Decorators
accessible method net/minecraft/entity/Entity setRotation (FF)V
# for MutableBlockEntityType

View file

@ -23,8 +23,8 @@
"door_type": "dimdoors:quartz_dimensional_door",
"x": "width/2",
"facing": "north",
"y": "5",
"z": "4",
"y": "0",
"z": "-1",
"type": "dimdoors:door",
"rift_data": {
"destination": {

View file

@ -23,8 +23,8 @@
"door_type": "dimdoors:iron_dimensional_door",
"x": "width/2",
"facing": "north",
"y": "5",
"z": "4",
"y": "0",
"z": "-1",
"type": "dimdoors:door",
"rift_data": {
"destination": {

View file

@ -1,9 +1,9 @@
package org.dimdev.dimdoors;
import org.junit.Test;
public class MiscellaneousTest {
@Test
public void runSomeTestStuff() {
}
}
//package org.dimdev.dimdoors;
//
//import org.junit.Test;
//
//public class MiscellaneousTest {
// @Test
// public void runSomeTestStuff() {
// }
//}

View file

@ -1,100 +1,100 @@
package org.dimdev.dimdoors.api;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.Bootstrap;
import net.minecraft.SharedConstants;
import net.minecraft.util.registry.Registry;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.door.data.condition.Condition;
import org.dimdev.dimdoors.pockets.generator.PocketGenerator;
import org.dimdev.dimdoors.pockets.modifier.Modifier;
import org.dimdev.dimdoors.pockets.virtual.ImplementedVirtualPocket;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.world.pocket.type.AbstractPocket;
import org.dimdev.dimdoors.world.pocket.type.addon.PocketAddon;
import org.dimdev.test.ServerTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
@RunWith(ServerTestRunner.class)
public class DimensionalDoorsApiTest {
@Test
public void apiTest() {
SharedConstants.createGameVersion();
Bootstrap.initialize();
FabricLoader.getInstance().getEntrypoints("main", ModInitializer.class).stream()
.filter(DimensionalDoorsInitializer.class::isInstance)
.map(DimensionalDoorsInitializer.class::cast)
.forEach(DimensionalDoorsInitializer::onInitialize);
DimDoorsTestApi apiTest = FabricLoader.getInstance().getEntrypoints("dimdoors:api", DimensionalDoorsApi.class).stream()
.filter(DimDoorsTestApi.class::isInstance)
.map(DimDoorsTestApi.class::cast)
.findFirst()
.orElseThrow(RuntimeException::new);
assertTrue(apiTest.hasCalledRegisterVirtualTargetTypes);
assertTrue(apiTest.hasCalledRegisterVirtualSingularPocketTypes);
assertTrue(apiTest.hasCalledRegisterModifierTypes);
assertTrue(apiTest.hasCalledRegisterPocketGeneratorTypes);
assertTrue(apiTest.hasCalledRegisterAbstractPocketTypes);
assertTrue(apiTest.hasCalledRegisterPocketAddonTypes);
assertTrue(apiTest.hasCalledRegisterConditionTypes);
assertTrue(apiTest.hasCalledPostInitialize);
}
public static class DimDoorsTestApi implements DimensionalDoorsApi {
private boolean hasCalledRegisterVirtualTargetTypes = false;
private boolean hasCalledRegisterVirtualSingularPocketTypes = false;
private boolean hasCalledRegisterModifierTypes = false;
private boolean hasCalledRegisterPocketGeneratorTypes = false;
private boolean hasCalledRegisterAbstractPocketTypes = false;
private boolean hasCalledRegisterPocketAddonTypes = false;
private boolean hasCalledRegisterConditionTypes = false;
private boolean hasCalledPostInitialize = false;
@Override
public void registerVirtualTargetTypes(Registry<VirtualTarget.VirtualTargetType<?>> registry) {
hasCalledRegisterVirtualTargetTypes = true;
}
@Override
public void registerVirtualSingularPocketTypes(Registry<ImplementedVirtualPocket.VirtualPocketType<?>> registry) {
hasCalledRegisterVirtualSingularPocketTypes = true;
}
@Override
public void registerModifierTypes(Registry<Modifier.ModifierType<?>> registry) {
hasCalledRegisterModifierTypes = true;
}
@Override
public void registerPocketGeneratorTypes(Registry<PocketGenerator.PocketGeneratorType<?>> registry) {
hasCalledRegisterPocketGeneratorTypes = true;
}
@Override
public void registerAbstractPocketTypes(Registry<AbstractPocket.AbstractPocketType<?>> registry) {
hasCalledRegisterAbstractPocketTypes = true;
}
@Override
public void registerPocketAddonTypes(Registry<PocketAddon.PocketAddonType<?>> registry) {
hasCalledRegisterPocketAddonTypes = true;
}
@Override
public void registerConditionTypes(Registry<Condition.ConditionType<?>> registry) {
hasCalledRegisterConditionTypes= true;
}
@Override
public void postInitialize() {
hasCalledPostInitialize = true;
}
}
}
//package org.dimdev.dimdoors.api;
//
//import net.fabricmc.api.ModInitializer;
//import net.fabricmc.loader.api.FabricLoader;
//import net.minecraft.Bootstrap;
//import net.minecraft.SharedConstants;
//import net.minecraft.util.registry.Registry;
//import org.dimdev.dimdoors.DimensionalDoorsInitializer;
//import org.dimdev.dimdoors.block.door.data.condition.Condition;
//import org.dimdev.dimdoors.pockets.generator.PocketGenerator;
//import org.dimdev.dimdoors.pockets.modifier.Modifier;
//import org.dimdev.dimdoors.pockets.virtual.ImplementedVirtualPocket;
//import org.dimdev.dimdoors.rift.targets.VirtualTarget;
//import org.dimdev.dimdoors.world.pocket.type.AbstractPocket;
//import org.dimdev.dimdoors.world.pocket.type.addon.PocketAddon;
//import org.dimdev.test.ServerTestRunner;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//
//import static org.junit.Assert.*;
//
//@RunWith(ServerTestRunner.class)
//public class DimensionalDoorsApiTest {
//
// @Test
// public void apiTest() {
// SharedConstants.createGameVersion();
// Bootstrap.initialize();
// FabricLoader.getInstance().getEntrypoints("main", ModInitializer.class).stream()
// .filter(DimensionalDoorsInitializer.class::isInstance)
// .map(DimensionalDoorsInitializer.class::cast)
// .forEach(DimensionalDoorsInitializer::onInitialize);
//
// DimDoorsTestApi apiTest = FabricLoader.getInstance().getEntrypoints("dimdoors:api", DimensionalDoorsApi.class).stream()
// .filter(DimDoorsTestApi.class::isInstance)
// .map(DimDoorsTestApi.class::cast)
// .findFirst()
// .orElseThrow(RuntimeException::new);
//
// assertTrue(apiTest.hasCalledRegisterVirtualTargetTypes);
// assertTrue(apiTest.hasCalledRegisterVirtualSingularPocketTypes);
// assertTrue(apiTest.hasCalledRegisterModifierTypes);
// assertTrue(apiTest.hasCalledRegisterPocketGeneratorTypes);
// assertTrue(apiTest.hasCalledRegisterAbstractPocketTypes);
// assertTrue(apiTest.hasCalledRegisterPocketAddonTypes);
// assertTrue(apiTest.hasCalledRegisterConditionTypes);
// assertTrue(apiTest.hasCalledPostInitialize);
// }
//
// public static class DimDoorsTestApi implements DimensionalDoorsApi {
// private boolean hasCalledRegisterVirtualTargetTypes = false;
// private boolean hasCalledRegisterVirtualSingularPocketTypes = false;
// private boolean hasCalledRegisterModifierTypes = false;
// private boolean hasCalledRegisterPocketGeneratorTypes = false;
// private boolean hasCalledRegisterAbstractPocketTypes = false;
// private boolean hasCalledRegisterPocketAddonTypes = false;
// private boolean hasCalledRegisterConditionTypes = false;
// private boolean hasCalledPostInitialize = false;
//
// @Override
// public void registerVirtualTargetTypes(Registry<VirtualTarget.VirtualTargetType<?>> registry) {
// hasCalledRegisterVirtualTargetTypes = true;
// }
//
// @Override
// public void registerVirtualSingularPocketTypes(Registry<ImplementedVirtualPocket.VirtualPocketType<?>> registry) {
// hasCalledRegisterVirtualSingularPocketTypes = true;
// }
//
// @Override
// public void registerModifierTypes(Registry<Modifier.ModifierType<?>> registry) {
// hasCalledRegisterModifierTypes = true;
// }
//
// @Override
// public void registerPocketGeneratorTypes(Registry<PocketGenerator.PocketGeneratorType<?>> registry) {
// hasCalledRegisterPocketGeneratorTypes = true;
// }
//
// @Override
// public void registerAbstractPocketTypes(Registry<AbstractPocket.AbstractPocketType<?>> registry) {
// hasCalledRegisterAbstractPocketTypes = true;
// }
//
// @Override
// public void registerPocketAddonTypes(Registry<PocketAddon.PocketAddonType<?>> registry) {
// hasCalledRegisterPocketAddonTypes = true;
// }
//
// @Override
// public void registerConditionTypes(Registry<Condition.ConditionType<?>> registry) {
// hasCalledRegisterConditionTypes= true;
// }
//
// @Override
// public void postInitialize() {
// hasCalledPostInitialize = true;
// }
// }
//}

View file

@ -1,52 +1,52 @@
package org.dimdev.dimdoors.api.util.math;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
public class EquationTest {
@Test
public void parseAndApply() throws Equation.EquationParseException {
Map<String, Double> empty = new HashMap<>();
double expected;
String equation;
assertThrows(Equation.EquationParseException.class, () -> Equation.parse("."));
expected = 15d;
equation = Double.toString(expected);
assertEquals(expected, Equation.parse(equation).apply(empty), 0);
expected = 4d;
equation = "2 + 2";
assertEquals(expected, Equation.parse(equation).apply(empty), 0);
expected = 1;
equation = "1 ? 1 : 0";
assertEquals(expected, Equation.parse(equation).apply(empty), 0);
expected = 0;
equation = "0 ? 1 : 0";
assertEquals(expected, Equation.parse(equation).apply(empty), 0);
expected = 1;
equation = (Math.random() + 1d) + "? 1 : 0";
assertEquals(expected, Equation.parse(equation).apply(empty), 0);
expected = 1;
equation = (Math.random() - 1d) + "? 1 : 0";
assertEquals(expected, Equation.parse(equation).apply(empty), 0);
}
public void parseAndAsBoolean() throws Equation.EquationParseException {
Map<String, Double> empty = new HashMap<>();
}
}
//package org.dimdev.dimdoors.api.util.math;
//
//import org.junit.Test;
//
//import java.util.HashMap;
//import java.util.Map;
//
//import static org.junit.Assert.*;
//
//public class EquationTest {
//
// @Test
// public void parseAndApply() throws Equation.EquationParseException {
// Map<String, Double> empty = new HashMap<>();
// double expected;
// String equation;
//
// assertThrows(Equation.EquationParseException.class, () -> Equation.parse("."));
//
// expected = 15d;
// equation = Double.toString(expected);
// assertEquals(expected, Equation.parse(equation).apply(empty), 0);
//
//
// expected = 4d;
// equation = "2 + 2";
// assertEquals(expected, Equation.parse(equation).apply(empty), 0);
//
//
// expected = 1;
// equation = "1 ? 1 : 0";
// assertEquals(expected, Equation.parse(equation).apply(empty), 0);
//
// expected = 0;
// equation = "0 ? 1 : 0";
// assertEquals(expected, Equation.parse(equation).apply(empty), 0);
//
// expected = 1;
// equation = (Math.random() + 1d) + "? 1 : 0";
// assertEquals(expected, Equation.parse(equation).apply(empty), 0);
//
// expected = 1;
// equation = (Math.random() - 1d) + "? 1 : 0";
// assertEquals(expected, Equation.parse(equation).apply(empty), 0);
// }
//
// public void parseAndAsBoolean() throws Equation.EquationParseException {
// Map<String, Double> empty = new HashMap<>();
//
//
// }
//}

View file

@ -1,27 +1,27 @@
package org.dimdev.dimdoors.api.util.math;
import org.junit.Test;
import static org.junit.Assert.*;
public class GridUtilTest {
@Test
public void idToGridPos() {
GridUtil.GridPos pos;
// I scribbled the grid down so I could figure out these tests, lmao
pos = GridUtil.idToGridPos(86);
assertEquals(new GridUtil.GridPos(8, 1), pos);
pos = GridUtil.idToGridPos(90);
assertEquals(new GridUtil.GridPos(12, 0), pos);
pos = GridUtil.idToGridPos(100);
assertEquals(new GridUtil.GridPos(7, 0), pos);
}
@Test
public void conversionConsistencyTest() {
for (int i = 0; i < 1000; i++) {
assertEquals(i, GridUtil.gridPosToID(GridUtil.idToGridPos(i)));
}
}
}
//package org.dimdev.dimdoors.api.util.math;
//
//import org.junit.Test;
//
//import static org.junit.Assert.*;
//
//public class GridUtilTest {
//
// @Test
// public void idToGridPos() {
// GridUtil.GridPos pos;
// // I scribbled the grid down so I could figure out these tests, lmao
// pos = GridUtil.idToGridPos(86);
// assertEquals(new GridUtil.GridPos(8, 1), pos);
// pos = GridUtil.idToGridPos(90);
// assertEquals(new GridUtil.GridPos(12, 0), pos);
// pos = GridUtil.idToGridPos(100);
// assertEquals(new GridUtil.GridPos(7, 0), pos);
// }
//
// @Test
// public void conversionConsistencyTest() {
// for (int i = 0; i < 1000; i++) {
// assertEquals(i, GridUtil.gridPosToID(GridUtil.idToGridPos(i)));
// }
// }
//}

View file

@ -1,46 +1,46 @@
package org.dimdev.dimdoors.api.util.math;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.EulerAngle;
import net.minecraft.util.math.Vec3d;
import org.dimdev.test.TestUtil;
import org.junit.Test;
import static org.junit.Assert.*;
public class MathUtilTest {
@Test
public void eulerAngle() {
EulerAngle expected = new EulerAngle(0, 0, 0);
Vec3d direction = new Vec3d(0, 0, 1);
Vec3d upwards = new Vec3d(0, 1, 0);
EulerAngle angle = MathUtil.eulerAngle(direction, upwards);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
expected = new EulerAngle(-90, 0, 0);
direction = new Vec3d(0, 1, 0);
upwards = new Vec3d(0, 0, -1);
angle = MathUtil.eulerAngle(direction, upwards);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
expected = new EulerAngle(0, -45, 0);
direction = new Vec3d(Math.cos(Math.PI / 2), 0, Math.cos(Math.PI / 2));
upwards = new Vec3d(0, 1, 0);
angle = MathUtil.eulerAngle(direction, upwards);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
}
@Test
public void directionEulerAngle() {
for (Direction direction : Direction.values()) {
EulerAngle expected = MathUtil.directionEulerAngle(direction);
Vec3d dir = Vec3d.of(direction.getVector());
EulerAngle angle = new EulerAngle(MathUtil.pitch(dir), MathUtil.yaw(dir), 0);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
}
}
}
//package org.dimdev.dimdoors.api.util.math;
//
//import net.minecraft.util.math.Direction;
//import net.minecraft.util.math.EulerAngle;
//import net.minecraft.util.math.Vec3d;
//
//import org.dimdev.test.TestUtil;
//import org.junit.Test;
//
//import static org.junit.Assert.*;
//
//public class MathUtilTest {
//
// @Test
// public void eulerAngle() {
// EulerAngle expected = new EulerAngle(0, 0, 0);
//
// Vec3d direction = new Vec3d(0, 0, 1);
// Vec3d upwards = new Vec3d(0, 1, 0);
// EulerAngle angle = MathUtil.eulerAngle(direction, upwards);
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// expected = new EulerAngle(-90, 0, 0);
// direction = new Vec3d(0, 1, 0);
// upwards = new Vec3d(0, 0, -1);
// angle = MathUtil.eulerAngle(direction, upwards);
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// expected = new EulerAngle(0, -45, 0);
// direction = new Vec3d(Math.cos(Math.PI / 2), 0, Math.cos(Math.PI / 2));
// upwards = new Vec3d(0, 1, 0);
// angle = MathUtil.eulerAngle(direction, upwards);
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
// }
//
// @Test
// public void directionEulerAngle() {
// for (Direction direction : Direction.values()) {
// EulerAngle expected = MathUtil.directionEulerAngle(direction);
// Vec3d dir = Vec3d.of(direction.getVector());
// EulerAngle angle = new EulerAngle(MathUtil.pitch(dir), MathUtil.yaw(dir), 0);
//
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
// }
// }
//}

View file

@ -1,130 +1,130 @@
package org.dimdev.dimdoors.api.util.math;
import net.minecraft.util.math.EulerAngle;
import net.minecraft.util.math.Vec3d;
import org.dimdev.test.TestUtil;
import org.junit.Test;
import static org.junit.Assert.*;
public class TransformationMatrix3dTest {
@Test
public void identity() {
double[][] matrix = new double[4][4];
matrix[0] = new double[]{1, 0, 0, 0};
matrix[1] = new double[]{0, 1, 0, 0};
matrix[2] = new double[]{0, 0, 1, 0};
matrix[3] = new double[]{0, 0, 0, 1};
TransformationMatrix3d identity = new TransformationMatrix3d(matrix);
assertEquals(identity, TransformationMatrix3d.identity());
matrix[3] = new double[]{1, 0, 0, 1};
TransformationMatrix3d matrix3d = new TransformationMatrix3d(matrix);
assertNotEquals(matrix3d, TransformationMatrix3d.identity());
}
@Test
public void transformVec3d() {
// rotate around
Vec3d vector = new Vec3d(1, 0, 0);
Vec3d expected;
TransformationMatrix3d rotate90DegreesY = TransformationMatrix3d.builder().rotateY(Math.PI / 2).build();
vector = rotate90DegreesY.transform(vector);
expected = new Vec3d(0, 0, -1);
assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
vector = rotate90DegreesY.transform(vector);
expected = new Vec3d(-1, 0, 0);
assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
vector = rotate90DegreesY.transform(vector);
expected = new Vec3d(0, 0, 1);
assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
vector = rotate90DegreesY.transform(vector);
expected = new Vec3d(1, 0, 0);
assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
TransformationMatrix3d rotate45DegreesY = TransformationMatrix3d.builder().rotateY(Math.PI / 4).build();
vector = rotate45DegreesY.transform(vector);
expected = new Vec3d(Math.cos(Math.PI/4), 0, -Math.sin(Math.PI/4));
assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
double random = Math.random()*2*Math.PI;
expected = new Vec3d(Math.cos(random), 0, -Math.sin(random));
TransformationMatrix3d.TransformationMatrix3dBuilder builder = TransformationMatrix3d.builder()
.rotate(new EulerAngle((((float) Math.random()) - 0.5F) * 180, (((float) Math.random()) - 0.5F) * 360, (((float) Math.random()) - 0.5F) * 360))
.translate(new Vec3d(Math.random()*100, Math.random()*100, Math.random()*100))
.rotate(new EulerAngle((((float) Math.random()) - 0.5F) * 180, (((float) Math.random()) - 0.5F) * 360, (((float) Math.random()) - 0.5F) * 360))
.translate(new Vec3d(Math.random()*100, Math.random()*100, Math.random()*100));
vector = builder.buildReverse().transform(builder.build().transform(expected));
assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
}
@Test
public void transformEulerAngle() {
EulerAngle expected;
EulerAngle angle;
TransformationMatrix3d identity = TransformationMatrix3d.identity();
expected = new EulerAngle(0, 0, 0);
angle = identity.transform(expected);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
expected = new EulerAngle(90, 0, 0);
angle = identity.transform(expected);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
expected = new EulerAngle(0, 90, 0);
angle = identity.transform(expected);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
expected = new EulerAngle(0, 0, 90);
angle = identity.transform(expected);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
expected = new EulerAngle(90, 90, 90);
angle = identity.transform(expected);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
// randomize EulerAngle
expected = new EulerAngle((((float) Math.random()) - 0.5F) * 180, (((float) Math.random()) - 0.5F) * 360, (((float) Math.random()) - 0.5F) * 360);
angle = identity.transform(expected);
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
angle = expected;
TransformationMatrix3d rotate90DegreesY = TransformationMatrix3d.builder().rotateY(Math.PI / 2).build();
for (int i = 0; i < 4; i++) {
angle = rotate90DegreesY.transform(angle);
}
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
angle = expected;
TransformationMatrix3d rotate90DegreesX = TransformationMatrix3d.builder().rotateX(Math.PI / 2).build();
for (int i = 0; i < 4; i++) {
angle = rotate90DegreesX.transform(angle);
}
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
angle = expected;
TransformationMatrix3d rotate90DegreesZ = TransformationMatrix3d.builder().rotateZ(Math.PI / 2).build();
for (int i = 0; i < 4; i++) {
angle = rotate90DegreesZ.transform(angle);
}
assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
}
@Test
public void product() {
// compare I and I^2
assertEquals(TransformationMatrix3d.identity(), TransformationMatrix3d.identity().product(TransformationMatrix3d.identity()));
}
}
//package org.dimdev.dimdoors.api.util.math;
//
//import net.minecraft.util.math.EulerAngle;
//import net.minecraft.util.math.Vec3d;
//
//import org.dimdev.test.TestUtil;
//import org.junit.Test;
//
//import static org.junit.Assert.*;
//
//public class TransformationMatrix3dTest {
//
// @Test
// public void identity() {
// double[][] matrix = new double[4][4];
// matrix[0] = new double[]{1, 0, 0, 0};
// matrix[1] = new double[]{0, 1, 0, 0};
// matrix[2] = new double[]{0, 0, 1, 0};
// matrix[3] = new double[]{0, 0, 0, 1};
// TransformationMatrix3d identity = new TransformationMatrix3d(matrix);
// assertEquals(identity, TransformationMatrix3d.identity());
//
// matrix[3] = new double[]{1, 0, 0, 1};
// TransformationMatrix3d matrix3d = new TransformationMatrix3d(matrix);
// assertNotEquals(matrix3d, TransformationMatrix3d.identity());
// }
//
// @Test
// public void transformVec3d() {
// // rotate around
// Vec3d vector = new Vec3d(1, 0, 0);
// Vec3d expected;
// TransformationMatrix3d rotate90DegreesY = TransformationMatrix3d.builder().rotateY(Math.PI / 2).build();
//
// vector = rotate90DegreesY.transform(vector);
// expected = new Vec3d(0, 0, -1);
// assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
//
// vector = rotate90DegreesY.transform(vector);
// expected = new Vec3d(-1, 0, 0);
// assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
//
// vector = rotate90DegreesY.transform(vector);
// expected = new Vec3d(0, 0, 1);
// assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
//
// vector = rotate90DegreesY.transform(vector);
// expected = new Vec3d(1, 0, 0);
// assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
//
// TransformationMatrix3d rotate45DegreesY = TransformationMatrix3d.builder().rotateY(Math.PI / 4).build();
//
// vector = rotate45DegreesY.transform(vector);
// expected = new Vec3d(Math.cos(Math.PI/4), 0, -Math.sin(Math.PI/4));
// assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
//
// double random = Math.random()*2*Math.PI;
// expected = new Vec3d(Math.cos(random), 0, -Math.sin(random));
// TransformationMatrix3d.TransformationMatrix3dBuilder builder = TransformationMatrix3d.builder()
// .rotate(new EulerAngle((((float) Math.random()) - 0.5F) * 180, (((float) Math.random()) - 0.5F) * 360, (((float) Math.random()) - 0.5F) * 360))
// .translate(new Vec3d(Math.random()*100, Math.random()*100, Math.random()*100))
// .rotate(new EulerAngle((((float) Math.random()) - 0.5F) * 180, (((float) Math.random()) - 0.5F) * 360, (((float) Math.random()) - 0.5F) * 360))
// .translate(new Vec3d(Math.random()*100, Math.random()*100, Math.random()*100));
//
// vector = builder.buildReverse().transform(builder.build().transform(expected));
// assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector));
//
// }
//
// @Test
// public void transformEulerAngle() {
// EulerAngle expected;
// EulerAngle angle;
//
// TransformationMatrix3d identity = TransformationMatrix3d.identity();
//
// expected = new EulerAngle(0, 0, 0);
// angle = identity.transform(expected);
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// expected = new EulerAngle(90, 0, 0);
// angle = identity.transform(expected);
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// expected = new EulerAngle(0, 90, 0);
// angle = identity.transform(expected);
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// expected = new EulerAngle(0, 0, 90);
// angle = identity.transform(expected);
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// expected = new EulerAngle(90, 90, 90);
// angle = identity.transform(expected);
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// // randomize EulerAngle
// expected = new EulerAngle((((float) Math.random()) - 0.5F) * 180, (((float) Math.random()) - 0.5F) * 360, (((float) Math.random()) - 0.5F) * 360);
//
// angle = identity.transform(expected);
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// angle = expected;
// TransformationMatrix3d rotate90DegreesY = TransformationMatrix3d.builder().rotateY(Math.PI / 2).build();
// for (int i = 0; i < 4; i++) {
// angle = rotate90DegreesY.transform(angle);
// }
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// angle = expected;
// TransformationMatrix3d rotate90DegreesX = TransformationMatrix3d.builder().rotateX(Math.PI / 2).build();
// for (int i = 0; i < 4; i++) {
// angle = rotate90DegreesX.transform(angle);
// }
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
//
// angle = expected;
// TransformationMatrix3d rotate90DegreesZ = TransformationMatrix3d.builder().rotateZ(Math.PI / 2).build();
// for (int i = 0; i < 4; i++) {
// angle = rotate90DegreesZ.transform(angle);
// }
// assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle));
// }
//
// @Test
// public void product() {
// // compare I and I^2
// assertEquals(TransformationMatrix3d.identity(), TransformationMatrix3d.identity().product(TransformationMatrix3d.identity()));
// }
//}

View file

@ -1,48 +1,48 @@
package org.dimdev.dimdoors.world.pocket;
import net.minecraft.util.math.Vec3i;
import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
import org.dimdev.test.ServerTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
//@RunWith(ServerTestRunner.class)
public class PocketDirectoryTest {
//@Test
public void newPocket() {
PocketDirectory directory = new PocketDirectory(ModDimensions.DUNGEON, 13);//
Pocket.PocketBuilder<?, ?> builder = Pocket.builder().expand(new Vec3i(16 * directory.getGridSize(), 1, 1));
assertEquals(0, directory.newPocket(builder).getId()); // from 0 to 0
assertEquals(1, directory.newPocket(builder).getId()); // from 1 to 1
assertEquals(2, directory.newPocket(builder).getId()); // from 2 to 2
assertEquals(3, directory.newPocket(builder).getId()); // from 3 to 3
assertEquals(4, directory.newPocket(builder).getId()); // from 4 to 4
assertEquals(5, directory.newPocket(builder).getId()); // from 5 to 5
assertEquals(6, directory.newPocket(builder).getId()); // from 6 to 6
builder = Pocket.builder().expand(new Vec3i(16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1));
assertEquals(17, directory.newPocket(builder).getId()); // from 9 to 17
assertEquals(26, directory.newPocket(builder).getId()); // from 18 to 26
builder = Pocket.builder().expand(new Vec3i(3 * 16 * directory.getGridSize() + 1, 3 * 16 * directory.getGridSize() + 1, 3 * 16 * directory.getGridSize() + 1));
assertEquals(161, directory.newPocket(builder).getId()); // from 81 to 161
builder = Pocket.builder().expand(new Vec3i(16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1));
assertEquals(35, directory.newPocket(builder).getId()); // from 27 to 35
builder = Pocket.builder().expand(new Vec3i(1, 1, 1));
assertEquals(7, directory.newPocket(builder).getId()); // from 7 to 7
assertEquals(8, directory.newPocket(builder).getId()); // from 8 to 8
assertEquals(36, directory.newPocket(builder).getId()); // from 36 to 36
}
}
//package org.dimdev.dimdoors.world.pocket;
//
//import net.minecraft.util.math.Vec3i;
//import org.dimdev.dimdoors.world.ModDimensions;
//import org.dimdev.dimdoors.world.pocket.type.Pocket;
//import org.dimdev.test.ServerTestRunner;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//
//import static org.junit.Assert.*;
//
////@RunWith(ServerTestRunner.class)
//public class PocketDirectoryTest {
//
// //@Test
// public void newPocket() {
// PocketDirectory directory = new PocketDirectory(ModDimensions.DUNGEON, 13);//
//
// Pocket.PocketBuilder<?, ?> builder = Pocket.builder().expand(new Vec3i(16 * directory.getGridSize(), 1, 1));
//
// assertEquals(0, directory.newPocket(builder).getId()); // from 0 to 0
// assertEquals(1, directory.newPocket(builder).getId()); // from 1 to 1
// assertEquals(2, directory.newPocket(builder).getId()); // from 2 to 2
// assertEquals(3, directory.newPocket(builder).getId()); // from 3 to 3
// assertEquals(4, directory.newPocket(builder).getId()); // from 4 to 4
// assertEquals(5, directory.newPocket(builder).getId()); // from 5 to 5
// assertEquals(6, directory.newPocket(builder).getId()); // from 6 to 6
//
//
//
// builder = Pocket.builder().expand(new Vec3i(16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1));
// assertEquals(17, directory.newPocket(builder).getId()); // from 9 to 17
// assertEquals(26, directory.newPocket(builder).getId()); // from 18 to 26
//
// builder = Pocket.builder().expand(new Vec3i(3 * 16 * directory.getGridSize() + 1, 3 * 16 * directory.getGridSize() + 1, 3 * 16 * directory.getGridSize() + 1));
// assertEquals(161, directory.newPocket(builder).getId()); // from 81 to 161
//
//
//
// builder = Pocket.builder().expand(new Vec3i(16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1));
// assertEquals(35, directory.newPocket(builder).getId()); // from 27 to 35
//
// builder = Pocket.builder().expand(new Vec3i(1, 1, 1));
// assertEquals(7, directory.newPocket(builder).getId()); // from 7 to 7
// assertEquals(8, directory.newPocket(builder).getId()); // from 8 to 8
// assertEquals(36, directory.newPocket(builder).getId()); // from 36 to 36
// }
//}

View file

@ -1,16 +1,16 @@
package org.dimdev.test;
import net.devtech.potatounit.TestRunner;
import net.fabricmc.api.EnvType;
import org.junit.runners.model.InitializationError;
public class ClientTestRunner extends TestRunner {
public ClientTestRunner(Class<?> testClass) throws InitializationError, ReflectiveOperationException {
super(hackyOrderMethod(testClass), EnvType.CLIENT);
}
private static Class<?> hackyOrderMethod(Class<?> testClass) {
System.setProperty("fabric.dli.main", "net.fabricmc.loader.launch.knot.KnotClient");
return testClass;
}
}
//package org.dimdev.test;
//
//import net.devtech.potatounit.TestRunner;
//import net.fabricmc.api.EnvType;
//import org.junit.runners.model.InitializationError;
//
//public class ClientTestRunner extends TestRunner {
// public ClientTestRunner(Class<?> testClass) throws InitializationError, ReflectiveOperationException {
// super(hackyOrderMethod(testClass), EnvType.CLIENT);
// }
//
// private static Class<?> hackyOrderMethod(Class<?> testClass) {
// System.setProperty("fabric.dli.main", "net.fabricmc.loader.launch.knot.KnotClient");
// return testClass;
// }
//}

View file

@ -1,16 +1,16 @@
package org.dimdev.test;
import net.devtech.potatounit.TestRunner;
import net.fabricmc.api.EnvType;
import org.junit.runners.model.InitializationError;
public class ServerTestRunner extends TestRunner {
public ServerTestRunner(Class<?> testClass) throws InitializationError, ReflectiveOperationException {
super(hackyOrderMethod(testClass), EnvType.SERVER);
}
private static Class<?> hackyOrderMethod(Class<?> testClass) {
System.setProperty("fabric.dli.main", "net.fabricmc.loader.launch.knot.KnotServer");
return testClass;
}
}
//package org.dimdev.test;
//
//import net.devtech.potatounit.TestRunner;
//import net.fabricmc.api.EnvType;
//import org.junit.runners.model.InitializationError;
//
//public class ServerTestRunner extends TestRunner {
// public ServerTestRunner(Class<?> testClass) throws InitializationError, ReflectiveOperationException {
// super(hackyOrderMethod(testClass), EnvType.SERVER);
// }
//
// private static Class<?> hackyOrderMethod(Class<?> testClass) {
// System.setProperty("fabric.dli.main", "net.fabricmc.loader.launch.knot.KnotServer");
// return testClass;
// }
//}

View file

@ -1,48 +1,48 @@
package org.dimdev.test;
import net.minecraft.util.math.EulerAngle;
import net.minecraft.util.math.Vec3d;
import org.dimdev.dimdoors.api.util.math.AbstractMatrixd;
import java.util.function.Supplier;
public class TestUtil {
public static String expectedActual(Object expected,Object actual) {
return "\nexpected:\n" + expected + "\nactual:\n" + actual + "\n";
}
public static boolean closeEnough(Vec3d expected, Vec3d actual) {
return expected.squaredDistanceTo(actual) <= expected.lengthSquared() * 1E-10;
}
public static boolean closeEnough(AbstractMatrixd<?> expected, AbstractMatrixd<?> actual) {
if (expected.getDimensionX() != actual.getDimensionX() || expected.getDimensionY() != actual.getDimensionY()) return false;
for (int i = 0; i < expected.getDimensionX(); i++) {
for (int j = 0; j < expected.getDimensionY(); j++) {
double entry1 = expected.get(i, j);
double entry2 = actual.get(i, j);
if (entry1 == entry2) continue;
if (entry1 != 0 && entry2 != 0) {
double div = entry1/entry2;
if (0.991 <= div && div <= 0.001) continue;
}
if (Math.abs(entry1 - entry2) <= 1E-10) continue;
return false;
}
}
return true;
}
public static boolean closeEnough(EulerAngle expected, EulerAngle actual) {
float yawDiff = Math.abs(expected.getYaw() - actual.getYaw());
float pitchDiff = Math.abs(expected.getPitch() - actual.getPitch());
float rollDiff = Math.abs(expected.getRoll() - actual.getRoll());
return yawDiff <= 1 && pitchDiff <= 1 && rollDiff <= 1;
}
public static String toString(EulerAngle angle) {
return "{yaw: " + angle.getYaw() + "; pitch: " + angle.getPitch() + "; roll: " + angle.getRoll() + "}";
}
}
//package org.dimdev.test;
//
//import net.minecraft.util.math.EulerAngle;
//import net.minecraft.util.math.Vec3d;
//import org.dimdev.dimdoors.api.util.math.AbstractMatrixd;
//
//import java.util.function.Supplier;
//
//public class TestUtil {
// public static String expectedActual(Object expected,Object actual) {
// return "\nexpected:\n" + expected + "\nactual:\n" + actual + "\n";
// }
//
// public static boolean closeEnough(Vec3d expected, Vec3d actual) {
// return expected.squaredDistanceTo(actual) <= expected.lengthSquared() * 1E-10;
// }
//
// public static boolean closeEnough(AbstractMatrixd<?> expected, AbstractMatrixd<?> actual) {
// if (expected.getDimensionX() != actual.getDimensionX() || expected.getDimensionY() != actual.getDimensionY()) return false;
//
// for (int i = 0; i < expected.getDimensionX(); i++) {
// for (int j = 0; j < expected.getDimensionY(); j++) {
// double entry1 = expected.get(i, j);
// double entry2 = actual.get(i, j);
// if (entry1 == entry2) continue;
// if (entry1 != 0 && entry2 != 0) {
// double div = entry1/entry2;
// if (0.991 <= div && div <= 0.001) continue;
// }
// if (Math.abs(entry1 - entry2) <= 1E-10) continue;
// return false;
// }
// }
// return true;
// }
//
// public static boolean closeEnough(EulerAngle expected, EulerAngle actual) {
// float yawDiff = Math.abs(expected.getYaw() - actual.getYaw());
// float pitchDiff = Math.abs(expected.getPitch() - actual.getPitch());
// float rollDiff = Math.abs(expected.getRoll() - actual.getRoll());
//
// return yawDiff <= 1 && pitchDiff <= 1 && rollDiff <= 1;
// }
//
// public static String toString(EulerAngle angle) {
// return "{yaw: " + angle.getYaw() + "; pitch: " + angle.getPitch() + "; roll: " + angle.getRoll() + "}";
// }
//}