mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 06:40:55 +00:00
add getter/setter for loot table in LootPopulateEvent
This commit is contained in:
+21
-1
@@ -5,8 +5,10 @@ import com.dfsek.terra.api.event.events.Cancellable;
|
|||||||
import com.dfsek.terra.api.event.events.PackEvent;
|
import com.dfsek.terra.api.event.events.PackEvent;
|
||||||
import com.dfsek.terra.api.platform.block.Block;
|
import com.dfsek.terra.api.platform.block.Block;
|
||||||
import com.dfsek.terra.api.platform.block.state.Container;
|
import com.dfsek.terra.api.platform.block.state.Container;
|
||||||
|
import com.dfsek.terra.api.structures.loot.LootTable;
|
||||||
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedLootApplication;
|
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedLootApplication;
|
||||||
import com.dfsek.terra.config.pack.ConfigPack;
|
import com.dfsek.terra.config.pack.ConfigPack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when loot is populated via {@link BufferedLootApplication}.
|
* Called when loot is populated via {@link BufferedLootApplication}.
|
||||||
@@ -14,11 +16,13 @@ import com.dfsek.terra.config.pack.ConfigPack;
|
|||||||
public class LootPopulateEvent extends AbstractCancellable implements PackEvent, Cancellable {
|
public class LootPopulateEvent extends AbstractCancellable implements PackEvent, Cancellable {
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final Container container;
|
private final Container container;
|
||||||
|
private LootTable table;
|
||||||
private final ConfigPack pack;
|
private final ConfigPack pack;
|
||||||
|
|
||||||
public LootPopulateEvent(Block block, Container container, ConfigPack pack) {
|
public LootPopulateEvent(Block block, Container container, LootTable table, ConfigPack pack) {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
this.table = table;
|
||||||
this.pack = pack;
|
this.pack = pack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,4 +48,20 @@ public class LootPopulateEvent extends AbstractCancellable implements PackEvent,
|
|||||||
public Container getContainer() {
|
public Container getContainer() {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the loot table to be populated.
|
||||||
|
* @return Loot table.
|
||||||
|
*/
|
||||||
|
public LootTable getTable() {
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the loot table to be populated.
|
||||||
|
* @param table New loot table.
|
||||||
|
*/
|
||||||
|
public void setTable(@NotNull LootTable table) {
|
||||||
|
this.table = table;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -29,11 +29,11 @@ public class BufferedLootApplication implements BufferedItem {
|
|||||||
}
|
}
|
||||||
Container container = (Container) data;
|
Container container = (Container) data;
|
||||||
|
|
||||||
LootPopulateEvent event = new LootPopulateEvent(block, container, main.getWorld(block.getLocation().getWorld()).getGenerator().getConfigPack());
|
LootPopulateEvent event = new LootPopulateEvent(block, container, table, main.getWorld(block.getLocation().getWorld()).getGenerator().getConfigPack());
|
||||||
main.getEventManager().callEvent(event);
|
main.getEventManager().callEvent(event);
|
||||||
if(event.isCancelled()) return;
|
if(event.isCancelled()) return;
|
||||||
|
|
||||||
table.fillInventory(container.getInventory(), new FastRandom(origin.hashCode()));
|
event.getTable().fillInventory(container.getInventory(), new FastRandom(origin.hashCode()));
|
||||||
data.update(false);
|
data.update(false);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
main.logger().warning("Could not apply loot at " + origin + ": " + e.getMessage());
|
main.logger().warning("Could not apply loot at " + origin + ": " + e.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user