From 6dbe9ac4adfec2f0dd9e647b62de2ea2c3110512 Mon Sep 17 00:00:00 2001 From: Shnupbups Date: Sun, 22 Sep 2019 01:31:52 +1000 Subject: [PATCH] 2.8.2 - Updated Artifice to fix issues with resource reloading on dedicated servers - Piece Packs, Piece Sets, and Vanilla Pieces now all have a new optional field 'required_mod'. If this is specified, the pack, set, or piece will only be loaded if a mod with that id is present. --- gradle.properties | 8 +-- .../shnupbups/extrapieces/core/PieceSet.java | 62 ++++++++++++------- .../extrapieces/register/ModConfigs.java | 24 +++++-- src/main/resources/fabric.mod.json | 2 +- 4 files changed, 64 insertions(+), 32 deletions(-) diff --git a/gradle.properties b/gradle.properties index e5106e26..c1ee08cc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.6.1+build.165 # Mod Properties - mod_version = 2.8.1 + mod_version = 2.8.2 maven_group = com.shnupbups archives_base_name = extrapieces @@ -17,14 +17,14 @@ org.gradle.jvmargs=-Xmx1G fabric_version=0.3.2+build.218-1.14 # check on jitpack at https://jitpack.io/#swordglowsblue/artifice - artifice_version=0.3.4 + artifice_version=0.3.5 # check on cotton maven at http://server.bbkr.space:8081/artifactory/libs-release/io/github/cottonmc/Jankson/ jankson_version=1.0.0+j1.1.2 # Other Stuff # check on maven at https://maven.fabricmc.net/me/shedaniel/RoughlyEnoughItems/ - rei_version=3.1.3+build.15 + rei_version=3.1.4+build.22 # check on maven at https://maven.fabricmc.net/io/github/prospector/modmenu/ - modmenu_version=1.7.11+build.121 \ No newline at end of file + modmenu_version=1.7.13+build.123 \ No newline at end of file diff --git a/src/main/java/com/shnupbups/extrapieces/core/PieceSet.java b/src/main/java/com/shnupbups/extrapieces/core/PieceSet.java index ac6b8489..188ce48b 100644 --- a/src/main/java/com/shnupbups/extrapieces/core/PieceSet.java +++ b/src/main/java/com/shnupbups/extrapieces/core/PieceSet.java @@ -15,6 +15,9 @@ import com.shnupbups.extrapieces.register.ModLootTables; import com.shnupbups.extrapieces.register.ModRecipes; import com.swordglowsblue.artifice.api.ArtificeResourcePack; + +import net.fabricmc.loader.api.FabricLoader; + import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.Material; @@ -550,6 +553,7 @@ public void addLootTables(ArtificeResourcePack.ServerResourcePackBuilder data) { public static class Builder { public final String name; public final Identifier base; + public String requiredMod = "minecraft"; public boolean built = false; public Boolean stonecuttable; public Boolean woodmillable; @@ -625,32 +629,38 @@ public Builder(String name, JsonObject ob, String packName) { this.uncraftable.add(pt); } } + if (ob.containsKey("required_mod")) { + requiredMod = ob.get(String.class, "required_mod"); + } } public PieceSet build() { - if (built) { - return PieceSets.getSet(Registry.BLOCK.get(base)); - } - - PieceSet ps = new PieceSet(Registry.BLOCK.get(base), name, genTypes); - if (this.stonecuttable != null) ps.setStonecuttable(this.stonecuttable); - if (this.woodmillable != null) ps.setWoodmillable(this.woodmillable); - if (this.opaque != null) ps.setOpaque(this.opaque); - if (this.mainTexture != null) ps.setTexture(this.mainTexture); - if (this.topTexture != null) ps.setTopTexture(this.topTexture); - if (this.bottomTexture != null) ps.setBottomTexture(this.bottomTexture); - - for (Map.Entry vanillaPiece : this.getVanillaPieces().entrySet()) { - ps.addVanillaPiece(vanillaPiece.getKey(), Registry.BLOCK.get(vanillaPiece.getValue())); - } - - if (this.includeMode) ps.setInclude(); - for (PieceType pt : this.uncraftable) { - ps.setUncraftable(pt); + if(shouldLoad()) { + if (built) { + return PieceSets.getSet(Registry.BLOCK.get(base)); + } + + PieceSet ps = new PieceSet(Registry.BLOCK.get(base), name, genTypes); + if (this.stonecuttable != null) ps.setStonecuttable(this.stonecuttable); + if (this.woodmillable != null) ps.setWoodmillable(this.woodmillable); + if (this.opaque != null) ps.setOpaque(this.opaque); + if (this.mainTexture != null) ps.setTexture(this.mainTexture); + if (this.topTexture != null) ps.setTopTexture(this.topTexture); + if (this.bottomTexture != null) ps.setBottomTexture(this.bottomTexture); + + for (Map.Entry vanillaPiece : this.getVanillaPieces().entrySet()) { + ps.addVanillaPiece(vanillaPiece.getKey(), Registry.BLOCK.get(vanillaPiece.getValue())); + } + + if (this.includeMode) ps.setInclude(); + for (PieceType pt : this.uncraftable) { + ps.setUncraftable(pt); + } + + this.built = true; + return ps; } - - this.built = true; - return ps; + return null; } public void addVanillaPiece(Identifier type, Identifier piece) { @@ -678,6 +688,14 @@ public boolean isBuilt() { public String getPackName() { return packName; } + + public String getRequiredMod() { + return requiredMod; + } + + public boolean shouldLoad() { + return FabricLoader.getInstance().isModLoaded(getRequiredMod()); + } public boolean isReady() { if (!Registry.BLOCK.getOrEmpty(base).isPresent() || !Registry.ITEM.getOrEmpty(base).isPresent()) { diff --git a/src/main/java/com/shnupbups/extrapieces/register/ModConfigs.java b/src/main/java/com/shnupbups/extrapieces/register/ModConfigs.java index 864b1765..559cc2d9 100644 --- a/src/main/java/com/shnupbups/extrapieces/register/ModConfigs.java +++ b/src/main/java/com/shnupbups/extrapieces/register/ModConfigs.java @@ -154,6 +154,12 @@ public static void initPiecePacks() { JsonObject sets = null; JsonObject vanillaPieces = null; String ppVer; + if(pp.containsKey("required_mod")) { + String requiredMod = pp.get(String.class, "required_mod"); + if(!FabricLoader.getInstance().isModLoaded(requiredMod)) { + continue; + } + } if (!pp.containsKey("version")) { sets = pp; ppVer = "0.0.0"; @@ -168,9 +174,11 @@ public static void initPiecePacks() { for (Map.Entry entry : sets.entrySet()) { JsonObject jsonSet = (JsonObject) entry.getValue(); PieceSet.Builder psb = new PieceSet.Builder(entry.getKey(), jsonSet, f.getName()); - setsNum++; - ppSetsNum++; - ModBlocks.registerSet(psb); + if(psb.shouldLoad()) { + setsNum++; + ppSetsNum++; + ModBlocks.registerSet(psb); + } } ExtraPieces.debugLog("Generated " + ppSetsNum + " PieceSets from piece pack " + f.getName()); } @@ -181,8 +189,14 @@ public static void initPiecePacks() { Identifier base = new Identifier(jsonPiece.get(String.class, "base")); Identifier type = new Identifier(jsonPiece.get(String.class, "type")); Identifier piece = new Identifier(jsonPiece.get(String.class, "piece")); - ppVpNum++; - ModBlocks.registerVanillaPiece(base, type, piece); + boolean add = true; + if(jsonPiece.containsKey("required_mod")) { + add = FabricLoader.getInstance().isModLoaded(jsonPiece.get(String.class, "required_mod")); + } + if(add) { + ppVpNum++; + ModBlocks.registerVanillaPiece(base, type, piece); + } } else { ExtraPieces.debugLog("Invalid vanilla piece " + entry.getKey() + " in piece pack " + f.getName()); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 02df183b..118a2e80 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "extrapieces", - "version": "2.8.1", + "version": "2.8.2", "name": "Extra Pieces", "description": "Adds more block shapes to Minecraft!",