mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-23 21:49:58 +00:00
Merge pull request #3072 from HenryLoenwind/interstellarMakings
Add support for soulbound items in a Galacticraft inventory
This commit is contained in:
commit
3fc989e44e
2 files changed
+64
-2
No files matched your search
@@ -8,6 +8,7 @@ import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.EnumEnchantmentType;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
@@ -25,6 +26,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.util.BaublesUtil;
|
||||
import crazypants.util.GalacticraftUtil;
|
||||
|
||||
@Interface(iface = "tterrag.core.api.common.enchant.IAdvancedEnchant", modid = "ttCore")
|
||||
public class EnchantmentSoulBound extends Enchantment implements IAdvancedEnchant {
|
||||
@@ -59,7 +61,7 @@ public class EnchantmentSoulBound extends Enchantment implements IAdvancedEnchan
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called the moment the player dies and drops is stuff.
|
||||
* This is called the moment the player dies and drops his stuff.
|
||||
*
|
||||
* We go early, so we can get our items before other mods put them into some
|
||||
* grave. Also remove them from the list so they won't get duped. If the
|
||||
@@ -101,7 +103,23 @@ public class EnchantmentSoulBound extends Enchantment implements IAdvancedEnchan
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Galacticraft. Again we are too early for those items. We just dump the
|
||||
// stuff into the normal inventory to not have to keep a separate list.
|
||||
if (evt.entityPlayer instanceof EntityPlayerMP) {
|
||||
IInventory galacticraft = GalacticraftUtil.getGCInventoryForPlayer((EntityPlayerMP) evt.entityPlayer);
|
||||
if (galacticraft != null) {
|
||||
for (int i = 0; i < galacticraft.getSizeInventory(); i++) {
|
||||
ItemStack item = galacticraft.getStackInSlot(i);
|
||||
if (isSoulBound(item)) {
|
||||
if (addToPlayerInventory(evt.entityPlayer, item)) {
|
||||
galacticraft.setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package crazypants.util;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import crazypants.enderio.Log;
|
||||
|
||||
/**
|
||||
* This is a near-verbatim copy of Galacticraft's API class 'AccessInventoryGC'.
|
||||
*
|
||||
* We don't need the extended functionality and already have more APIs included
|
||||
* than is good for our sanity.
|
||||
*
|
||||
*/
|
||||
public class GalacticraftUtil {
|
||||
|
||||
private static Class<?> playerStatsClass;
|
||||
private static Method getMethod;
|
||||
private static Field extendedInventoryField;
|
||||
|
||||
private static boolean accessFailed = false;
|
||||
|
||||
public static IInventory getGCInventoryForPlayer(EntityPlayerMP player) {
|
||||
if (!accessFailed) {
|
||||
try {
|
||||
if (playerStatsClass == null || getMethod == null || extendedInventoryField == null) {
|
||||
playerStatsClass = Class.forName("micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats");
|
||||
getMethod = playerStatsClass.getMethod("get", EntityPlayerMP.class);
|
||||
extendedInventoryField = playerStatsClass.getField("extendedInventory");
|
||||
}
|
||||
Object stats = getMethod.invoke(null, player);
|
||||
return stats == null ? null : (IInventory) extendedInventoryField.get(stats);
|
||||
} catch (Exception e) {
|
||||
Log.info("Galacticraft inventory inaccessable. Most likely because it is not installed.");
|
||||
accessFailed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user