Skip to content

Commit

Permalink
Updated to work with version 1.19 of the game
Browse files Browse the repository at this point in the history
  • Loading branch information
Levoment committed Jun 7, 2022
1 parent f259da7 commit d6bc3cd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish'
}

Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19-pre1
yarn_mappings=1.19-pre1+build.1
loader_version=0.14.5
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6

# Mod Properties
mod_version = 2.0.0
mod_version = 3.0.0
maven_group = com.github.levoment.chestlootmodifier
archives_base_name = [1.19-pre1] Chest Loot Modifier
archives_base_name = [1.19] Chest Loot Modifier

# Dependencies
fabric_version=0.52.4+1.19
fabric_version=0.55.2+1.19
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.github.levoment.chestlootmodifier;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v1.FabricLootSupplierBuilder;
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
import net.fabricmc.fabric.api.loot.v2.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.minecraft.item.Item;
import net.minecraft.loot.LootManager;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.entry.ItemEntry;
Expand Down Expand Up @@ -38,9 +36,7 @@ public void onInitialize() {
// Read the config file if it exists
ConfigManager.readConfigFile();



LootTableLoadingCallback.EVENT.register((resourceManager, manager, id, supplier, setter) -> {
LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> {
this.addPool = false;
// Regex to match everything before a parenthesis
Pattern beforeParenthesisPattern = Pattern.compile("^.*?(?=\\()", Pattern.CASE_INSENSITIVE);
Expand Down Expand Up @@ -79,7 +75,7 @@ public void onInitialize() {
List<String> lootList = ConfigManager.CURRENT_CONFIG.LootDefinitions.get(key);
// Check if the list is not empty
if (lootList.size() > 0) {
LootPool currentLootPool = FabricLootPoolBuilder.builder().build();
LootPool currentLootPool = LootPool.builder().build();
// Go through all the loot definitions for this chest in the config file
for (String itemID : lootList) {

Expand Down Expand Up @@ -115,9 +111,9 @@ public void onInitialize() {
try {
int itemWeight = Integer.parseInt(secondMatch);
// Create the pool builder
currentLootPool = FabricLootPoolBuilder.of(currentLootPool).
withEntry(ItemEntry.builder(currentItem).weight(itemWeight).build())
.withFunction(SetCountLootFunction.builder(ConstantLootNumberProvider.create(itemCount)).build())
currentLootPool = FabricLootPoolBuilder.copyOf(currentLootPool).
with(ItemEntry.builder(currentItem).weight(itemWeight).build())
.apply(SetCountLootFunction.builder(ConstantLootNumberProvider.create(itemCount)).build())
.rolls(UniformLootNumberProvider.create(rarityMinRolls, rarityMaxRolls))
.build();
addPool = true;
Expand All @@ -142,7 +138,7 @@ public void onInitialize() {
}
}
// Add the item to the pool of items for the current chest
if (this.addPool) supplier.withPool(currentLootPool).build();
if (this.addPool) tableBuilder.pool(currentLootPool).build();
} else {
ChestLootModifierMod.LOGGER.error("[Chest Loot Modifier Mod] There is no loot defined for " + key + " in the config file LootDefinition object");
addPool = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.github.levoment.chestlootmodifier.ChestLootModifierMod;
import com.github.levoment.chestlootmodifier.ConfigManager;
import com.github.levoment.chestlootmodifier.RarityObject;
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v1.FabricLootSupplierBuilder;
import net.fabricmc.fabric.api.loot.v2.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v2.FabricLootTableBuilder;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -79,7 +79,7 @@ public void checkLootInteractionMixinCallback(PlayerEntity player, CallbackInfo
List<String> lootList = ConfigManager.CURRENT_CONFIG.LootDefinitions.get(key);
// Check if the list is not empty
if (lootList.size() > 0) {
LootPool currentLootPool = FabricLootPoolBuilder.builder().build();
LootPool currentLootPool = LootPool.builder().build();
// Go through all the loot definitions for this chest in the config file
for (String itemID : lootList) {

Expand Down Expand Up @@ -114,9 +114,9 @@ public void checkLootInteractionMixinCallback(PlayerEntity player, CallbackInfo
try {
int itemWeight = Integer.parseInt(secondMatch);
// Create the pool builder
currentLootPool = FabricLootPoolBuilder.of(currentLootPool).
withEntry(ItemEntry.builder(currentItem).weight(itemWeight).build())
.withFunction(SetCountLootFunction.builder(ConstantLootNumberProvider.create(itemCount)).build())
currentLootPool = FabricLootPoolBuilder.copyOf(currentLootPool).
with(ItemEntry.builder(currentItem).weight(itemWeight).build())
.apply(SetCountLootFunction.builder(ConstantLootNumberProvider.create(itemCount)).build())
.rolls(UniformLootNumberProvider.create(rarityMinRolls, rarityMaxRolls))
.build();
} catch (NumberFormatException numberFormatException) {
Expand All @@ -138,7 +138,7 @@ public void checkLootInteractionMixinCallback(PlayerEntity player, CallbackInfo
// Add the item to the pool of items for the current chest
LootManager lootManager = minecraftServer.getLootManager();
LootTable lootTable = lootManager.getTable(this.lootTableId);
this.chestLootModifierModModifiedLootTable = FabricLootSupplierBuilder.of(lootTable).withPool(currentLootPool).build();
this.chestLootModifierModModifiedLootTable = FabricLootTableBuilder.copyOf(lootTable).pool(currentLootPool).build();
this.addPool = true;
} else {
ChestLootModifierMod.LOGGER.error("[Chest Loot Modifier Mod] There is no loot defined for " + key + " in the config file LootDefinition object");
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
],

"depends": {
"fabricloader": ">=0.14.5",
"fabric": "*",
"minecraft": "1.19-beta.1",
"fabricloader": ">=0.14.6",
"fabric": "0.55.2+1.19",
"minecraft": "1.19",
"java": ">=17"
},
"suggests": {
Expand Down

0 comments on commit d6bc3cd

Please sign in to comment.