Small fixes

This commit is contained in:
Runemoro 2018-01-24 05:17:42 -05:00
parent ed8f57e0d9
commit 5ba2c7a82b
16 changed files with 71 additions and 111 deletions

View file

@ -24,7 +24,7 @@ import java.util.Random;
* method of the block that would have been hit if the block wasn't there. Left clicks pass through the
* block (or maybe add an onLeftClick method).
*/ // TODO
public abstract class BlockSpecialAir extends Block { // TODO: make water and pistons pass through but not destroy
public abstract class BlockSpecialAir extends Block {
public BlockSpecialAir() {
// This is the only way to make it collide with water but not other entities, but still have a collision box for raytracing.
@ -67,8 +67,7 @@ public abstract class BlockSpecialAir extends Block { // TODO: make water and pi
// Disable raytrace hitting this block in survival unless the hitIfLiquid flag is true
@Override
public boolean canCollideCheck(IBlockState state, boolean hitIfLiquid) {
//EntityPlayer player = DimDoors.proxy.getLocalPlayer();
return /*player != null && player.isCreative() ||*/ hitIfLiquid; // TODO: re-enable this later
return hitIfLiquid;
}
// Disable dropping/picking item

View file

@ -41,5 +41,4 @@ public final class GridUtils {
return (z + 1) * z + z - x; // (number of points in the rectangle (z + 1) * z) + (z - x points on the top layer)
}
}
// TODO: add more modes: hexagonal sphere packing and maybe spiral, triangle
}

View file

@ -4,7 +4,7 @@ import net.minecraft.nbt.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import lombok.Getter;
import org.dimdev.ddutils.StringUtils;
public final class NBTUtils {

View file

@ -1,7 +1,6 @@
package org.dimdev.ddutils.schem;
import com.flowpowered.math.vector.Vector3i;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import cubicchunks.world.ICubicWorld;
import cubicchunks.world.cube.Cube;
import net.minecraft.block.Block;
@ -20,6 +19,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
@ -169,55 +169,53 @@ public class Schematic {
return schematic;
}
public static NBTTagCompound saveToNBT(Schematic schematic) {
public NBTTagCompound saveToNBT() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("Version", schematic.version);
nbt.setInteger("Version", version);
NBTTagCompound metadataCompound = new NBTTagCompound();
if (schematic.author != null) metadataCompound.setString("Author", schematic.author); // Author is not required
metadataCompound.setString("Name", schematic.name);
metadataCompound.setLong("Date", schematic.creationDate);
if (author != null) metadataCompound.setString("Author", author); // Author is not required
metadataCompound.setString("Name", name);
metadataCompound.setLong("Date", creationDate);
NBTTagList requiredModsTagList = new NBTTagList();
for (String requiredMod : schematic.requiredMods) {
for (String requiredMod : requiredMods) {
requiredModsTagList.appendTag(new NBTTagString(requiredMod));
}
metadataCompound.setTag("RequiredMods", requiredModsTagList);
nbt.setTag("Metadata", metadataCompound);
nbt.setShort("Width", schematic.width);
nbt.setShort("Height", schematic.height);
nbt.setShort("Length", schematic.length);
nbt.setIntArray("Offset", schematic.offset);
nbt.setInteger("PaletteMax", schematic.paletteMax);
nbt.setShort("Width", width);
nbt.setShort("Height", height);
nbt.setShort("Length", length);
nbt.setIntArray("Offset", offset);
nbt.setInteger("PaletteMax", paletteMax);
NBTTagCompound paletteNBT = new NBTTagCompound();
for (int i = 0; i < schematic.palette.size(); i++) {
IBlockState state = schematic.palette.get(i);
for (int i = 0; i < palette.size(); i++) {
IBlockState state = palette.get(i);
String blockStateString = getBlockStateStringFromState(state);
paletteNBT.setInteger(blockStateString, i);
}
nbt.setTag("Palette", paletteNBT);
byte[] blockDataIntArray = new byte[schematic.width * schematic.height * schematic.length];
for (int x = 0; x < schematic.width; x++) {
for (int y = 0; y < schematic.height; y++) {
for (int z = 0; z < schematic.length; z++) {
blockDataIntArray[x + z * schematic.width + y * schematic.width * schematic.length] = (byte) schematic.blockData[x][y][z]; //according to the documentation on https://github.com/SpongePowered/Schematic-Specification/blob/master/versions/schematic-1.md
byte[] blockDataIntArray = new byte[width * height * length];
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
blockDataIntArray[x + z * width + y * width * length] = (byte) blockData[x][y][z]; //according to the documentation on https://github.com/SpongePowered/Schematic-Specification/blob/master/versions/schematic-1.md
}
}
}
nbt.setByteArray("BlockData", blockDataIntArray);
NBTTagList tileEntitiesTagList = new NBTTagList();
for (int i = 0; i < schematic.tileEntities.size(); i++) {
NBTTagCompound tileEntityTagCompound = schematic.tileEntities.get(i);
for (NBTTagCompound tileEntityTagCompound : tileEntities) {
tileEntitiesTagList.appendTag(tileEntityTagCompound);
}
nbt.setTag("TileEntities", tileEntitiesTagList);
NBTTagList entitiesTagList = new NBTTagList();
for (int i = 0; i < schematic.entities.size(); i++) {
NBTTagCompound entityTagCompound = schematic.entities.get(i);
for (NBTTagCompound entityTagCompound : entities) {
entitiesTagList.appendTag(entityTagCompound);
}
nbt.setTag("Entities", entitiesTagList);
@ -277,39 +275,28 @@ public class Schematic {
return totalString;
}
// TODO: use the setBlockState method
public static Schematic createFromWorld(World world, Vector3i from, Vector3i to) {
Schematic schematic = new Schematic();
public static Schematic createFromWorld(World world, BlockPos from, BlockPos to) {
BlockPos dimensions = to.subtract(from).add(1, 1, 1);
Schematic schematic = new Schematic((short) dimensions.getX(), (short) dimensions.getY(), (short) dimensions.getZ());
Vector3i min = from.min(to);
Vector3i max = from.max(to);
Vector3i dimensions = max.sub(min).add(1, 1, 1);
schematic.width = (short) dimensions.getX();
schematic.height = (short) dimensions.getY();
schematic.length = (short) dimensions.getZ();
schematic.blockData = new short[schematic.width][schematic.height][schematic.length];
ArrayListMultimap<IBlockState, BlockPos> states = ArrayListMultimap.create();
Set<String> mods = new HashSet<>();
for (int x = 0; x < dimensions.getX(); x++) {
for (int y = 0; y < dimensions.getY(); y++) {
for (int z = 0; z < dimensions.getZ(); z++) {
BlockPos pos = new BlockPos(min.getX() + x, min.getY() + y, min.getZ() + z);
BlockPos pos = new BlockPos(from.getX() + x, from.getY() + y, from.getZ() + z);
IBlockState state = world.getBlockState(pos);
String id = getBlockStateStringFromState(state);
if (id.contains(":")) mods.add(id.split(":")[0]);
states.put(state, new BlockPos(x, y, z));
schematic.setBlockState(x, y, z, state);
TileEntity tileEntity = world.getChunkFromBlockCoords(pos).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK);
if (tileEntity != null) {
NBTTagCompound tileEntityNBT = tileEntity.serializeNBT();
tileEntityNBT.setInteger("x", tileEntityNBT.getInteger("x") - min.getX());
tileEntityNBT.setInteger("y", tileEntityNBT.getInteger("y") - min.getY());
tileEntityNBT.setInteger("z", tileEntityNBT.getInteger("z") - min.getZ());
tileEntityNBT.setInteger("x", tileEntityNBT.getInteger("x") - from.getX());
tileEntityNBT.setInteger("y", tileEntityNBT.getInteger("y") - from.getY());
tileEntityNBT.setInteger("z", tileEntityNBT.getInteger("z") - from.getZ());
schematic.tileEntities.add(tileEntityNBT);
}
@ -317,16 +304,6 @@ public class Schematic {
}
}
IBlockState[] keys = states.keySet().toArray(new IBlockState[states.keySet().size()]);
for (short i = 0; i < keys.length; i++) {
for (BlockPos pos : states.get(keys[i])) {
schematic.blockData[pos.getX()][pos.getY()][pos.getZ()] = i;
}
schematic.palette.add(i, keys[i]);
}
for (Entity entity : world.getEntitiesInAABBexcluding(null, getBoundingBox(from, to), entity -> !(entity instanceof EntityPlayerMP))) {
NBTTagCompound entityNBT = entity.serializeNBT();
@ -341,26 +318,23 @@ public class Schematic {
}
schematic.requiredMods = mods.toArray(new String[mods.size()]);
schematic.paletteMax = keys.length - 1;
schematic.creationDate = System.currentTimeMillis();
return schematic;
}
private static AxisAlignedBB getBoundingBox(Vector3i pos1, Vector3i pos2) {
return new AxisAlignedBB(new BlockPos(pos1.getX(), pos1.getY(), pos1.getZ()), new BlockPos(pos2.getX(), pos2.getY(), pos2.getZ()));
private static AxisAlignedBB getBoundingBox(Vec3i from, Vec3i to) {
return new AxisAlignedBB(new BlockPos(from.getX(), from.getY(), from.getZ()), new BlockPos(to.getX(), to.getY(), to.getZ()));
}
public static void place(Schematic schematic, World world, int xBase, int yBase, int zBase) { // TODO: check if entities and tileentities are within pocket bounds
public void place(World world, int xBase, int yBase, int zBase) {
// Place the schematic's blocks
setBlocks(schematic, world, xBase, yBase, zBase);
setBlocks(world, xBase, yBase, zBase);
// Set TileEntity data
for (NBTTagCompound tileEntityNBT : schematic.tileEntities) {
BlockPos pos = new BlockPos(
xBase + tileEntityNBT.getInteger("x"),
yBase + tileEntityNBT.getInteger("y"),
zBase + tileEntityNBT.getInteger("z"));
for (NBTTagCompound tileEntityNBT : tileEntities) {
Vec3i schematicPos = new BlockPos(tileEntityNBT.getInteger("x"), tileEntityNBT.getInteger("y"), tileEntityNBT.getInteger("z"));
BlockPos pos = new BlockPos(xBase, yBase, zBase).add(schematicPos);
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null) {
String schematicTileEntityId = tileEntityNBT.getString("id");
@ -381,7 +355,7 @@ public class Schematic {
}
// Spawn entities
for (NBTTagCompound entityNBT : schematic.entities) {
for (NBTTagCompound entityNBT : entities) {
// Correct the position and UUID
NBTTagList posNBT = (NBTTagList) entityNBT.getTag("Pos");
NBTTagList newPosNBT = new NBTTagList();
@ -406,7 +380,7 @@ public class Schematic {
}
}
private static void setBlocks(Schematic schematic, World world, int xBase, int yBase, int zBase) {
private void setBlocks(World world, int xBase, int yBase, int zBase) {
long setTime = 0;
long relightTime = 0;
// CubicChunks makes cubic worlds implement ICubicWorld
@ -415,9 +389,9 @@ public class Schematic {
if (cubicChunks && world instanceof ICubicWorld) {
DimDoors.log.info("Setting cube blockstates");
ICubicWorld cubicWorld = (ICubicWorld) world;
for (int cubeX = 0; cubeX <= (schematic.width >> 4) + 1; cubeX++) {
for (int cubeY = 0; cubeY <= (schematic.length >> 4) + 1; cubeY++) {
for (int cubeZ = 0; cubeZ <= (schematic.height >> 4) + 1; cubeZ++) {
for (int cubeX = 0; cubeX <= (width >> 4) + 1; cubeX++) {
for (int cubeY = 0; cubeY <= (length >> 4) + 1; cubeY++) {
for (int cubeZ = 0; cubeZ <= (height >> 4) + 1; cubeZ++) {
long setStart = System.nanoTime();
// Get the cube only once for efficiency
Cube cube = cubicWorld.getCubeFromCubeCoords((xBase << 4) + cubeX, (yBase << 4) + cubeY, (zBase << 4) + cubeZ);
@ -429,8 +403,8 @@ public class Schematic {
int sx = (cubeX << 4) + x - (xBase & 0x0F);
int sy = (cubeY << 4) + y - (yBase & 0x0F);
int sz = (cubeZ << 4) + z - (zBase & 0x0F);
if (sx >= 0 && sy >= 0 && sz >= 0 && sx < schematic.width && sy < schematic.height && sz < schematic.length) {
IBlockState state = schematic.palette.get(schematic.blockData[sx][sy][sz]);
if (sx >= 0 && sy >= 0 && sz >= 0 && sx < width && sy < height && sz < length) {
IBlockState state = palette.get(blockData[sx][sy][sz]);
if (!state.getBlock().equals(Blocks.AIR)) {
if (storage == null) {
cube.setStorage(storage = new ExtendedBlockStorage(cube.getY() << 4, world.provider.hasSkyLight()));
@ -455,13 +429,13 @@ public class Schematic {
}
} else {
DimDoors.log.info("Setting chunk blockstates");
for (int chunkX = 0; chunkX <= (schematic.width >> 4) + 1; chunkX++) {
for (int chunkZ = 0; chunkZ <= (schematic.length >> 4) + 1; chunkZ++) {
for (int chunkX = 0; chunkX <= (width >> 4) + 1; chunkX++) {
for (int chunkZ = 0; chunkZ <= (length >> 4) + 1; chunkZ++) {
long setStart = System.nanoTime();
// Get the chunk only once for efficiency
Chunk chunk = world.getChunkFromChunkCoords((xBase >> 4) + chunkX, (zBase >> 4) + chunkZ);
ExtendedBlockStorage[] storageArray = chunk.getBlockStorageArray();
for (int storageY = 0; storageY <= (schematic.height >> 4) + 1; storageY++) {
for (int storageY = 0; storageY <= (height >> 4) + 1; storageY++) {
// Get the storage only once for eficiency
ExtendedBlockStorage storage = storageArray[(yBase >> 4) + storageY];
boolean setAir = storage != null;
@ -471,8 +445,8 @@ public class Schematic {
int sx = (chunkX << 4) + x - (xBase & 0x0F);
int sy = (storageY << 4) + y - (yBase & 0x0F);
int sz = (chunkZ << 4) + z - (zBase & 0x0F);
if (sx >= 0 && sy >= 0 && sz >= 0 && sx < schematic.width && sy < schematic.height && sz < schematic.length) {
IBlockState state = schematic.palette.get(schematic.blockData[sx][sy][sz]);
if (sx >= 0 && sy >= 0 && sz >= 0 && sx < width && sy < height && sz < length) {
IBlockState state = palette.get(blockData[sx][sy][sz]);
if (!state.getBlock().equals(Blocks.AIR)) {
if (storage == null) {
storageArray[storageY] = storage = new ExtendedBlockStorage(storageY << 4, world.provider.hasSkyLight());
@ -497,7 +471,7 @@ public class Schematic {
}
}
}
world.markBlockRangeForRenderUpdate(xBase, yBase, zBase, xBase + schematic.width, yBase + schematic.height, zBase + schematic.length);
world.markBlockRangeForRenderUpdate(xBase, yBase, zBase, xBase + width, yBase + height, zBase + length);
DimDoors.log.info("Set block states in " + setTime / 1000000 + " ms and relit chunks/cubes in " + relightTime / 1000000);
}
}

View file

@ -4,7 +4,6 @@ import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;

View file

@ -27,12 +27,12 @@ public class CommandPocket extends CommandBase {
@Override
public String getName() {
return "pockets";
return "pocket";
}
@Override
public String getUsage(ICommandSender sender) {
return "commands.pockets.usage";
return "commands.pocket.usage";
}
@Override
@ -41,7 +41,7 @@ public class CommandPocket extends CommandBase {
// Check that the number of arguments is correct
if (args.length < 2 || args.length > 3) {
throw new WrongUsageException("commands.pockets.usage");
throw new WrongUsageException("commands.pocket.usage");
}
// Make sure the player is in a pocket world
@ -54,12 +54,12 @@ public class CommandPocket extends CommandBase {
// Check if the schematic exists
if (!SchematicHandler.INSTANCE.getTemplateGroups().contains(group)) {
throw new CommandException("commands.pockets.groupnotfound", group);
throw new CommandException("commands.pocket.group_not_found", group);
} else if (!SchematicHandler.INSTANCE.getTemplateNames(group).contains(name)) {
throw new CommandException("commands.pockets.templatenotfound", group);
throw new CommandException("commands.pocket.template_not_found", name);
}
boolean setup = parseBoolean(args[3]);
boolean setup = args.length < 3 || parseBoolean(args[2]);
// Generate the schematic
PocketTemplate template = SchematicHandler.INSTANCE.getTemplate(group, name);

View file

@ -1,13 +1,12 @@
package org.dimdev.dimdoors.shared.commands;
import com.flowpowered.math.vector.Vector3i;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import org.dimdev.ddutils.schem.Schematic;
import org.dimdev.dimdoors.shared.pockets.SchematicHandler;
import org.dimdev.pocketlib.Pocket;
@ -39,15 +38,12 @@ public class CommandSaveSchem extends CommandBase {
Pocket pocket = PocketRegistry.instance(player.dimension).getPocketAt(player.getPosition());
if (pocket == null) throw new CommandException("commands.generic.dimdoors.not_in_pocket");
Schematic schematic = Schematic.createFromWorld(player.world, toVector3i(pocket.getOrigin()), toVector3i(pocket.getOrigin()).add(Vector3i.from((pocket.getSize() + 1) * 16 - 1)));
int size = (pocket.getSize() + 1) * 16 - 1;
Schematic schematic = Schematic.createFromWorld(player.world, pocket.getOrigin(), pocket.getOrigin().add(new Vec3i(size, size, size)));
schematic.name = args[0];
schematic.author = player.getName();
SchematicHandler.INSTANCE.saveSchematic(schematic, args[0]);
notifyCommandListener(sender, this, "commands.saveschem.success", args[0]);
}
private Vector3i toVector3i(BlockPos pos) {
return Vector3i.from(pos.getX(), pos.getY(), pos.getZ());
}
}

View file

@ -17,7 +17,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import java.awt.*;
import java.util.List;
public class ItemRiftRemover extends Item {

View file

@ -68,7 +68,7 @@ public class PocketTemplate {
// Place the schematic
DimDoors.log.info("Placing new pocket using schematic " + id + " at x = " + xBase + ", z = " + zBase);
Schematic.place(schematic, world, xBase, yBase, zBase);
schematic.place(world, xBase, yBase, zBase);
}
public void setup(Pocket pocket, RiftDestination linkTo, LinkProperties linkProperties) {

View file

@ -220,8 +220,6 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
}
}
}
nameMap.put(SAVED_POCKETS_GROUP_NAME, new HashMap<>());
}
public Set<String> getTemplateGroups() {
@ -294,7 +292,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
}
public void saveSchematic(Schematic schematic, String id) {
NBTTagCompound schematicNBT = Schematic.saveToNBT(schematic);
NBTTagCompound schematicNBT = schematic.saveToNBT();
File saveFolder = new File(DimDoors.getConfigurationFolder(), "/schematics/saved");
if (!saveFolder.exists()) {
saveFolder.mkdirs();

View file

@ -10,7 +10,6 @@ import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import org.dimdev.dimdoors.shared.rifts.RiftDestination;

View file

@ -7,7 +7,6 @@ import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import org.dimdev.dimdoors.shared.rifts.RiftDestination;

View file

@ -79,7 +79,7 @@ public final class PocketSchematicGenerator {
String[] saveFolders = {"public/", "private/", "blank/", "blank/", "blank/"};
int i = 0;
for (Schematic schematic : schematics) {
NBTTagCompound schematicNBT = Schematic.saveToNBT(schematic);
NBTTagCompound schematicNBT = schematic.saveToNBT();
File saveFile = new File(schematicDir, saveFolders[i++ % saveFolders.length] + schematic.name + ".schem");
saveFile.getParentFile().mkdirs();
DataOutputStream schematicDataStream = new DataOutputStream(new FileOutputStream(saveFile));

View file

@ -252,6 +252,7 @@ public final class SchematicConverter {
if (baseState.getBlock().equals(ModBlocks.FABRIC) || baseState.getBlock().equals(ModBlocks.ANCIENT_FABRIC)) {
blockState = baseState;
} else {
//noinspection deprecation
blockState = baseState.getBlock().getStateFromMeta(metadata);
}
if (schematic.palette.contains(blockState)) { //check whether or not this blockstate is already in the list

View file

@ -51,7 +51,7 @@ public abstract class BaseSchematicGateway extends BaseGateway {
@Override
public void generate(World world, int x, int y, int z) {
Schematic.place(schematic, world, x, y, z);
schematic.place(world, x, y, z);
generateRandomBits(world, x, y, z);
}

View file

@ -112,10 +112,7 @@ info.stabilized_rift_signature.unbound2=the first and last locations together.
info.chaos_dimensional_door=Caution: Leads to random destination
info.warp_dimensional_door0=Place on the block under
info.warp_dimensional_door1=a rift to create a portal,
info.warp_dimensional_door2=or place anywhere in a
info.warp_dimensional_door3=pocket dimension to exit.
info.warp_dimensional_door0=Place on the block under a rift to create a portal, or place anywhere in a pocket dimension to exit.
entity.dimdoors.monolith.name=Monolith
@ -123,10 +120,10 @@ commands.dimteleport.usage=/dimteleport <dimension> <x> <y> <z> [yaw] [pitch]
commands.fabricconvert.usage=/fabricconvert
commands.fabricconvert.success=All fabric of reality has been converted to black.
commands.pocket.usage=/pocket <group> <name> [setup]
commands.pocket.groupnotfound=Group %s not found
commands.pocket.templatenotfound=Template %s not found
commands.pocket.group_not_found=Group %s not found
commands.pocket.template_not_found=Template %s not found
commands.saveschem.usage=/saveschem <name>
commands.saveshcem.success=Pocket %s has been successfully saved
commands.saveschem.success=Pocket %s has been successfully saved
commands.generic.dimdoors.not_in_pocket_dim=You must be in a pocket dimension to use this command.
commands.generic.dimdoors.not_in_pocket=You must be in a pocket to use this command.