From f19f5be0fafa2f565f24308354310ccc7daefae1 Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Sat, 28 Feb 2015 10:33:55 -0500 Subject: [PATCH] Move TC API into correct folder and switch to using the entire API --- .../java/thaumcraft/api/BlockCoordinates.java | 108 +++++++ src/api/java/thaumcraft/api/IArchitect.java | 27 ++ src/api/java/thaumcraft/api/IGoggles.java | 22 ++ src/api/java/thaumcraft/api/IRepairable.java | 13 + .../thaumcraft/api/IRepairableExtended.java | 17 ++ src/api/java/thaumcraft/api/IRunicArmor.java | 22 ++ src/api/java/thaumcraft/api/IScribeTools.java | 14 + .../java/thaumcraft/api/IVisDiscountGear.java | 20 ++ src/api/java/thaumcraft/api/IWarpingGear.java | 22 ++ src/api/java/thaumcraft/api/ItemApi.java | 70 +++++ src/api/java/thaumcraft/api/ItemRunic.java | 21 ++ .../java/thaumcraft/api/ThaumcraftApi.java | 0 .../thaumcraft/api/ThaumcraftApiHelper.java | 0 .../java/thaumcraft/api/TileThaumcraft.java | 63 ++++ .../java/thaumcraft/api/WorldCoordinates.java | 117 ++++++++ .../java/thaumcraft/api/aspects/Aspect.java | 4 +- .../thaumcraft/api/aspects/AspectList.java | 0 .../api/aspects/AspectSourceHelper.java | 0 .../api/aspects/IAspectContainer.java | 0 .../thaumcraft/api/aspects/IAspectSource.java | 0 .../api/aspects/IEssentiaContainerItem.java | 0 .../api/aspects/IEssentiaTransport.java | 0 .../api/crafting/CrucibleRecipe.java | 0 .../api/crafting/IArcaneRecipe.java | 0 .../api/crafting/IInfusionStabiliser.java | 0 .../crafting/InfusionEnchantmentRecipe.java | 0 .../api/crafting/InfusionRecipe.java | 0 .../api/crafting/ShapedArcaneRecipe.java | 0 .../api/crafting/ShapelessArcaneRecipe.java | 0 .../DamageSourceIndirectThaumcraftEntity.java | 32 ++ .../damagesource/DamageSourceThaumcraft.java | 47 +++ .../thaumcraft/api/entities/IEldritchMob.java | 5 + .../thaumcraft/api/entities/ITaintedMob.java | 5 + .../internal/DummyInternalMethodHandler.java | 0 .../api/internal/IInternalMethodHandler.java | 0 .../api/internal/WeightedRandomLoot.java | 0 src/api/java/thaumcraft/api/nodes/INode.java | 53 ++++ .../java/thaumcraft/api/nodes/IRevealer.java | 22 ++ .../thaumcraft/api/nodes/NodeModifier.java | 6 + .../java/thaumcraft/api/nodes/NodeType.java | 6 + .../java/thaumcraft/api/package-info.java | 2 +- .../api/potions/PotionFluxTaint.java | 67 +++++ .../api/potions/PotionVisExhaust.java | 48 +++ .../api/research/IScanEventHandler.java | 0 .../api/research/ResearchCategories.java | 0 .../api/research/ResearchCategoryList.java | 0 .../thaumcraft/api/research/ResearchItem.java | 0 .../thaumcraft/api/research/ResearchPage.java | 0 .../thaumcraft/api/research/ScanResult.java | 0 .../thaumcraft/api/visnet/TileVisNode.java | 188 ++++++++++++ .../thaumcraft/api/visnet/VisNetHandler.java | 282 ++++++++++++++++++ .../api/wands/FocusUpgradeType.java | 114 +++++++ .../api/wands/IWandRodOnUpdate.java | 16 + .../api/wands/IWandTriggerManager.java | 15 + .../java/thaumcraft/api/wands/IWandable.java | 25 ++ .../thaumcraft/api/wands/ItemFocusBasic.java | 276 +++++++++++++++++ .../java/thaumcraft/api/wands/StaffRod.java | 48 +++ .../java/thaumcraft/api/wands/WandCap.java | 129 ++++++++ .../java/thaumcraft/api/wands/WandRod.java | 158 ++++++++++ .../api/wands/WandTriggerRegistry.java | 126 ++++++++ .../cricketcraft/chisel/init/ChiselTabs.java | 72 +++-- 61 files changed, 2246 insertions(+), 36 deletions(-) create mode 100644 src/api/java/thaumcraft/api/BlockCoordinates.java create mode 100644 src/api/java/thaumcraft/api/IArchitect.java create mode 100644 src/api/java/thaumcraft/api/IGoggles.java create mode 100644 src/api/java/thaumcraft/api/IRepairable.java create mode 100644 src/api/java/thaumcraft/api/IRepairableExtended.java create mode 100644 src/api/java/thaumcraft/api/IRunicArmor.java create mode 100644 src/api/java/thaumcraft/api/IScribeTools.java create mode 100644 src/api/java/thaumcraft/api/IVisDiscountGear.java create mode 100644 src/api/java/thaumcraft/api/IWarpingGear.java create mode 100644 src/api/java/thaumcraft/api/ItemApi.java create mode 100644 src/api/java/thaumcraft/api/ItemRunic.java rename src/{main => api}/java/thaumcraft/api/ThaumcraftApi.java (100%) rename src/{main => api}/java/thaumcraft/api/ThaumcraftApiHelper.java (100%) create mode 100644 src/api/java/thaumcraft/api/TileThaumcraft.java create mode 100644 src/api/java/thaumcraft/api/WorldCoordinates.java rename src/{main => api}/java/thaumcraft/api/aspects/Aspect.java (99%) rename src/{main => api}/java/thaumcraft/api/aspects/AspectList.java (100%) rename src/{main => api}/java/thaumcraft/api/aspects/AspectSourceHelper.java (100%) rename src/{main => api}/java/thaumcraft/api/aspects/IAspectContainer.java (100%) rename src/{main => api}/java/thaumcraft/api/aspects/IAspectSource.java (100%) rename src/{main => api}/java/thaumcraft/api/aspects/IEssentiaContainerItem.java (100%) rename src/{main => api}/java/thaumcraft/api/aspects/IEssentiaTransport.java (100%) rename src/{main => api}/java/thaumcraft/api/crafting/CrucibleRecipe.java (100%) rename src/{main => api}/java/thaumcraft/api/crafting/IArcaneRecipe.java (100%) rename src/{main => api}/java/thaumcraft/api/crafting/IInfusionStabiliser.java (100%) rename src/{main => api}/java/thaumcraft/api/crafting/InfusionEnchantmentRecipe.java (100%) rename src/{main => api}/java/thaumcraft/api/crafting/InfusionRecipe.java (100%) rename src/{main => api}/java/thaumcraft/api/crafting/ShapedArcaneRecipe.java (100%) rename src/{main => api}/java/thaumcraft/api/crafting/ShapelessArcaneRecipe.java (100%) create mode 100644 src/api/java/thaumcraft/api/damagesource/DamageSourceIndirectThaumcraftEntity.java create mode 100644 src/api/java/thaumcraft/api/damagesource/DamageSourceThaumcraft.java create mode 100644 src/api/java/thaumcraft/api/entities/IEldritchMob.java create mode 100644 src/api/java/thaumcraft/api/entities/ITaintedMob.java rename src/{main => api}/java/thaumcraft/api/internal/DummyInternalMethodHandler.java (100%) rename src/{main => api}/java/thaumcraft/api/internal/IInternalMethodHandler.java (100%) rename src/{main => api}/java/thaumcraft/api/internal/WeightedRandomLoot.java (100%) create mode 100644 src/api/java/thaumcraft/api/nodes/INode.java create mode 100644 src/api/java/thaumcraft/api/nodes/IRevealer.java create mode 100644 src/api/java/thaumcraft/api/nodes/NodeModifier.java create mode 100644 src/api/java/thaumcraft/api/nodes/NodeType.java rename src/{main => api}/java/thaumcraft/api/package-info.java (53%) create mode 100644 src/api/java/thaumcraft/api/potions/PotionFluxTaint.java create mode 100644 src/api/java/thaumcraft/api/potions/PotionVisExhaust.java rename src/{main => api}/java/thaumcraft/api/research/IScanEventHandler.java (100%) rename src/{main => api}/java/thaumcraft/api/research/ResearchCategories.java (100%) rename src/{main => api}/java/thaumcraft/api/research/ResearchCategoryList.java (100%) rename src/{main => api}/java/thaumcraft/api/research/ResearchItem.java (100%) rename src/{main => api}/java/thaumcraft/api/research/ResearchPage.java (100%) rename src/{main => api}/java/thaumcraft/api/research/ScanResult.java (100%) create mode 100644 src/api/java/thaumcraft/api/visnet/TileVisNode.java create mode 100644 src/api/java/thaumcraft/api/visnet/VisNetHandler.java create mode 100644 src/api/java/thaumcraft/api/wands/FocusUpgradeType.java create mode 100644 src/api/java/thaumcraft/api/wands/IWandRodOnUpdate.java create mode 100644 src/api/java/thaumcraft/api/wands/IWandTriggerManager.java create mode 100644 src/api/java/thaumcraft/api/wands/IWandable.java create mode 100644 src/api/java/thaumcraft/api/wands/ItemFocusBasic.java create mode 100644 src/api/java/thaumcraft/api/wands/StaffRod.java create mode 100644 src/api/java/thaumcraft/api/wands/WandCap.java create mode 100644 src/api/java/thaumcraft/api/wands/WandRod.java create mode 100644 src/api/java/thaumcraft/api/wands/WandTriggerRegistry.java diff --git a/src/api/java/thaumcraft/api/BlockCoordinates.java b/src/api/java/thaumcraft/api/BlockCoordinates.java new file mode 100644 index 00000000..27a28f8f --- /dev/null +++ b/src/api/java/thaumcraft/api/BlockCoordinates.java @@ -0,0 +1,108 @@ +package thaumcraft.api; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +public class BlockCoordinates implements Comparable +{ + public int x; + + /** the y coordinate */ + public int y; + + /** the z coordinate */ + public int z; + + public BlockCoordinates() {} + + public BlockCoordinates(int par1, int par2, int par3) + { + this.x = par1; + this.y = par2; + this.z = par3; + } + + public BlockCoordinates(TileEntity tile) + { + this.x = tile.xCoord; + this.y = tile.yCoord; + this.z = tile.zCoord; + } + + public BlockCoordinates(BlockCoordinates par1ChunkCoordinates) + { + this.x = par1ChunkCoordinates.x; + this.y = par1ChunkCoordinates.y; + this.z = par1ChunkCoordinates.z; + } + + public boolean equals(Object par1Obj) + { + if (!(par1Obj instanceof BlockCoordinates)) + { + return false; + } + else + { + BlockCoordinates coordinates = (BlockCoordinates)par1Obj; + return this.x == coordinates.x && this.y == coordinates.y && this.z == coordinates.z ; + } + } + + public int hashCode() + { + return this.x + this.y << 8 + this.z << 16; + } + + /** + * Compare the coordinate with another coordinate + */ + public int compareWorldCoordinate(BlockCoordinates par1) + { + return this.y == par1.y ? (this.z == par1.z ? this.x - par1.x : this.z - par1.z) : this.y - par1.y; + } + + public void set(int par1, int par2, int par3, int d) + { + this.x = par1; + this.y = par2; + this.z = par3; + } + + /** + * 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(BlockCoordinates par1ChunkCoordinates) + { + return this.getDistanceSquared(par1ChunkCoordinates.x, par1ChunkCoordinates.y, par1ChunkCoordinates.z); + } + + public int compareTo(Object par1Obj) + { + return this.compareWorldCoordinate((BlockCoordinates)par1Obj); + } + + public void readNBT(NBTTagCompound nbt) { + this.x = nbt.getInteger("b_x"); + this.y = nbt.getInteger("b_y"); + this.z = nbt.getInteger("b_z"); + } + + public void writeNBT(NBTTagCompound nbt) { + nbt.setInteger("b_x",x); + nbt.setInteger("b_y",y); + nbt.setInteger("b_z",z); + } + +} diff --git a/src/api/java/thaumcraft/api/IArchitect.java b/src/api/java/thaumcraft/api/IArchitect.java new file mode 100644 index 00000000..c733af5e --- /dev/null +++ b/src/api/java/thaumcraft/api/IArchitect.java @@ -0,0 +1,27 @@ +package thaumcraft.api; + +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IArchitect { + + /** + * Returns a list of blocks that should be highlighted in world. + */ + public ArrayList getArchitectBlocks(ItemStack stack, World world, + int x, int y, int z, int side, EntityPlayer player); + + /** + * which axis should be displayed. + */ + public boolean showAxis(ItemStack stack, World world, EntityPlayer player, int side, EnumAxis axis); + + public enum EnumAxis { + X, // east / west + Y, // up / down + Z; // north / south + } +} diff --git a/src/api/java/thaumcraft/api/IGoggles.java b/src/api/java/thaumcraft/api/IGoggles.java new file mode 100644 index 00000000..2f53d816 --- /dev/null +++ b/src/api/java/thaumcraft/api/IGoggles.java @@ -0,0 +1,22 @@ +package thaumcraft.api; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +/** + * + * @author Azanor + * + * Equipped head slot items that extend this class will be able to perform most functions that + * goggles of revealing can apart from view nodes which is handled by IRevealer. + * + */ + +public interface IGoggles { + + /* + * If this method returns true things like block essentia contents will be shown. + */ + public boolean showIngamePopups(ItemStack itemstack, EntityLivingBase player); + +} diff --git a/src/api/java/thaumcraft/api/IRepairable.java b/src/api/java/thaumcraft/api/IRepairable.java new file mode 100644 index 00000000..48c6dff9 --- /dev/null +++ b/src/api/java/thaumcraft/api/IRepairable.java @@ -0,0 +1,13 @@ +package thaumcraft.api; + + + +/** + * @author Azanor + * Items, armor and tools with this interface can receive the Repair enchantment. + * Repairs 1 point of durability every 10 seconds (2 for repair II) + */ +public interface IRepairable { + + +} diff --git a/src/api/java/thaumcraft/api/IRepairableExtended.java b/src/api/java/thaumcraft/api/IRepairableExtended.java new file mode 100644 index 00000000..33827124 --- /dev/null +++ b/src/api/java/thaumcraft/api/IRepairableExtended.java @@ -0,0 +1,17 @@ +package thaumcraft.api; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + + + +/** + * @author Azanor + * Items, armor and tools with this interface can receive the Repair enchantment. + * Repairs 1 point of durability every 10 seconds (2 for repair II) + */ +public interface IRepairableExtended extends IRepairable { + + public boolean doRepair(ItemStack stack, EntityPlayer player, int enchantlevel); + +} diff --git a/src/api/java/thaumcraft/api/IRunicArmor.java b/src/api/java/thaumcraft/api/IRunicArmor.java new file mode 100644 index 00000000..5dd31100 --- /dev/null +++ b/src/api/java/thaumcraft/api/IRunicArmor.java @@ -0,0 +1,22 @@ +package thaumcraft.api; + +import net.minecraft.item.ItemStack; + +/** + * + * @author Azanor + * + * Armor or bauble slot items that implement this interface can provide runic shielding. + * Recharging, hardening, etc. is handled internally by thaumcraft. + * + */ + +public interface IRunicArmor { + + /** + * returns how much charge this item can provide. This is the base shielding value - any hardening is stored and calculated internally. + */ + public int getRunicCharge(ItemStack itemstack); + + +} diff --git a/src/api/java/thaumcraft/api/IScribeTools.java b/src/api/java/thaumcraft/api/IScribeTools.java new file mode 100644 index 00000000..8800fa57 --- /dev/null +++ b/src/api/java/thaumcraft/api/IScribeTools.java @@ -0,0 +1,14 @@ +package thaumcraft.api; + + +/** + * + * @author Azanor + * + * Interface used to identify scribing tool items used in research table + * + */ + +public interface IScribeTools { + +} diff --git a/src/api/java/thaumcraft/api/IVisDiscountGear.java b/src/api/java/thaumcraft/api/IVisDiscountGear.java new file mode 100644 index 00000000..3793ea3e --- /dev/null +++ b/src/api/java/thaumcraft/api/IVisDiscountGear.java @@ -0,0 +1,20 @@ +package thaumcraft.api; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import thaumcraft.api.aspects.Aspect; + + + + +/** + * @author Azanor + * ItemArmor with this interface will grant a discount to the vis cost of actions the wearer performs with casting wands. + * The amount returned is the percentage by which the cost is discounted. There is a built-int max discount of 50%, but + * individual items really shouldn't have a discount more than 5% + */ +public interface IVisDiscountGear { + + int getVisDiscount(ItemStack stack, EntityPlayer player, Aspect aspect); + +} diff --git a/src/api/java/thaumcraft/api/IWarpingGear.java b/src/api/java/thaumcraft/api/IWarpingGear.java new file mode 100644 index 00000000..e7415ab7 --- /dev/null +++ b/src/api/java/thaumcraft/api/IWarpingGear.java @@ -0,0 +1,22 @@ +package thaumcraft.api; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +/** + * + * @author Azanor + * + * Armor, held items or bauble slot items that implement this interface add warp when equipped or held. + * + */ + +public interface IWarpingGear { + + /** + * returns how much warp this item adds while worn or held. + */ + public int getWarp(ItemStack itemstack, EntityPlayer player); + + +} diff --git a/src/api/java/thaumcraft/api/ItemApi.java b/src/api/java/thaumcraft/api/ItemApi.java new file mode 100644 index 00000000..25dda282 --- /dev/null +++ b/src/api/java/thaumcraft/api/ItemApi.java @@ -0,0 +1,70 @@ +package thaumcraft.api; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.FMLLog; + +/** + * @author Azanor + * + * This is used to gain access to the items in my mod. + * I only give some examples and it will probably still + * require a bit of work for you to get hold of everything you need. + * + */ +public class ItemApi { + + public static ItemStack getItem(String itemString, int meta) { + ItemStack item = null; + + try { + String itemClass = "thaumcraft.common.config.ConfigItems"; + Object obj = Class.forName(itemClass).getField(itemString).get(null); + if (obj instanceof Item) { + item = new ItemStack((Item) obj,1,meta); + } else if (obj instanceof ItemStack) { + item = (ItemStack) obj; + } + } catch (Exception ex) { + FMLLog.warning("[Thaumcraft] Could not retrieve item identified by: " + itemString); + } + + return item; + } + + public static ItemStack getBlock(String itemString, int meta) { + ItemStack item = null; + + try { + String itemClass = "thaumcraft.common.config.ConfigBlocks"; + Object obj = Class.forName(itemClass).getField(itemString).get(null); + if (obj instanceof Block) { + item = new ItemStack((Block) obj,1,meta); + } else if (obj instanceof ItemStack) { + item = (ItemStack) obj; + } + } catch (Exception ex) { + FMLLog.warning("[Thaumcraft] Could not retrieve block identified by: " + itemString); + } + + return item; + } + + /** + * + * Some examples + * + * Casting Wands: + * itemWandCasting + * + * Resources: + * itemEssence, itemWispEssence, itemResource, itemShard, itemNugget, + * itemNuggetChicken, itemNuggetBeef, itemNuggetPork, itemTripleMeatTreat + * + * Research: + * itemResearchNotes, itemInkwell, itemThaumonomicon + * + */ + +} diff --git a/src/api/java/thaumcraft/api/ItemRunic.java b/src/api/java/thaumcraft/api/ItemRunic.java new file mode 100644 index 00000000..80251f59 --- /dev/null +++ b/src/api/java/thaumcraft/api/ItemRunic.java @@ -0,0 +1,21 @@ +package thaumcraft.api; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class ItemRunic extends Item implements IRunicArmor { + + int charge; + + public ItemRunic (int charge) + { + super(); + this.charge = charge; + } + + @Override + public int getRunicCharge(ItemStack itemstack) { + return charge; + } + +} diff --git a/src/main/java/thaumcraft/api/ThaumcraftApi.java b/src/api/java/thaumcraft/api/ThaumcraftApi.java similarity index 100% rename from src/main/java/thaumcraft/api/ThaumcraftApi.java rename to src/api/java/thaumcraft/api/ThaumcraftApi.java diff --git a/src/main/java/thaumcraft/api/ThaumcraftApiHelper.java b/src/api/java/thaumcraft/api/ThaumcraftApiHelper.java similarity index 100% rename from src/main/java/thaumcraft/api/ThaumcraftApiHelper.java rename to src/api/java/thaumcraft/api/ThaumcraftApiHelper.java diff --git a/src/api/java/thaumcraft/api/TileThaumcraft.java b/src/api/java/thaumcraft/api/TileThaumcraft.java new file mode 100644 index 00000000..56ccae87 --- /dev/null +++ b/src/api/java/thaumcraft/api/TileThaumcraft.java @@ -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()); + } + + + + +} diff --git a/src/api/java/thaumcraft/api/WorldCoordinates.java b/src/api/java/thaumcraft/api/WorldCoordinates.java new file mode 100644 index 00000000..6c620af5 --- /dev/null +++ b/src/api/java/thaumcraft/api/WorldCoordinates.java @@ -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); + } + +} diff --git a/src/main/java/thaumcraft/api/aspects/Aspect.java b/src/api/java/thaumcraft/api/aspects/Aspect.java similarity index 99% rename from src/main/java/thaumcraft/api/aspects/Aspect.java rename to src/api/java/thaumcraft/api/aspects/Aspect.java index 0ea13f5e..3c33a4a7 100644 --- a/src/main/java/thaumcraft/api/aspects/Aspect.java +++ b/src/api/java/thaumcraft/api/aspects/Aspect.java @@ -181,14 +181,14 @@ public class Aspect { public static final Aspect BEAST = new Aspect("bestia",0x9f6409, new Aspect[] {MOTION, LIFE}); public static final Aspect FLESH = new Aspect("corpus",0xee478d, new Aspect[] {DEATH, BEAST}); public static final Aspect UNDEAD = new Aspect("exanimis",0x3a4000, new Aspect[] {MOTION, DEATH}); - public static final Aspect MIND = new Aspect("cognitio",0xffc2b3, new Aspect[] {FIRE, SOUL}); + public static final Aspect MIND = new Aspect("cognitio",0xffc2b3, new Aspect[] {EARTH, SOUL}); public static final Aspect SENSES = new Aspect("sensus",0x0fd9ff, new Aspect[] {AIR, SOUL}); public static final Aspect MAN = new Aspect("humanus",0xffd7c0, new Aspect[] {BEAST, MIND}); public static final Aspect CROP = new Aspect("messis",0xe1b371, new Aspect[] {PLANT, MAN}); public static final Aspect MINE = new Aspect("perfodio",0xdcd2d8, new Aspect[] {MAN, EARTH}); public static final Aspect TOOL = new Aspect("instrumentum",0x4040ee, new Aspect[] {MAN, ORDER}); public static final Aspect HARVEST = new Aspect("meto",0xeead82, new Aspect[] {CROP, TOOL}); - public static final Aspect WEAPON = new Aspect("telum",0xc05050, new Aspect[] {TOOL, FIRE}); + public static final Aspect WEAPON = new Aspect("telum",0xc05050, new Aspect[] {TOOL, ENTROPY}); public static final Aspect ARMOR = new Aspect("tutamen",0x00c0c0, new Aspect[] {TOOL, EARTH}); public static final Aspect HUNGER = new Aspect("fames",0x9a0305, new Aspect[] {LIFE, VOID}); public static final Aspect GREED = new Aspect("lucrum",0xe6be44, new Aspect[] {MAN, HUNGER}); diff --git a/src/main/java/thaumcraft/api/aspects/AspectList.java b/src/api/java/thaumcraft/api/aspects/AspectList.java similarity index 100% rename from src/main/java/thaumcraft/api/aspects/AspectList.java rename to src/api/java/thaumcraft/api/aspects/AspectList.java diff --git a/src/main/java/thaumcraft/api/aspects/AspectSourceHelper.java b/src/api/java/thaumcraft/api/aspects/AspectSourceHelper.java similarity index 100% rename from src/main/java/thaumcraft/api/aspects/AspectSourceHelper.java rename to src/api/java/thaumcraft/api/aspects/AspectSourceHelper.java diff --git a/src/main/java/thaumcraft/api/aspects/IAspectContainer.java b/src/api/java/thaumcraft/api/aspects/IAspectContainer.java similarity index 100% rename from src/main/java/thaumcraft/api/aspects/IAspectContainer.java rename to src/api/java/thaumcraft/api/aspects/IAspectContainer.java diff --git a/src/main/java/thaumcraft/api/aspects/IAspectSource.java b/src/api/java/thaumcraft/api/aspects/IAspectSource.java similarity index 100% rename from src/main/java/thaumcraft/api/aspects/IAspectSource.java rename to src/api/java/thaumcraft/api/aspects/IAspectSource.java diff --git a/src/main/java/thaumcraft/api/aspects/IEssentiaContainerItem.java b/src/api/java/thaumcraft/api/aspects/IEssentiaContainerItem.java similarity index 100% rename from src/main/java/thaumcraft/api/aspects/IEssentiaContainerItem.java rename to src/api/java/thaumcraft/api/aspects/IEssentiaContainerItem.java diff --git a/src/main/java/thaumcraft/api/aspects/IEssentiaTransport.java b/src/api/java/thaumcraft/api/aspects/IEssentiaTransport.java similarity index 100% rename from src/main/java/thaumcraft/api/aspects/IEssentiaTransport.java rename to src/api/java/thaumcraft/api/aspects/IEssentiaTransport.java diff --git a/src/main/java/thaumcraft/api/crafting/CrucibleRecipe.java b/src/api/java/thaumcraft/api/crafting/CrucibleRecipe.java similarity index 100% rename from src/main/java/thaumcraft/api/crafting/CrucibleRecipe.java rename to src/api/java/thaumcraft/api/crafting/CrucibleRecipe.java diff --git a/src/main/java/thaumcraft/api/crafting/IArcaneRecipe.java b/src/api/java/thaumcraft/api/crafting/IArcaneRecipe.java similarity index 100% rename from src/main/java/thaumcraft/api/crafting/IArcaneRecipe.java rename to src/api/java/thaumcraft/api/crafting/IArcaneRecipe.java diff --git a/src/main/java/thaumcraft/api/crafting/IInfusionStabiliser.java b/src/api/java/thaumcraft/api/crafting/IInfusionStabiliser.java similarity index 100% rename from src/main/java/thaumcraft/api/crafting/IInfusionStabiliser.java rename to src/api/java/thaumcraft/api/crafting/IInfusionStabiliser.java diff --git a/src/main/java/thaumcraft/api/crafting/InfusionEnchantmentRecipe.java b/src/api/java/thaumcraft/api/crafting/InfusionEnchantmentRecipe.java similarity index 100% rename from src/main/java/thaumcraft/api/crafting/InfusionEnchantmentRecipe.java rename to src/api/java/thaumcraft/api/crafting/InfusionEnchantmentRecipe.java diff --git a/src/main/java/thaumcraft/api/crafting/InfusionRecipe.java b/src/api/java/thaumcraft/api/crafting/InfusionRecipe.java similarity index 100% rename from src/main/java/thaumcraft/api/crafting/InfusionRecipe.java rename to src/api/java/thaumcraft/api/crafting/InfusionRecipe.java diff --git a/src/main/java/thaumcraft/api/crafting/ShapedArcaneRecipe.java b/src/api/java/thaumcraft/api/crafting/ShapedArcaneRecipe.java similarity index 100% rename from src/main/java/thaumcraft/api/crafting/ShapedArcaneRecipe.java rename to src/api/java/thaumcraft/api/crafting/ShapedArcaneRecipe.java diff --git a/src/main/java/thaumcraft/api/crafting/ShapelessArcaneRecipe.java b/src/api/java/thaumcraft/api/crafting/ShapelessArcaneRecipe.java similarity index 100% rename from src/main/java/thaumcraft/api/crafting/ShapelessArcaneRecipe.java rename to src/api/java/thaumcraft/api/crafting/ShapelessArcaneRecipe.java diff --git a/src/api/java/thaumcraft/api/damagesource/DamageSourceIndirectThaumcraftEntity.java b/src/api/java/thaumcraft/api/damagesource/DamageSourceIndirectThaumcraftEntity.java new file mode 100644 index 00000000..1562d052 --- /dev/null +++ b/src/api/java/thaumcraft/api/damagesource/DamageSourceIndirectThaumcraftEntity.java @@ -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; + } +} diff --git a/src/api/java/thaumcraft/api/damagesource/DamageSourceThaumcraft.java b/src/api/java/thaumcraft/api/damagesource/DamageSourceThaumcraft.java new file mode 100644 index 00000000..bb55672b --- /dev/null +++ b/src/api/java/thaumcraft/api/damagesource/DamageSourceThaumcraft.java @@ -0,0 +1,47 @@ +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"); + public static DamageSource dissolve = new DamageSourceThaumcraft("dissolve").setDamageBypassesArmor(); + + 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); + } + +} diff --git a/src/api/java/thaumcraft/api/entities/IEldritchMob.java b/src/api/java/thaumcraft/api/entities/IEldritchMob.java new file mode 100644 index 00000000..79fc75b5 --- /dev/null +++ b/src/api/java/thaumcraft/api/entities/IEldritchMob.java @@ -0,0 +1,5 @@ +package thaumcraft.api.entities; + +public interface IEldritchMob { + +} diff --git a/src/api/java/thaumcraft/api/entities/ITaintedMob.java b/src/api/java/thaumcraft/api/entities/ITaintedMob.java new file mode 100644 index 00000000..83fb1fcb --- /dev/null +++ b/src/api/java/thaumcraft/api/entities/ITaintedMob.java @@ -0,0 +1,5 @@ +package thaumcraft.api.entities; + +public interface ITaintedMob { + +} diff --git a/src/main/java/thaumcraft/api/internal/DummyInternalMethodHandler.java b/src/api/java/thaumcraft/api/internal/DummyInternalMethodHandler.java similarity index 100% rename from src/main/java/thaumcraft/api/internal/DummyInternalMethodHandler.java rename to src/api/java/thaumcraft/api/internal/DummyInternalMethodHandler.java diff --git a/src/main/java/thaumcraft/api/internal/IInternalMethodHandler.java b/src/api/java/thaumcraft/api/internal/IInternalMethodHandler.java similarity index 100% rename from src/main/java/thaumcraft/api/internal/IInternalMethodHandler.java rename to src/api/java/thaumcraft/api/internal/IInternalMethodHandler.java diff --git a/src/main/java/thaumcraft/api/internal/WeightedRandomLoot.java b/src/api/java/thaumcraft/api/internal/WeightedRandomLoot.java similarity index 100% rename from src/main/java/thaumcraft/api/internal/WeightedRandomLoot.java rename to src/api/java/thaumcraft/api/internal/WeightedRandomLoot.java diff --git a/src/api/java/thaumcraft/api/nodes/INode.java b/src/api/java/thaumcraft/api/nodes/INode.java new file mode 100644 index 00000000..61da1f77 --- /dev/null +++ b/src/api/java/thaumcraft/api/nodes/INode.java @@ -0,0 +1,53 @@ +package thaumcraft.api.nodes; + +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.AspectList; +import thaumcraft.api.aspects.IAspectContainer; + +public interface INode extends IAspectContainer { + + /** + * Unique identifier to distinguish nodes. Normal node id's are based on world id and coordinates + * @return + */ + public String getId(); + + public AspectList getAspectsBase(); + + /** + * Return the type of node + * @return + */ + public NodeType getNodeType(); + + /** + * Set the type of node + * @return + */ + public void setNodeType(NodeType nodeType); + + /** + * Set the node modifier + * @return + */ + public void setNodeModifier(NodeModifier nodeModifier); + + /** + * Return the node modifier + * @return + */ + public NodeModifier getNodeModifier(); + + /** + * Return the maximum capacity of each aspect the node can hold + * @return + */ + public int getNodeVisBase(Aspect aspect); + + /** + * Set the maximum capacity of each aspect the node can hold + * @return + */ + public void setNodeVisBase(Aspect aspect, short nodeVisBase); + +} diff --git a/src/api/java/thaumcraft/api/nodes/IRevealer.java b/src/api/java/thaumcraft/api/nodes/IRevealer.java new file mode 100644 index 00000000..14a19b54 --- /dev/null +++ b/src/api/java/thaumcraft/api/nodes/IRevealer.java @@ -0,0 +1,22 @@ +package thaumcraft.api.nodes; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +/** + * + * @author Azanor + * + * Equipped head slot items that extend this class will make nodes visible in world. + * + */ + +public interface IRevealer { + + /* + * If this method returns true the nodes will be visible. + */ + public boolean showNodes(ItemStack itemstack, EntityLivingBase player); + + +} diff --git a/src/api/java/thaumcraft/api/nodes/NodeModifier.java b/src/api/java/thaumcraft/api/nodes/NodeModifier.java new file mode 100644 index 00000000..885b8678 --- /dev/null +++ b/src/api/java/thaumcraft/api/nodes/NodeModifier.java @@ -0,0 +1,6 @@ +package thaumcraft.api.nodes; + +public enum NodeModifier +{ + BRIGHT, PALE, FADING +} \ No newline at end of file diff --git a/src/api/java/thaumcraft/api/nodes/NodeType.java b/src/api/java/thaumcraft/api/nodes/NodeType.java new file mode 100644 index 00000000..355324b5 --- /dev/null +++ b/src/api/java/thaumcraft/api/nodes/NodeType.java @@ -0,0 +1,6 @@ +package thaumcraft.api.nodes; + +public enum NodeType +{ + NORMAL, UNSTABLE, DARK, TAINTED, HUNGRY, PURE +} \ No newline at end of file diff --git a/src/main/java/thaumcraft/api/package-info.java b/src/api/java/thaumcraft/api/package-info.java similarity index 53% rename from src/main/java/thaumcraft/api/package-info.java rename to src/api/java/thaumcraft/api/package-info.java index cceaf891..0de39267 100644 --- a/src/main/java/thaumcraft/api/package-info.java +++ b/src/api/java/thaumcraft/api/package-info.java @@ -1,4 +1,4 @@ -@API(owner = "Thaumcraft", apiVersion = "4.2.2.0", provides = "Thaumcraft|API") +@API(owner = "Thaumcraft", apiVersion = "4.2.0.0", provides = "Thaumcraft|API") package thaumcraft.api; import cpw.mods.fml.common.API; diff --git a/src/api/java/thaumcraft/api/potions/PotionFluxTaint.java b/src/api/java/thaumcraft/api/potions/PotionFluxTaint.java new file mode 100644 index 00000000..b950de0e --- /dev/null +++ b/src/api/java/thaumcraft/api/potions/PotionFluxTaint.java @@ -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(); + } + + static final 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; + } + +} diff --git a/src/api/java/thaumcraft/api/potions/PotionVisExhaust.java b/src/api/java/thaumcraft/api/potions/PotionVisExhaust.java new file mode 100644 index 00000000..cd7fc18c --- /dev/null +++ b/src/api/java/thaumcraft/api/potions/PotionVisExhaust.java @@ -0,0 +1,48 @@ +package thaumcraft.api.potions; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.potion.Potion; +import net.minecraft.util.ResourceLocation; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PotionVisExhaust extends Potion +{ + public static PotionVisExhaust instance = null; // will be instantiated at runtime + private int statusIconIndex = -1; + + public PotionVisExhaust(int par1, boolean par2, int par3) + { + super(par1,par2,par3); + setIconIndex(0, 0); + } + + public static void init() + { + instance.setPotionName("potion.visexhaust"); + instance.setIconIndex(5, 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(); + } + + static final ResourceLocation rl = new ResourceLocation("thaumcraft","textures/misc/potions.png"); + + @Override + public void performEffect(EntityLivingBase target, int par2) { + + } + + +} diff --git a/src/main/java/thaumcraft/api/research/IScanEventHandler.java b/src/api/java/thaumcraft/api/research/IScanEventHandler.java similarity index 100% rename from src/main/java/thaumcraft/api/research/IScanEventHandler.java rename to src/api/java/thaumcraft/api/research/IScanEventHandler.java diff --git a/src/main/java/thaumcraft/api/research/ResearchCategories.java b/src/api/java/thaumcraft/api/research/ResearchCategories.java similarity index 100% rename from src/main/java/thaumcraft/api/research/ResearchCategories.java rename to src/api/java/thaumcraft/api/research/ResearchCategories.java diff --git a/src/main/java/thaumcraft/api/research/ResearchCategoryList.java b/src/api/java/thaumcraft/api/research/ResearchCategoryList.java similarity index 100% rename from src/main/java/thaumcraft/api/research/ResearchCategoryList.java rename to src/api/java/thaumcraft/api/research/ResearchCategoryList.java diff --git a/src/main/java/thaumcraft/api/research/ResearchItem.java b/src/api/java/thaumcraft/api/research/ResearchItem.java similarity index 100% rename from src/main/java/thaumcraft/api/research/ResearchItem.java rename to src/api/java/thaumcraft/api/research/ResearchItem.java diff --git a/src/main/java/thaumcraft/api/research/ResearchPage.java b/src/api/java/thaumcraft/api/research/ResearchPage.java similarity index 100% rename from src/main/java/thaumcraft/api/research/ResearchPage.java rename to src/api/java/thaumcraft/api/research/ResearchPage.java diff --git a/src/main/java/thaumcraft/api/research/ScanResult.java b/src/api/java/thaumcraft/api/research/ScanResult.java similarity index 100% rename from src/main/java/thaumcraft/api/research/ScanResult.java rename to src/api/java/thaumcraft/api/research/ScanResult.java diff --git a/src/api/java/thaumcraft/api/visnet/TileVisNode.java b/src/api/java/thaumcraft/api/visnet/TileVisNode.java new file mode 100644 index 00000000..204879e6 --- /dev/null +++ b/src/api/java/thaumcraft/api/visnet/TileVisNode.java @@ -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 parent = null; + ArrayList> children = new ArrayList>(); + + /** + * @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 n:getChildren()) { + if (n!=null && n.get()!=null) { + n.get().removeThisNode(); + } + } + + children = new ArrayList>(); + if (VisNetHandler.isNodeValid(this.getParent())) { + this.getParent().get().nodeRefresh=true; + } + this.setParent(null); + this.parentChanged(); + + if (this.isSource()) { + HashMap> sourcelist = VisNetHandler.sources.get(worldObj.provider.dimensionId); + if (sourcelist==null) { + sourcelist = new HashMap>(); + } + 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 getParent() { + return parent; + } + + /** + * @return + */ + public WeakReference getRootSource() { + return VisNetHandler.isNodeValid(getParent()) ? + getParent().get().getRootSource() : this.isSource() ? + new WeakReference(this) : null; + } + + /** + * @param parent + */ + public void setParent(WeakReference parent) { + this.parent = parent; + } + + /** + * @return + */ + public ArrayList> 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 n:children) { + if (n==null || n.get()==null || !VisNetHandler.canNodeBeSeen(this, n.get())) { + nodeRefresh=true; + break; + } + } + } + + //refresh linked nodes + if (nodeRefresh) { + for (WeakReference 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; + } + + +} diff --git a/src/api/java/thaumcraft/api/visnet/VisNetHandler.java b/src/api/java/thaumcraft/api/visnet/VisNetHandler.java new file mode 100644 index 00000000..7ac4c699 --- /dev/null +++ b/src/api/java/thaumcraft/api/visnet/VisNetHandler.java @@ -0,0 +1,282 @@ +package thaumcraft.api.visnet; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.HashMap; + +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.MovingObjectPosition.MovingObjectType; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import thaumcraft.api.ThaumcraftApi; +import thaumcraft.api.ThaumcraftApiHelper; +import thaumcraft.api.WorldCoordinates; +import thaumcraft.api.aspects.Aspect; + +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 amount 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> nodes = nearbyNodes.get(drainer); + if (nodes!=null && nodes.size()>0) + for (WeakReference 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; + } + + public static void generateVisEffect(int dim, int x, int y, int z, int x2, int y2, int z2, int color) { + ThaumcraftApi.internalMethods.generateVisEffect(dim, x, y, z, x2, y2, z2, color); + } + + public static HashMap>> sources = new HashMap>>(); + + public static void addSource(World world, TileVisNode vs) { + HashMap> sourcelist = sources + .get(world.provider.dimensionId); + if (sourcelist == null) { + sourcelist = new HashMap>(); + } + sourcelist.put(vs.getLocation(), new WeakReference(vs)); + sources.put(world.provider.dimensionId, sourcelist); + nearbyNodes.clear(); + } + + public static boolean isNodeValid(WeakReference node) { + if (node == null || node.get() == null || node.get().isInvalid()) + return false; + return true; + } + + public static WeakReference addNode(World world, TileVisNode vn) { + WeakReference ref = new WeakReference(vn); + + HashMap> sourcelist = sources + .get(world.provider.dimensionId); + if (sourcelist == null) { + sourcelist = new HashMap>(); + return null; + } + + ArrayList nearby = new ArrayList(); + + for (WeakReference 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); + cache.clear(); + } + + float dist = Float.MAX_VALUE; + TileVisNode closest = null; + if (nearby.size() > 0) { + for (Object[] o : nearby) { + if ((Float) o[1] < dist && + (vn.getAttunement() == -1 || ((TileVisNode) o[0]).getAttunement() == -1 || + vn.getAttunement() == ((TileVisNode) o[0]).getAttunement())//) { + && 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; + } + + static ArrayList cache = new ArrayList(); + public static ArrayList findClosestNodes(TileVisNode target, + TileVisNode parent, ArrayList in) { + + if (cache.size() > 512 || cache.contains(new WorldCoordinates(parent))) return in; + cache.add(new WorldCoordinates(parent)); + + for (WeakReference childWR : parent.getChildren()) { + TileVisNode child = childWR.get(); + + if (child != null && !child.equals(target) && !child.equals(parent)) { + float r2 = inRange(child.getWorldObj(), child.getLocation(), + target.getLocation(), target.getRange()); + if (r2 > 0) { + in.add(new Object[] { child, r2 }); + } + + in = findClosestNodes(target, child, 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>> nearbyNodes = new HashMap>>(); + + private static void calculateNearbyNodes(World world, int x, int y, int z) { + + HashMap> sourcelist = sources + .get(world.provider.dimensionId); + if (sourcelist == null) { + sourcelist = new HashMap>(); + return; + } + + ArrayList> cn = new ArrayList>(); + WorldCoordinates drainer = new WorldCoordinates(x, y, z, + world.provider.dimensionId); + + ArrayList nearby = new ArrayList(); + + for (WeakReference 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> children = new ArrayList>(); + children = getAllChildren(source,children); + + for (WeakReference 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> getAllChildren(TileVisNode source, ArrayList> list) { + for (WeakReference child : source.getChildren()) { + TileVisNode n = child.get(); + + if (n != null && n.getWorldObj()!=null && isChunkLoaded(n.getWorldObj(), n.xCoord, n.zCoord)) { + list.add(child); + list = getAllChildren(n,list); + } + } + return list; + } + + public static boolean isChunkLoaded(World world, int x, int z) { + int xx = x >> 4; + int zz = z >> 4; + return world.getChunkProvider().chunkExists(xx, zz); + } + + public static boolean canNodeBeSeen(TileVisNode source,TileVisNode target) + { + MovingObjectPosition mop = ThaumcraftApiHelper.rayTraceIgnoringSource(source.getWorldObj(), + Vec3.createVectorHelper(source.xCoord+.5, source.yCoord+.5,source.zCoord+.5), + Vec3.createVectorHelper(target.xCoord+.5, target.yCoord+.5,target.zCoord+.5), + false, true, false); + return mop == null || (mop.typeOfHit==MovingObjectType.BLOCK && + mop.blockX==target.xCoord && mop.blockY==target.yCoord && mop.blockZ==target.zCoord); + } + + // public static HashMap> + // noderef = new HashMap>(); + // + // 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=types.length) { + FocusUpgradeType[] temp = new FocusUpgradeType[id+1]; + System.arraycopy(types, 0, temp, 0, types.length); + types = temp; + } + + types[id] = this; + } + + public String getLocalizedName() { + return StatCollector.translateToLocal(name); + } + + public String getLocalizedText() { + return StatCollector.translateToLocal(text); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof FocusUpgradeType) { + return this.id == ((FocusUpgradeType)obj).id; + } else return false; + } + + // basic upgrade types + public static FocusUpgradeType potency = new FocusUpgradeType( 0, + new ResourceLocation("thaumcraft", "textures/foci/potency.png"), + "focus.upgrade.potency.name","focus.upgrade.potency.text", + new AspectList().add(Aspect.WEAPON,1)); + + public static FocusUpgradeType frugal = new FocusUpgradeType( 1, + new ResourceLocation("thaumcraft", "textures/foci/frugal.png"), + "focus.upgrade.frugal.name","focus.upgrade.frugal.text", + new AspectList().add(Aspect.HUNGER,1)); + + public static FocusUpgradeType treasure = new FocusUpgradeType( 2, + new ResourceLocation("thaumcraft", "textures/foci/treasure.png"), + "focus.upgrade.treasure.name","focus.upgrade.treasure.text", + new AspectList().add(Aspect.GREED,1)); + + public static FocusUpgradeType enlarge = new FocusUpgradeType( 3, + new ResourceLocation("thaumcraft", "textures/foci/enlarge.png"), + "focus.upgrade.enlarge.name","focus.upgrade.enlarge.text", + new AspectList().add(Aspect.TRAVEL,1)); + + public static FocusUpgradeType alchemistsfire = new FocusUpgradeType( 4, + new ResourceLocation("thaumcraft", "textures/foci/alchemistsfire.png"), + "focus.upgrade.alchemistsfire.name","focus.upgrade.alchemistsfire.text", + new AspectList().add(Aspect.ENERGY,1).add(Aspect.SLIME,1)); + + public static FocusUpgradeType alchemistsfrost = new FocusUpgradeType( 5, + new ResourceLocation("thaumcraft", "textures/foci/alchemistsfrost.png"), + "focus.upgrade.alchemistsfrost.name","focus.upgrade.alchemistsfrost.text", + new AspectList().add(Aspect.COLD,1).add(Aspect.TRAP,1)); + + public static FocusUpgradeType architect = new FocusUpgradeType( 6, + new ResourceLocation("thaumcraft", "textures/foci/architect.png"), + "focus.upgrade.architect.name","focus.upgrade.architect.text", + new AspectList().add(Aspect.CRAFT,1)); + + public static FocusUpgradeType extend = new FocusUpgradeType( 7, + new ResourceLocation("thaumcraft", "textures/foci/extend.png"), + "focus.upgrade.extend.name","focus.upgrade.extend.text", + new AspectList().add(Aspect.EXCHANGE,1)); + + public static FocusUpgradeType silktouch = new FocusUpgradeType( 8, + new ResourceLocation("thaumcraft", "textures/foci/silktouch.png"), + "focus.upgrade.silktouch.name","focus.upgrade.silktouch.text", + new AspectList().add(Aspect.GREED,1)); + + +} diff --git a/src/api/java/thaumcraft/api/wands/IWandRodOnUpdate.java b/src/api/java/thaumcraft/api/wands/IWandRodOnUpdate.java new file mode 100644 index 00000000..4ef8c849 --- /dev/null +++ b/src/api/java/thaumcraft/api/wands/IWandRodOnUpdate.java @@ -0,0 +1,16 @@ +package thaumcraft.api.wands; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +/** + * + * @author azanor + * + * Implemented by a class that you wish to be called whenever a wand with this rod performs its + * update tick. + * + */ +public interface IWandRodOnUpdate { + void onUpdate(ItemStack itemstack, EntityPlayer player); +} diff --git a/src/api/java/thaumcraft/api/wands/IWandTriggerManager.java b/src/api/java/thaumcraft/api/wands/IWandTriggerManager.java new file mode 100644 index 00000000..7c299deb --- /dev/null +++ b/src/api/java/thaumcraft/api/wands/IWandTriggerManager.java @@ -0,0 +1,15 @@ +package thaumcraft.api.wands; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IWandTriggerManager { + + /** + * This class will be called by wands with the proper parameters. It is up to you to decide what to do with them. + */ + public boolean performTrigger(World world, ItemStack wand, EntityPlayer player, + int x, int y, int z, int side, int event); + +} diff --git a/src/api/java/thaumcraft/api/wands/IWandable.java b/src/api/java/thaumcraft/api/wands/IWandable.java new file mode 100644 index 00000000..aeb9bac7 --- /dev/null +++ b/src/api/java/thaumcraft/api/wands/IWandable.java @@ -0,0 +1,25 @@ +package thaumcraft.api.wands; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +/** + * + * @author azanor + * + * Add this to a tile entity that you wish wands to interact with in some way. + * + */ + +public interface IWandable { + + public int onWandRightClick(World world, ItemStack wandstack, EntityPlayer player, int x, int y, int z, int side, int md); + + public ItemStack onWandRightClick(World world, ItemStack wandstack, EntityPlayer player); + + public void onUsingWandTick(ItemStack wandstack, EntityPlayer player, int count); + + public void onWandStoppedUsing(ItemStack wandstack, World world, EntityPlayer player, int count); + +} diff --git a/src/api/java/thaumcraft/api/wands/ItemFocusBasic.java b/src/api/java/thaumcraft/api/wands/ItemFocusBasic.java new file mode 100644 index 00000000..e8938e91 --- /dev/null +++ b/src/api/java/thaumcraft/api/wands/ItemFocusBasic.java @@ -0,0 +1,276 @@ +package thaumcraft.api.wands; + +import java.text.DecimalFormat; +import java.util.LinkedHashMap; +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.AspectList; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class ItemFocusBasic extends Item { + + public ItemFocusBasic () + { + super(); + maxStackSize = 1; + canRepair=false; + this.setMaxDamage(0); + } + + public IIcon icon; + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIconFromDamage(int par1) { + return icon; + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public void addInformation(ItemStack stack,EntityPlayer player, List list, boolean par4) { + AspectList al = this.getVisCost(stack); + if (al!=null && al.size()>0) { + list.add(StatCollector.translateToLocal(isVisCostPerTick(stack)?"item.Focus.cost2":"item.Focus.cost1")); + for (Aspect aspect:al.getAspectsSorted()) { + DecimalFormat myFormatter = new DecimalFormat("#####.##"); + String amount = myFormatter.format(al.getAmount(aspect)/100f); + list.add(" \u00A7"+aspect.getChatcolor()+aspect.getName()+"\u00A7r x "+ amount); + } + } + addFocusInformation(stack,player,list,par4); + } + + public void addFocusInformation(ItemStack focusstack,EntityPlayer player, List list, boolean par4) { + LinkedHashMap map = new LinkedHashMap(); + for (short id:this.getAppliedUpgrades(focusstack)) { + if (id>=0) { + int amt = 1; + if (map.containsKey(id)) { + amt = map.get(id) + 1; + } + map.put(id, amt); + } + } + for (Short id:map.keySet()) { + list.add(EnumChatFormatting.DARK_PURPLE +FocusUpgradeType.types[id].getLocalizedName()+ + (map.get(id)>1?" "+StatCollector.translateToLocal("enchantment.level." + map.get(id)):"")); + } + } + + /** + * Purely for display on the focus tooltip (see addInformation method above) + */ + public boolean isVisCostPerTick(ItemStack focusstack) { + return false; + } + + @Override + public EnumRarity getRarity(ItemStack focusstack) + { + return EnumRarity.rare; + } + + /** + * What color will the focus orb be rendered on the held wand + */ + public int getFocusColor(ItemStack focusstack) { + return 0; + } + + + /** + * Does the focus have ornamentation like the focus of the nine hells. Ornamentation is a standard icon rendered in a cross around the focus + */ + public IIcon getOrnament(ItemStack focusstack) { + // TODO Auto-generated method stub + return null; + } + + /** + * An icon to be rendered inside the focus itself + */ + public IIcon getFocusDepthLayerIcon(ItemStack focusstack) { + // TODO Auto-generated method stub + return null; + } + + public enum WandFocusAnimation { + WAVE, CHARGE; + } + + public WandFocusAnimation getAnimation(ItemStack focusstack) { + return WandFocusAnimation.WAVE; + } + + /** + * Just insert two alphanumeric characters before this string in your focus item class + */ + public String getSortingHelper(ItemStack focusstack) { + String out=""; + for (short id:this.getAppliedUpgrades(focusstack)) { + out = out + id; + } + return out; + } + + + /** + * How much vis does this focus consume per activation. + */ + public AspectList getVisCost(ItemStack focusstack) { + return null; + } + + /** + * This returns how many milliseconds must pass before the focus can be activated again. + */ + public int getActivationCooldown(ItemStack focusstack) { + return 0; + } + + /** + * Used by foci like equal trade to determine their area in artchitect mode + */ + public int getMaxAreaSize(ItemStack focusstack) { + return 1; + } + + /** + * What upgrades can be applied to this focus for ranks 1 to 5 + */ + public FocusUpgradeType[] getPossibleUpgradesByRank(ItemStack focusstack, int rank) { + return null; + } + + /** + * What upgrades does the focus currently have + */ + public short[] getAppliedUpgrades(ItemStack focusstack) { + short[] l = new short[] {-1,-1,-1,-1,-1}; + NBTTagList nbttaglist = getFocusUpgradeTagList(focusstack); + if (nbttaglist == null) + { + return l; + } + else + { + for (int j = 0; j < nbttaglist.tagCount(); ++j) + { + if (j>=5) break; + l[j] = nbttaglist.getCompoundTagAt(j).getShort("id"); + } + + return l; + } + } + + public boolean applyUpgrade(ItemStack focusstack, FocusUpgradeType type, int rank) { + short[] upgrades = getAppliedUpgrades(focusstack); + if (upgrades[rank-1]!=-1 || rank<1 || rank>5) { + return false; + } + upgrades[rank-1] = type.id; + setFocusUpgradeTagList(focusstack, upgrades); + return true; + } + + /** + * Use this method to define custom logic about which upgrades can be applied. This can be used to set up upgrade "trees" + * that make certain upgrades available only when others are unlocked first, when certain research is completed, or similar logic. + * + */ + public boolean canApplyUpgrade(ItemStack focusstack, EntityPlayer player, FocusUpgradeType type, int rank) { + return true; + } + + /** + * Does this focus have the passed upgrade type + */ + public boolean isUpgradedWith(ItemStack focusstack, FocusUpgradeType focusUpgradetype) { + return getUpgradeLevel(focusstack,focusUpgradetype)>0; + } + + /** + * What level is the passed upgrade type on the focus. If it is not present it returns 0 + */ + public int getUpgradeLevel(ItemStack focusstack, FocusUpgradeType focusUpgradetype) { + short[] list = getAppliedUpgrades(focusstack); + int level=0; + for (short id:list) { + if (id == focusUpgradetype.id) + { + level++; + } + } + return level; + } + + public ItemStack onFocusRightClick(ItemStack wandstack, World world,EntityPlayer player, MovingObjectPosition movingobjectposition) { + // TODO Auto-generated method stub + return null; + } + + public void onUsingFocusTick(ItemStack wandstack, EntityPlayer player,int count) { + // TODO Auto-generated method stub + } + + public void onPlayerStoppedUsingFocus(ItemStack wandstack, World world, EntityPlayer player, int count) { + // TODO Auto-generated method stub + + } + + public boolean onFocusBlockStartBreak(ItemStack wandstack, int x, int y,int z, EntityPlayer player) { + // TODO Auto-generated method stub + return false; + } + + /** + * Internal helper methods + */ + private NBTTagList getFocusUpgradeTagList(ItemStack focusstack) + { + return focusstack.stackTagCompound == null ? null : focusstack.stackTagCompound.getTagList("upgrade", 10); + } + + private void setFocusUpgradeTagList(ItemStack focusstack, short[] upgrades) { + if (!focusstack.hasTagCompound()) + focusstack.setTagCompound(new NBTTagCompound()); + NBTTagCompound nbttagcompound = focusstack.getTagCompound(); + NBTTagList tlist = new NBTTagList(); + nbttagcompound.setTag("upgrade", tlist); + for (short id : upgrades) { + NBTTagCompound f = new NBTTagCompound(); + f.setShort("id", id); + tlist.appendTag(f); + } + } + + @Override + public void onUpdate(ItemStack stack, World world, Entity entity, int p_77663_4_, boolean p_77663_5_) { + if (stack.stackTagCompound !=null && stack.stackTagCompound.hasKey("ench")) { + stack.stackTagCompound.removeTag("ench"); + } + super.onUpdate(stack, world, entity, p_77663_4_, p_77663_5_); + } + + + +} diff --git a/src/api/java/thaumcraft/api/wands/StaffRod.java b/src/api/java/thaumcraft/api/wands/StaffRod.java new file mode 100644 index 00000000..e7ae90f0 --- /dev/null +++ b/src/api/java/thaumcraft/api/wands/StaffRod.java @@ -0,0 +1,48 @@ +package thaumcraft.api.wands; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +/** + * + * @author Azanor + * + * This class is used to keep the material information for the various rods. + * It is also used to generate the wand recipes ingame. + * + */ +public class StaffRod extends WandRod { + + boolean runes=false; + + public StaffRod(String tag, int capacity, ItemStack item, int craftCost) { + super(tag+"_staff", capacity, item, craftCost); + this.texture = new ResourceLocation("thaumcraft","textures/models/wand_rod_"+tag+".png"); + } + + public StaffRod(String tag, int capacity, ItemStack item, int craftCost, + IWandRodOnUpdate onUpdate, ResourceLocation texture) { + super(tag+"_staff", capacity, item, craftCost, onUpdate, texture); + } + + public StaffRod(String tag, int capacity, ItemStack item, int craftCost, + IWandRodOnUpdate onUpdate) { + super(tag+"_staff", capacity, item, craftCost, onUpdate); + this.texture = new ResourceLocation("thaumcraft","textures/models/wand_rod_"+tag+".png"); + } + + public StaffRod(String tag, int capacity, ItemStack item, int craftCost, + ResourceLocation texture) { + super(tag+"_staff", capacity, item, craftCost, texture); + } + + public boolean hasRunes() { + return runes; + } + + public void setRunes(boolean hasRunes) { + this.runes = hasRunes; + } + + +} diff --git a/src/api/java/thaumcraft/api/wands/WandCap.java b/src/api/java/thaumcraft/api/wands/WandCap.java new file mode 100644 index 00000000..17b4581c --- /dev/null +++ b/src/api/java/thaumcraft/api/wands/WandCap.java @@ -0,0 +1,129 @@ +package thaumcraft.api.wands; + +import java.util.LinkedHashMap; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import thaumcraft.api.aspects.Aspect; + +/** + * This class is used to keep the material information for the various caps. + * It is also used to generate the wand recipes ingame. + * @author Azanor + * + */ +public class WandCap { + + private String tag; + + /** + * Cost to craft this wand. Combined with the rod cost. + */ + private int craftCost; + + /** + * the amount by which all aspect costs are multiplied + */ + float baseCostModifier; + + /** + * specifies a list of primal aspects that use the special discount figure instead of the normal discount. + */ + List specialCostModifierAspects; + + /** + * the amount by which the specified aspect costs are multiplied + */ + float specialCostModifier; + + /** + * The texture that will be used for the ingame wand cap + */ + ResourceLocation texture; + + /** + * the actual item that makes up this cap and will be used to generate the wand recipes + */ + ItemStack item; + + public static LinkedHashMap caps = new LinkedHashMap(); + + public WandCap (String tag, float discount, ItemStack item, int craftCost) { + this.setTag(tag); + this.baseCostModifier = discount; + this.specialCostModifierAspects = null; + texture = new ResourceLocation("thaumcraft","textures/models/wand_cap_"+getTag()+".png"); + this.item=item; + this.setCraftCost(craftCost); + caps.put(tag, this); + } + + public WandCap (String tag, float discount, List specialAspects, float discountSpecial, ItemStack item, int craftCost) { + this.setTag(tag); + this.baseCostModifier = discount; + this.specialCostModifierAspects = specialAspects; + this.specialCostModifier = discountSpecial; + texture = new ResourceLocation("thaumcraft","textures/models/wand_cap_"+getTag()+".png"); + this.item=item; + this.setCraftCost(craftCost); + caps.put(tag, this); + } + + public float getBaseCostModifier() { + return baseCostModifier; + } + + public List getSpecialCostModifierAspects() { + return specialCostModifierAspects; + } + + public float getSpecialCostModifier() { + return specialCostModifier; + } + + public ResourceLocation getTexture() { + return texture; + } + + public void setTexture(ResourceLocation texture) { + this.texture = texture; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + + public ItemStack getItem() { + return item; + } + + public void setItem(ItemStack item) { + this.item = item; + } + + public int getCraftCost() { + return craftCost; + } + + public void setCraftCost(int craftCost) { + 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); + +} diff --git a/src/api/java/thaumcraft/api/wands/WandRod.java b/src/api/java/thaumcraft/api/wands/WandRod.java new file mode 100644 index 00000000..85954e46 --- /dev/null +++ b/src/api/java/thaumcraft/api/wands/WandRod.java @@ -0,0 +1,158 @@ +package thaumcraft.api.wands; + +import java.util.LinkedHashMap; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +/** + * + * @author Azanor + * + * This class is used to keep the material information for the various rods. + * It is also used to generate the wand recipes ingame. + * + */ +public class WandRod { + + + private String tag; + + /** + * Cost to craft this wand. Combined with the rod cost. + */ + private int craftCost; + + /** + * The amount of vis that can be stored - this number is actually multiplied + * by 100 for use by the wands internals + */ + int capacity; + + /** + * The texture that will be used for the ingame wand rod + */ + protected ResourceLocation texture; + + /** + * the actual item that makes up this rod and will be used to generate the wand recipes + */ + ItemStack item; + + /** + * A class that will be called whenever the wand onUpdate tick is run + */ + IWandRodOnUpdate onUpdate; + + /** + * Does the rod glow in the dark? + */ + boolean glow; + + public static LinkedHashMap rods = new LinkedHashMap(); + + public WandRod (String tag, int capacity, ItemStack item, int craftCost, ResourceLocation texture) { + this.setTag(tag); + this.capacity = capacity; + this.texture = texture; + this.item=item; + this.setCraftCost(craftCost); + rods.put(tag, this); + } + + public WandRod (String tag, int capacity, ItemStack item, int craftCost, IWandRodOnUpdate onUpdate, ResourceLocation texture) { + this.setTag(tag); + this.capacity = capacity; + this.texture = texture; + this.item=item; + this.setCraftCost(craftCost); + rods.put(tag, this); + this.onUpdate = onUpdate; + } + + public WandRod (String tag, int capacity, ItemStack item, int craftCost) { + this.setTag(tag); + this.capacity = capacity; + this.texture = new ResourceLocation("thaumcraft","textures/models/wand_rod_"+getTag()+".png"); + this.item=item; + this.setCraftCost(craftCost); + rods.put(tag, this); + } + + public WandRod (String tag, int capacity, ItemStack item, int craftCost, IWandRodOnUpdate onUpdate) { + this.setTag(tag); + this.capacity = capacity; + this.texture = new ResourceLocation("thaumcraft","textures/models/wand_rod_"+getTag()+".png"); + this.item=item; + this.setCraftCost(craftCost); + rods.put(tag, this); + this.onUpdate = onUpdate; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + public int getCapacity() { + return capacity; + } + + public void setCapacity(int capacity) { + this.capacity = capacity; + } + + public ResourceLocation getTexture() { + return texture; + } + + public void setTexture(ResourceLocation texture) { + this.texture = texture; + } + + public ItemStack getItem() { + return item; + } + + public void setItem(ItemStack item) { + this.item = item; + } + + public int getCraftCost() { + return craftCost; + } + + public void setCraftCost(int craftCost) { + this.craftCost = craftCost; + } + + public IWandRodOnUpdate getOnUpdate() { + return onUpdate; + } + + public void setOnUpdate(IWandRodOnUpdate onUpdate) { + this.onUpdate = onUpdate; + } + + public boolean isGlowing() { + return glow; + } + + 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); + // WandRod WAND_ROD_BLAZE = new WandRod("blaze",100,new ItemStack(Item.blazeRod),7,new WandRodBlazeOnUpdate()); +} diff --git a/src/api/java/thaumcraft/api/wands/WandTriggerRegistry.java b/src/api/java/thaumcraft/api/wands/WandTriggerRegistry.java new file mode 100644 index 00000000..7224e12f --- /dev/null +++ b/src/api/java/thaumcraft/api/wands/WandTriggerRegistry.java @@ -0,0 +1,126 @@ +package thaumcraft.api.wands; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +/** + * This class serves a similar function to IWandable in that it allows wands to interact + * with object in the world. In this case it is most useful for adding interaction with non-mod + * blocks where you can't control what happens in their code. + * Example where it is used is in crafting the thaumonomicon from a bookshelf and the + * crucible from a cauldron + * + * @author azanor + * + */ +public class WandTriggerRegistry { + + private static HashMap> triggers = new HashMap>(); + private static final String DEFAULT = "default"; + + /** + * Registers an action to perform when a casting wand right clicks on a specific block. + * A manager class needs to be created that implements IWandTriggerManager. + * @param manager + * @param event a logical number that you can use to differentiate different events or actions + * @param block + * @param meta send -1 as a wildcard value for all possible meta values + * @param modid a unique identifier. It is best to register your own triggers using your mod id to avoid conflicts with mods that register triggers for the same block + */ + public static void registerWandBlockTrigger(IWandTriggerManager manager, int event, Block block, int meta, String modid) { + if (!triggers.containsKey(modid)) { + triggers.put(modid, new HashMap()); + } + HashMap temp = triggers.get(modid); + temp.put(Arrays.asList(block,meta),Arrays.asList(manager,event)); + triggers.put(modid, temp); + } + + /** + * for legacy support + */ + public static void registerWandBlockTrigger(IWandTriggerManager manager, int event, Block block, int meta) { + registerWandBlockTrigger(manager, event, block, meta, DEFAULT); + } + + /** + * Checks all trigger registries if one exists for the given block and meta + * @param block + * @param meta + * @return + */ + public static boolean hasTrigger(Block block, int meta) { + for (String modid:triggers.keySet()) { + HashMap temp = triggers.get(modid); + if (temp.containsKey(Arrays.asList(block,meta)) || + temp.containsKey(Arrays.asList(block,-1))) return true; + } + return false; + } + + /** + * modid sensitive version + */ + public static boolean hasTrigger(Block block, int meta, String modid) { + if (!triggers.containsKey(modid)) return false; + HashMap temp = triggers.get(modid); + if (temp.containsKey(Arrays.asList(block,meta)) || + temp.containsKey(Arrays.asList(block,-1))) return true; + return false; + } + + + /** + * This is called by the onItemUseFirst function in wands. + * Parameters and return value functions like you would expect for that function. + * @param world + * @param wand + * @param player + * @param x + * @param y + * @param z + * @param side + * @param block + * @param meta + * @return + */ + public static boolean performTrigger(World world, ItemStack wand, EntityPlayer player, + int x, int y, int z, int side, Block block, int meta) { + + for (String modid:triggers.keySet()) { + HashMap temp = triggers.get(modid); + List l = temp.get(Arrays.asList(block,meta)); + if (l==null) l = temp.get(Arrays.asList(block,-1)); + if (l==null) continue; + + IWandTriggerManager manager = (IWandTriggerManager) l.get(0); + int event = (Integer) l.get(1); + boolean result = manager.performTrigger(world, wand, player, x, y, z, side, event); + if (result) return true; + } + return false; + } + + /** + * modid sensitive version + */ + public static boolean performTrigger(World world, ItemStack wand, EntityPlayer player, + int x, int y, int z, int side, Block block, int meta, String modid) { + if (!triggers.containsKey(modid)) return false; + HashMap temp = triggers.get(modid); + List l = temp.get(Arrays.asList(block,meta)); + if (l==null) l = temp.get(Arrays.asList(block,-1)); + if (l==null) return false; + + IWandTriggerManager manager = (IWandTriggerManager) l.get(0); + int event = (Integer) l.get(1); + return manager.performTrigger(world, wand, player, x, y, z, side, event); + } + +} diff --git a/src/main/java/com/cricketcraft/chisel/init/ChiselTabs.java b/src/main/java/com/cricketcraft/chisel/init/ChiselTabs.java index 26d324bc..c27a2b1b 100644 --- a/src/main/java/com/cricketcraft/chisel/init/ChiselTabs.java +++ b/src/main/java/com/cricketcraft/chisel/init/ChiselTabs.java @@ -14,7 +14,7 @@ import cpw.mods.fml.relauncher.SideOnly; public class ChiselTabs { private static class CustomCreativeTab extends CreativeTabs { - + private boolean search; private ItemStack stack; @@ -37,25 +37,25 @@ public class ChiselTabs { public ItemStack getIconItemStack() { return stack; } - + @Override - @SideOnly(Side.CLIENT) - public String getBackgroundImageName() { + @SideOnly(Side.CLIENT) + public String getBackgroundImageName() { - return search ? "item_search.png" : super.getBackgroundImageName(); - } + return search ? "item_search.png" : super.getBackgroundImageName(); + } - @Override - public int getSearchbarWidth() { + @Override + public int getSearchbarWidth() { - return 89; - } - - @Override - public boolean hasSearchBar() { + return 89; + } - return search; - } + @Override + public boolean hasSearchBar() { + + return search; + } } private static boolean atLeastOneModIsLoaded = false; @@ -74,21 +74,26 @@ public class ChiselTabs { public static void postInit() { - if(Features.CHISEL.enabled()) - tabChisel.setTabIconItemStack(new ItemStack(ChiselItems.chisel)); - else tabChisel.setTabIconItemStack(new ItemStack(Items.stick)); - if(Features.HOLYSTONE.enabled()) - tabStoneChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.holystone)); - else tabStoneChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.stonebrick)); - if(Features.WOOD.enabled()) - tabWoodChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.planks[0], 1, 1)); - else tabWoodChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.planks)); - if(Features.TECHNICAL.enabled()) - tabMetalChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.technical)); - else tabMetalChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.iron_block)); - if(Features.JACKOLANTERN.enabled()) - tabOtherChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.jackolantern[0])); - else tabOtherChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.lit_pumpkin)); + if (Features.CHISEL.enabled()) + tabChisel.setTabIconItemStack(new ItemStack(ChiselItems.chisel)); + else + tabChisel.setTabIconItemStack(new ItemStack(Items.stick)); + if (Features.HOLYSTONE.enabled()) + tabStoneChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.holystone)); + else + tabStoneChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.stonebrick)); + if (Features.WOOD.enabled()) + tabWoodChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.planks[0], 1, 1)); + else + tabWoodChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.planks)); + if (Features.TECHNICAL.enabled()) + tabMetalChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.technical)); + else + tabMetalChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.iron_block)); + if (Features.JACKOLANTERN.enabled()) + tabOtherChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.jackolantern[0])); + else + tabOtherChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.lit_pumpkin)); if (atLeastOneModIsLoaded) { if (Features.ARCANE.enabled()) { @@ -96,9 +101,10 @@ public class ChiselTabs { } else if (Features.BLOOD_RUNE.enabled()) { tabModdedChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.bloodRune)); } else { - if(ChiselBlocks.voidstone != null) - tabModdedChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.voidstone)); - else tabModdedChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.obsidian)); + if (ChiselBlocks.voidstone != null) + tabModdedChiselBlocks.setTabIconItemStack(new ItemStack(ChiselBlocks.voidstone)); + else + tabModdedChiselBlocks.setTabIconItemStack(new ItemStack(Blocks.obsidian)); } } }