mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Implement loot system
This commit is contained in:
parent
9a54f364be
commit
2b460f8617
11
pom.xml
11
pom.xml
@ -25,10 +25,6 @@
|
||||
<version>3.2.4</version>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.polydev.gaea</pattern>
|
||||
<shadedPattern>com.dfsek.terra.lib.gaea</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.apache.commons</pattern>
|
||||
<shadedPattern>com.dfsek.terra.lib.commons</shadedPattern>
|
||||
@ -96,6 +92,7 @@
|
||||
<groupId>org.polydev</groupId>
|
||||
<artifactId>gaea</artifactId>
|
||||
<version>1.10.93</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@ -120,6 +117,12 @@
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,20 +1,16 @@
|
||||
package com.dfsek.terra.async;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.genconfig.StructureConfig;
|
||||
import com.dfsek.terra.structure.GaeaStructure;
|
||||
import com.dfsek.terra.structure.StructureSpawnRequirement;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.profiler.ProfileFuture;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@ -91,8 +87,8 @@ public class AsyncStructureFinder implements Runnable {
|
||||
Location spawn = target.getSpawn().getNearestSpawn(x, z, world.getSeed()).toLocation(world);
|
||||
if(! TerraWorld.getWorld(world).getConfig().getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(target)) return false;
|
||||
Random r2 = new Random(spawn.hashCode());
|
||||
GaeaStructure struc = target.getStructure(r2);
|
||||
GaeaStructure.Rotation rotation = GaeaStructure.Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||
Structure struc = target.getStructure(r2);
|
||||
Structure.Rotation rotation = Structure.Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||
for(int y = target.getSearchStart().get(r2); y > 0; y--) {
|
||||
if(!target.getBound().isInRange(y)) return false;
|
||||
spawn.setY(y);
|
||||
|
@ -4,7 +4,7 @@ import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.util.structure.WorldEditUtil;
|
||||
import com.dfsek.terra.command.type.PlayerCommand;
|
||||
import com.dfsek.terra.structure.GaeaStructure;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.structure.InitializationException;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
@ -24,9 +24,9 @@ public class ExportCommand extends PlayerCommand {
|
||||
if(l == null) return true;
|
||||
Location l1 = l[0];
|
||||
Location l2 = l[1];
|
||||
GaeaStructure structure;
|
||||
Structure structure;
|
||||
try {
|
||||
structure = new GaeaStructure(l1, l2, args[0]);
|
||||
structure = new Structure(l1, l2, args[0]);
|
||||
} catch(InitializationException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
return true;
|
||||
|
@ -4,7 +4,7 @@ import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.command.type.DebugCommand;
|
||||
import com.dfsek.terra.command.type.PlayerCommand;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.structure.GaeaStructure;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -19,14 +19,14 @@ public class LoadCommand extends PlayerCommand implements DebugCommand {
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
try {
|
||||
GaeaStructure.Rotation r;
|
||||
Structure.Rotation r;
|
||||
try {
|
||||
r =GaeaStructure.Rotation.fromDegrees(Integer.parseInt(args[1]));
|
||||
r = Structure.Rotation.fromDegrees(Integer.parseInt(args[1]));
|
||||
} catch(NumberFormatException e) {
|
||||
LangUtil.send("command.structure.invalid-rotation", sender, args[1]);
|
||||
return true;
|
||||
}
|
||||
GaeaStructure struc = GaeaStructure.load(new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
|
||||
Structure struc = Structure.load(new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
|
||||
if("true".equals(args[2])) struc.paste(sender.getLocation(), r);
|
||||
else struc.paste(sender.getLocation(), sender.getLocation().getChunk(), r);
|
||||
//sender.sendMessage(String.valueOf(struc.checkSpawns(sender.getLocation(), r)));
|
||||
|
@ -8,24 +8,29 @@ import com.dfsek.terra.config.exception.ConfigException;
|
||||
import com.dfsek.terra.config.exception.NotFoundException;
|
||||
import com.dfsek.terra.population.StructurePopulator;
|
||||
import com.dfsek.terra.procgen.GridSpawn;
|
||||
import com.dfsek.terra.structure.GaeaStructure;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.structures.loot.LootTable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class StructureConfig extends TerraConfig {
|
||||
private final ProbabilityCollection<GaeaStructure> structure = new ProbabilityCollection<>();
|
||||
private final ProbabilityCollection<Structure> structure = new ProbabilityCollection<>();
|
||||
private final GridSpawn spawn;
|
||||
private final String id;
|
||||
private final Range searchStart;
|
||||
private final Range bound;
|
||||
private final Map<Integer, LootTable> loot = new HashMap<>();
|
||||
StructurePopulator.SearchType type;
|
||||
public StructureConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
@ -36,7 +41,7 @@ public class StructureConfig extends TerraConfig {
|
||||
for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("files")).getValues(false).entrySet()) {
|
||||
try {
|
||||
File structureFile = new File(config.getDataFolder() + File.separator + "structures" + File.separator + "data", e.getKey() + ".tstructure");
|
||||
structure.add(GaeaStructure.load(structureFile), (Integer) e.getValue());
|
||||
structure.add(Structure.load(structureFile), (Integer) e.getValue());
|
||||
} catch(FileNotFoundException ex) {
|
||||
Debug.stack(ex);
|
||||
throw new NotFoundException("Structure File", e.getKey(), getID());
|
||||
@ -51,6 +56,24 @@ public class StructureConfig extends TerraConfig {
|
||||
}
|
||||
throw new NotFoundException("Structure", getString("file"), getID());
|
||||
}
|
||||
if(contains("loot")) {
|
||||
for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("loot")).getValues(false).entrySet()) {
|
||||
File lootFile = new File(config.getDataFolder() + File.separator + "structures" + File.separator + "loot", e.getValue().toString() + ".json");
|
||||
try {
|
||||
loot.put(Integer.valueOf(e.getKey()), new LootTable(FileUtils.readFileToString(lootFile)));
|
||||
Debug.info("Loaded loot table from " + lootFile.getAbsolutePath() + " with ID " + e.getKey());
|
||||
} catch(FileNotFoundException ex) {
|
||||
Debug.stack(ex);
|
||||
throw new NotFoundException("Loot Table File", e.getKey(), getID());
|
||||
} catch(ClassCastException | NumberFormatException ex) {
|
||||
Debug.stack(ex);
|
||||
throw new ConfigException("Unable to parse Structure Loot configuration! Check YAML syntax.", getID());
|
||||
} catch(ParseException parseException) {
|
||||
Debug.stack(parseException);
|
||||
throw new ConfigException("Invalid loot table data in file: " + lootFile.getAbsolutePath(), getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spawn = new GridSpawn(getInt("spawn.width", 500), getInt("spawn.padding", 100));
|
||||
searchStart = new Range(getInt("spawn.start.min", 72), getInt("spawn.start.max", 72));
|
||||
@ -67,7 +90,7 @@ public class StructureConfig extends TerraConfig {
|
||||
return id;
|
||||
}
|
||||
|
||||
public GaeaStructure getStructure(Random r) {
|
||||
public Structure getStructure(Random r) {
|
||||
return structure.get(r);
|
||||
}
|
||||
|
||||
@ -82,4 +105,8 @@ public class StructureConfig extends TerraConfig {
|
||||
public Range getSearchStart() {
|
||||
return searchStart;
|
||||
}
|
||||
|
||||
public LootTable getLoot(int id) {
|
||||
return loot.get(id);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
import com.dfsek.terra.config.exception.NotFoundException;
|
||||
import com.dfsek.terra.structure.GaeaStructure;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@ -17,7 +17,6 @@ import org.polydev.gaea.tree.Tree;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
@ -27,7 +26,7 @@ public class TreeConfig extends TerraConfig implements Tree {
|
||||
private final Set<Material> spawnable;
|
||||
private final String id;
|
||||
private final int yOffset;
|
||||
private final ProbabilityCollection<GaeaStructure> structure = new ProbabilityCollection<>();
|
||||
private final ProbabilityCollection<Structure> structure = new ProbabilityCollection<>();
|
||||
public TreeConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
spawnable = ConfigUtil.toBlockData(getStringList("spawnable"), "spawnable", getID());
|
||||
@ -39,7 +38,7 @@ public class TreeConfig extends TerraConfig implements Tree {
|
||||
for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("files")).getValues(false).entrySet()) {
|
||||
try {
|
||||
File structureFile = new File(config.getDataFolder() + File.separator + "trees" + File.separator + "data", e.getKey() + ".tstructure");
|
||||
structure.add(GaeaStructure.load(structureFile), (Integer) e.getValue());
|
||||
structure.add(Structure.load(structureFile), (Integer) e.getValue());
|
||||
} catch(FileNotFoundException ex) {
|
||||
Debug.stack(ex);
|
||||
throw new NotFoundException("Tree Structure File", e.getKey(), getID());
|
||||
@ -65,8 +64,8 @@ public class TreeConfig extends TerraConfig implements Tree {
|
||||
public boolean plant(Location location, Random random, boolean b, JavaPlugin javaPlugin) {
|
||||
Location mut = location.clone().subtract(0, yOffset, 0);
|
||||
if(!spawnable.contains(location.getBlock().getType())) return false;
|
||||
GaeaStructure struc = structure.get(random);
|
||||
GaeaStructure.Rotation rotation = GaeaStructure.Rotation.fromDegrees(random.nextInt(4) * 90);
|
||||
Structure struc = structure.get(random);
|
||||
Structure.Rotation rotation = Structure.Rotation.fromDegrees(random.nextInt(4) * 90);
|
||||
if(!struc.checkSpawns(mut, rotation)) return false;
|
||||
struc.paste(mut, rotation);
|
||||
return true;
|
||||
|
@ -1,22 +1,25 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.genconfig.StructureConfig;
|
||||
import com.dfsek.terra.structure.GaeaStructure;
|
||||
import com.dfsek.terra.structure.StructureSpawnRequirement;
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.structure.StructureContainedInventory;
|
||||
import com.dfsek.terra.util.structure.RotationUtil;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.inventory.BlockInventoryHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.profiler.ProfileFuture;
|
||||
import org.polydev.gaea.structures.loot.LootTable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
public class StructurePopulator extends BlockPopulator {
|
||||
@ -34,8 +37,8 @@ public class StructurePopulator extends BlockPopulator {
|
||||
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
|
||||
if(!config.getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(conf)) continue;
|
||||
Random r2 = new Random(spawn.hashCode());
|
||||
GaeaStructure struc = conf.getStructure(r2);
|
||||
GaeaStructure.Rotation rotation = GaeaStructure.Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||
Structure struc = conf.getStructure(r2);
|
||||
Structure.Rotation rotation = Structure.Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||
for(int y = conf.getSearchStart().get(r2); y > 0; y--) {
|
||||
if(!conf.getBound().isInRange(y)) continue structure;
|
||||
spawn.setY(y);
|
||||
@ -44,6 +47,19 @@ public class StructurePopulator extends BlockPopulator {
|
||||
if(Math.abs((cx + 8) - spawn.getBlockX()) <= horizontal && Math.abs((cz + 8) - spawn.getBlockZ()) <= horizontal) {
|
||||
try(ProfileFuture ignore = TerraProfiler.fromWorld(world).measure("StructurePasteTime")) {
|
||||
struc.paste(spawn, chunk, rotation);
|
||||
for(StructureContainedInventory i : struc.getInventories()) {
|
||||
Debug.info("Attempting to populate loot: " + i.getUid());
|
||||
Vector2 lootCoords = RotationUtil.getRotatedCoords(new Vector2(i.getX()-struc.getStructureInfo().getCenterX(), i.getZ()-struc.getStructureInfo().getCenterZ()), rotation);
|
||||
Location inv = spawn.clone().add(lootCoords.getX(), 0, lootCoords.getZ());
|
||||
Debug.info(spawn.toString() + " became: " + inv.toString());
|
||||
Debug.info(Math.floorDiv(inv.getBlockX(), 16) + ":" + chunk.getX() + ", " + Math.floorDiv(inv.getBlockZ(), 16) + ":" + chunk.getZ() );
|
||||
if(Math.floorDiv(inv.getBlockX(), 16) != chunk.getX() || Math.floorDiv(inv.getBlockZ(), 16) != chunk.getZ()) continue;
|
||||
Debug.info("Target is in chunk.");
|
||||
LootTable table = conf.getLoot(i.getUid());
|
||||
if(table == null) continue;
|
||||
Debug.info("Target has table assigned.");
|
||||
table.fillInventory(((BlockInventoryHolder) inv.getBlock().getState()).getInventory(), random);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.dfsek.terra.structure;
|
||||
|
||||
import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import com.dfsek.terra.util.structure.RotationUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
@ -10,6 +9,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
@ -17,7 +17,8 @@ import org.bukkit.block.data.MultipleFacing;
|
||||
import org.bukkit.block.data.Orientable;
|
||||
import org.bukkit.block.data.Rail;
|
||||
import org.bukkit.block.data.Rotatable;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.block.data.type.RedstoneWire;
|
||||
import org.bukkit.inventory.BlockInventoryHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
@ -30,26 +31,25 @@ import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.dfsek.terra.util.structure.RotationUtil.*;
|
||||
|
||||
public class GaeaStructure implements Serializable {
|
||||
public class Structure implements Serializable {
|
||||
public static final long serialVersionUID = -6664585217063842035L;
|
||||
private final StructureContainedBlock[][][] structure;
|
||||
private final GaeaStructureInfo structureInfo;
|
||||
private final StructureInfo structureInfo;
|
||||
private final String id;
|
||||
private final UUID uuid;
|
||||
private final HashSet<StructureContainedBlock> spawns;
|
||||
private final HashSet<StructureContainedInventory> inventories;
|
||||
|
||||
@NotNull
|
||||
public static GaeaStructure load(@NotNull File f) throws IOException {
|
||||
public static Structure load(@NotNull File f) throws IOException {
|
||||
try {
|
||||
return fromFile(f);
|
||||
} catch(ClassNotFoundException e) {
|
||||
@ -57,11 +57,12 @@ public class GaeaStructure implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public GaeaStructure(@NotNull Location l1, @NotNull Location l2, @NotNull String id) throws InitializationException {
|
||||
public Structure(@NotNull Location l1, @NotNull Location l2, @NotNull String id) throws InitializationException {
|
||||
int centerX = -1, centerZ = -1;
|
||||
this.id = id;
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.spawns = new HashSet<>();
|
||||
this.inventories = new HashSet<>();
|
||||
if(l1.getX() > l2.getX() || l1.getY() > l2.getY() || l1.getZ() > l2.getZ()) throw new IllegalArgumentException("Invalid locations provided!");
|
||||
structure = new StructureContainedBlock[l2.getBlockX()-l1.getBlockX()+1][l2.getBlockZ()-l1.getBlockZ()+1][l2.getBlockY()-l1.getBlockY()+1];
|
||||
for(int x = 0; x <= l2.getBlockX()-l1.getBlockX(); x++) {
|
||||
@ -96,13 +97,16 @@ public class GaeaStructure implements Serializable {
|
||||
}
|
||||
}
|
||||
StructureContainedBlock block = new StructureContainedBlock(x, y, z, useState ? state : null, d, requirement);
|
||||
if(state instanceof BlockInventoryHolder) {
|
||||
inventories.add(new StructureContainedInventory(((BlockInventoryHolder) state).getInventory(), block));
|
||||
}
|
||||
if(!requirement.equals(StructureSpawnRequirement.BLANK)) spawns.add(block);
|
||||
structure[x][z][y] = block;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(centerX < 0 || centerZ < 0) throw new InitializationException("No structure center specified.");
|
||||
structureInfo = new GaeaStructureInfo(l2.getBlockX()-l1.getBlockX()+1, l2.getBlockY()-l1.getBlockY()+1, l2.getBlockZ()-l1.getBlockZ()+1, new Vector2(centerX, centerZ));
|
||||
structureInfo = new StructureInfo(l2.getBlockX()-l1.getBlockX()+1, l2.getBlockY()-l1.getBlockY()+1, l2.getBlockZ()-l1.getBlockZ()+1, new Vector2(centerX, centerZ));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,7 +114,7 @@ public class GaeaStructure implements Serializable {
|
||||
* @return Structure Info
|
||||
*/
|
||||
@NotNull
|
||||
public GaeaStructureInfo getStructureInfo() {
|
||||
public StructureInfo getStructureInfo() {
|
||||
return structureInfo;
|
||||
}
|
||||
|
||||
@ -131,7 +135,9 @@ public class GaeaStructure implements Serializable {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public HashSet<StructureContainedInventory> getInventories() {
|
||||
return inventories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste structure at an origin location, confined to a single chunk.
|
||||
@ -181,10 +187,15 @@ public class GaeaStructure implements Serializable {
|
||||
} else if(data instanceof Orientable) {
|
||||
org.bukkit.Axis newAxis = getRotatedAxis(((Orientable) data).getAxis(), r);
|
||||
((Orientable) data).setAxis(newAxis);
|
||||
} else if(data instanceof RedstoneWire) {
|
||||
RedstoneWire rData = (RedstoneWire) data;
|
||||
for(BlockFace f : rData.getAllowedFaces()) {
|
||||
rData.setFace(getRotatedFace(f, r), rData.getFace(f));
|
||||
}
|
||||
}
|
||||
worldBlock.setBlockData(data, false);
|
||||
if(block.getState() != null) {
|
||||
block.getState().getState(worldBlock.getState()).update();
|
||||
block.getState().getState(worldBlock.getState()).update(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -249,19 +260,19 @@ public class GaeaStructure implements Serializable {
|
||||
* @throws ClassNotFoundException If structure data is invalid.
|
||||
*/
|
||||
@NotNull
|
||||
private static GaeaStructure fromFile(@NotNull File f) throws IOException, ClassNotFoundException {
|
||||
private static Structure fromFile(@NotNull File f) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
|
||||
Object o = ois.readObject();
|
||||
ois.close();
|
||||
return (GaeaStructure) o;
|
||||
return (Structure) o;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GaeaStructure fromStream(@NotNull InputStream f) throws IOException, ClassNotFoundException {
|
||||
public static Structure fromStream(@NotNull InputStream f) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(f);
|
||||
Object o = ois.readObject();
|
||||
ois.close();
|
||||
return (GaeaStructure) o;
|
||||
return (Structure) o;
|
||||
}
|
||||
|
||||
private static void toFile(@NotNull Serializable o, @NotNull File f) throws IOException {
|
@ -3,7 +3,6 @@ package com.dfsek.terra.structure;
|
||||
import com.dfsek.terra.structure.serialize.SerializableBlockData;
|
||||
import com.dfsek.terra.structure.serialize.block.SerializableBlockState;
|
||||
import com.dfsek.terra.structure.serialize.block.SerializableSign;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.dfsek.terra.structure;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class StructureContainedInventory implements Serializable {
|
||||
public static final long serialVersionUID = -175339605585943678L;
|
||||
private final int uid;
|
||||
private final int x, y, z;
|
||||
public StructureContainedInventory(Inventory orig, StructureContainedBlock link) {
|
||||
ItemStack stack = orig.getItem(0);
|
||||
x = link.getX();
|
||||
y = link.getY();
|
||||
z = link.getZ();
|
||||
if(stack == null) {
|
||||
uid = 0;
|
||||
return;
|
||||
}
|
||||
uid = stack.getAmount();
|
||||
}
|
||||
|
||||
public int getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
}
|
@ -5,14 +5,14 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class GaeaStructureInfo implements Serializable {
|
||||
public class StructureInfo implements Serializable {
|
||||
public static final long serialVersionUID = -175639605885943678L;
|
||||
private final int sizeX;
|
||||
private final int sizeY;
|
||||
private final int sizeZ;
|
||||
private final int centerX;
|
||||
private final int centerZ;
|
||||
public GaeaStructureInfo(int sizeX, int sizeY, int sizeZ, Vector2 center) {
|
||||
public StructureInfo(int sizeX, int sizeY, int sizeZ, Vector2 center) {
|
||||
this.sizeX = sizeX;
|
||||
this.sizeY = sizeY;
|
||||
this.sizeZ = sizeZ;
|
@ -1,12 +1,10 @@
|
||||
package com.dfsek.terra.util.structure;
|
||||
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import com.dfsek.terra.structure.GaeaStructure;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Rail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class RotationUtil {
|
||||
/**
|
||||
* Rotate and mirror a coordinate pair.
|
||||
@ -14,7 +12,7 @@ public class RotationUtil {
|
||||
* @param r Rotation
|
||||
* @return Rotated coordinate pair
|
||||
*/
|
||||
public static Vector2 getRotatedCoords(Vector2 orig, GaeaStructure.Rotation r) {
|
||||
public static Vector2 getRotatedCoords(Vector2 orig, Structure.Rotation r) {
|
||||
Vector2 copy = orig.clone();
|
||||
switch(r) {
|
||||
case CW_90:
|
||||
@ -36,7 +34,7 @@ public class RotationUtil {
|
||||
* @param r Rotation
|
||||
* @return Rotated BlockFace
|
||||
*/
|
||||
public static BlockFace getRotatedFace(BlockFace f, GaeaStructure.Rotation r) {
|
||||
public static BlockFace getRotatedFace(BlockFace f, Structure.Rotation r) {
|
||||
BlockFace n = f;
|
||||
int rotateNum = r.getDegrees()/90;
|
||||
int rn = faceRotation(f);
|
||||
@ -46,9 +44,9 @@ public class RotationUtil {
|
||||
return n;
|
||||
}
|
||||
|
||||
public static org.bukkit.Axis getRotatedAxis(org.bukkit.Axis orig, GaeaStructure.Rotation r) {
|
||||
public static org.bukkit.Axis getRotatedAxis(org.bukkit.Axis orig, Structure.Rotation r) {
|
||||
org.bukkit.Axis other = orig;
|
||||
final boolean shouldSwitch = r.equals(GaeaStructure.Rotation.CW_90) || r.equals(GaeaStructure.Rotation.CCW_90);
|
||||
final boolean shouldSwitch = r.equals(Structure.Rotation.CW_90) || r.equals(Structure.Rotation.CCW_90);
|
||||
switch(orig) {
|
||||
case X:
|
||||
if(shouldSwitch) other = org.bukkit.Axis.Z;
|
||||
@ -67,7 +65,7 @@ public class RotationUtil {
|
||||
* @param r Rotate
|
||||
* @return Rotated/mirrored shape
|
||||
*/
|
||||
public static Rail.Shape getRotatedRail(Rail.Shape orig, GaeaStructure.Rotation r) {
|
||||
public static Rail.Shape getRotatedRail(Rail.Shape orig, Structure.Rotation r) {
|
||||
switch(r) {
|
||||
case CCW_90:
|
||||
switch(orig) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
name: Terra
|
||||
depend: [ "Gaea" ]
|
||||
main: com.dfsek.terra.Terra
|
||||
version: 1.0.0
|
||||
load: STARTUP
|
||||
|
@ -0,0 +1 @@
|
||||
config: DEFAULT
|
Loading…
x
Reference in New Issue
Block a user