New AddReloadListenerEvent that gathers server side data reload handlers. (#6849)
This commit is contained in:
parent
8e5138da27
commit
ff86201523
5 changed files with 65 additions and 23 deletions
|
@ -1,28 +1,10 @@
|
||||||
--- a/net/minecraft/resources/DataPackRegistries.java
|
--- a/net/minecraft/resources/DataPackRegistries.java
|
||||||
+++ b/net/minecraft/resources/DataPackRegistries.java
|
+++ b/net/minecraft/resources/DataPackRegistries.java
|
||||||
@@ -22,6 +22,8 @@
|
@@ -31,6 +31,7 @@
|
||||||
private final AdvancementManager field_240958_h_ = new AdvancementManager(this.field_240956_f_);
|
|
||||||
private final FunctionReloader field_240959_i_;
|
|
||||||
|
|
||||||
+ private final net.minecraftforge.common.loot.LootModifierManager lootManager = new net.minecraftforge.common.loot.LootModifierManager();
|
|
||||||
+
|
|
||||||
public DataPackRegistries(Commands.EnvironmentType p_i232598_1_, int p_i232598_2_) {
|
|
||||||
this.field_240953_c_ = new Commands(p_i232598_1_);
|
|
||||||
this.field_240959_i_ = new FunctionReloader(p_i232598_2_, this.field_240953_c_.func_197054_a());
|
|
||||||
@@ -31,6 +33,7 @@
|
|
||||||
this.field_240952_b_.func_219534_a(this.field_240957_g_);
|
this.field_240952_b_.func_219534_a(this.field_240957_g_);
|
||||||
this.field_240952_b_.func_219534_a(this.field_240959_i_);
|
this.field_240952_b_.func_219534_a(this.field_240959_i_);
|
||||||
this.field_240952_b_.func_219534_a(this.field_240958_h_);
|
this.field_240952_b_.func_219534_a(this.field_240958_h_);
|
||||||
+ this.field_240952_b_.func_219534_a(this.lootManager);
|
+ net.minecraftforge.event.ForgeEventFactory.onResourceReload().forEach(field_240952_b_::func_219534_a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FunctionReloader func_240960_a_() {
|
public FunctionReloader func_240960_a_() {
|
||||||
@@ -85,4 +88,8 @@
|
|
||||||
public void close() {
|
|
||||||
this.field_240952_b_.close();
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+ public net.minecraftforge.common.loot.LootModifierManager getLootModifierManager() {
|
|
||||||
+ return lootManager;
|
|
||||||
+ }
|
|
||||||
}
|
|
||||||
|
|
|
@ -109,6 +109,8 @@ import net.minecraft.world.IWorld;
|
||||||
import net.minecraft.world.IWorldReader;
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.data.IOptionalTagEntry;
|
import net.minecraftforge.common.data.IOptionalTagEntry;
|
||||||
|
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||||
|
import net.minecraftforge.common.loot.LootModifierManager;
|
||||||
import net.minecraftforge.common.util.BlockSnapshot;
|
import net.minecraftforge.common.util.BlockSnapshot;
|
||||||
import net.minecraftforge.event.AnvilUpdateEvent;
|
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||||
import net.minecraftforge.event.DifficultyChangeEvent;
|
import net.minecraftforge.event.DifficultyChangeEvent;
|
||||||
|
@ -1165,12 +1167,10 @@ public class ForgeHooks
|
||||||
* @return The modified list
|
* @return The modified list
|
||||||
*/
|
*/
|
||||||
public static List<ItemStack> modifyLoot(List<ItemStack> list, LootContext context) {
|
public static List<ItemStack> modifyLoot(List<ItemStack> list, LootContext context) {
|
||||||
/*
|
LootModifierManager man = ForgeInternalHandler.getLootModifierManager();
|
||||||
LootModifierManager man = context.getWorld().getServer().getLootModifierManager();
|
|
||||||
for(IGlobalLootModifier mod : man.getAllLootMods()) {
|
for(IGlobalLootModifier mod : man.getAllLootMods()) {
|
||||||
list = mod.apply(list, context);
|
list = mod.apply(list, context);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,9 @@ import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
|
import net.minecraftforge.common.loot.LootModifierManager;
|
||||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||||
|
import net.minecraftforge.event.AddReloadListenerEvent;
|
||||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
import net.minecraftforge.event.world.ChunkEvent;
|
import net.minecraftforge.event.world.ChunkEvent;
|
||||||
|
@ -109,5 +111,21 @@ public class ForgeInternalHandler
|
||||||
{
|
{
|
||||||
ForgeHooks.updateBurns();
|
ForgeHooks.updateBurns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static LootModifierManager INSTANCE;
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onResourceReload(AddReloadListenerEvent event)
|
||||||
|
{
|
||||||
|
INSTANCE = new LootModifierManager();
|
||||||
|
event.addListener(INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static LootModifierManager getLootModifierManager()
|
||||||
|
{
|
||||||
|
if(INSTANCE == null)
|
||||||
|
throw new IllegalStateException("Can not retrieve LootModifierManager until resources have loaded once.");
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package net.minecraftforge.event;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import net.minecraft.resources.DataPackRegistries;
|
||||||
|
import net.minecraft.resources.IFutureReloadListener;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.eventbus.api.Event;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main ResourceManager is recreated on each reload, through {@link DataPackRegistries}'s creation.
|
||||||
|
*
|
||||||
|
* The event is fired on each reload and lets modders add their own ReloadListeners, for server-side resources.
|
||||||
|
* The event is fired on the {@link MinecraftForge#EVENT_BUS}
|
||||||
|
*/
|
||||||
|
public class AddReloadListenerEvent extends Event
|
||||||
|
{
|
||||||
|
private final List<IFutureReloadListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param listener the listener to add to the ResourceManager on reload
|
||||||
|
*/
|
||||||
|
public void addListener(IFutureReloadListener listener)
|
||||||
|
{
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<IFutureReloadListener> getListeners()
|
||||||
|
{
|
||||||
|
return ImmutableList.copyOf(listeners);
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,6 +51,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ItemUseContext;
|
import net.minecraft.item.ItemUseContext;
|
||||||
import net.minecraft.loot.LootTable;
|
import net.minecraft.loot.LootTable;
|
||||||
import net.minecraft.loot.LootTableManager;
|
import net.minecraft.loot.LootTableManager;
|
||||||
|
import net.minecraft.resources.IFutureReloadListener;
|
||||||
import net.minecraft.world.spawner.AbstractSpawner;
|
import net.minecraft.world.spawner.AbstractSpawner;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.util.ActionResultType;
|
||||||
|
@ -722,4 +723,11 @@ public class ForgeEventFactory
|
||||||
MinecraftForge.EVENT_BUS.post(event);
|
MinecraftForge.EVENT_BUS.post(event);
|
||||||
return event.getNewTime();
|
return event.getNewTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<IFutureReloadListener> onResourceReload()
|
||||||
|
{
|
||||||
|
AddReloadListenerEvent event = new AddReloadListenerEvent();
|
||||||
|
MinecraftForge.EVENT_BUS.post(event);
|
||||||
|
return event.getListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue