Skip to content

Commit

Permalink
register loot tables with vanilla dungeon chests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark authored and Mark committed Dec 14, 2020
1 parent e7d32d8 commit 962aca4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 32 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ buildscript {
classpath 'net.minecraftforge.gradle:ForgeGradle:3.+'
}
}
plugins {
// must use gradle v3.0+ for this version of shadow (2.0.1). Update gradle-wrapper.properties
id "com.github.johnrengelman.shadow" version "4.0.4"
}

apply plugin: 'net.minecraftforge.gradle'
//Only edit below this line, the above code adds and enables the nessasary things for Forge to be setup.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mc_version=1.12.2
forge_version=14.23.5.2854
mappings_version=20171003-1.12
gottschcore_version=1.14.0
gottschcore_forge_version=14.23.5.2768
gottschcore_forge_version=14.23.5.2854
patchouli_version=1.0-20.108

# paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
package com.someguyssoftware.treasure2.eventhandler;

import static com.someguyssoftware.treasure2.Treasure.logger;

import java.util.Map.Entry;

import com.someguyssoftware.gottschcore.mod.IMod;
Expand All @@ -14,7 +16,16 @@
import com.someguyssoftware.treasure2.registry.ChestRegistry;
import com.someguyssoftware.treasure2.worldgen.ITreasureWorldGenerator;

import net.minecraft.util.ResourceLocation;
import net.minecraft.world.WorldServer;
import net.minecraft.world.storage.loot.LootEntry;
import net.minecraft.world.storage.loot.LootEntryTable;
import net.minecraft.world.storage.loot.LootPool;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraft.world.storage.loot.RandomValueRange;
import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraftforge.event.LootTableLoadEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -27,7 +38,7 @@ public class WorldEventHandler {

// reference to the mod.
private IMod mod;

/**
*
*/
Expand All @@ -38,44 +49,56 @@ public WorldEventHandler(IMod mod) {
@SubscribeEvent(priority = EventPriority.HIGH)
public void onWorldLoad(WorldEvent.Load event) {
Treasure.logger.debug("In world load event for dimension {}", event.getWorld().provider.getDimension());

/*
* On load of dimension 0 (overworld), initialize the loot table's context and other static loot tables
*/
if (WorldInfo.isServerSide(event.getWorld()) && event.getWorld().provider.getDimension() == 0) {
// Treasure.logger.debug("server event");
// Treasure.logger.debug("server event");
WorldServer world = (WorldServer) event.getWorld();

// called once to initiate world-level properties in the LootTableMaster
Treasure.LOOT_TABLE_MASTER.init(world);

// register mod's loot tables
TreasureLootTableRegistry.register(mod.getId());

// register files with their respective managers
Treasure.META_MANAGER.register(getMod().getId());
Treasure.TEMPLATE_MANAGER.register(getMod().getId());
Treasure.DECAY_MANAGER.register(getMod().getId());

/*
* clear the current World Gens values and reload
*/
for (Entry<WorldGeneratorType, ITreasureWorldGenerator> worldGenEntry : Treasure.WORLD_GENERATORS.entrySet()) {
worldGenEntry.getValue().init();
}

/*
* un-load the chest registry
*/
Treasure.logger.debug("Chest registry size BEFORE cleaning -> {}", ChestRegistry.getInstance().getValues().size());
ChestRegistry.getInstance().clear();
Treasure.logger.debug("Chest registry size AFTER cleaning -> {}", ChestRegistry.getInstance().getValues().size());

GenDataPersistence.get(world);
Treasure.logger.debug("Chest registry size after world event load -> {}", ChestRegistry.getInstance().getValues().size());
}
}


@SubscribeEvent
public void lootLoad(LootTableLoadEvent event) {
if (event.getName().toString().equals(LootTableList.CHESTS_SIMPLE_DUNGEON.toString()/*"minecraft:chests/simple_dungeon"*/)) {

// load a loot table
ResourceLocation location = new ResourceLocation(Treasure.MODID, "pools/treasure/scarce");
LootEntry entry = new LootEntryTable(location, 1, 1, new LootCondition[] {}, "treasure");
LootPool pool = new LootPool(new LootEntry[] {entry}, new LootCondition[] {}, new RandomValueRange(1), new RandomValueRange(1), "treasure");
event.getTable().addPool(pool);
}
}

/**
* @return the mod
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "item",
"name": "treasure2:lightning_key",
"weight": 10
},
},
{
"entryName": "metallurgists_key",
"type": "item",
Expand Down Expand Up @@ -168,12 +168,6 @@
]
}
]
},
{
"name": "rare_charms",
"rolls": 1,
"entries": [
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"max": 2
}
}
]
]
},
{
"entryName": "stone_key",
Expand All @@ -33,7 +33,7 @@
"max": 2
}
}
]
]
},
{
"entryName": "pilferers_lock_pick",
Expand Down Expand Up @@ -63,7 +63,7 @@
"max": 2
}
}
]
]
},
{
"entryName": "thiefs_lock_pick",
Expand All @@ -78,7 +78,7 @@
"max": 2
}
}
]
]
},
{
"entryName": "ember_key",
Expand All @@ -91,7 +91,7 @@
"type": "item",
"name": "treasure2:leaf_key",
"weight": 15
},
},
{
"entryName": "gold_key",
"type": "item",
Expand All @@ -103,7 +103,7 @@
"type": "item",
"name": "treasure2:spider_key",
"weight": 10
}
}
]
},
{
Expand Down Expand Up @@ -141,12 +141,6 @@
]
}
]
},
{
"name": "uncommon_charms",
"rolls": 1,
"entries": [
]
}
}
]
}
}
2 changes: 1 addition & 1 deletion update.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"1.13.0": "Added Ember Lock and Key.\nAdded Leaf Lock and Key.\nAdded Lightning Key.\nAdded ability to merge Keys on anvil.\nAdded Volcano Pit.\nAdded Blackstone Block (from mc1.16).\nIncreased Key success rate to 95%.\nIncreased Pilferer's Lock Pick success rate to 32%.\nIncreased Thief's Lock Pick success rate to 48%.\nUpdated loot tables to include Ember, Leaf and Lightning Keys.\nUpdated Chinese lang file.\n",
"1.13.1": "Fixed the large number of TileEntities created because of Gravestones. (Note, this is only for newly generated chunks).\nReduced likihood of Bound Soul gravestone to 30%.\nFixed the versioning.\n",
"1.13.2": "Fixed duplication bug on Harvesting Charms.\nFixed some loot tables with item spelling errors.Tweaked the epic charmed loot table.",
"1.14.0": "Revamped Loot Table management system - uses vanilla with tweaks.\nAdded Cardboard Box, Milk Crate and Crystal Skull chests.\nAdded -facing, -chest, -locked and -sealed arguments to SpawnChestCommand.\nAdded Enchantment glow to Charmed Coins/Gems and updated images.\nUpdated to Forge 1.12.2-14.23.5.2854.\n"
"1.14.0": "Revamped Loot Table management system - uses vanilla with tweaks.\nAdded Cardboard Box, Milk Crate and Crystal Skull chests.\nRegistered treasure loot tables with vanilla dungeon chests.\nAdded -facing, -chest, -locked and -sealed arguments to SpawnChestCommand.\nAdded Enchantment glow to Charmed Coins/Gems and updated images.\nUpdated to Forge 1.12.2-14.23.5.2854.\n"
}
}

0 comments on commit 962aca4

Please sign in to comment.