Added SaveSchem Command and added Entity Support
This commit is contained in:
parent
be1c8ceda8
commit
874fa612aa
3 changed files with 98 additions and 2 deletions
|
@ -2,12 +2,14 @@ package org.dimdev.ddutils.schem;
|
||||||
|
|
||||||
import com.flowpowered.math.vector.Vector3i;
|
import com.flowpowered.math.vector.Vector3i;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
|
import javafx.geometry.BoundingBox;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.properties.IProperty;
|
import net.minecraft.block.properties.IProperty;
|
||||||
import net.minecraft.block.state.BlockStateContainer;
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityList;
|
import net.minecraft.entity.EntityList;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagDouble;
|
import net.minecraft.nbt.NBTTagDouble;
|
||||||
|
@ -15,6 +17,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.nbt.NBTTagString;
|
import net.minecraft.nbt.NBTTagString;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
@ -275,7 +278,7 @@ public class Schematic {
|
||||||
IBlockState state = world.getBlockState(pos);
|
IBlockState state = world.getBlockState(pos);
|
||||||
String id = getBlockStateStringFromState(state);
|
String id = getBlockStateStringFromState(state);
|
||||||
if(id.contains(":")) mods.add(id.split(":")[0]);
|
if(id.contains(":")) mods.add(id.split(":")[0]);
|
||||||
states.put(state, pos);
|
states.put(state, new BlockPos(x,y,z));
|
||||||
|
|
||||||
Optional.ofNullable(world.getTileEntity(pos)).ifPresent(tileEntity -> schematic.tileEntities.add(tileEntity.serializeNBT()));
|
Optional.ofNullable(world.getTileEntity(pos)).ifPresent(tileEntity -> schematic.tileEntities.add(tileEntity.serializeNBT()));
|
||||||
}
|
}
|
||||||
|
@ -292,13 +295,26 @@ public class Schematic {
|
||||||
schematic.pallette.add(i, keys[i]);
|
schematic.pallette.add(i, keys[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
schematic.requiredMods = mods.toArray(new String[0]);
|
for(Entity entity : world.getEntitiesInAABBexcluding(null, getBoundingBox(pos1, pos2), entity -> !(entity instanceof EntityPlayerMP))) {
|
||||||
|
try {
|
||||||
|
schematic.entities.add(entity.serializeNBT());
|
||||||
|
System.out.println(entity.getName() + " has serialized. Skipping.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(entity.getName() + " has failed to serialize. Skipping.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
schematic.requiredMods = mods.toArray(new String[0]);
|
||||||
|
schematic.paletteMax = keys.length;
|
||||||
schematic.creationDate = System.currentTimeMillis();
|
schematic.creationDate = System.currentTimeMillis();
|
||||||
|
|
||||||
return schematic;
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
public static void place(Schematic schematic, World world, int xBase, int yBase, int zBase) {
|
public static void place(Schematic schematic, World world, int xBase, int yBase, int zBase) {
|
||||||
// Place the schematic's blocks
|
// Place the schematic's blocks
|
||||||
List<IBlockState> palette = schematic.pallette;
|
List<IBlockState> palette = schematic.pallette;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.dimdev.dimdoors.shared.commands.CommandPocket;
|
||||||
import org.dimdev.dimdoors.shared.commands.CommandDimTeleport;
|
import org.dimdev.dimdoors.shared.commands.CommandDimTeleport;
|
||||||
import org.dimdev.dimdoors.shared.Config;
|
import org.dimdev.dimdoors.shared.Config;
|
||||||
import org.dimdev.dimdoors.shared.CommonProxy;
|
import org.dimdev.dimdoors.shared.CommonProxy;
|
||||||
|
import org.dimdev.dimdoors.shared.commands.CommandSaveSchem;
|
||||||
import org.dimdev.dimdoors.shared.items.ModItems;
|
import org.dimdev.dimdoors.shared.items.ModItems;
|
||||||
import org.dimdev.dimdoors.shared.world.gateways.GatewayGenerator;
|
import org.dimdev.dimdoors.shared.world.gateways.GatewayGenerator;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -68,6 +69,7 @@ public class DimDoors {
|
||||||
private void registerCommands(FMLServerStartingEvent event) {
|
private void registerCommands(FMLServerStartingEvent event) {
|
||||||
event.registerServerCommand(new CommandDimTeleport());
|
event.registerServerCommand(new CommandDimTeleport());
|
||||||
event.registerServerCommand(new CommandPocket());
|
event.registerServerCommand(new CommandPocket());
|
||||||
|
event.registerServerCommand(new CommandSaveSchem());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(Entity entity, String text) {
|
public static void sendMessage(Entity entity, String text) {
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
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.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
import org.dimdev.ddutils.Location;
|
||||||
|
import org.dimdev.ddutils.TeleportUtils;
|
||||||
|
import org.dimdev.ddutils.WorldUtils;
|
||||||
|
import org.dimdev.ddutils.schem.Schematic;
|
||||||
|
import org.dimdev.dimdoors.DimDoors;
|
||||||
|
import org.dimdev.dimdoors.shared.pockets.Pocket;
|
||||||
|
import org.dimdev.dimdoors.shared.pockets.PocketGenerator;
|
||||||
|
import org.dimdev.dimdoors.shared.pockets.PocketTemplate;
|
||||||
|
import org.dimdev.dimdoors.shared.pockets.SchematicHandler;
|
||||||
|
import org.dimdev.dimdoors.shared.rifts.TileEntityRift;
|
||||||
|
import org.dimdev.dimdoors.shared.world.ModDimensions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandSaveSchem extends CommandBase {
|
||||||
|
private final List<String> aliases;
|
||||||
|
|
||||||
|
public CommandSaveSchem() {
|
||||||
|
aliases = new ArrayList<>();
|
||||||
|
aliases.add("saveschem");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "saveschem";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsage(ICommandSender sender) {
|
||||||
|
return "saveschem <name> <amount>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAliases() {
|
||||||
|
return aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { // TODO: more pocket commands (replace pocket, get ID, teleport to pocket, etc.)
|
||||||
|
// Check that the number of arguments is correct
|
||||||
|
if (args.length > 2) {
|
||||||
|
sender.sendMessage(new TextComponentString("[DimDoors] Usage: /" + getUsage(sender)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Execute only if it's a player
|
||||||
|
if (sender instanceof EntityPlayerMP) {
|
||||||
|
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
|
||||||
|
|
||||||
|
Vector3i center = toVector3i(player.getPosition());
|
||||||
|
|
||||||
|
Vector3i amount = Vector3i.from(Integer.parseInt(args[1]));
|
||||||
|
|
||||||
|
Schematic schematic = Schematic.createFromWorld(args[0], player.getName(), player.world, center.sub(amount), center.add(amount));
|
||||||
|
|
||||||
|
SchematicHandler.INSTANCE.saveSchematic(schematic, args[0]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
DimDoors.log.info("Not executing command /" + getName() + " because it wasn't sent by a player.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector3i toVector3i(BlockPos pos) {
|
||||||
|
return Vector3i.from(pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue