Updated Thaumcraft API and, as per request, added converter for items including apsect info.

Keeping TC converters disabled by default, though, because this seems kind of cheaty to me (usually you'd have to research aspects to see them on items).
This commit is contained in:
Florian Nücke 2014-10-11 20:20:50 +02:00
parent a1ec488588
commit febcabdde9
11 changed files with 124 additions and 10 deletions

View File

@ -1,5 +1,5 @@
minecraft.version=1.7.10
forge.version=10.13.1.1217
forge.version=10.13.1.1224
oc.version=1.4.0
oc.subversion=dev

View File

@ -1,6 +1,5 @@
package thaumcraft.api;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
/**

View File

@ -2,6 +2,7 @@ package thaumcraft.api;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@ -133,6 +134,29 @@ public class ThaumcraftApiHelper {
}
return false;
}
public static boolean areItemStackTagsEqualForCrafting(ItemStack slotItem,ItemStack recipeItem)
{
if (recipeItem == null || slotItem == null) return false;
if (recipeItem.stackTagCompound!=null && slotItem.stackTagCompound==null ) return false;
if (recipeItem.stackTagCompound==null ) return true;
Iterator iterator = recipeItem.stackTagCompound.func_150296_c().iterator();
while (iterator.hasNext())
{
String s = (String)iterator.next();
if (slotItem.stackTagCompound.hasKey(s)) {
if (!slotItem.stackTagCompound.getTag(s).toString().equals(
recipeItem.stackTagCompound.getTag(s).toString())) {
return false;
}
} else {
return false;
}
}
return true;
}
public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict)
{
@ -140,7 +164,8 @@ public class ThaumcraftApiHelper {
{
return false;
}
return (target.getItem() == input.getItem() && ((target.getItemDamage() == OreDictionary.WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage()));
return (target.getItem() == input.getItem() &&
((target.getItemDamage() == OreDictionary.WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage()));
}
@ -265,4 +290,47 @@ public class ThaumcraftApiHelper {
}
return ot;
}
static Method addWarpToPlayer;
/**
* This adds permanents or temporary warp to a player. It will automatically be synced clientside
* @param player the player using the wand
* @param amount how much warp to add. Negative amounts are only valid for temporary warp
* @param temporary add temporary warp instead of permanent
*/
public static void addWarpToPlayer(EntityPlayer player, int amount, boolean temporary) {
boolean ot = false;
try {
if(addWarpToPlayer == null) {
Class fake = Class.forName("thaumcraft.common.Thaumcraft");
addWarpToPlayer = fake.getMethod("addWarpToPlayer",
EntityPlayer.class, int.class, boolean.class);
}
addWarpToPlayer.invoke(null, player, amount, temporary);
} catch(Exception ex) {
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.Thaumcraft method addWarpToPlayer");
}
}
static Method addStickyWarpToPlayer;
/**
* This "sticky" warp to a player. Sticky warp is permanent warp that can be removed.
* It will automatically be synced clientside
* @param player the player using the wand
* @param amount how much warp to add. Can have negative amounts.
*/
public static void addStickyWarpToPlayer(EntityPlayer player, int amount) {
boolean ot = false;
try {
if(addStickyWarpToPlayer == null) {
Class fake = Class.forName("thaumcraft.common.Thaumcraft");
addStickyWarpToPlayer = fake.getMethod("addStickyWarpToPlayer",
EntityPlayer.class, int.class);
}
addStickyWarpToPlayer.invoke(null, player, amount);
} catch(Exception ex) {
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.Thaumcraft method addStickyWarpToPlayer");
}
}
}

View File

@ -233,6 +233,19 @@ public class AspectList implements Serializable {
}
}
public void readFromNBT(NBTTagCompound nbttagcompound, String label)
{
aspects.clear();
NBTTagList tlist = nbttagcompound.getTagList(label,(byte)10);
for (int j = 0; j < tlist.tagCount(); j++) {
NBTTagCompound rs = (NBTTagCompound) tlist.getCompoundTagAt(j);
if (rs.hasKey("key")) {
add( Aspect.getAspect(rs.getString("key")),
rs.getInteger("amount"));
}
}
}
/**
* Writes the list of aspects to nbt
* @param nbttagcompound
@ -251,6 +264,17 @@ public class AspectList implements Serializable {
}
}
public void writeToNBT(NBTTagCompound nbttagcompound, String label)
{
NBTTagList tlist = new NBTTagList();
nbttagcompound.setTag(label, tlist);
for (Aspect aspect : getAspects())
if (aspect != null) {
NBTTagCompound f = new NBTTagCompound();
f.setString("key", aspect.getTag());
f.setInteger("amount", getAmount(aspect));
tlist.appendTag(f);
}
}
}

View File

@ -10,6 +10,7 @@ public class DamageSourceThaumcraft extends DamageSource
public static DamageSource taint = new DamageSourceThaumcraft("taint").setDamageBypassesArmor().setMagicDamage();
public static DamageSource tentacle = new DamageSourceThaumcraft("tentacle");
public static DamageSource swarm = new DamageSourceThaumcraft("swarm");
public static DamageSource dissolve = new DamageSourceThaumcraft("dissolve").setDamageBypassesArmor();
protected DamageSourceThaumcraft(String par1Str) {
super(par1Str);

View File

@ -40,7 +40,7 @@ public class PotionFluxTaint extends Potion
return super.getStatusIconIndex();
}
ResourceLocation rl = new ResourceLocation("thaumcraft","textures/misc/potions.png");
static final ResourceLocation rl = new ResourceLocation("thaumcraft","textures/misc/potions.png");
@Override
public void performEffect(EntityLivingBase target, int par2) {

View File

@ -20,6 +20,7 @@
"ProjRed|Transmission",
"RedLogic",
"StargateTech2",
"Thaumcraft",
"ThermalExpansion",
"UniversalElectricity"
],

View File

@ -15,7 +15,7 @@ object ConverterSafariNet extends Converter {
"MineFactoryReloaded:item.mfr.safarinet.singleuse",
"MineFactoryReloaded:item.mfr.safarinet.jailer")
override def convert(value: scala.Any, output: util.Map[AnyRef, AnyRef]) = value match {
override def convert(value: scala.Any, output: util.Map[AnyRef, AnyRef]): Unit = value match {
case stack: ItemStack =>
val name = Item.itemRegistry.getNameForObject(stack.getItem)
if (SafariNetNames.contains(name)) {

View File

@ -0,0 +1,19 @@
package li.cil.oc.integration.thaumcraft
import java.util
import li.cil.oc.api.driver.Converter
import net.minecraft.item.ItemStack
import thaumcraft.api.aspects.AspectList
import scala.collection.convert.WrapAsScala._
object ConverterAspectItem extends Converter {
override def convert(value: scala.Any, output: util.Map[AnyRef, AnyRef]): Unit = value match {
case stack: ItemStack if stack.hasTagCompound =>
val aspects = new AspectList()
aspects.readFromNBT(stack.getTagCompound)
output += "aspects" -> aspects
case _ =>
}
}

View File

@ -14,17 +14,17 @@ public class ConverterIAspectContainer implements Converter {
public void convert(final Object value, final Map<Object, Object> output) {
if (value instanceof IAspectContainer) {
final IAspectContainer container = (IAspectContainer) value;
output.put("aspectList", container.getAspects());
output.put("aspects", container.getAspects());
}
if (value instanceof AspectList) {
final AspectList aspectList = (AspectList) value;
final AspectList aspects = (AspectList) value;
int i = 0;
for (Aspect aspect : aspectList.getAspects()) {
for (Aspect aspect : aspects.getAspects()) {
if (aspect == null) continue;
final HashMap<Object, Object> aspectMap = Maps.newHashMap();
aspectMap.put("name", aspect.getName());
aspectMap.put("quantity", aspectList.getAmount(aspect));
aspectMap.put("amount", aspects.getAmount(aspect));
output.put(++i, aspectMap);
}
}

View File

@ -9,6 +9,8 @@ object ModThaumcraft extends ModProxy {
override def initialize() {
Driver.add(new DriverAspectContainer)
Driver.add(new ConverterIAspectContainer)
Driver.add(ConverterAspectItem)
}
}