Skip to content

Commit

Permalink
Add toggle option to load entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Sentropic committed Dec 10, 2023
1 parent fe51411 commit 7d2667d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class BuilderTrait extends Trait implements Toggleable {
boolean excavate = false;
@Persist("Silent")
boolean silent = false;
@Persist("LoadEntities")
boolean loadEntities = false;
@Persist("State")
BuilderState state = BuilderState.IDLE;
@Persist("PatternXY")
Expand Down Expand Up @@ -127,6 +129,10 @@ public class BuilderTrait extends Trait implements Toggleable {

public void setSilent(boolean silent) {this.silent = silent;}

public boolean isLoadEntities() {return loadEntities;}

public void setLoadEntities(boolean loadEntities) {this.loadEntities = loadEntities;}

@NotNull
public BuilderState getState() {return state;}

Expand Down Expand Up @@ -351,7 +357,7 @@ private boolean StartBuild(CommandSender player) {
else {start = npc.getEntity().getLocation().clone();}

queue = schematic.buildQueue(this);
entityQueue = schematic.getEntities();
if (loadEntities) entityQueue = schematic.getEntities();

startingcount = queue.size();
continueLoc = start.clone();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/fr/weefle/constructor/menus/BuilderMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,17 @@ public void onLeftClick() {
}
};
}
case "load-entities": {
ItemStack itemStack = this.getItem(function);
ItemUT.replaceLore(itemStack, "%current%", String.valueOf(builder.isLoadEntities()));
return new Slot(itemStack) {
@Override
public void onLeftClick() {
builder.setLoadEntities(!builder.isLoadEntities());
this.menu.open();
}
};
}
}
return null;
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/fr/weefle/constructor/schematic/RawSchematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

public class RawSchematic extends Schematic {
private int width, height, length;
private Vector absolutePosition;
private EmptyBuildBlock[][][] blocks;
private Map<Material, Integer> materials;
private final List<SchematicEntity> entities = new ArrayList<>();
private Vector absolutePosition;
private EmptyBuildBlock[][][] blocks;
private Map<Material, Integer> materials;
private List<SchematicEntity> entities;

public RawSchematic(Path path) {
super(path);
Expand Down Expand Up @@ -57,7 +57,7 @@ public EmptyBuildBlock getBlockAt(int x, int y, int z) {
return block == null ? new EmptyBuildBlock(x, y, z) : block;
}

private void load(boolean full) { // TODO load entities
private void load(boolean full) {
File file = new File(getPath());
if (getPath().endsWith(".schem")) {
Object data;
Expand Down Expand Up @@ -142,12 +142,11 @@ private void load(boolean full) { // TODO load entities
index++;
}

this.entities = new ArrayList<>();
for (Object object : NMS.getInstance().getNMSProvider().nbtTagCompound_getList(data, "Entities", 10)) {
try {
this.entities.add(new SchematicEntity(object, absolutePosition));
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception ignored) {}
}
} else {
CompoundTag data;
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/menus/builder-settings-admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ items:
material: "barrel"
amount: 1
custom-model-data: 0
load-entities:
display-name: "&aLoad Entities"
lore:
- "&9Current: &b%current%"
material: "sheep_spawn_egg"
amount: 1
custom-model-data: 0
slots:
0: "silent"
1: "hold-item"
Expand All @@ -147,4 +154,4 @@ slots:
10: "ignore-liquid"
11: "needs-materials"
12: "citizens"

13: "load-entities"

0 comments on commit 7d2667d

Please sign in to comment.