Skip to content

Commit

Permalink
cleaned up some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Wong, Dylan committed Dec 4, 2023
1 parent 6e365c3 commit 4fab325
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
10 changes: 0 additions & 10 deletions src/main/java/com/cleanroommc/groovyscript/compat/loot/Loot.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,4 @@ public void afterScriptLoad() {
}
}

public LootTable getTable(ResourceLocation name) {
LootTable lootTable = tables.get(name);
if (lootTable == null) GroovyLog.msg("GroovyScript found 0 LootTable(s) named " + name).post();
return lootTable;
}

public LootTable getTable(String name) {
return getTable(new ResourceLocation(name));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class LootEntryBuilder {
private int quality;
private final List<LootFunction> functions = new ArrayList<>();
private final List<LootCondition> conditions = new ArrayList<>();
private String tableName;
private ResourceLocation tableName;
private String poolName;
private final GroovyLog.Msg out = GroovyLog.msg("Error creating GroovyScript LootPool").warn();

Expand Down Expand Up @@ -76,12 +76,12 @@ public LootEntryBuilder quality(int quality) {
}

public LootEntryBuilder table(String table) {
this.tableName = table;
this.tableName = new ResourceLocation(table);
return this;
}

public LootEntryBuilder table(ResourceLocation table) {
this.tableName = table.toString();
this.tableName = table;
return this;
}

Expand Down Expand Up @@ -317,9 +317,9 @@ else if (name == null || name.isEmpty()) {
if (quality < 0) out.add("quality < 0 may make the loot entry unable to be rolled");

if (validateForRegister) {
if (tableName == null || tableName.isEmpty() || VanillaModule.loot.getTable(tableName) == null) out.add("No valid LootTable specified").error();
else if (poolName == null || poolName.isEmpty() || VanillaModule.loot.getTable(tableName).getPool(poolName) == null) out.add("No valid LootPool specified").error();
else if (VanillaModule.loot.getTable(tableName).getPool(poolName).getEntry(name) != null) out.add("Attempted to add duplicate key " + name + " to " + tableName + " - " + poolName);
if (tableName == null || VanillaModule.loot.tables.get(tableName) == null) out.add("No valid LootTable specified").error();
else if (poolName == null || poolName.isEmpty() || VanillaModule.loot.tables.get(tableName).getPool(poolName) == null) out.add("No valid LootPool specified").error();
else if (VanillaModule.loot.tables.get(tableName).getPool(poolName).getEntry(name) != null) out.add("Attempted to add duplicate entry " + name + " to " + tableName + " - " + poolName);
}

out.postIfNotEmpty();
Expand All @@ -333,7 +333,7 @@ public LootEntry build() {

public void register() {
if (!validate(true)) return;
VanillaModule.loot.getTable(tableName).getPool(poolName).addEntry(
VanillaModule.loot.tables.get(tableName).getPool(poolName).addEntry(
new LootEntryItem(item, weight, quality, functions.toArray(new LootFunction[0]), conditions.toArray(new LootCondition[0]), name)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class LootPoolBuilder {
private final List<LootCondition> poolConditions = new ArrayList<>();
private RandomValueRange rolls = new RandomValueRange(1);
private RandomValueRange bonusRolls = new RandomValueRange(0);
private String tableName;
private ResourceLocation tableName;
private final GroovyLog.Msg out = GroovyLog.msg("Error creating GroovyScript LootPool").warn();

public LootPoolBuilder name(String name) {
Expand All @@ -41,12 +41,12 @@ public LootPoolBuilder name(ResourceLocation name) {
}

public LootPoolBuilder table(String table) {
this.tableName = table;
this.tableName = new ResourceLocation(table);
return this;
}

public LootPoolBuilder table(ResourceLocation table) {
this.tableName = table.toString();
this.tableName = table;
return this;
}

Expand Down Expand Up @@ -121,8 +121,9 @@ public LootPoolBuilder bonusRollsRange(float min, float max) {
private boolean validate(boolean validateForRegister) {
if (name == null || name.isEmpty()) out.add("No name provided").error();
if (validateForRegister) {
if (tableName == null || tableName.isEmpty() || VanillaModule.loot.getTable(tableName) == null) out.add("No valid LootTable specified").error();
else if (name != null && !name.isEmpty() && VanillaModule.loot.getTable(tableName) != null && VanillaModule.loot.getTable(tableName).getPool(name) != null) out.add("No valid LootPool specified for table " + tableName).error();
if (tableName == null || !VanillaModule.loot.tables.containsKey(tableName)) out.add("No valid LootTable specified").error();
else if (name == null || name.isEmpty()) out.add("LootPool must have a name specified with .name()").error();
else if (VanillaModule.loot.tables.get(tableName).getPool(name) != null) out.add("Attempted to add duplicate pool " + name + " to " + tableName).error();
}
out.postIfNotEmpty();
return out.getLevel() != Level.ERROR;
Expand All @@ -135,7 +136,7 @@ public LootPool build() {

public void register() {
if (!validate(true)) return;
VanillaModule.loot.getTable(tableName).addPool(
VanillaModule.loot.tables.get(tableName).addPool(
new LootPool(lootEntries.toArray(new LootEntry[0]), poolConditions.toArray(new LootCondition[0]), rolls, bonusRolls, name)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public static class Loot {
public static final LootTable EMPTY_LOOT_TABLE = new LootTable(new LootPool[0]);

public LootTable getTable(ResourceLocation name) {
return VanillaModule.loot.getTable(name);
LootTable lootTable = VanillaModule.loot.tables.get(name);
if (lootTable == null) GroovyLog.msg("GroovyScript found 0 LootTable(s) named " + name).post();
return lootTable;
}

public LootTable getTable(String name) {
Expand Down

0 comments on commit 4fab325

Please sign in to comment.