Fixing Sanguine armour, adding some fancy rendering, doing other random bug fixes

This commit is contained in:
WayofTime 2014-08-10 14:38:51 -04:00
parent 4f9fad22c5
commit 14f9e3c61b
66 changed files with 2425 additions and 911 deletions

View file

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

View file

@ -115,7 +115,7 @@ public class ThaumcraftApi {
*/
public static void addSmeltingBonus(ItemStack in, ItemStack out) {
smeltingBonus.put(
Arrays.asList(Item.getIdFromItem(in.getItem()),in.getItemDamage()),
Arrays.asList(in.getItem(),in.getItemDamage()),
new ItemStack(out.getItem(),0,out.getItemDamage()));
}
@ -135,9 +135,9 @@ public class ThaumcraftApi {
* @return the The bonus item that can be produced
*/
public static ItemStack getSmeltingBonus(ItemStack in) {
ItemStack out = smeltingBonus.get(Arrays.asList(Item.getIdFromItem(in.getItem()),in.getItemDamage()));
ItemStack out = smeltingBonus.get(Arrays.asList(in.getItem(),in.getItemDamage()));
if (out==null) {
out = smeltingBonus.get(Arrays.asList(Item.getIdFromItem(in.getItem()),OreDictionary.WILDCARD_VALUE));
out = smeltingBonus.get(Arrays.asList(in.getItem(),OreDictionary.WILDCARD_VALUE));
}
if (out==null) {
String od = OreDictionary.getOreName( OreDictionary.getOreID(in));
@ -232,6 +232,7 @@ public class ThaumcraftApi {
/**
* @param key the research key required for this recipe to work.
* @param result the output result
* @param catalyst an itemstack of the catalyst or a string if it is an ore dictionary item
* @param cost the vis cost
* @param tags the aspects required to craft this
*/
@ -388,6 +389,43 @@ public class ThaumcraftApi {
registerObjectTag(item,tmp);
}
}
//WARP ///////////////////////////////////////////////////////////////////////////////////////
private static HashMap<Object,Integer> warpMap = new HashMap<Object,Integer>();
/**
* This method is used to determine how much warp is gained if the item is crafted
* @param craftresult The item crafted
* @param amount how much warp is gained
*/
public static void addWarpToItem(ItemStack craftresult, int amount) {
warpMap.put(Arrays.asList(craftresult.getItem(),craftresult.getItemDamage()),amount);
}
/**
* This method is used to determine how much warp is gained if the sent item is crafted
* @param in The item crafted
* @param amount how much warp is gained
*/
public static void addWarpToResearch(String research, int amount) {
warpMap.put(research, amount);
}
/**
* Returns how much warp is gained from the item or research passed in
* @param in itemstack or string
* @return how much warp it will give
*/
public static int getWarp(Object in) {
if (in==null) return 0;
if (in instanceof ItemStack && warpMap.containsKey(Arrays.asList(((ItemStack)in).getItem(),((ItemStack)in).getItemDamage()))) {
return warpMap.get(Arrays.asList(((ItemStack)in).getItem(),((ItemStack)in).getItemDamage()));
} else
if (in instanceof String && warpMap.containsKey((String)in)) {
return warpMap.get((String)in);
}
return 0;
}
//CROPS //////////////////////////////////////////////////////////////////////////////////////////

View file

@ -140,7 +140,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()));
}

View file

@ -0,0 +1,63 @@
package thaumcraft.api;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
/**
*
* @author azanor
*
* Custom tile entity class I use for most of my tile entities. Setup in such a way that only
* the nbt data within readCustomNBT / writeCustomNBT will be sent to the client when the tile
* updates. Apart from all the normal TE data that gets sent that is.
*
*/
public class TileThaumcraft extends TileEntity {
//NBT stuff
@Override
public void readFromNBT(NBTTagCompound nbttagcompound)
{
super.readFromNBT(nbttagcompound);
readCustomNBT(nbttagcompound);
}
public void readCustomNBT(NBTTagCompound nbttagcompound)
{
//TODO
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound)
{
super.writeToNBT(nbttagcompound);
writeCustomNBT(nbttagcompound);
}
public void writeCustomNBT(NBTTagCompound nbttagcompound)
{
//TODO
}
//Client Packet stuff
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeCustomNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, -999, nbttagcompound);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
super.onDataPacket(net, pkt);
this.readCustomNBT(pkt.func_148857_g());
}
}

View file

@ -0,0 +1,117 @@
package thaumcraft.api;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class WorldCoordinates implements Comparable
{
public int x;
/** the y coordinate */
public int y;
/** the z coordinate */
public int z;
public int dim;
public WorldCoordinates() {}
public WorldCoordinates(int par1, int par2, int par3, int d)
{
this.x = par1;
this.y = par2;
this.z = par3;
this.dim = d;
}
public WorldCoordinates(TileEntity tile)
{
this.x = tile.xCoord;
this.y = tile.yCoord;
this.z = tile.zCoord;
this.dim = tile.getWorldObj().provider.dimensionId;
}
public WorldCoordinates(WorldCoordinates par1ChunkCoordinates)
{
this.x = par1ChunkCoordinates.x;
this.y = par1ChunkCoordinates.y;
this.z = par1ChunkCoordinates.z;
this.dim = par1ChunkCoordinates.dim;
}
public boolean equals(Object par1Obj)
{
if (!(par1Obj instanceof WorldCoordinates))
{
return false;
}
else
{
WorldCoordinates coordinates = (WorldCoordinates)par1Obj;
return this.x == coordinates.x && this.y == coordinates.y && this.z == coordinates.z && this.dim == coordinates.dim ;
}
}
public int hashCode()
{
return this.x + this.y << 8 + this.z << 16 + this.dim << 24;
}
/**
* Compare the coordinate with another coordinate
*/
public int compareWorldCoordinate(WorldCoordinates par1)
{
return this.dim == par1.dim ? (
this.y == par1.y ? (this.z == par1.z ? this.x - par1.x : this.z - par1.z) : this.y - par1.y) : -1;
}
public void set(int par1, int par2, int par3, int d)
{
this.x = par1;
this.y = par2;
this.z = par3;
this.dim = d;
}
/**
* Returns the squared distance between this coordinates and the coordinates given as argument.
*/
public float getDistanceSquared(int par1, int par2, int par3)
{
float f = (float)(this.x - par1);
float f1 = (float)(this.y - par2);
float f2 = (float)(this.z - par3);
return f * f + f1 * f1 + f2 * f2;
}
/**
* Return the squared distance between this coordinates and the ChunkCoordinates given as argument.
*/
public float getDistanceSquaredToWorldCoordinates(WorldCoordinates par1ChunkCoordinates)
{
return this.getDistanceSquared(par1ChunkCoordinates.x, par1ChunkCoordinates.y, par1ChunkCoordinates.z);
}
public int compareTo(Object par1Obj)
{
return this.compareWorldCoordinate((WorldCoordinates)par1Obj);
}
public void readNBT(NBTTagCompound nbt) {
this.x = nbt.getInteger("w_x");
this.y = nbt.getInteger("w_y");
this.z = nbt.getInteger("w_z");
this.dim = nbt.getInteger("w_d");
}
public void writeNBT(NBTTagCompound nbt) {
nbt.setInteger("w_x",x);
nbt.setInteger("w_y",y);
nbt.setInteger("w_z",z);
nbt.setInteger("w_d",dim);
}
}

View file

@ -9,6 +9,7 @@ import cpw.mods.fml.common.FMLLog;
public class AspectSourceHelper {
static Method drainEssentia;
static Method findEssentia;
/**
* This method is what is used to drain essentia from jars and other sources for things like
* infusion crafting or powering the arcane furnace. A record of possible sources are kept track of
@ -23,14 +24,35 @@ public class AspectSourceHelper {
public static boolean drainEssentia(TileEntity tile, Aspect aspect, ForgeDirection direction, int range) {
try {
if(drainEssentia == null) {
Class fake = Class.forName("thaumcraft.common.lib.EssentiaHandler");
Class fake = Class.forName("thaumcraft.common.lib.events.EssentiaHandler");
drainEssentia = fake.getMethod("drainEssentia", TileEntity.class, Aspect.class, ForgeDirection.class, int.class);
}
return (Boolean) drainEssentia.invoke(null, tile, aspect, direction, range);
} catch(Exception ex) {
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.lib.EssentiaHandler method drainEssentia");
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.lib.events.EssentiaHandler method drainEssentia");
}
return false;
}
/**
* This method returns if there is any essentia of the passed type that can be drained. It in no way checks how
* much there is, only if an essentia container nearby contains at least 1 point worth.
* @param tile the tile entity that is checking the essentia
* @param aspect the aspect that you are looking for
* @param direction the direction from which you wish to drain. Forgedirection.Unknown simply seeks in all directions.
* @param range how many blocks you wish to search for essentia sources.
* @return boolean returns true if essentia was found and removed from a source.
*/
public static boolean findEssentia(TileEntity tile, Aspect aspect, ForgeDirection direction, int range) {
try {
if(findEssentia == null) {
Class fake = Class.forName("thaumcraft.common.lib.events.EssentiaHandler");
findEssentia = fake.getMethod("findEssentia", TileEntity.class, Aspect.class, ForgeDirection.class, int.class);
}
return (Boolean) findEssentia.invoke(null, tile, aspect, direction, range);
} catch(Exception ex) {
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.lib.events.EssentiaHandler method findEssentia");
}
return false;
}
}

View file

@ -34,7 +34,8 @@ public class CrucibleRecipe {
return false;
} else
if (catalyst instanceof ArrayList && ((ArrayList<ItemStack>)catalyst).size()>0) {
if (!ThaumcraftApiHelper.containsMatch(true, ((ArrayList<ItemStack>)catalyst).toArray(new ItemStack[]{}), cat)) return false;
ItemStack[] ores = ((ArrayList<ItemStack>)catalyst).toArray(new ItemStack[]{});
if (!ThaumcraftApiHelper.containsMatch(false, new ItemStack[]{cat},ores)) return false;
}
if (itags==null) return false;
for (Aspect tag:aspects.getAspects()) {
@ -48,8 +49,8 @@ public class CrucibleRecipe {
return true;
} else
if (catalyst instanceof ArrayList && ((ArrayList<ItemStack>)catalyst).size()>0) {
if (ThaumcraftApiHelper.containsMatch(true,
((ArrayList<ItemStack>)catalyst).toArray(new ItemStack[]{}), cat)) return true;
ItemStack[] ores = ((ArrayList<ItemStack>)catalyst).toArray(new ItemStack[]{});
if (ThaumcraftApiHelper.containsMatch(false, new ItemStack[]{cat},ores)) return true;
}
return false;
}
@ -71,4 +72,24 @@ public class CrucibleRecipe {
return recipeOutput;
}
// @Override
// public int hashCode() {
// String hash = "";
// if (catalyst instanceof ItemStack) {
// hash += ((ItemStack)catalyst).toString();
// } else if (catalyst instanceof ArrayList && ((ArrayList<ItemStack>)catalyst).size()>0) {
// for (ItemStack s:(ArrayList<ItemStack>)catalyst) {
// hash += s.toString();
// }
// } else {
// hash += catalyst.hashCode();
// }
// hash += getRecipeOutput().toString();
// for (Aspect a:aspects.getAspectsSorted()) {
// hash += a.getTag() + aspects.getAmount(a);
// }
// return hash.hashCode();
// }
}

View file

@ -0,0 +1,32 @@
package thaumcraft.api.damagesource;
import net.minecraft.entity.Entity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSourceIndirect;
public class DamageSourceIndirectThaumcraftEntity extends EntityDamageSourceIndirect {
private boolean fireDamage;
private float hungerDamage;
private boolean isUnblockable;
public DamageSourceIndirectThaumcraftEntity(String par1Str,
Entity par2Entity, Entity par3Entity) {
super(par1Str, par2Entity, par3Entity);
}
public DamageSource setFireDamage()
{
this.fireDamage = true;
return this;
}
public DamageSource setDamageBypassesArmor()
{
this.isUnblockable = true;
this.hungerDamage = 0.0F;
return this;
}
}

View file

@ -0,0 +1,46 @@
package thaumcraft.api.damagesource;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSource;
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");
protected DamageSourceThaumcraft(String par1Str) {
super(par1Str);
}
/** This kind of damage can be blocked or not. */
private boolean isUnblockable = false;
private boolean isDamageAllowedInCreativeMode = false;
private float hungerDamage = 0.3F;
/** This kind of damage is based on fire or not. */
private boolean fireDamage;
/** This kind of damage is based on a projectile or not. */
private boolean projectile;
/**
* Whether this damage source will have its damage amount scaled based on the current difficulty.
*/
private boolean difficultyScaled;
private boolean magicDamage = false;
private boolean explosion = false;
public static DamageSource causeSwarmDamage(EntityLivingBase par0EntityLiving)
{
return new EntityDamageSource("swarm", par0EntityLiving);
}
public static DamageSource causeTentacleDamage(EntityLivingBase par0EntityLiving)
{
return new EntityDamageSource("tentacle", par0EntityLiving);
}
}

View file

@ -0,0 +1,5 @@
package thaumcraft.api.entities;
public interface ITaintedMob {
}

View file

@ -0,0 +1,4 @@
@API(owner = "Thaumcraft", apiVersion = "4.2.0.0", provides = "Thaumcraft|API")
package thaumcraft.api;
import cpw.mods.fml.common.API;

View file

@ -0,0 +1,67 @@
package thaumcraft.api.potions;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
import thaumcraft.api.damagesource.DamageSourceThaumcraft;
import thaumcraft.api.entities.ITaintedMob;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PotionFluxTaint extends Potion
{
public static PotionFluxTaint instance = null; // will be instantiated at runtime
private int statusIconIndex = -1;
public PotionFluxTaint(int par1, boolean par2, int par3)
{
super(par1,par2,par3);
setIconIndex(0, 0);
}
public static void init()
{
instance.setPotionName("potion.fluxtaint");
instance.setIconIndex(3, 1);
instance.setEffectiveness(0.25D);
}
@Override
public boolean isBadEffect() {
return true;
}
@Override
@SideOnly(Side.CLIENT)
public int getStatusIconIndex() {
Minecraft.getMinecraft().renderEngine.bindTexture(rl);
return super.getStatusIconIndex();
}
ResourceLocation rl = new ResourceLocation("thaumcraft","textures/misc/potions.png");
@Override
public void performEffect(EntityLivingBase target, int par2) {
if (target instanceof ITaintedMob) {
target.heal(1);
} else
if (!target.isEntityUndead() && !(target instanceof EntityPlayer))
{
target.attackEntityFrom(DamageSourceThaumcraft.taint, 1);
}
else
if (!target.isEntityUndead() && (target.getMaxHealth() > 1 || (target instanceof EntityPlayer)))
{
target.attackEntityFrom(DamageSourceThaumcraft.taint, 1);
}
}
public boolean isReady(int par1, int par2)
{
int k = 40 >> par2;
return k > 0 ? par1 % k == 0 : true;
}
}

View file

@ -3,6 +3,7 @@ package thaumcraft.api.research;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
@ -24,7 +25,8 @@ public class ResearchPage {
NORMAL_CRAFTING,
INFUSION_CRAFTING,
COMPOUND_CRAFTING,
INFUSION_ENCHANTMENT
INFUSION_ENCHANTMENT,
SMELTING
}
public PageType type = PageType.TEXT;
@ -79,6 +81,14 @@ public class ResearchPage {
this.recipe = recipe;
}
/**
* @param recipe a collection of arcane crafting recipes.
*/
public ResearchPage(CrucibleRecipe[] recipe) {
this.type = PageType.CRUCIBLE_CRAFTING;
this.recipe = recipe;
}
/**
* @param recipe a collection of infusion crafting recipes.
*/
@ -113,6 +123,15 @@ public class ResearchPage {
this.recipeOutput = recipe.getRecipeOutput();
}
/**
* @param recipe a furnace smelting crafting recipe.
*/
public ResearchPage(ItemStack input) {
this.type = PageType.SMELTING;
this.recipe = input;
this.recipeOutput = FurnaceRecipes.smelting().getSmeltingResult(input);
}
/**
* @param recipe an infusion crafting recipe.
*/

View file

@ -0,0 +1,188 @@
package thaumcraft.api.visnet;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import thaumcraft.api.TileThaumcraft;
import thaumcraft.api.WorldCoordinates;
import thaumcraft.api.aspects.Aspect;
/**
* @author Azanor
*
* The tile entity used by nodes in the vis energy network. A node is either a source (like an aura node),
* a transport relay or vis receiver (like the infernal furnace).
*
*/
public abstract class TileVisNode extends TileThaumcraft {
WeakReference<TileVisNode> parent = null;
ArrayList<WeakReference<TileVisNode>> children = new ArrayList<WeakReference<TileVisNode>>();
/**
* @return the WorldCoordinates location of where this node is located
*/
public WorldCoordinates getLocation() {
return new WorldCoordinates(this);
}
/**
* @return the number of blocks away this node will check for parent nodes to connect to.
*/
public abstract int getRange();
/**
* @return true if this is the source or root node of the vis network.
*/
public abstract boolean isSource();
/**
* This method should never be called directly. Use VisNetHandler.drainVis() instead
* @param aspect what aspect to drain
* @param vis how much to drain
* @return how much was actually drained
*/
public int consumeVis(Aspect aspect, int vis) {
if (VisNetHandler.isNodeValid(getParent())) {
int out = getParent().get().consumeVis(aspect, vis);
if (out>0) {
triggerConsumeEffect(aspect);
}
return out;
}
return 0;
}
public void removeThisNode() {
for (WeakReference<TileVisNode> n:getChildren()) {
if (n!=null && n.get()!=null) {
n.get().removeThisNode();
}
}
children = new ArrayList<WeakReference<TileVisNode>>();
if (VisNetHandler.isNodeValid(this.getParent())) {
this.getParent().get().nodeRefresh=true;
}
this.setParent(null);
this.parentChanged();
if (this.isSource()) {
HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = VisNetHandler.sources.get(worldObj.provider.dimensionId);
if (sourcelist==null) {
sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
}
sourcelist.remove(getLocation());
VisNetHandler.sources.put( worldObj.provider.dimensionId, sourcelist );
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
public void invalidate() {
removeThisNode();
super.invalidate();
}
public void triggerConsumeEffect(Aspect aspect) { }
/**
* @return
*/
public WeakReference<TileVisNode> getParent() {
return parent;
}
/**
* @return
*/
public WeakReference<TileVisNode> getRootSource() {
return VisNetHandler.isNodeValid(getParent()) ?
getParent().get().getRootSource() : this.isSource() ?
new WeakReference(this) : null;
}
/**
* @param parent
*/
public void setParent(WeakReference<TileVisNode> parent) {
this.parent = parent;
}
/**
* @return
*/
public ArrayList<WeakReference<TileVisNode>> getChildren() {
return children;
}
@Override
public boolean canUpdate() {
return true;
}
protected int nodeCounter = 0;
private boolean nodeRegged = false;
public boolean nodeRefresh = false;
@Override
public void updateEntity() {
if (!worldObj.isRemote && ((nodeCounter++) % 40==0 || nodeRefresh)) {
//check for changes
if (!nodeRefresh && children.size()>0) {
for (WeakReference<TileVisNode> n:children) {
if (n==null || n.get()==null) {
nodeRefresh=true;
break;
}
}
}
//refresh linked nodes
if (nodeRefresh) {
for (WeakReference<TileVisNode> n:children) {
if (n.get()!=null) {
n.get().nodeRefresh=true;
}
}
children.clear();
parent=null;
}
//redo stuff
if (isSource() && !nodeRegged) {
VisNetHandler.addSource(getWorldObj(), this);
nodeRegged = true;
} else
if (!isSource() && !VisNetHandler.isNodeValid(getParent())) {
setParent(VisNetHandler.addNode(getWorldObj(), this));
nodeRefresh=true;
}
if (nodeRefresh) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
parentChanged();
}
nodeRefresh=false;
}
}
public void parentChanged() { }
/**
* @return the type of shard this is attuned to:
* none -1, air 0, fire 1, water 2, earth 3, order 4, entropy 5
* Should return -1 for most implementations
*/
public byte getAttunement() {
return -1;
}
}

View file

@ -0,0 +1,284 @@
package thaumcraft.api.visnet;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import net.minecraft.world.World;
import thaumcraft.api.WorldCoordinates;
import thaumcraft.api.aspects.Aspect;
import cpw.mods.fml.common.FMLLog;
public class VisNetHandler {
// / NODE DRAINING
/**
* This method drains vis from a relay or source near the passed in
* location. The amount received can be less than the amount requested so
* take that into account.
*
* @param world
* @param x the x position of the draining block or entity
* @param y the y position of the draining block or entity
* @param z the z position of the draining block or entity
* @param aspect what aspect to drain
* @param vis how much to drain
* @return how much was actually drained
*/
public static int drainVis(World world, int x, int y, int z, Aspect aspect, int amount) {
int drainedAmount = 0;
WorldCoordinates drainer = new WorldCoordinates(x, y, z,
world.provider.dimensionId);
if (!nearbyNodes.containsKey(drainer)) {
calculateNearbyNodes(world, x, y, z);
}
ArrayList<WeakReference<TileVisNode>> nodes = nearbyNodes.get(drainer);
if (nodes!=null && nodes.size()>0)
for (WeakReference<TileVisNode> noderef : nodes) {
TileVisNode node = noderef.get();
if (node == null) continue;
int a = node.consumeVis(aspect, amount);
drainedAmount += a;
amount -= a;
if (a>0) {
int color = Aspect.getPrimalAspects().indexOf(aspect);
generateVisEffect(world.provider.dimensionId, x, y, z, node.xCoord, node.yCoord, node.zCoord, color);
}
if (amount <= 0) {
break;
}
}
return drainedAmount;
}
static Method generateVisEffect;
public static void generateVisEffect(int dim, int x, int y, int z, int x2, int y2, int z2, int color) {
try {
if(generateVisEffect == null) {
Class fake = Class.forName("thaumcraft.common.lib.Utils");
generateVisEffect = fake.getMethod("generateVisEffect", int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class);
}
generateVisEffect.invoke(null, dim, x,y,z,x2,y2,z2,color);
} catch(Exception ex) {
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.lib.Utils method generateVisEffect");
}
}
public static HashMap<Integer, HashMap<WorldCoordinates, WeakReference<TileVisNode>>> sources = new HashMap<Integer, HashMap<WorldCoordinates, WeakReference<TileVisNode>>>();
public static void addSource(World world, TileVisNode vs) {
HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
.get(world.provider.dimensionId);
if (sourcelist == null) {
sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
}
sourcelist.put(vs.getLocation(), new WeakReference(vs));
sources.put(world.provider.dimensionId, sourcelist);
nearbyNodes.clear();
}
public static boolean isNodeValid(WeakReference<TileVisNode> node) {
if (node == null || node.get() == null || node.get().isInvalid())
return false;
return true;
}
public static WeakReference<TileVisNode> addNode(World world, TileVisNode vn) {
WeakReference ref = new WeakReference(vn);
HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
.get(world.provider.dimensionId);
if (sourcelist == null) {
sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
return null;
}
ArrayList<Object[]> nearby = new ArrayList<Object[]>();
for (WeakReference<TileVisNode> root : sourcelist.values()) {
if (!isNodeValid(root))
continue;
TileVisNode source = root.get();
float r = inRange(world, vn.getLocation(), source.getLocation(),
vn.getRange());
if (r > 0) {
nearby.add(new Object[] { source, r - vn.getRange() * 2 });
}
nearby = findClosestNodes(vn, source, nearby);
}
float dist = Float.MAX_VALUE;
TileVisNode closest = null;
if (nearby.size() > 0) {
for (Object[] o : nearby) {
if ((Float) o[1] < dist) {// && canNodeBeSeen(vn,(TileVisNode)
// o[0])) {
dist = (Float) o[1];
closest = (TileVisNode) o[0];
}
}
}
if (closest != null) {
closest.getChildren().add(ref);
nearbyNodes.clear();
return new WeakReference(closest);
}
return null;
}
public static ArrayList<Object[]> findClosestNodes(TileVisNode target,
TileVisNode root, ArrayList<Object[]> in) {
TileVisNode closestChild = null;
for (WeakReference<TileVisNode> child : root.getChildren()) {
TileVisNode n = child.get();
if (n != null
&& !n.equals(target)
&& !n.equals(root)
&& (target.getAttunement() == -1 || n.getAttunement() == -1 || n
.getAttunement() == target.getAttunement())) {
float r2 = inRange(n.getWorldObj(), n.getLocation(),
target.getLocation(), target.getRange());
if (r2 > 0) {
in.add(new Object[] { n, r2 });
}
in = findClosestNodes(target, n, in);
}
}
return in;
}
private static float inRange(World world, WorldCoordinates cc1,
WorldCoordinates cc2, int range) {
float distance = cc1.getDistanceSquaredToWorldCoordinates(cc2);
return distance > range * range ? -1 : distance;
}
private static HashMap<WorldCoordinates, ArrayList<WeakReference<TileVisNode>>> nearbyNodes = new HashMap<WorldCoordinates, ArrayList<WeakReference<TileVisNode>>>();
private static void calculateNearbyNodes(World world, int x, int y, int z) {
HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
.get(world.provider.dimensionId);
if (sourcelist == null) {
sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
return;
}
ArrayList<WeakReference<TileVisNode>> cn = new ArrayList<WeakReference<TileVisNode>>();
WorldCoordinates drainer = new WorldCoordinates(x, y, z,
world.provider.dimensionId);
ArrayList<Object[]> nearby = new ArrayList<Object[]>();
for (WeakReference<TileVisNode> root : sourcelist.values()) {
if (!isNodeValid(root))
continue;
TileVisNode source = root.get();
TileVisNode closest = null;
float range = Float.MAX_VALUE;
float r = inRange(world, drainer, source.getLocation(),
source.getRange());
if (r > 0) {
range = r;
closest = source;
}
ArrayList<WeakReference<TileVisNode>> children = new ArrayList<WeakReference<TileVisNode>>();
children = getAllChildren(source,children);
for (WeakReference<TileVisNode> child : children) {
TileVisNode n = child.get();
if (n != null && !n.equals(root)) {
float r2 = inRange(n.getWorldObj(), n.getLocation(),
drainer, n.getRange());
if (r2 > 0 && r2 < range) {
range = r2;
closest = n;
}
}
}
if (closest != null) {
cn.add(new WeakReference(closest));
}
}
nearbyNodes.put(drainer, cn);
}
private static ArrayList<WeakReference<TileVisNode>> getAllChildren(TileVisNode source, ArrayList<WeakReference<TileVisNode>> list) {
for (WeakReference<TileVisNode> child : source.getChildren()) {
TileVisNode n = child.get();
if (n != null) {
list.add(child);
list = getAllChildren(n,list);
}
}
return list;
}
// public static boolean canNodeBeSeen(TileVisNode source,TileVisNode
// target)
// {
// double d = Math.sqrt(source.getDistanceFrom(target.xCoord, target.yCoord,
// target.zCoord));
// double xd = (source.xCoord-target.xCoord) / d;
// double yd = (source.yCoord-target.yCoord) / d;
// double zd = (source.zCoord-target.zCoord) / d;
// return source.getWorldObj().rayTraceBlocks(
// Vec3.createVectorHelper(source.xCoord-xd+.5+.5, source.yCoord-yd,
// source.zCoord-zd),
// Vec3.createVectorHelper(target.xCoord+.5, target.yCoord+.5,
// target.zCoord+.5)) == null;
// }
// public static HashMap<WorldCoordinates,WeakReference<TileVisNode>>
// noderef = new HashMap<WorldCoordinates,WeakReference<TileVisNode>>();
//
// public static TileVisNode getClosestNodeWithinRadius(World world, int x,
// int y, int z, int radius) {
// TileVisNode out = null;
// WorldCoordinates wc = null;
// float cd = Float.MAX_VALUE;
// for (int sx = x - radius; sx <= x + radius; sx++) {
// for (int sy = y - radius; sy <= y + radius; sy++) {
// for (int sz = z - radius; sz <= z + radius; sz++) {
// wc = new WorldCoordinates(sx,sy,sz,world.provider.dimensionId);
// if (noderef.containsKey(wc)) {
// float d = wc.getDistanceSquared(x, y, z);
// if (d<radius*radius && noderef.get(wc).get()!=null &&
// !noderef.get(wc).get().isReceiver() &&
// isNodeValid(noderef.get(wc).get().getParent())
// ) {
// out = noderef.get(wc).get();
// cd = d;
// }
// }
// }
// }
// }
// return out;
// }
}

View file

@ -115,6 +115,13 @@ public class WandCap {
this.craftCost = craftCost;
}
/**
* The research a player needs to have finished to be able to craft a wand with this cap.
*/
public String getResearch() {
return "CAP_"+getTag();
}
// Some examples:
// WandCap WAND_CAP_IRON = new WandCap("iron", 1.1f, Arrays.asList(Aspect.ORDER),1, new ItemStack(ConfigItems.itemWandCap,1,0),1);
// WandCap WAND_CAP_GOLD = new WandCap("gold", 1f, new ItemStack(ConfigItems.itemWandCap,1,1),3);

View file

@ -144,6 +144,13 @@ public class WandRod {
public void setGlowing(boolean hasGlow) {
this.glow = hasGlow;
}
/**
* The research a player needs to have finished to be able to craft a wand with this rod.
*/
public String getResearch() {
return "ROD_"+getTag();
}
// Some examples:
// WandRod WAND_ROD_WOOD = new WandRod("wood",25,new ItemStack(Item.stick),1);