Skip to content

Commit

Permalink
API changes for 5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Azanor committed Jan 9, 2016
1 parent c0bcec9 commit 6ae8d26
Show file tree
Hide file tree
Showing 35 changed files with 1,369 additions and 42 deletions.
32 changes: 28 additions & 4 deletions ThaumcraftApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -263,13 +264,15 @@ public static InfusionRecipe getInfusionRecipe(ItemStack res) {
* @param cost the vis cost
* @param tags the aspects required to craft this
*/
public static CrucibleRecipe addCrucibleRecipe(String key, ItemStack result, Object catalyst, AspectList tags) {
CrucibleRecipe rc = new CrucibleRecipe(key, result, catalyst, tags);
public static CrucibleRecipe addCrucibleRecipe(String key, ItemStack result, Object catalyst, AspectList tags) {
return addCrucibleRecipe(new String[] {key},result,catalyst,tags);
}

public static CrucibleRecipe addCrucibleRecipe(String[] keys, ItemStack result, Object catalyst, AspectList tags) {
CrucibleRecipe rc = new CrucibleRecipe(keys, result, catalyst, tags);
getCraftingRecipes().add(rc);
return rc;
}



/**
* @param stack the recipe result
Expand Down Expand Up @@ -538,6 +541,8 @@ public static void addLootBagItem(ItemStack item, int weight, int... bagTypes) {
}
}
}



// PORTABLE HOLE BLACKLIST
/**
Expand All @@ -556,6 +561,25 @@ public static void addLootBagItem(ItemStack item, int weight, int... bagTypes) {


// CROPS

public static HashMap<String,ItemStack> seedList = new HashMap<String,ItemStack>();

/**
* This method is used to register an item that will act as a seed for the specified block.
* If your seed items use IPlantable it might not be necessary to do this as I
* attempt to automatically detect such links.
* @param block
* @param seed
*/
public static void registerSeed(Block block, ItemStack seed) {
seedList.put(block.getUnlocalizedName(), seed);
}

public static ItemStack getSeed(Block block) {
return seedList.get(block.getUnlocalizedName());
}


/**
* To define mod crops you need to use FMLInterModComms in your @Mod.Init method.
* There are two 'types' of crops you can add. Standard crops and clickable crops.
Expand Down
40 changes: 39 additions & 1 deletion ThaumcraftApiHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package thaumcraft.api;

import java.util.HashMap;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -326,4 +326,42 @@ public static Object getNBTDataFromId(NBTTagCompound nbt, byte id, String key) {
default: return null;
}
}

public static int setByteInInt(int data, byte b, int index)
{
ByteBuffer bb = ByteBuffer.allocate(4);
bb.putInt(0,data);
bb.put(index, b);
return bb.getInt(0);
}

public static byte getByteInInt(int data, int index) {
ByteBuffer bb = ByteBuffer.allocate(4);
bb.putInt(0,data);
return bb.get(index);
}

public static long setByteInLong(long data, byte b, int index)
{
ByteBuffer bb = ByteBuffer.allocate(8);
bb.putLong(0,data);
bb.put(index, b);
return bb.getLong(0);
}

public static byte getByteInLong(long data, int index) {
ByteBuffer bb = ByteBuffer.allocate(8);
bb.putLong(0,data);
return bb.get(index);
}

public static int setNibbleInInt(int data, int nibble, int nibbleIndex)
{
int shift = nibbleIndex * 4;
return (data & ~(0xf << shift)) | (nibble << shift);
}

public static int getNibbleInInt(int data, int nibbleIndex) {
return (data >> (nibbleIndex << 2)) & 0xF;
}
}
2 changes: 1 addition & 1 deletion aspects/Aspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void setChatcolor(String chatcolor) {

//SECONDARY (PRIMAL + PRIMAL)
public static final Aspect VOID = new Aspect("vacuos",0x888888, new Aspect[] {AIR, ENTROPY},771);
public static final Aspect LIGHT = new Aspect("lux",0xfff663, new Aspect[] {AIR, FIRE});
public static final Aspect LIGHT = new Aspect("lux",0xffd585, new Aspect[] {AIR, FIRE});
public static final Aspect MOTION = new Aspect("motus",0xcdccf4, new Aspect[] {AIR, ORDER});
public static final Aspect COLD = new Aspect("gelum",0xe1ffff, new Aspect[] {FIRE, ENTROPY});
public static final Aspect CRYSTAL = new Aspect("vitreus",0x80ffff, new Aspect[] {EARTH, AIR});
Expand Down
2 changes: 1 addition & 1 deletion aspects/AspectHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static AspectList getEntityAspects(Entity entity) {
entity.writeToNBT(tc);
for (EntityTagsNBT nbt:et.nbts) {
if (tc.hasKey(nbt.name)) {
if (!ThaumcraftApiHelper.getNBTDataFromId(tc, tc.getTagType(nbt.name), nbt.name).equals(nbt.value)) continue f1;
if (!ThaumcraftApiHelper.getNBTDataFromId(tc, tc.getTagId(nbt.name), nbt.name).equals(nbt.value)) continue f1;
} else {
continue f1;
}
Expand Down
14 changes: 14 additions & 0 deletions aura/AuraHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package thaumcraft.api.aura;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import thaumcraft.api.ThaumcraftApi;
Expand Down Expand Up @@ -66,6 +67,19 @@ public static int getAuraBase(World world, BlockPos pos) {
return ThaumcraftApi.internalMethods.getAuraBase(world,pos);
}

/**
* Gets if the local aura for the given aspect is below 10% and that the player has the node preserver research.
* If the passed in player is null it will ignore the need for the research to be completed and just assume it is.
* @param world
* @param player
* @param pos
* @param aspect
* @return
*/
public static boolean shouldPreserveAura(World world, EntityPlayer player, BlockPos pos, Aspect aspect) {
return ThaumcraftApi.internalMethods.shouldPreserveAura(world,player,pos,aspect);
}

/**
* Adds flux to the aura at the specified block position.
* @param world
Expand Down
7 changes: 7 additions & 0 deletions blocks/BlocksTC.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public class BlocksTC {
public static Block lampArcane;
public static Block lampFertility;
public static Block lampGrowth;
public static Block golemBuilder;
public static Block nodeStabilizer;
public static Block essentiaTransportInput;
public static Block essentiaTransportOutput;

// Fluids
public static Block fluxGoo;
Expand Down Expand Up @@ -124,6 +128,9 @@ public class BlocksTC {









Expand Down
7 changes: 4 additions & 3 deletions crafting/CrucibleRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ public class CrucibleRecipe {

public Object catalyst;
public AspectList aspects;
public String research;
public String[] research;

public int hash;

public CrucibleRecipe(String researchKey, ItemStack result, Object cat, AspectList tags) {
public CrucibleRecipe(String[] researchKey, ItemStack result, Object cat, AspectList tags) {
recipeOutput = result;
this.aspects = tags;
this.research = researchKey;
this.catalyst = cat;
if (cat instanceof String) {
this.catalyst = OreDictionary.getOres((String) cat);
}
String hc = researchKey;
String hc = "";
for (String ss:research) hc+=ss;
hc += result.toString();
for (Aspect tag:tags.getAspects()) {
hc += tag.getTag()+tags.getAmount(tag);
Expand Down
51 changes: 51 additions & 0 deletions golems/EnumGolemTrait.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package thaumcraft.api.golems;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;

public enum EnumGolemTrait {
SMART(new ResourceLocation("thaumcraft","textures/misc/golem/tag_smart.png")),
DEFT(new ResourceLocation("thaumcraft","textures/misc/golem/tag_deft.png")),
CLUMSY(new ResourceLocation("thaumcraft","textures/misc/golem/tag_clumsy.png")),
FIGHTER(new ResourceLocation("thaumcraft","textures/misc/golem/tag_fighter.png")),
WHEELED(new ResourceLocation("thaumcraft","textures/misc/golem/tag_wheeled.png")),
FLYER(new ResourceLocation("thaumcraft","textures/misc/golem/tag_flyer.png")),
CLIMBER(new ResourceLocation("thaumcraft","textures/misc/golem/tag_climber.png")),
HEAVY(new ResourceLocation("thaumcraft","textures/misc/golem/tag_heavy.png")),
LIGHT(new ResourceLocation("thaumcraft","textures/misc/golem/tag_light.png")),
FRAGILE(new ResourceLocation("thaumcraft","textures/misc/golem/tag_fragile.png")),
REPAIR(new ResourceLocation("thaumcraft","textures/misc/golem/tag_repair.png")),
SCOUT(new ResourceLocation("thaumcraft","textures/misc/golem/tag_scout.png")),
ARMORED(new ResourceLocation("thaumcraft","textures/misc/golem/tag_armored.png")),
BRUTAL(new ResourceLocation("thaumcraft","textures/misc/golem/tag_brutal.png")),
FIREPROOF(new ResourceLocation("thaumcraft","textures/misc/golem/tag_fireproof.png")),
BREAKER(new ResourceLocation("thaumcraft","textures/misc/golem/tag_breaker.png")),
HAULER(new ResourceLocation("thaumcraft","textures/misc/golem/tag_hauler.png")),
RANGED(new ResourceLocation("thaumcraft","textures/misc/golem/tag_ranged.png"));

static {
CLUMSY.opposite = DEFT;
DEFT.opposite = CLUMSY;

HEAVY.opposite = LIGHT;
LIGHT.opposite = HEAVY;

FRAGILE.opposite = ARMORED;
ARMORED.opposite = FRAGILE;
}

public ResourceLocation icon;
public EnumGolemTrait opposite;

private EnumGolemTrait(ResourceLocation icon) {
this.icon = icon;
}

public String getLocalizedName() {
return StatCollector.translateToLocal("golem.trait."+this.name().toLowerCase());
}

public String getLocalizedDescription() {
return StatCollector.translateToLocal("golem.trait.text."+this.name().toLowerCase());
}
}
103 changes: 103 additions & 0 deletions golems/GolemHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package thaumcraft.api.golems;

import java.util.ArrayList;
import java.util.HashMap;

import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import thaumcraft.api.ThaumcraftApi;
import thaumcraft.api.golems.seals.ISeal;
import thaumcraft.api.golems.seals.ISealEntity;
import thaumcraft.api.golems.seals.SealPos;
import thaumcraft.api.golems.tasks.Task;

public class GolemHelper {

/**
* Make sure to register your seals during the preInit phase.
* @param seal
*/
public static void registerSeal(ISeal seal) {
ThaumcraftApi.internalMethods.registerSeal(seal);
}

public static ISeal getSeal(String key) {
return ThaumcraftApi.internalMethods.getSeal(key);
}

public static ISealEntity getSealEntity(int dim, SealPos pos) {
return ThaumcraftApi.internalMethods.getSealEntity(dim, pos);
}

public static void addGolemTask(int dim, Task task) {
ThaumcraftApi.internalMethods.addGolemTask(dim, task);
}

public static HashMap<Integer,ArrayList<ProvisionRequest>> provisionRequests = new HashMap<Integer,ArrayList<ProvisionRequest>>();

public static void requestProvisioning(World world, ISealEntity seal, ItemStack stack) {
if (!provisionRequests.containsKey(world.provider.getDimensionId()))
provisionRequests.put(world.provider.getDimensionId(), new ArrayList<ProvisionRequest>());
ArrayList<ProvisionRequest> list = provisionRequests.get(world.provider.getDimensionId());
ProvisionRequest pr = new ProvisionRequest(seal,stack);
if (!list.contains(pr))
list.add(pr);
}

/**
* This method is used to get a single blockpos from within a designated seal area.
* This method is best used if you want to increment through the blocks in the area.
* @param seal
* @param count a value used to derive a specific pos
* @return
*/
public static BlockPos getPosInArea(ISealEntity seal, int count) {
int xx = 1 + (seal.getArea().getX()-1) * (seal.getSealPos().face.getFrontOffsetX()==0?2:1);
int yy = 1 + (seal.getArea().getY()-1) * (seal.getSealPos().face.getFrontOffsetY()==0?2:1);
int zz = 1 + (seal.getArea().getZ()-1) * (seal.getSealPos().face.getFrontOffsetZ()==0?2:1);

int qx = seal.getSealPos().face.getFrontOffsetX()!=0?seal.getSealPos().face.getFrontOffsetX():1;
int qy = seal.getSealPos().face.getFrontOffsetY()!=0?seal.getSealPos().face.getFrontOffsetY():1;
int qz = seal.getSealPos().face.getFrontOffsetZ()!=0?seal.getSealPos().face.getFrontOffsetZ():1;

int y = qy*((count/zz)/xx)%yy + seal.getSealPos().face.getFrontOffsetY();
int x = qx*(count/zz)%xx + seal.getSealPos().face.getFrontOffsetX();
int z = qz*count%zz + seal.getSealPos().face.getFrontOffsetZ();

BlockPos p = seal.getSealPos().pos.add(
x - (seal.getSealPos().face.getFrontOffsetX()==0?xx/2:0),
y - (seal.getSealPos().face.getFrontOffsetY()==0?yy/2:0),
z - (seal.getSealPos().face.getFrontOffsetZ()==0?zz/2:0));

return p;
}


/**
* Returns the designated seal area as a AxisAlignedBB
* @param seal
* @return
*/
public static AxisAlignedBB getBoundsForArea(ISealEntity seal) {
return AxisAlignedBB.fromBounds(
seal.getSealPos().pos.getX(), seal.getSealPos().pos.getY(), seal.getSealPos().pos.getZ(),
seal.getSealPos().pos.getX()+1, seal.getSealPos().pos.getY()+1, seal.getSealPos().pos.getZ()+1)
.offset(
seal.getSealPos().face.getFrontOffsetX(),
seal.getSealPos().face.getFrontOffsetY(),
seal.getSealPos().face.getFrontOffsetZ())
.addCoord(
seal.getSealPos().face.getFrontOffsetX()!=0?(seal.getArea().getX()-1) * seal.getSealPos().face.getFrontOffsetX():0,
seal.getSealPos().face.getFrontOffsetY()!=0?(seal.getArea().getY()-1) * seal.getSealPos().face.getFrontOffsetY():0,
seal.getSealPos().face.getFrontOffsetZ()!=0?(seal.getArea().getZ()-1) * seal.getSealPos().face.getFrontOffsetZ():0)
.expand(
seal.getSealPos().face.getFrontOffsetX()==0?seal.getArea().getX()-1:0,
seal.getSealPos().face.getFrontOffsetY()==0?seal.getArea().getY()-1:0,
seal.getSealPos().face.getFrontOffsetZ()==0?seal.getArea().getZ()-1:0 );
}



}
Loading

0 comments on commit 6ae8d26

Please sign in to comment.