[ci skip] Add loot table modification event (#287)

* Add loot table modification event

Closes #42. It's a simple wrapper around the platform events.

* Add param for builtin loot tables

Co-authored-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
Juuxel
2022-07-20 18:22:47 +03:00
committed by GitHub
parent c259d62ba3
commit f0555ce0eb
7 changed files with 228 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraftforge.event.CommandEvent;
import net.minecraftforge.event.LootTableLoadEvent;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.event.TickEvent.LevelTickEvent;
@@ -415,6 +416,11 @@ public class EventHandlerImplCommon {
ChunkEvent.LOAD_DATA.invoker().load(event.getChunk(), level instanceof ServerLevel ? (ServerLevel) level : null, event.getData());
}
@SubscribeEvent(priority = EventPriority.HIGH)
public static void event(LootTableLoadEvent event) {
LootEvent.MODIFY_LOOT_TABLE.invoker().modifyLootTable(event.getLootTableManager(), event.getName(), new LootTableModificationContextImpl(event.getTable()), true);
}
public interface LevelEventAttachment {
LevelAccessor architectury$getAttachedLevel();

View File

@@ -0,0 +1,37 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.event.forge;
import dev.architectury.event.events.common.LootEvent;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
final class LootTableModificationContextImpl implements LootEvent.LootTableModificationContext {
private final LootTable table;
LootTableModificationContextImpl(LootTable table) {
this.table = table;
}
@Override
public void addPool(LootPool pool) {
table.addPool(pool);
}
}