Skip to content

Commit

Permalink
Get ready to convert the schematics
Browse files Browse the repository at this point in the history
 - Simplified code to have a single blockstate loop and made everything simpler
 - Palette no longer contains unused IDs such as sandstone or door default blockstates
 - Schematics use placeholders for doors and monolith to make updating them not require changing all the schematics
 - Fixed bug where book wasn't being translated
 - Make a library with default destinations and link properties
 - Remove translateIdCrude, since the schematic conversion code won't be run from outside the dev environment anymore
 - Looked at net.minecraft.util.datafix to check if there were any updates that needed to be done
 - Added error checking code to make sure everything is being converted correctly
 - Removed schematic info generator, that will be added to a separate tool that can run on the new schematics (once the old ones are replaced)
 - Manually checked the NBT to make sure everything is ok
 - Fixed the schematic containing sandstone at y=0 (it was obvious it needed to be ancient fabric)
 - Changed door item ids from "dimensional_door" to "iron_dimensional_door" and from "warp_dimensional_door" to "oak_dimensional_door" to match vanilla (we might want to implement more/all wood types in the future, so it's better to do it now rather than have to convert all schematics) and renamed "rift"
 - Added "powered" to note blocks NBT (checked which were powered before)
 - Added "CookTimeTotal" to furnace NBT
 - Fix the_nexus having SenseiKiwi's hideout door being converted to a dimensional door
  • Loading branch information
Runemoro committed Jan 27, 2018
1 parent ad3bbe4 commit 9350b91
Show file tree
Hide file tree
Showing 49 changed files with 597 additions and 621 deletions.
72 changes: 0 additions & 72 deletions src/main/java/org/dimdev/ddutils/StringUtils.java

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/java/org/dimdev/ddutils/nbt/NBTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.dimdev.ddutils.StringUtils;

public final class NBTUtils {

public final static int NBT_COMPOUND_TAG_ID = StringUtils.simpleSearch(NBTTagCompound.NBT_TYPES, "COMPOUND");
public final static int STRING_TAG_ID = StringUtils.simpleSearch(NBTTagCompound.NBT_TYPES, "STRING");
//Arrays.binarySearch(NBTTagCompound.NBT_TYPES, "COMPOUND", new StringComparator()); does not seem to work?;
//netiher does Arrays.binarySearch(NBTTagCompound.NBT_TYPES, "COMPOUND", String::compareTo);

public static NBTTagCompound writeToNBT(Object obj, NBTTagCompound nbt) {
try {
Class<?> callingClass = Class.forName(new Exception().getStackTrace()[1].getClassName());
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/dimdev/ddutils/schem/Schematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Schematic(short width, short height, short length) {
this.width = width;
this.height = height;
this.length = length;
blockData = new short[width][length][height];
blockData = new short[width][height][length];
palette.add(Blocks.AIR.getDefaultState());
paletteMax++;
creationDate = System.currentTimeMillis();
Expand All @@ -87,6 +87,8 @@ public static Schematic loadFromNBT(NBTTagCompound nbt) {

if (nbt.hasKey("Date")) { //Date is not required
schematic.creationDate = metadataCompound.getLong("Date");
} else {
schematic.creationDate = -1;
}
if (nbt.hasKey("RequiredMods")) { //RequiredMods is not required (ironically)
NBTTagList requiredModsTagList = (NBTTagList) metadataCompound.getTag("RequiredMods");
Expand Down Expand Up @@ -175,7 +177,7 @@ public NBTTagCompound saveToNBT() {
NBTTagCompound metadataCompound = new NBTTagCompound();
if (author != null) metadataCompound.setString("Author", author); // Author is not required
metadataCompound.setString("Name", name);
metadataCompound.setLong("Date", creationDate);
if (creationDate != -1) metadataCompound.setLong("Date", creationDate);
NBTTagList requiredModsTagList = new NBTTagList();
for (String requiredMod : requiredMods) {
requiredModsTagList.appendTag(new NBTTagString(requiredMod));
Expand Down Expand Up @@ -366,10 +368,15 @@ public void place(World world, int xBase, int yBase, int zBase) {
adjustedEntityNBT.setUniqueId("UUID", UUID.randomUUID());

Entity entity = EntityList.createEntityFromNBT(adjustedEntityNBT, world);
// TODO: check if it is in pocket bounds
world.spawnEntity(entity);
}
}

public IBlockState getBlockState(int x, int y, int z) {
return palette.get(blockData[x][y][z]);
}

public void setBlockState(int x, int y, int z, IBlockState state) {
if (palette.contains(state)) {
blockData[x][y][z] = (short) palette.indexOf(state); // TODO: optimize this (there must be some efficient list implementations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class BlockDimensionalDoorIron extends BlockDimensionalDoor {

public static final String ID = "dimensional_door";
public static final String ID = "iron_dimensional_door";

public BlockDimensionalDoorIron() {
super(Material.IRON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class BlockDimensionalDoorWood extends BlockDimensionalDoor {

public static final String ID = "warp_dimensional_door";
public static final String ID = "oak_dimensional_door";

public BlockDimensionalDoorWood() {
super(Material.WOOD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public ItemDimensionalDoorIron() {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flagIn) {
tooltip.addAll(I18nUtils.translateMultiline("info.dimensional_door"));
tooltip.addAll(I18nUtils.translateMultiline("info.iron_dimensional_door"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public ItemDimensionalDoorWarp() {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flagIn) {
tooltip.addAll(I18nUtils.translateMultiline("info.warp_dimensional_door"));
tooltip.addAll(I18nUtils.translateMultiline("info.oak_dimensional_door"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public ItemDimensionalTrapdoorWood() {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
tooltip.addAll(I18nUtils.translateMultiline("info.wood_dimensional_trapdoor"));
tooltip.addAll(I18nUtils.translateMultiline("info.dimensional_trapdoor"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.dimdev.dimdoors.shared.pockets;

import org.dimdev.dimdoors.shared.rifts.RiftDestination;
import org.dimdev.dimdoors.shared.rifts.destinations.AvailableLinkDestination;
import org.dimdev.dimdoors.shared.rifts.destinations.PocketEntranceMarker;
import org.dimdev.dimdoors.shared.rifts.destinations.PocketExitMarker;
import org.dimdev.dimdoors.shared.rifts.registry.LinkProperties;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;

public final class DefaultDungeonDestinations { // TODO: lower weights?

public static final LinkProperties pocketLinkProperties = LinkProperties.builder()
.groups(new HashSet<>(Arrays.asList(0, 1)))
.linksRemaining(1).build();

public static final LinkProperties overworldLinkProperties = LinkProperties.builder()
.groups(new HashSet<>(Arrays.asList(0, 1)))
.entranceWeight(50)
.linksRemaining(1).build();

public static final RiftDestination deeperDungeonDestination = AvailableLinkDestination.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1)
.negativeDepthFactor(10000)
.positiveDepthFactor(160)
.weightMaximum(100)
.newRiftWeight(1).build();

public static final RiftDestination shallowerDungeonDestination = AvailableLinkDestination.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1)
.negativeDepthFactor(160)
.positiveDepthFactor(10000)
.weightMaximum(100)
.newRiftWeight(1).build();

public static final RiftDestination overworldDestination = AvailableLinkDestination.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1)
.negativeDepthFactor(0.00000000001) // The division result is cast to an int, so Double.MIN_VALUE would cause an overflow
.positiveDepthFactor(Double.POSITIVE_INFINITY)
.weightMaximum(100)
.newRiftWeight(1).build();

public static final RiftDestination twoWayPocketEntrance = PocketEntranceMarker.builder()
.weight(1)
.ifDestination(PocketExitMarker.builder().build())
.otherwiseDestination(AvailableLinkDestination.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1)
.negativeDepthFactor(80)
.positiveDepthFactor(10000)
.weightMaximum(100)
.newRiftWeight(1).build()).build();

public static final RiftDestination gatewayDestination = AvailableLinkDestination.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1) // TODO: lower value?
.negativeDepthFactor(Double.POSITIVE_INFINITY)
.positiveDepthFactor(160) // TODO: lower value?
.weightMaximum(300) // Link further away
.newRiftWeight(1)
.build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.minecraft.block.state.IBlockState;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
Expand All @@ -19,6 +20,7 @@
import org.dimdev.ddutils.math.MathUtils;
import org.dimdev.ddutils.schem.Schematic;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.dimdoors.shared.entities.EntityMonolith;
import org.dimdev.dimdoors.shared.rifts.RiftDestination;
import org.dimdev.dimdoors.shared.rifts.TileEntityRift;
import org.dimdev.dimdoors.shared.rifts.destinations.PocketEntranceMarker;
Expand All @@ -29,9 +31,7 @@
import org.dimdev.pocketlib.Pocket;
import org.dimdev.pocketlib.PocketRegistry;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.*;

/**
* @author Robijnvogel
Expand All @@ -57,6 +57,95 @@ public float getWeight(int depth) {
}
}

public void replacePlaceholders() { // TODO: it should be possible to place a schematic without replacing placeholders
// Replace placeholders (some schematics will contain them)
List<NBTTagCompound> tileEntities = new ArrayList<>();
for (NBTTagCompound tileEntityNBT : schematic.tileEntities) {
if (tileEntityNBT.hasKey("placeholder")) {
int x = tileEntityNBT.getInteger("x");
int y = tileEntityNBT.getInteger("y");
int z = tileEntityNBT.getInteger("z");

IBlockState state = schematic.palette.get(schematic.blockData[x][y][z]);

NBTTagCompound newNBT;
switch (tileEntityNBT.getString("placeholder")) {
case "deeper_depth_door":
TileEntityEntranceRift rift = (TileEntityEntranceRift) state.getBlock().createTileEntity(null, state);
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
rift.setDestination(DefaultDungeonDestinations.deeperDungeonDestination);
newNBT = rift.serializeNBT();
break;
case "shallower_depth_door":
/*TileEntityEntranceRift*/ rift = (TileEntityEntranceRift) state.getBlock().createTileEntity(null, state);
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
rift.setDestination(DefaultDungeonDestinations.shallowerDungeonDestination);
newNBT = rift.serializeNBT();
break;
case "overworld_door":
/*TileEntityEntranceRift*/ rift = (TileEntityEntranceRift) state.getBlock().createTileEntity(null, state);
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
rift.setDestination(DefaultDungeonDestinations.overworldDestination);
newNBT = rift.serializeNBT();
break;
case "pocket_entrance_door":
/*TileEntityEntranceRift*/ rift = (TileEntityEntranceRift) state.getBlock().createTileEntity(null, state);
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
rift.setDestination(DefaultDungeonDestinations.twoWayPocketEntrance);
newNBT = rift.serializeNBT();
break;
case "gateway_portal":
/*TileEntityEntranceRift*/ rift = (TileEntityEntranceRift) state.getBlock().createTileEntity(null, state);
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.overworldLinkProperties);
rift.setDestination(DefaultDungeonDestinations.gatewayDestination);
rift.setCloseAfterPassThrough(true);
newNBT = rift.serializeNBT();
break;
default:
throw new RuntimeException("Unknown tile entity placeholder: " + tileEntityNBT.getString("placeholder"));
}
// TODO: allow overriding some placeholder properties by copying other properties (not placeholder and x/y/z) to the new nbt
tileEntities.add(newNBT);
} else {
tileEntities.add(tileEntityNBT);
}
}
schematic.tileEntities = tileEntities;


List<NBTTagCompound> entities = new ArrayList<>();
for (NBTTagCompound entitiesNBT : schematic.entities) {
if (entitiesNBT.hasKey("placeholder")) {
double x = entitiesNBT.getDouble("x");
double y = entitiesNBT.getDouble("y");
double z = entitiesNBT.getDouble("z");
float yaw = entitiesNBT.getFloat("yaw");
float pitch = entitiesNBT.getFloat("pitch");

NBTTagCompound newNBT;
switch (entitiesNBT.getString("placeholder")) {
case "monolith":
EntityMonolith monolith = new EntityMonolith(null);
monolith.setLocationAndAngles(x, y, z, yaw, pitch);
newNBT = monolith.serializeNBT();
break;
default:
throw new RuntimeException("Unknown entity placeholder: " + entitiesNBT.getString("placeholder"));
}
// TODO: allow overriding some placeholder properties by copying other properties (not placeholder and x/y/z) to the new nbt
entities.add(newNBT);
} else {
entities.add(entitiesNBT);
}
}
schematic.entities = entities;
}

public void place(Pocket pocket) {
pocket.setSize(size);
int gridSize = PocketRegistry.instance(pocket.getDim()).getGridSize();
Expand All @@ -79,8 +168,8 @@ public void setup(Pocket pocket, RiftDestination linkTo, LinkProperties linkProp
int yBase = 0;
int zBase = pocket.getZ() * gridSize * 16;

// Fill chests and make rift list
List<TileEntityRift> rifts = new ArrayList<>();

for (NBTTagCompound tileEntityNBT : schematic.tileEntities) {
BlockPos pos = new BlockPos(
xBase + tileEntityNBT.getInteger("x"),
Expand Down
Loading

0 comments on commit 9350b91

Please sign in to comment.