generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple item values loader, make Conflagrate scale in size by consumin…
…g blaze dust/rods
- Loading branch information
Showing
10 changed files
with
134 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/io/github/reoseah/magisterium/data/ItemValuesLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.github.reoseah.magisterium.data; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
import it.unimi.dsi.fastutil.objects.Object2IntMap; | ||
import it.unimi.dsi.fastutil.objects.Object2IntMaps; | ||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.resource.JsonDataLoader; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.JsonHelper; | ||
import net.minecraft.util.profiler.Profiler; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.Map; | ||
|
||
public class ItemValuesLoader extends JsonDataLoader implements IdentifiableResourceReloadListener { | ||
public static final Identifier ID = Identifier.of("magisterium", "item_values"); | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(); | ||
private static final Gson GSON = new Gson(); | ||
|
||
// TODO: support item tags (for more flexibility) | ||
public static Object2IntMap<Identifier> ITEM_VALUES = Object2IntMaps.emptyMap(); | ||
|
||
public static int getValue(ItemStack stack) { | ||
return ITEM_VALUES.getInt(Registries.ITEM.getId(stack.getItem())); | ||
} | ||
|
||
public ItemValuesLoader() { | ||
super(GSON, "magisterium/item_values"); | ||
} | ||
|
||
@Override | ||
public Identifier getFabricId() { | ||
return ID; | ||
} | ||
|
||
@Override | ||
protected void apply(Map<Identifier, JsonElement> prepared, ResourceManager manager, Profiler profiler) { | ||
boolean errors = false; | ||
|
||
var data = new Object2IntOpenHashMap<Identifier>(); | ||
|
||
for (Map.Entry<Identifier, JsonElement> entry : prepared.entrySet()) { | ||
try { | ||
var json = JsonHelper.asObject(entry.getValue(), "item value entry"); | ||
var item = JsonHelper.getString(json, "item"); | ||
var value = JsonHelper.getInt(json, "value"); | ||
data.put(Identifier.of(item), value); | ||
} catch (Exception e) { | ||
LOGGER.error("Error loading item value from {}", entry.getKey(), e); | ||
errors = true; | ||
} | ||
} | ||
if (errors) { | ||
throw new IllegalStateException("Failed to load item values"); | ||
} | ||
|
||
ITEM_VALUES = Object2IntMaps.unmodifiable(data); | ||
LOGGER.debug("Loaded {} item values", ITEM_VALUES.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/resources/data/magisterium/magisterium/item_values/blaze_powder.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"item": "minecraft:blaze_powder", | ||
"value": 2 | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/data/magisterium/magisterium/item_values/blaze_rod.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"item": "minecraft:blaze_rod", | ||
"value": 4 | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/data/magisterium/magisterium/item_values/breeze_rod.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"item": "minecraft:breeze_rod", | ||
"value": 4 | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/data/magisterium/magisterium/item_values/experience_bottle.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"item": "minecraft:experience_bottle", | ||
"value": 4 | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/data/magisterium/magisterium/item_values/wind_charge.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"item": "minecraft:wind_charge", | ||
"value": 1 | ||
} |