added OffsetModifier
removed offset from pocket generators
This commit is contained in:
parent
fe827cebe3
commit
fd71a9054b
7 changed files with 75 additions and 56 deletions
|
@ -41,7 +41,6 @@ public class ChunkGenerator extends PocketGenerator {
|
||||||
|
|
||||||
private Identifier dimensionID;
|
private Identifier dimensionID;
|
||||||
private Vec3i size; // TODO: equation-ify
|
private Vec3i size; // TODO: equation-ify
|
||||||
private Vec3i offset; // TODO: equation-ify
|
|
||||||
private int virtualYOffset; // TODO: equation-ify
|
private int virtualYOffset; // TODO: equation-ify
|
||||||
|
|
||||||
public ChunkGenerator() {
|
public ChunkGenerator() {
|
||||||
|
@ -56,9 +55,6 @@ public class ChunkGenerator extends PocketGenerator {
|
||||||
int[] temp = tag.getIntArray("size");
|
int[] temp = tag.getIntArray("size");
|
||||||
this.size = new Vec3i(temp[0], temp[1], temp[2]);
|
this.size = new Vec3i(temp[0], temp[1], temp[2]);
|
||||||
|
|
||||||
temp = tag.contains("offset") ? tag.getIntArray("offset") : new int[]{0, 0, 0};
|
|
||||||
this.offset = new Vec3i(temp[0], temp[1], temp[2]);
|
|
||||||
|
|
||||||
this.virtualYOffset = tag.contains("virtual_y_offset") ? tag.getInt("virtual_y_offset") : 0;
|
this.virtualYOffset = tag.contains("virtual_y_offset") ? tag.getInt("virtual_y_offset") : 0;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -69,9 +65,6 @@ public class ChunkGenerator extends PocketGenerator {
|
||||||
|
|
||||||
tag.putString("dimension_id", dimensionID.toString());
|
tag.putString("dimension_id", dimensionID.toString());
|
||||||
tag.putIntArray("size", new int[]{this.size.getX(), this.size.getY(), this.size.getZ()});
|
tag.putIntArray("size", new int[]{this.size.getX(), this.size.getY(), this.size.getZ()});
|
||||||
if (!(offset.getX() == 0 && offset.getY() == 0 && offset.getZ() == 0)) {
|
|
||||||
tag.putIntArray("offset", new int[]{this.offset.getX(), this.offset.getY(), this.offset.getZ()});
|
|
||||||
}
|
|
||||||
tag.putInt("virtual_y_offset", this.virtualYOffset);
|
tag.putInt("virtual_y_offset", this.virtualYOffset);
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
@ -85,8 +78,6 @@ public class ChunkGenerator extends PocketGenerator {
|
||||||
int chunkSizeZ = ((this.size.getZ() >> 4) + (this.size.getZ() % 16 == 0 ? 0 : 1));
|
int chunkSizeZ = ((this.size.getZ() >> 4) + (this.size.getZ() % 16 == 0 ? 0 : 1));
|
||||||
|
|
||||||
Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket(builder);
|
Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket(builder);
|
||||||
pocket.setSize(size);
|
|
||||||
pocket.offsetOrigin(offset);
|
|
||||||
|
|
||||||
LOGGER.info("Generating chunk pocket at location " + pocket.getOrigin());
|
LOGGER.info("Generating chunk pocket at location " + pocket.getOrigin());
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,6 @@ public class SchematicGenerator extends PocketGenerator {
|
||||||
private String id;
|
private String id;
|
||||||
private Identifier templateID;
|
private Identifier templateID;
|
||||||
|
|
||||||
private String offsetX;
|
|
||||||
private Equation offsetXEquation;
|
|
||||||
private String offsetY;
|
|
||||||
private Equation offsetYEquation;
|
|
||||||
private String offsetZ;
|
|
||||||
private Equation offsetZEquation;
|
|
||||||
|
|
||||||
public SchematicGenerator() {
|
public SchematicGenerator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,17 +58,6 @@ public class SchematicGenerator extends PocketGenerator {
|
||||||
|
|
||||||
SchematicV2Handler.getInstance().loadSchematic(templateID, id);
|
SchematicV2Handler.getInstance().loadSchematic(templateID, id);
|
||||||
|
|
||||||
try {
|
|
||||||
offsetX = tag.contains("offset_x") ? tag.getString("offset_x") : "0";
|
|
||||||
offsetXEquation = Equation.parse(offsetX);
|
|
||||||
offsetY = tag.contains("offset_y") ? tag.getString("offset_y") : "0";
|
|
||||||
offsetYEquation = Equation.parse(offsetY);
|
|
||||||
offsetZ = tag.contains("offset_z") ? tag.getString("offset_z") : "0";
|
|
||||||
offsetZEquation = Equation.parse(offsetZ);
|
|
||||||
} catch (Equation.EquationParseException e) {
|
|
||||||
LOGGER.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,10 +67,6 @@ public class SchematicGenerator extends PocketGenerator {
|
||||||
|
|
||||||
tag.putString("id", this.id);
|
tag.putString("id", this.id);
|
||||||
|
|
||||||
if (!offsetX.equals("0")) tag.putString("offset_x", offsetX);
|
|
||||||
if (!offsetY.equals("0")) tag.putString("offset_y", offsetY);
|
|
||||||
if (!offsetZ.equals("0")) tag.putString("offset_z", offsetZ);
|
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +81,6 @@ public class SchematicGenerator extends PocketGenerator {
|
||||||
Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket(builder);
|
Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket(builder);
|
||||||
LOGGER.info("Generating pocket from template " + template.getId() + " at location " + pocket.getOrigin());
|
LOGGER.info("Generating pocket from template " + template.getId() + " at location " + pocket.getOrigin());
|
||||||
|
|
||||||
pocket.offsetOrigin((int) offsetXEquation.apply(variableMap), (int) offsetYEquation.apply(variableMap), (int) offsetZEquation.apply(variableMap));
|
|
||||||
|
|
||||||
template.place(pocket);
|
template.place(pocket);
|
||||||
|
|
||||||
pocket.virtualLocation = parameters.getSourceVirtualLocation(); // TODO: this makes very little sense
|
pocket.virtualLocation = parameters.getSourceVirtualLocation(); // TODO: this makes very little sense
|
||||||
|
|
|
@ -22,19 +22,12 @@ public class VoidGenerator extends PocketGenerator {
|
||||||
private Equation widthEquation;
|
private Equation widthEquation;
|
||||||
private String length;
|
private String length;
|
||||||
private Equation lengthEquation;
|
private Equation lengthEquation;
|
||||||
private String offsetX;
|
|
||||||
private Equation offsetXEquation;
|
|
||||||
private String offsetY;
|
|
||||||
private Equation offsetYEquation;
|
|
||||||
private String offsetZ;
|
|
||||||
private Equation offsetZEquation;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pocket prepareAndPlacePocket(PocketGenerationParameters parameters, Pocket.PocketBuilder<?, ?> builder) {
|
public Pocket prepareAndPlacePocket(PocketGenerationParameters parameters, Pocket.PocketBuilder<?, ?> builder) {
|
||||||
Pocket pocket = DimensionalRegistry.getPocketDirectory(parameters.getWorld().getRegistryKey()).newPocket(builder);
|
Pocket pocket = DimensionalRegistry.getPocketDirectory(parameters.getWorld().getRegistryKey()).newPocket(builder);
|
||||||
Map<String, Double> variableMap = parameters.toVariableMap(new HashMap<>());
|
Map<String, Double> variableMap = parameters.toVariableMap(new HashMap<>());
|
||||||
pocket.setSize((int) widthEquation.apply(variableMap), (int) heightEquation.apply(variableMap), (int) lengthEquation.apply(variableMap));
|
pocket.setSize((int) widthEquation.apply(variableMap), (int) heightEquation.apply(variableMap), (int) lengthEquation.apply(variableMap));
|
||||||
pocket.offsetOrigin((int) offsetXEquation.apply(variableMap), (int) offsetYEquation.apply(variableMap), (int) offsetZEquation.apply(variableMap));
|
|
||||||
|
|
||||||
return pocket;
|
return pocket;
|
||||||
}
|
}
|
||||||
|
@ -67,12 +60,6 @@ public class VoidGenerator extends PocketGenerator {
|
||||||
length = tag.getString("length");
|
length = tag.getString("length");
|
||||||
lengthEquation = Equation.parse(length);
|
lengthEquation = Equation.parse(length);
|
||||||
|
|
||||||
offsetX = tag.contains("offset_x") ? tag.getString("offset_x") : "0";
|
|
||||||
offsetXEquation = Equation.parse(offsetX);
|
|
||||||
offsetY = tag.contains("offset_y") ? tag.getString("offset_y") : "0";
|
|
||||||
offsetYEquation = Equation.parse(offsetY);
|
|
||||||
offsetZ = tag.contains("offset_z") ? tag.getString("offset_z") : "0";
|
|
||||||
offsetZEquation = Equation.parse(offsetZ);
|
|
||||||
} catch (EquationParseException e) {
|
} catch (EquationParseException e) {
|
||||||
LOGGER.error(e);
|
LOGGER.error(e);
|
||||||
}
|
}
|
||||||
|
@ -88,10 +75,6 @@ public class VoidGenerator extends PocketGenerator {
|
||||||
tag.putString("height", height);
|
tag.putString("height", height);
|
||||||
tag.putString("length", length);
|
tag.putString("length", length);
|
||||||
|
|
||||||
if (!offsetX.equals("0")) tag.putString("offset_x", offsetX);
|
|
||||||
if (!offsetY.equals("0")) tag.putString("offset_y", offsetY);
|
|
||||||
if (!offsetZ.equals("0")) tag.putString("offset_z", offsetZ);
|
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,8 @@ public interface Modifier {
|
||||||
ModifierType<PocketEntranceModifier> PUBLIC_MODIFIER_TYPE = register(new Identifier("dimdoors", PocketEntranceModifier.KEY), PocketEntranceModifier::new);
|
ModifierType<PocketEntranceModifier> PUBLIC_MODIFIER_TYPE = register(new Identifier("dimdoors", PocketEntranceModifier.KEY), PocketEntranceModifier::new);
|
||||||
ModifierType<RiftDataModifier> RIFT_DATA_MODIFIER_TYPE = register(new Identifier("dimdoors", RiftDataModifier.KEY), RiftDataModifier::new);
|
ModifierType<RiftDataModifier> RIFT_DATA_MODIFIER_TYPE = register(new Identifier("dimdoors", RiftDataModifier.KEY), RiftDataModifier::new);
|
||||||
ModifierType<RelativeReferenceModifier> RELATIVE_REFERENCE_MODIFIER_TYPE = register(new Identifier("dimdoors", RelativeReferenceModifier.KEY), RelativeReferenceModifier::new);
|
ModifierType<RelativeReferenceModifier> RELATIVE_REFERENCE_MODIFIER_TYPE = register(new Identifier("dimdoors", RelativeReferenceModifier.KEY), RelativeReferenceModifier::new);
|
||||||
|
ModifierType<OffsetModifier> OFFSET_MODIFIER_TYPE = register(new Identifier("dimdoors", OffsetModifier.KEY), OffsetModifier::new);
|
||||||
|
|
||||||
Modifier fromTag(CompoundTag tag);
|
Modifier fromTag(CompoundTag tag);
|
||||||
|
|
||||||
CompoundTag toTag(CompoundTag tag);
|
CompoundTag toTag(CompoundTag tag);
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
package org.dimdev.dimdoors.pockets.modifier;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.dimdev.dimdoors.util.PocketGenerationParameters;
|
||||||
|
import org.dimdev.dimdoors.util.math.Equation;
|
||||||
|
import org.dimdev.dimdoors.world.pocket.type.Pocket;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class OffsetModifier implements Modifier {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
public static final String KEY = "offset";
|
||||||
|
|
||||||
|
private String offsetX;
|
||||||
|
private Equation offsetXEquation;
|
||||||
|
private String offsetY;
|
||||||
|
private Equation offsetYEquation;
|
||||||
|
private String offsetZ;
|
||||||
|
private Equation offsetZEquation;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Modifier fromTag(CompoundTag tag) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
offsetX = tag.contains("offset_x") ? tag.getString("offset_x") : "0";
|
||||||
|
offsetXEquation = Equation.parse(offsetX);
|
||||||
|
offsetY = tag.contains("offset_y") ? tag.getString("offset_y") : "0";
|
||||||
|
offsetYEquation = Equation.parse(offsetY);
|
||||||
|
offsetZ = tag.contains("offset_z") ? tag.getString("offset_z") : "0";
|
||||||
|
offsetZEquation = Equation.parse(offsetZ);
|
||||||
|
} catch (Equation.EquationParseException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag toTag(CompoundTag tag) {
|
||||||
|
Modifier.super.toTag(tag);
|
||||||
|
|
||||||
|
if (!offsetX.equals("0")) tag.putString("offset_x", offsetX);
|
||||||
|
if (!offsetY.equals("0")) tag.putString("offset_y", offsetY);
|
||||||
|
if (!offsetZ.equals("0")) tag.putString("offset_z", offsetZ);
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModifierType<? extends Modifier> getType() {
|
||||||
|
return ModifierType.OFFSET_MODIFIER_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(PocketGenerationParameters parameters, RiftManager manager) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(PocketGenerationParameters parameters, Pocket.PocketBuilder<?, ?> builder) {
|
||||||
|
Map<String, Double> variableMap = parameters.toVariableMap(new HashMap<>());
|
||||||
|
builder.offsetOrigin(new Vec3i((int) offsetXEquation.apply(variableMap), (int) offsetYEquation.apply(variableMap), (int) offsetZEquation.apply(variableMap)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,8 +39,5 @@
|
||||||
"id": 0
|
"id": 0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"offset_x": "5",
|
|
||||||
"offset_y": "5",
|
|
||||||
"offset_z": "5",
|
|
||||||
"height": "5 + 16 * min(15, private_size)"
|
"height": "5 + 16 * min(15, private_size)"
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,5 @@
|
||||||
"id": 0
|
"id": 0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"offset_x": "5",
|
|
||||||
"offset_y": "5",
|
|
||||||
"offset_z": "5",
|
|
||||||
"height": "5 + 16 * min(15, public_size)"
|
"height": "5 + 16 * min(15, public_size)"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue