Fix dungeon linking
This commit is contained in:
parent
86971a9871
commit
8fbd238fae
11 changed files with 126 additions and 68 deletions
|
@ -4,8 +4,11 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -27,7 +30,7 @@ public class Schematic {
|
|||
|
||||
public int version = 1;
|
||||
public String author = null;
|
||||
public String schematicName = "Unknown";
|
||||
public String name = "Unknown";
|
||||
public long creationDate;
|
||||
public String[] requiredMods = {};
|
||||
public short width;
|
||||
|
@ -38,6 +41,7 @@ public class Schematic {
|
|||
public List<IBlockState> pallette = new ArrayList<>();
|
||||
public int[][][] blockData; //[x][y][z]
|
||||
public List<NBTTagCompound> tileEntities = new ArrayList<>();
|
||||
public List<NBTTagCompound> entities = new ArrayList<>(); // Not in the specification, but we need this
|
||||
|
||||
public static Schematic loadFromNBT(NBTTagCompound nbt, String name) {
|
||||
Schematic schematic = new Schematic();
|
||||
|
@ -50,7 +54,7 @@ public class Schematic {
|
|||
schematic.author = metadataCompound.getString("Author");
|
||||
}
|
||||
//Name is not required (may be null)
|
||||
schematic.schematicName = (name == null || name.equals("")) && nbt.hasKey("Name") ? metadataCompound.getString("Name") : name;
|
||||
schematic.name = (name == null || name.equals("")) && nbt.hasKey("Name") ? metadataCompound.getString("Name") : name;
|
||||
|
||||
if (nbt.hasKey("Date")) { //Date is not required
|
||||
schematic.creationDate = metadataCompound.getLong("Date");
|
||||
|
@ -124,6 +128,14 @@ public class Schematic {
|
|||
}
|
||||
}
|
||||
|
||||
if (nbt.hasKey("Entities")) { //Entities is not required
|
||||
NBTTagList entitiesTagList = (NBTTagList) nbt.getTag("Entities");
|
||||
for (int i = 0; i < entitiesTagList.tagCount(); i++) {
|
||||
NBTTagCompound tileEntityTagCompound = entitiesTagList.getCompoundTagAt(i);
|
||||
schematic.tileEntities.add(tileEntityTagCompound);
|
||||
}
|
||||
}
|
||||
|
||||
return schematic;
|
||||
}
|
||||
|
||||
|
@ -133,7 +145,7 @@ public class Schematic {
|
|||
nbt.setInteger("Version", schematic.version);
|
||||
NBTTagCompound metadataCompound = new NBTTagCompound();
|
||||
if (schematic.author != null) metadataCompound.setString("Author", schematic.author); // Author is not required
|
||||
metadataCompound.setString("Name", schematic.schematicName);
|
||||
metadataCompound.setString("Name", schematic.name);
|
||||
metadataCompound.setLong("Date", schematic.creationDate);
|
||||
NBTTagList requiredModsTagList = new NBTTagList();
|
||||
for (String requiredMod : schematic.requiredMods) {
|
||||
|
@ -173,6 +185,13 @@ public class Schematic {
|
|||
}
|
||||
nbt.setTag("TileEntities", tileEntitiesTagList);
|
||||
|
||||
NBTTagList entitiesTagList = new NBTTagList();
|
||||
for (int i = 0; i < schematic.entities.size(); i++) {
|
||||
NBTTagCompound entityTagCompound = schematic.entities.get(i);
|
||||
entitiesTagList.appendTag(entityTagCompound);
|
||||
}
|
||||
nbt.setTag("Entities", entitiesTagList);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
|
@ -274,13 +293,35 @@ public class Schematic {
|
|||
zBase + tileEntityNBT.getInteger("z"));
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (tileEntity != null) {
|
||||
tileEntity.readFromNBT(tileEntityNBT);
|
||||
String schematicTileEntityId = tileEntityNBT.getString("id");
|
||||
String blockTileEntityId = TileEntity.getKey(tileEntity.getClass()).toString();
|
||||
if (schematicTileEntityId.equals(blockTileEntityId)) {
|
||||
tileEntity.readFromNBT(tileEntityNBT);
|
||||
|
||||
// Correct the position
|
||||
tileEntity.setWorld(world);
|
||||
tileEntity.setPos(pos);
|
||||
tileEntity.markDirty();
|
||||
// Correct the position
|
||||
tileEntity.setWorld(world);
|
||||
tileEntity.setPos(pos);
|
||||
tileEntity.markDirty();
|
||||
} else {
|
||||
throw new RuntimeException("Schematic contained TileEntity " + schematicTileEntityId + " at " + pos + " but the TileEntity of that block (" + world.getBlockState(pos) + ") must be " + blockTileEntityId);
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Schematic contained TileEntity info at " + pos + "but the block there (" + world.getBlockState(pos) + ") has no TileEntity.");
|
||||
}
|
||||
}
|
||||
|
||||
// Set Entity data
|
||||
for (NBTTagCompound entityNBT : schematic.entities) {
|
||||
NBTTagList posNBT = (NBTTagList) entityNBT.getTag("Pos");
|
||||
NBTTagList newPosNBT = new NBTTagList();
|
||||
newPosNBT.appendTag(new NBTTagDouble(posNBT.getDoubleAt(0) + xBase));
|
||||
newPosNBT.appendTag(new NBTTagDouble(posNBT.getDoubleAt(1) + yBase));
|
||||
newPosNBT.appendTag(new NBTTagDouble(posNBT.getDoubleAt(2) + zBase));
|
||||
entityNBT.setTag("Pos", newPosNBT);
|
||||
entityNBT.setUniqueId("UUID", UUID.randomUUID());
|
||||
|
||||
Entity entity = EntityList.createEntityFromNBT(entityNBT, world);
|
||||
world.spawnEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.dimdev.annotatednbt.NBTSerializable;
|
|||
import org.dimdev.annotatednbt.Saved;
|
||||
import org.dimdev.ddutils.nbt.INBTStorable;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.shared.pockets.Pocket;
|
||||
import org.dimdev.dimdoors.shared.pockets.PocketRegistry;
|
||||
import org.dimdev.ddutils.Location;
|
||||
|
@ -29,13 +30,15 @@ import org.dimdev.dimdoors.shared.world.limbodimension.WorldProviderLimbo;
|
|||
if (pocket != null) {
|
||||
virtualLocation = pocket.getVirtualLocation(); // TODO: pocket-relative coordinates
|
||||
} else {
|
||||
DimDoors.log.warn("Tried to get VirtualLocation at " + location + " which is inside a pocket dimension but outside of a pocket");
|
||||
virtualLocation = null; // TODO: door was placed in a pocket dim but outside of a pocket...
|
||||
}
|
||||
} else if (location.getWorld().provider instanceof WorldProviderLimbo) {
|
||||
virtualLocation = new VirtualLocation(location.getDim(), location.getX(), location.getZ(), Config.getMaxDungeonDepth());
|
||||
}
|
||||
if (virtualLocation == null) {
|
||||
virtualLocation = new VirtualLocation(location.getDim(), location.getX(), location.getZ(), 0);
|
||||
virtualLocation = new VirtualLocation(0, location.getX(), location.getZ(), 5); // TODO
|
||||
DimDoors.log.warn("VirtualLocation was null at " + location);
|
||||
}
|
||||
return virtualLocation;
|
||||
}
|
||||
|
|
|
@ -41,8 +41,7 @@ public abstract class BlockDimensionalDoor extends BlockDoor implements IRiftPro
|
|||
boolean successful = rift.teleport(entity);
|
||||
if (successful) entity.timeUntilPortal = 0; // Allow the entity to teleport if successful
|
||||
if (successful && entity instanceof EntityPlayer) {
|
||||
if (!state.getValue(POWERED))
|
||||
toggleDoor(world, pos, false); // TODO: config option playerClosesDoorBehind
|
||||
if (!state.getValue(POWERED)) toggleDoor(world, pos, false); // TODO: config option playerClosesDoorBehind
|
||||
if (rift.isCloseAfterPassThrough()) world.destroyBlock(pos, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@ public class CommandPocket extends CommandBase {
|
|||
}
|
||||
|
||||
// Generate the schematic
|
||||
DimDoors.sendMessage(player, "Generating schematic " + name);
|
||||
PocketTemplate template = SchematicHandler.INSTANCE.getTemplate(group, name);
|
||||
Pocket pocket = PocketGenerator.generatePocketFromTemplate(WorldUtils.getDim(player.world), template, null);
|
||||
if (setup) pocket.setup();
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.dimdev.ddutils.Location;
|
|||
import org.dimdev.ddutils.math.MathUtils;
|
||||
import org.dimdev.ddutils.nbt.INBTStorable;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.shared.VirtualLocation;
|
||||
import org.dimdev.dimdoors.shared.rifts.RiftDestination;
|
||||
import org.dimdev.dimdoors.shared.rifts.TileEntityRift;
|
||||
|
@ -84,7 +85,10 @@ import java.util.List;
|
|||
}
|
||||
}
|
||||
|
||||
if (entranceWeights.size() == 0) return;
|
||||
if (entranceWeights.size() == 0) {
|
||||
DimDoors.log.warn("Pocket had no possible entrance in schematic!");
|
||||
return;
|
||||
}
|
||||
TileEntityRift selectedEntrance = MathUtils.weightedRandom(entranceWeights);
|
||||
|
||||
// Replace entrances with appropriate destinations
|
||||
|
|
|
@ -48,7 +48,7 @@ public class PocketTemplate {
|
|||
int xBase = pocket.getX() * gridSize * 16;
|
||||
int yBase = 0;
|
||||
int zBase = pocket.getZ() * gridSize * 16;
|
||||
DimDoors.log.info("Placing new pocket using schematic " + schematic.schematicName + " at x = " + xBase + ", z = " + zBase);
|
||||
DimDoors.log.info("Placing new pocket using schematic " + schematic.name + " at x = " + xBase + ", z = " + zBase);
|
||||
|
||||
WorldServer world = WorldUtils.getWorld(dim);
|
||||
Schematic.place(schematic, world, xBase, yBase, zBase);
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.dimdev.annotatednbt.Saved;
|
|||
import org.dimdev.ddutils.*;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.shared.VirtualLocation;
|
||||
import org.dimdev.dimdoors.shared.blocks.BlockDimensionalDoor;
|
||||
import org.dimdev.dimdoors.shared.blocks.BlockFloatingRift;
|
||||
import org.dimdev.dimdoors.shared.rifts.registry.LinkProperties;
|
||||
|
@ -124,6 +125,7 @@ import javax.annotation.Nonnull;
|
|||
if (destination != null) {
|
||||
if (isRegistered()) destination.register(new Location(world, pos));
|
||||
}
|
||||
riftStateChanged = true;
|
||||
markDirty();
|
||||
updateColor();
|
||||
}
|
||||
|
@ -204,7 +206,11 @@ import javax.annotation.Nonnull;
|
|||
|
||||
// Attempt a teleport
|
||||
try {
|
||||
return destination.teleport(new RotatedLocation(new Location(world, pos), yaw, pitch), entity);
|
||||
if (destination.teleport(new RotatedLocation(new Location(world, pos), yaw, pitch), entity)) {
|
||||
VirtualLocation vloc = VirtualLocation.fromLocation(new Location(entity.world, entity.getPosition()));
|
||||
DimDoors.sendMessage(entity, "You are at x = " + vloc.getX() + ", y = ?, z = " + vloc.getZ() + ", w = " + vloc.getDepth());
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DimDoors.sendMessage(entity, "There was an exception while teleporting!");
|
||||
DimDoors.log.error("Teleporting failed with the following exception: ", e);
|
||||
|
|
|
@ -56,6 +56,7 @@ import java.util.Set;
|
|||
|
||||
for (Rift otherRift : RiftRegistry.instance().getRifts()) {
|
||||
VirtualLocation otherVirtualLocation = VirtualLocation.fromLocation(otherRift.location);
|
||||
if (otherRift.properties == null) continue;
|
||||
double otherWeight = otherRift.isFloating ? otherRift.properties.floatingWeight : otherRift.properties.entranceWeight;
|
||||
if (otherWeight == 0 || Sets.intersection(acceptedGroups, otherRift.properties.groups).isEmpty()) continue;
|
||||
|
||||
|
@ -129,6 +130,10 @@ import java.util.Set;
|
|||
// This will lead to the overworld
|
||||
World world = WorldUtils.getWorld(virtualLocation.getDim());
|
||||
BlockPos pos = world.getTopSolidOrLiquidBlock(new BlockPos(virtualLocation.getX(), 0, virtualLocation.getZ()));
|
||||
if (pos.getY() == -1) {
|
||||
// No blocks at that XZ (hole in bedrock)
|
||||
pos = new BlockPos(virtualLocation.getX(), 0, virtualLocation.getZ());
|
||||
}
|
||||
world.setBlockState(pos, ModBlocks.RIFT.getDefaultState());
|
||||
|
||||
TileEntityRift thisRift = (TileEntityRift) location.getLocation().getTileEntity();
|
||||
|
@ -136,13 +141,12 @@ import java.util.Set;
|
|||
// TODO: Should the rift not be configured like the other link
|
||||
riftEntity.setProperties(thisRift.getProperties().toBuilder().linksRemaining(1).build());
|
||||
|
||||
if (!noLinkBack && !riftEntity.getProperties().oneWay) linkRifts(selectedLink, location.getLocation());
|
||||
if (!noLink) linkRifts(location.getLocation(), selectedLink);
|
||||
if (!noLinkBack && !riftEntity.getProperties().oneWay) linkRifts(new Location(world, pos), location.getLocation());
|
||||
if (!noLink) linkRifts(location.getLocation(), new Location(world, pos));
|
||||
riftEntity.teleportTo(entity, thisRift.getYaw(), thisRift.getPitch());
|
||||
} else {
|
||||
// Make a new dungeon pocket
|
||||
//Pocket pocket = PocketGenerator.generateDungeonPocket(virtualLocation);
|
||||
Pocket pocket = PocketGenerator.generatePublicPocket(virtualLocation);
|
||||
Pocket pocket = PocketGenerator.generateDungeonPocket(virtualLocation);
|
||||
pocket.setup();
|
||||
|
||||
// Link the pocket back
|
||||
|
@ -152,7 +156,7 @@ import java.util.Set;
|
|||
pocket.linkPocketTo(new GlobalDestination(!noLinkBack && !riftEntity.getProperties().oneWay ? location.getLocation() : null), newLink); // TODO: linkId
|
||||
|
||||
// Link the rift if necessary and teleport the entity
|
||||
if (!noLink) linkRifts(location.getLocation(), selectedLink);
|
||||
if (!noLink) linkRifts(location.getLocation(), pocket.getEntrance());
|
||||
((TileEntityRift) pocket.getEntrance().getTileEntity()).teleportTo(entity, location.getYaw(), location.getPitch());
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -21,7 +21,8 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class RiftRegistry extends WorldSavedData {
|
||||
|
||||
private static final String DATA_NAME = DimDoors.MODID + "_global_rifts"; // TODO: can we use the same name as subregistries?
|
||||
// Both are saved in the "data" folder, so we can't use the same name
|
||||
private static final String DATA_NAME = DimDoors.MODID + "_global_rifts";
|
||||
private static final String SUBREGISTRY_DATA_NAME = DimDoors.MODID + "_rifts";
|
||||
|
||||
protected Map<Integer, RiftSubregistry> subregistries = new HashMap<>();
|
||||
|
@ -40,8 +41,9 @@ public class RiftRegistry extends WorldSavedData {
|
|||
|
||||
// <editor-fold defaultstate="collapsed" desc="Code for reading/writing/getting the registry">
|
||||
|
||||
public class RiftSubregistry extends WorldSavedData {
|
||||
public static class RiftSubregistry extends WorldSavedData {
|
||||
private int dim;
|
||||
RiftRegistry riftRegistry = (RiftRegistry) WorldUtils.getWorld(0).getMapStorage().getOrLoadData(RiftRegistry.class, DATA_NAME);
|
||||
|
||||
public RiftSubregistry() {
|
||||
super(SUBREGISTRY_DATA_NAME);
|
||||
|
@ -53,7 +55,7 @@ public class RiftRegistry extends WorldSavedData {
|
|||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) {
|
||||
// Registry is already loaded
|
||||
if (subregistries.get(dim) != null) return;
|
||||
if (riftRegistry.subregistries.get(dim) != null) return;
|
||||
|
||||
// Read rifts in this dimension
|
||||
NBTTagList riftsNBT = (NBTTagList) nbt.getTag("rifts");
|
||||
|
@ -61,9 +63,9 @@ public class RiftRegistry extends WorldSavedData {
|
|||
Rift rift = new Rift();
|
||||
rift.readFromNBT((NBTTagCompound) riftNBT);
|
||||
rift.dim = dim;
|
||||
graph.addVertex(rift);
|
||||
uuidMap.put(rift.id, rift);
|
||||
locationMap.put(rift.location, rift);
|
||||
riftRegistry.graph.addVertex(rift);
|
||||
riftRegistry.uuidMap.put(rift.id, rift);
|
||||
riftRegistry.locationMap.put(rift.location, rift);
|
||||
}
|
||||
|
||||
NBTTagList pocketsNBT = (NBTTagList) nbt.getTag("pockets");
|
||||
|
@ -71,18 +73,18 @@ public class RiftRegistry extends WorldSavedData {
|
|||
PocketEntrancePointer pocket = new PocketEntrancePointer();
|
||||
pocket.readFromNBT((NBTTagCompound) pocketNBT);
|
||||
pocket.dim = dim;
|
||||
graph.addVertex(pocket);
|
||||
uuidMap.put(pocket.id, pocket);
|
||||
pocketEntranceMap.put(PocketRegistry.instance(pocket.dim).getPocket(pocket.pocketId), pocket);
|
||||
riftRegistry.graph.addVertex(pocket);
|
||||
riftRegistry.uuidMap.put(pocket.id, pocket);
|
||||
riftRegistry.pocketEntranceMap.put(PocketRegistry.instance(pocket.dim).getPocket(pocket.pocketId), pocket);
|
||||
}
|
||||
|
||||
// Read the connections between links that have a source or destination in this dimension
|
||||
NBTTagList linksNBT = (NBTTagList) nbt.getTag("links");
|
||||
for (NBTBase linkNBT : linksNBT) {
|
||||
RegistryVertex from = uuidMap.get(((NBTTagCompound) linkNBT).getUniqueId("from"));
|
||||
RegistryVertex to = uuidMap.get(((NBTTagCompound) linkNBT).getUniqueId("to"));
|
||||
RegistryVertex from = riftRegistry.uuidMap.get(((NBTTagCompound) linkNBT).getUniqueId("from"));
|
||||
RegistryVertex to = riftRegistry.uuidMap.get(((NBTTagCompound) linkNBT).getUniqueId("to"));
|
||||
if (from != null && to != null) {
|
||||
graph.addEdge(from, to);
|
||||
riftRegistry.graph.addEdge(from, to);
|
||||
// We need a system for detecting links that are incomplete after processing them in the other subregistry too
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +97,7 @@ public class RiftRegistry extends WorldSavedData {
|
|||
// Write rifts in this dimension
|
||||
NBTTagList riftsNBT = new NBTTagList();
|
||||
NBTTagList pocketsNBT = new NBTTagList();
|
||||
for (RegistryVertex vertex : graph.vertexSet()) {
|
||||
for (RegistryVertex vertex : riftRegistry.graph.vertexSet()) {
|
||||
if (vertex.dim == dim) {
|
||||
NBTTagCompound vertexNBT = vertex.writeToNBT(new NBTTagCompound());
|
||||
if (vertex instanceof Rift) {
|
||||
|
@ -112,9 +114,9 @@ public class RiftRegistry extends WorldSavedData {
|
|||
|
||||
// Write the connections between links that have a source or destination in this dimension
|
||||
NBTTagList linksNBT = new NBTTagList();
|
||||
for (DefaultEdge edge : graph.edgeSet()) {
|
||||
RegistryVertex from = graph.getEdgeSource(edge);
|
||||
RegistryVertex to = graph.getEdgeTarget(edge);
|
||||
for (DefaultEdge edge : riftRegistry.graph.edgeSet()) {
|
||||
RegistryVertex from = riftRegistry.graph.getEdgeSource(edge);
|
||||
RegistryVertex to = riftRegistry.graph.getEdgeTarget(edge);
|
||||
if (from.dim == dim || to.dim == dim && !(from instanceof PlayerRiftPointer)) {
|
||||
NBTTagCompound linkNBT = new NBTTagCompound();
|
||||
linkNBT.setUniqueId("from", from.id);
|
||||
|
@ -155,6 +157,7 @@ public class RiftRegistry extends WorldSavedData {
|
|||
// done last since links are only in the subregistries.
|
||||
// TODO: If non-dirty but new WorldSavedDatas aren't automatically saved, then create the subregistries here
|
||||
// TODO: rather then in the markSubregistryDirty method.
|
||||
// TODO: try to get rid of this code:
|
||||
for (int dim : DimensionManager.getStaticDimensionIDs()) {
|
||||
MapStorage storage = WorldUtils.getWorld(dim).getPerWorldStorage();
|
||||
RiftSubregistry instance = (RiftSubregistry) storage.getOrLoadData(RiftSubregistry.class, SUBREGISTRY_DATA_NAME);
|
||||
|
|
|
@ -75,7 +75,7 @@ public final class PocketSchematicGenerator {
|
|||
boolean isPublic = true;
|
||||
for (Schematic schematic : schematics) {
|
||||
NBTTagCompound schematicNBT = Schematic.saveToNBT(schematic);
|
||||
File saveFile = new File(schematicDir, (isPublic ? "public/" : "private/") + schematic.schematicName + ".schem");
|
||||
File saveFile = new File(schematicDir, (isPublic ? "public/" : "private/") + schematic.name + ".schem");
|
||||
saveFile.getParentFile().mkdirs();
|
||||
DataOutputStream schematicDataStream = new DataOutputStream(new FileOutputStream(saveFile));
|
||||
CompressedStreamTools.writeCompressed(schematicNBT, schematicDataStream);
|
||||
|
@ -116,7 +116,7 @@ public final class PocketSchematicGenerator {
|
|||
Schematic schematic = new Schematic();
|
||||
schematic.version = 1;
|
||||
schematic.author = "Robijnvogel"; //@todo set in build.gradle ${modID}
|
||||
schematic.schematicName = baseName + "_" + pocketSize;
|
||||
schematic.name = baseName + "_" + pocketSize;
|
||||
schematic.creationDate = System.currentTimeMillis();
|
||||
schematic.requiredMods = new String[1];
|
||||
schematic.requiredMods[0] = DimDoors.MODID;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package org.dimdev.dimdoors.shared.tools;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.*;
|
||||
|
@ -16,16 +16,14 @@ import org.dimdev.ddutils.schem.Schematic;
|
|||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.shared.blocks.BlockFabric;
|
||||
import org.dimdev.dimdoors.shared.blocks.ModBlocks;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.init.Blocks;
|
||||
import org.dimdev.dimdoors.shared.rifts.destinations.AvailableLinkDestination;
|
||||
import org.dimdev.dimdoors.shared.rifts.destinations.PocketEntranceDestination;
|
||||
import org.dimdev.dimdoors.shared.rifts.destinations.PocketExitDestination;
|
||||
import org.dimdev.dimdoors.shared.rifts.registry.LinkProperties;
|
||||
import org.dimdev.dimdoors.shared.tileentities.TileEntityEntranceRift;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
|
@ -48,7 +46,7 @@ public final class SchematicConverter {
|
|||
|
||||
schematic.version = 1; //already the default value
|
||||
schematic.author = "DimDoors"; // Old schematics didn't have an author
|
||||
schematic.schematicName = name.equals("") ? "Unknown" : name;
|
||||
schematic.name = name.equals("") ? "Unknown" : name;
|
||||
schematic.creationDate = System.currentTimeMillis();
|
||||
schematic.requiredMods = new String[]{DimDoors.MODID};
|
||||
|
||||
|
@ -142,19 +140,19 @@ public final class SchematicConverter {
|
|||
|
||||
IBlockState baseState = schematic.pallette.get(blockInt); //this is the default blockstate except for ancient fabric
|
||||
if (baseState == baseState.getBlock().getDefaultState()) { //should only be false if {@code baseState} is ancient fabric
|
||||
IBlockState additionalState = baseState.getBlock().getStateFromMeta(metadata);
|
||||
if (schematic.pallette.contains(additionalState)) { //check whether or not this blockstate is already in the list
|
||||
blockInt = schematic.pallette.indexOf(additionalState);
|
||||
IBlockState blockState = baseState.getBlock().getStateFromMeta(metadata);
|
||||
if (schematic.pallette.contains(blockState)) { //check whether or not this blockstate is already in the list
|
||||
blockInt = schematic.pallette.indexOf(blockState);
|
||||
} else {
|
||||
schematic.pallette.add(additionalState);
|
||||
schematic.pallette.add(blockState);
|
||||
//DimDoors.log.info("New blockstate detected. Original blockInt = " + blockInt + " and baseState is " + baseState);
|
||||
blockInt = schematic.pallette.size() - 1;
|
||||
}
|
||||
|
||||
if (baseState.getBlock().equals(ModBlocks.DIMENSIONAL_DOOR) || baseState.getBlock().equals(ModBlocks.WARP_DIMENSIONAL_DOOR)) {
|
||||
//DimDoors.log.info("Door found: " + baseState.getBlock().getUnlocalizedName());
|
||||
if (additionalState.getProperties().get(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER)) {
|
||||
TileEntityEntranceRift rift = new TileEntityEntranceRift();
|
||||
if (blockState.getProperties().get(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.LOWER)) {
|
||||
TileEntityEntranceRift rift = (TileEntityEntranceRift) baseState.getBlock().createTileEntity(null, blockState);
|
||||
rift.setPos(new BlockPos(x, y, z));
|
||||
|
||||
rift.setProperties(LinkProperties.builder()
|
||||
|
@ -171,38 +169,39 @@ public final class SchematicConverter {
|
|||
.noLink(false)
|
||||
.newRiftWeight(1).build());
|
||||
} else { //if (baseState.equals(ModBlocks.WARP_DIMENSIONAL_DOOR))
|
||||
IBlockState baseStateTwoDown = schematic.pallette.get(schematic.blockData[x][y - 2][z]);
|
||||
if (baseStateTwoDown.getBlock().equals(Blocks.SANDSTONE)) {
|
||||
IBlockState stateBelow = schematic.pallette.get(schematic.blockData[x][y - 1][z]);
|
||||
if (stateBelow.getBlock().equals(Blocks.SANDSTONE)) {
|
||||
rift.setDestination(AvailableLinkDestination.builder()
|
||||
.acceptedGroups(Collections.singleton(0))
|
||||
.coordFactor(1)
|
||||
.negativeDepthFactor(Double.MIN_VALUE)
|
||||
.negativeDepthFactor(0.00000000001)
|
||||
.positiveDepthFactor(Double.POSITIVE_INFINITY)
|
||||
.weightMaximum(100)
|
||||
.noLink(false)
|
||||
.newRiftWeight(1).build());
|
||||
//change the sandstone to the block below it.
|
||||
if (y > 2) {
|
||||
schematic.blockData[x][y - 2][z] = schematic.blockData[x][y - 3][z];
|
||||
if (y >= 2) {
|
||||
schematic.blockData[x][y - 1][z] = schematic.blockData[x][y - 2][z];
|
||||
} else {
|
||||
DimDoors.log.error("Someone placed a door on a sandstone block at the bottom of a schematic. This causes problems and should be remedied. Schematic name: " + schematic.schematicName);
|
||||
DimDoors.log.error("Someone placed a door on a sandstone block at the bottom of a schematic. This causes problems and should be remedied. Schematic name: " + schematic.name);
|
||||
}
|
||||
} else {
|
||||
rift.setDestination(AvailableLinkDestination.builder()
|
||||
.acceptedGroups(Collections.singleton(0))
|
||||
.coordFactor(1)
|
||||
.negativeDepthFactor(80)
|
||||
.positiveDepthFactor(10000)
|
||||
.weightMaximum(100)
|
||||
.noLink(false)
|
||||
.newRiftWeight(1).build());
|
||||
rift.setDestination(PocketEntranceDestination.builder()
|
||||
.weight(1)
|
||||
.ifDestination(PocketExitDestination.builder().build())
|
||||
.otherwiseDestination(AvailableLinkDestination.builder()
|
||||
.acceptedGroups(Collections.singleton(0))
|
||||
.coordFactor(1)
|
||||
.negativeDepthFactor(80)
|
||||
.positiveDepthFactor(10000)
|
||||
.weightMaximum(100)
|
||||
.noLink(false).newRiftWeight(1).build()).build());
|
||||
}
|
||||
}
|
||||
|
||||
schematic.tileEntities.add(rift.serializeNBT());
|
||||
}
|
||||
}
|
||||
|
||||
} else { // if this is ancient fabric
|
||||
blockInt = schematic.pallette.indexOf(baseState);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue