Add an inventory wrap hook

This commit is contained in:
quat committed 2018-08-03 00:59:55 -04:00
1 parent 15f71c8a53
commit a122253791
2 files changed
+47 -4

No files matched your search

@@ -0,0 +1,40 @@
/**
* This class was created by <quaternary>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
*/
package vazkii.botania.api.corporea;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* InventoryWrapEvent is fired when the corporea system attempts to wrap an inventory for use.
* */
public class InventoryWrapEvent extends Event {
private IWrappedInventory wrapped = null;
final ICorporeaSpark spark;
public InventoryWrapEvent(ICorporeaSpark spark) {
this.spark = spark;
}
public IWrappedInventory getWrappedInventory() {
return wrapped;
}
public void setWrappedInventory(IWrappedInventory wrapped) {
this.wrapped = wrapped;
}
public ICorporeaSpark getSpark() {
return spark;
}
public InvWithLocation getInvWithLocation() {
return spark.getSparkInventory();
}
}
@@ -27,6 +27,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.items.IItemHandlerModifiable;
import vazkii.botania.api.BotaniaAPIClient;
@@ -34,6 +35,7 @@ import vazkii.botania.api.corporea.CorporeaHelper;
import vazkii.botania.api.corporea.ICorporeaSpark;
import vazkii.botania.api.corporea.IWrappedInventory;
import vazkii.botania.api.corporea.InvWithLocation;
import vazkii.botania.api.corporea.InventoryWrapEvent;
import vazkii.botania.api.internal.DummyMethodHandler;
import vazkii.botania.api.internal.IManaNetwork;
import vazkii.botania.api.lexicon.LexiconPage;
@@ -270,13 +272,14 @@ public class InternalMethodHandler extends DummyMethodHandler {
List<IWrappedInventory> arrayList = new ArrayList<IWrappedInventory>();
for(InvWithLocation inv : inventories) {
ICorporeaSpark spark = CorporeaHelper.getSparkForInventory(inv);
IWrappedInventory wrapped = null;
// try integrations
// last chance - this will always work
InventoryWrapEvent wrapEvent = new InventoryWrapEvent(spark);
MinecraftForge.EVENT_BUS.post(wrapEvent);
IWrappedInventory wrapped = wrapEvent.getWrappedInventory();
if(wrapped == null) {
wrapped = WrappedIInventory.wrap(inv, spark);
}
arrayList.add(wrapped);
}
return arrayList;