Merge pull request #519 from Arcaratus/1.8-Rewrite

More sigils
This commit is contained in:
Nick Ignoffo 2015-12-28 16:23:28 -08:00
commit c755282d79
31 changed files with 1011 additions and 53 deletions

View file

@ -69,6 +69,8 @@ public class BloodMagic {
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
ModRecipes.addCompressionHandlers();
proxy.postInit();
}
}

View file

@ -26,7 +26,7 @@ public interface IBloodAltar {
int getBufferCapacity();
void sacrificialDaggerCall(int amount, boolean b);
void sacrificialDaggerCall(int amount, boolean isSacrifice);
void startCycle();

View file

@ -0,0 +1,14 @@
package WayofTime.bloodmagic.api.compress;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public abstract class CompressionHandler {
/**
* Called to look at the inventory and syphons the required stack. Returns resultant stack if successful, and null if not.
* @param inv The inventory iterated through
* @return The result of the compression
*/
public abstract ItemStack compressInventory(ItemStack[] inv, World world);
}

View file

@ -0,0 +1,57 @@
package WayofTime.bloodmagic.api.compress;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A registry aimed to help compress items in an inventory into its compressible form.
*/
public class CompressionRegistry {
public static List<CompressionHandler> compressionRegistry = new ArrayList<CompressionHandler>();
public static Map<ItemStack, Integer> thresholdMap = new HashMap<ItemStack, Integer>();
public static void registerHandler(CompressionHandler handler) {
compressionRegistry.add(handler);
}
/**
* Registers an item so that it only compresses while above this threshold
*
* @param stack item/block to be compressed
* @param threshold amount that is to be compressed
*/
public static void registerItemThreshold(ItemStack stack, int threshold) {
thresholdMap.put(stack, threshold);
}
public static ItemStack compressInventory(ItemStack[] inv, World world) {
for (CompressionHandler handler : compressionRegistry) {
ItemStack stack = handler.compressInventory(inv, world);
if (stack != null) {
return stack;
}
}
return null;
}
public static int getItemThreshold(ItemStack stack) {
for (Map.Entry<ItemStack, Integer> entry : thresholdMap.entrySet()) {
if (areItemStacksEqual(entry.getKey(), stack)) {
return entry.getValue();
}
}
return 0;
}
public static boolean areItemStacksEqual(ItemStack stack, ItemStack compressedStack) {
return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? compressedStack.getTagCompound() == null : stack.getTagCompound().equals(compressedStack.getTagCompound()));
}
}

View file

@ -35,10 +35,17 @@ public class BlockPhantom extends BlockContainer {
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean isTranslucent()
{
return true;
}
@Override
@SideOnly(Side.CLIENT)
public EnumWorldBlockLayer getBlockLayer() {
return EnumWorldBlockLayer.CUTOUT;
return EnumWorldBlockLayer.TRANSLUCENT;
}
@Override

View file

@ -0,0 +1,141 @@
package WayofTime.bloodmagic.compress;
import WayofTime.bloodmagic.api.compress.CompressionHandler;
import WayofTime.bloodmagic.api.compress.CompressionRegistry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class AdvancedCompressionHandler extends CompressionHandler {
@Override
public ItemStack compressInventory(ItemStack[] inv, World world) {
return test(inv, true, world);
}
public ItemStack test(ItemStack[] inv, boolean doDrain, World world) {
for (ItemStack invStack : inv) {
if (invStack == null) {
continue;
}
for (int i = 2; i <= 3; i++) {
ItemStack stacky = getRecipe(invStack, world, i);
if (stacky != null) {
int threshold = CompressionRegistry.getItemThreshold(invStack);
int needed = i * i;
int neededLeft = iterateThroughInventory(invStack, threshold + invStack.getMaxStackSize() - needed, inv, needed, false);
if (neededLeft <= 0) {
iterateThroughInventory(invStack, 0, inv, needed, true);
return stacky;
}
}
}
}
return null;
}
public int iterateThroughInventory(ItemStack required, int kept, ItemStack[] inv, int needed, boolean doDrain) {
int i = -1;
for (ItemStack invStack : inv) {
i++;
if (invStack == null) {
continue;
}
if (invStack.isItemEqual(required) && (invStack.getTagCompound() == null ? required.getTagCompound() == null : invStack.getTagCompound().equals(required.getTagCompound()))) {
int stackSize = invStack.stackSize;
int used = 0;
if (kept > 0) {
int remainingFromStack = Math.max(stackSize - kept, 0);
used += stackSize - remainingFromStack;
}
kept -= used;
if (kept <= 0 && needed > 0) {
int remainingFromStack = Math.max(stackSize - used - needed, 0);
if (doDrain) {
invStack.stackSize = remainingFromStack + used;
if (invStack.stackSize <= 0) {
inv[i] = null;
}
}
needed -= (stackSize - used - remainingFromStack);
}
if (needed <= 0) {
return 0;
}
}
}
return needed;
}
public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world) {
if (stack == null) {
return false;
}
InventoryCrafting inventory = new InventoryCrafting(new Container() {
public boolean canInteractWith(EntityPlayer player) {
return false;
}
}, 2, 2);
inventory.setInventorySlotContents(0, stack);
ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world);
if (returnStack == null) {
return false;
}
ItemStack compressedStack = null;
switch (gridSize) {
case 2:
compressedStack = get22Recipe(returnStack, world);
break;
case 3:
compressedStack = get33Recipe(returnStack, world);
break;
}
return compressedStack != null && CompressionRegistry.areItemStacksEqual(stack, compressedStack);
}
public static ItemStack getRecipe(ItemStack stack, World world, int gridSize) {
InventoryCrafting inventory = new InventoryCrafting(new Container() {
public boolean canInteractWith(EntityPlayer player) {
return false;
}
}, gridSize, gridSize);
for (int i = 0; i < inventory.getSizeInventory(); i++) {
inventory.setInventorySlotContents(i, stack);
}
return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world);
}
public static boolean has22Recipe(ItemStack stack, World world) {
return get22Recipe(stack, world) != null;
}
public static ItemStack get22Recipe(ItemStack stack, World world) {
return getRecipe(stack, world, 2);
}
public static boolean has33Recipe(ItemStack stack, World world) {
return get33Recipe(stack, world) != null;
}
public static ItemStack get33Recipe(ItemStack stack, World world) {
return getRecipe(stack, world, 3);
}
}

View file

@ -0,0 +1,93 @@
package WayofTime.bloodmagic.compress;
import WayofTime.bloodmagic.api.compress.CompressionHandler;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class BaseCompressionHandler extends CompressionHandler {
private final ItemStack required;
private final ItemStack result;
private final int leftover;
public BaseCompressionHandler(ItemStack requested, ItemStack result, int leftover) {
super();
this.required = requested;
this.result = result;
this.leftover = leftover;
}
public ItemStack getResultStack() {
return this.result.copy();
}
public ItemStack getRequiredStack() {
return this.required.copy();
}
@Override
public ItemStack compressInventory(ItemStack[] inv, World world) {
int remaining = this.getRemainingNeeded(inv);
if (remaining <= 0) {
this.drainInventory(inv);
return this.getResultStack();
}
return null;
}
public int getRemainingNeeded(ItemStack[] inv) {
return iterateThroughInventory(inv, false);
}
public int drainInventory(ItemStack[] inv) {
return iterateThroughInventory(inv, true);
}
public int iterateThroughInventory(ItemStack[] inv, boolean doDrain) {
int needed = this.required.stackSize;
int kept = this.getLeftover();
int i = -1;
for (ItemStack invStack : inv) {
i++;
if (invStack == null) {
continue;
}
if (invStack.isItemEqual(this.required) && (invStack.getTagCompound() == null ? this.required.getTagCompound() == null : invStack.getTagCompound().equals(this.required.getTagCompound()))) {
int stackSize = invStack.stackSize;
int used = 0;
if (kept > 0) {
int remainingFromStack = Math.max(stackSize - kept, 0);
used += stackSize - remainingFromStack;
}
kept -= used;
if (kept <= 0 && needed > 0) {
int remainingFromStack = Math.max(stackSize - used - needed, 0);
if (doDrain) {
invStack.stackSize = remainingFromStack + used;
if (invStack.stackSize <= 0) {
inv[i] = null;
}
}
needed -= (stackSize - used - remainingFromStack);
}
if (needed <= 0) {
return 0;
}
}
}
return needed;
}
public int getLeftover() {
return this.leftover;
}
}

View file

@ -0,0 +1,140 @@
package WayofTime.bloodmagic.compress;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.compress.CompressionRegistry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import java.util.LinkedList;
import java.util.List;
public class StorageBlockCraftingManager {
private static final StorageBlockCraftingManager instance = new StorageBlockCraftingManager();
private List recipes = new LinkedList();
public static StorageBlockCraftingManager getInstance() {
return instance;
}
public void addStorageBlockRecipes() {
this.recipes = new StorageBlockCraftingRecipeAssimilator().getPackingRecipes();
BloodMagic.instance.getLogger().info("Total number of compression recipes: " + this.recipes.size());
}
private static boolean isResultStackReversible(ItemStack stack, int gridSize, World world, List list) {
if (stack == null) {
return false;
}
InventoryCrafting inventory = new InventoryCrafting(new Container() {
public boolean canInteractWith(EntityPlayer player) {
return false;
}
}, 2, 2);
inventory.setInventorySlotContents(0, stack);
ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
if (returnStack == null || returnStack.getItem() == null) {
return false;
}
ItemStack compressedStack = null;
switch (gridSize) {
case 2:
compressedStack = get22Recipe(returnStack, world, list);
break;
case 3:
compressedStack = get33Recipe(returnStack, world, list);
break;
}
return compressedStack != null && CompressionRegistry.areItemStacksEqual(stack, compressedStack);
}
private static ItemStack getRecipe(ItemStack stack, World world, int gridSize, List list) {
InventoryCrafting inventory = new InventoryCrafting(new Container() {
public boolean canInteractWith(EntityPlayer player) {
return false;
}
}, gridSize, gridSize);
for (int i = 0; i < inventory.getSizeInventory(); i++) {
inventory.setInventorySlotContents(i, stack);
}
return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
}
private static boolean has22Recipe(ItemStack stack, World world, List list) {
return get22Recipe(stack, world, list) != null;
}
private static ItemStack get22Recipe(ItemStack stack, World world, List list) {
return getRecipe(stack, world, 2, list);
}
private static boolean has33Recipe(ItemStack stack, World world, List list) {
return get33Recipe(stack, world, list) != null;
}
private static ItemStack get33Recipe(ItemStack stack, World world, List list) {
return getRecipe(stack, world, 3, list);
}
public ItemStack findMatchingRecipe(InventoryCrafting craftingInventory, World world) {
return this.findMatchingRecipe(craftingInventory, world, this.recipes);
}
private ItemStack findMatchingRecipe(InventoryCrafting craftingInventory, World world, List list) {
int i = 0;
ItemStack itemstack = null;
ItemStack itemstack1 = null;
int j;
for (j = 0; j < craftingInventory.getSizeInventory(); ++j) {
ItemStack itemstack2 = craftingInventory.getStackInSlot(j);
if (itemstack2 != null) {
if (i == 0) {
itemstack = itemstack2;
}
if (i == 1) {
itemstack1 = itemstack2;
}
++i;
}
}
if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable()) {
Item item = itemstack.getItem();
int j1 = item.getMaxDamage() - itemstack.getItemDamage();
int k = item.getMaxDamage() - itemstack1.getItemDamage();
int l = j1 + k + item.getMaxDamage() * 5 / 100;
int i1 = item.getMaxDamage() - l;
if (i1 < 0) {
i1 = 0;
}
return new ItemStack(itemstack.getItem(), 1, i1);
} else {
for (j = 0; j < list.size(); ++j) {
IRecipe irecipe = (IRecipe) list.get(j);
if (irecipe.matches(craftingInventory, world)) {
return irecipe.getCraftingResult(craftingInventory);
}
}
return null;
}
}
}

View file

@ -0,0 +1,253 @@
package WayofTime.bloodmagic.compress;
import WayofTime.bloodmagic.BloodMagic;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import java.util.*;
public class StorageBlockCraftingRecipeAssimilator {
public List<IRecipe> getPackingRecipes() {
// grab all recipes potentially suitable for packing or unpacking
List<PackingRecipe> packingRecipes = new LinkedList<PackingRecipe>();
List<IRecipe> unpackingRecipes = new ArrayList<IRecipe>();
for (IRecipe recipe : getCraftingRecipes()) {
ItemStack output = recipe.getRecipeOutput();
if (output == null || output.getItem() == null) continue;
if (output.stackSize == 1) {
PackingRecipe packingRecipe = getPackingRecipe(recipe);
if (packingRecipe != null) {
packingRecipes.add(packingRecipe);
}
} else if ((output.stackSize == 4 || output.stackSize == 9) && recipe.getRecipeSize() == 1) {
unpackingRecipes.add(recipe);
}
}
// grab all packing recipes which accept the output of any of the unpacking recipes
Container container = makeDummyContainer();
InventoryCrafting inventoryUnpack = new InventoryCrafting(container, 2, 2);
InventoryCrafting inventory2x2 = new InventoryCrafting(container, 2, 2);
InventoryCrafting inventory3x3 = new InventoryCrafting(container, 3, 3);
World world = null; // TODO: use a proper dummy world?
List<IRecipe> ret = new ArrayList<IRecipe>();
for (IRecipe recipeUnpack : unpackingRecipes) {
ItemStack unpacked = recipeUnpack.getRecipeOutput();
InventoryCrafting inventory = null;
for (Iterator<PackingRecipe> it = packingRecipes.iterator(); it.hasNext(); ) {
PackingRecipe recipePack = it.next();
// check if the packing recipe accepts the unpacking recipe's output
boolean matched = false;
if (recipePack.possibleInputs != null) { // the recipe could be parsed, use its inputs directly since that's faster
// verify recipe size
if (recipePack.inputCount != unpacked.stackSize) continue;
// check if any of the input options matches the unpacked item stack
for (ItemStack stack : recipePack.possibleInputs) {
if (areInputsIdentical(unpacked, stack)) {
matched = true;
break;
}
}
} else { // unknown IRecipe, check through the recipe conventionally
// verify recipe size for 3x3 to skip anything smaller quickly
if (unpacked.stackSize == 9 && recipePack.recipe.getRecipeSize() < 9) continue;
// initialize inventory late, but only once per unpack recipe
if (inventory == null) {
if (unpacked.stackSize == 4) {
inventory = inventory2x2;
} else {
inventory = inventory3x3;
}
for (int i = 0; i < unpacked.stackSize; i++) {
inventory.setInventorySlotContents(i, unpacked.copy());
}
}
// check if the packing recipe accepts the unpacked item stack
matched = recipePack.recipe.matches(inventory, world);
}
if (matched) {
// check if the unpacking recipe accepts the packing recipe's output
ItemStack packOutput = recipePack.recipe.getRecipeOutput();
inventoryUnpack.setInventorySlotContents(0, packOutput.copy());
if (recipeUnpack.matches(inventoryUnpack, world)) {
ret.add(recipePack.recipe);
BloodMagic.instance.getLogger().info("Adding the following recipe to the Compression Handler: " + packOutput);
it.remove();
}
}
}
}
return ret;
}
@SuppressWarnings("unchecked")
private List<IRecipe> getCraftingRecipes() {
return CraftingManager.getInstance().getRecipeList();
}
private Container makeDummyContainer() {
return new Container() {
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
}
};
}
private PackingRecipe getPackingRecipe(IRecipe recipe) {
if (recipe.getRecipeSize() < 4) return null;
List<?> inputs;
if (recipe instanceof ShapedRecipes) {
inputs = Arrays.asList(((ShapedRecipes) recipe).recipeItems);
} else if (recipe instanceof ShapelessRecipes) {
inputs = ((ShapelessRecipes) recipe).recipeItems;
} else if (recipe instanceof ShapedOreRecipe) {
inputs = Arrays.asList(((ShapedOreRecipe) recipe).getInput());
} else if (recipe instanceof ShapelessOreRecipe) {
inputs = ((ShapelessOreRecipe) recipe).getInput();
} else {
return new PackingRecipe(recipe, null, -1);
}
// check if the recipe inputs are size 4 or 9
int count = 0;
for (Object o : inputs) {
if (o != null) count++;
}
if (count != 4 && count != 9) return null;
// grab identical inputs
List<ItemStack> identicalInputs = getIdenticalInputs(inputs);
if (identicalInputs == null) return null;
return new PackingRecipe(recipe, identicalInputs, count);
}
/**
* Determine the item stacks from the provided inputs which are suitable for every input element.
*
* @param inputs List of all inputs, null elements are being ignored.
* @return List List of all options.
*/
@SuppressWarnings("unchecked")
private List<ItemStack> getIdenticalInputs(List<?> inputs) {
List<ItemStack> options = null;
for (Object input : inputs) {
if (input == null) continue;
List<ItemStack> offers;
if (input instanceof ItemStack) {
offers = Collections.singletonList((ItemStack) input);
} else if (input instanceof List) {
offers = (List<ItemStack>) input;
if (offers.isEmpty()) return null;
} else {
throw new RuntimeException("invalid input: "+input.getClass());
}
if (options == null) {
options = new ArrayList<ItemStack>(offers);
continue;
}
for (Iterator<ItemStack> it = options.iterator(); it.hasNext(); ) {
ItemStack stackReq = it.next();
boolean found = false;
for (ItemStack stackCmp : offers) {
if (areInputsIdentical(stackReq, stackCmp)) {
found = true;
break;
}
}
if (!found) {
it.remove();
if (options.isEmpty()) return null;
}
}
}
return options;
}
private boolean areInputsIdentical(ItemStack a, ItemStack b) {
try {
if (a.getItem() != b.getItem())
return false;
int dmgA = a.getItemDamage();
int dmgB = b.getItemDamage();
return dmgA == dmgB || dmgA == OreDictionary.WILDCARD_VALUE || dmgB == OreDictionary.WILDCARD_VALUE;
} catch (NullPointerException e) {
BloodMagic.instance.getLogger().error("A mod in this instance has registered an item with a null input. Known problem mods are:");
// String err = "";
// for (String problem : problemMods)
// err += (err.length() > 0 ? ", " : "") + problem;
// BloodMagic.instance.getLogger().error(err);
return false;
}
}
private static class PackingRecipe {
PackingRecipe(IRecipe recipe, List<ItemStack> possibleInputs, int inputCount) {
this.recipe = recipe;
this.possibleInputs = possibleInputs;
this.inputCount = inputCount;
}
final IRecipe recipe;
final List<ItemStack> possibleInputs;
final int inputCount;
}
}

View file

@ -0,0 +1,89 @@
package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.DamageSourceBloodMagic;
import WayofTime.bloodmagic.api.altar.IBloodAltar;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntitySlime;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
public class ItemDaggerOfSacrifice extends Item {
public ItemDaggerOfSacrifice() {
super();
setUnlocalizedName(Constants.Mod.MODID + ".daggerOfSacrifice");
setCreativeTab(BloodMagic.tabBloodMagic);
setMaxStackSize(1);
setFull3D();
}
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
if (target == null || attacker == null || attacker.worldObj.isRemote || (attacker instanceof EntityPlayer && !(attacker instanceof EntityPlayerMP)))
return false;
if (target.isChild() || target instanceof EntityPlayer || target instanceof IBossDisplayData)
return false;
if (target.isDead || target.getHealth() < 0.5F)
return false;
//TODO Make these configurable
int lifeEssence = 500;
if (target instanceof EntityVillager) lifeEssence = 2000;
else if (target instanceof EntitySlime) lifeEssence = 150;
else if (target instanceof EntityEnderman) lifeEssence = 200;
else if (target instanceof EntityAnimal) lifeEssence = 250;
if (findAndFillAltar(attacker.worldObj, target, lifeEssence)) {
double posX = target.posX;
double posY = target.posY;
double posZ = target.posZ;
target.worldObj.playSoundEffect((double) ((float) posX + 0.5F), (double) ((float) posY + 0.5F), (double) ((float) posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (target.worldObj.rand.nextFloat() - target.worldObj.rand.nextFloat()) * 0.8F);
target.setHealth(-1);
target.onDeath(new DamageSourceBloodMagic());
}
return false;
}
public boolean findAndFillAltar(World world, EntityLivingBase sacrifice, int amount) {
IBloodAltar bloodAltar = findBloodAltar(world, sacrifice.getPosition());
if (bloodAltar != null) {
bloodAltar.sacrificialDaggerCall(amount, true);
bloodAltar.startCycle();
return true;
}
return false;
}
public IBloodAltar findBloodAltar(World world, BlockPos blockPos) {
TileEntity tileEntity;
for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) {
for (int k = -2; k <= 1; k++) {
tileEntity = world.getTileEntity(blockPos.add(i, k, j));
if ((tileEntity instanceof IBloodAltar))
return (IBloodAltar) tileEntity;
}
}
}
return null;
}
}

View file

@ -1,4 +1,27 @@
package WayofTime.bloodmagic.item.sigil;
public class ItemSigilCompression {
import WayofTime.bloodmagic.api.compress.CompressionRegistry;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ItemSigilCompression extends ItemSigilToggleable {
public ItemSigilCompression() {
super("compression", 200);
}
//TODO REWRITE all compression stuff if someone has time
//TODO for now, there is a semi-working system in place
@Override
public void onSigilUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected) {
ItemStack compressedStack = CompressionRegistry.compressInventory(player.inventory.mainInventory, world);
if (compressedStack != null) {
EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, compressedStack);
world.spawnEntityInWorld(entityItem);
}
}
}

View file

@ -1,4 +1,28 @@
package WayofTime.bloodmagic.item.sigil;
public class ItemSigilEnderSeverance {
import WayofTime.bloodmagic.registry.ModPotions;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import java.util.List;
public class ItemSigilEnderSeverance extends ItemSigilToggleable {
public ItemSigilEnderSeverance() {
super("enderSeverance", 200);
}
@Override
public void onSigilUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected) {
List<Entity> entityList = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(player.posX - 4.5, player.posY - 4.5, player.posZ - 4.5, player.posX + 4.5, player.posY + 4.5, player.posZ + 4.5));
for (Entity entity : entityList) {
if (entity instanceof EntityEnderman)
((EntityEnderman) entity).addPotionEffect(new PotionEffect(ModPotions.planarBinding.id, 40, 0));
}
}
}

View file

@ -1,4 +0,0 @@
package WayofTime.bloodmagic.item.sigil;
public class ItemSigilHurricane {
}

View file

@ -0,0 +1,19 @@
package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.registry.ModPotions;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
public class ItemSigilWhirlwind extends ItemSigilToggleable {
public ItemSigilWhirlwind() {
super("whirlwind", 250);
}
@Override
public void onSigilUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected) {
player.addPotionEffect(new PotionEffect(ModPotions.whirlwind.id, 2, 0, true, false));
}
}

View file

@ -1,14 +1,19 @@
package WayofTime.bloodmagic.potion;
import WayofTime.bloodmagic.registry.ModPotions;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.ArrayList;
import java.util.List;
public class PotionEventHandlers {
@ -31,11 +36,6 @@ public class PotionEventHandlers {
@SubscribeEvent
public void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
// EntityLivingBase entityLiving = event.entityLiving;
// double x = entityLiving.posX;
// double y = entityLiving.posY;
// double z = entityLiving.posZ;
if (event.entityLiving.isPotionActive(ModPotions.boost)) {
int i = event.entityLiving.getActivePotionEffect(ModPotions.boost).getAmplifier();
@ -51,5 +51,66 @@ public class PotionEventHandlers {
}
}
}
if (event.entityLiving.isPotionActive(ModPotions.whirlwind)) {
int d0 = 3;
AxisAlignedBB axisAlignedBB = AxisAlignedBB.fromBounds(event.entityLiving.posX - 0.5, event.entityLiving.posY - 0.5, event.entityLiving.posZ - 0.5, event.entityLiving.posX + 0.5, event.entityLiving.posY + 0.5, event.entityLiving.posZ + 0.5).expand(d0, d0, d0);
List entityList = event.entityLiving.worldObj.getEntitiesWithinAABB(Entity.class, axisAlignedBB);
for (Object thing : entityList) {
Entity projectile = (Entity) thing;
if (projectile == null) continue;
if (!(projectile instanceof IProjectile)) continue;
Entity throwingEntity = null;
if (projectile instanceof EntityArrow) throwingEntity = ((EntityArrow) projectile).shootingEntity;
else if (projectile instanceof EntityThrowable)
throwingEntity = ((EntityThrowable) projectile).getThrower();
if (throwingEntity != null && throwingEntity.equals(event.entityLiving)) continue;
double delX = projectile.posX - event.entityLiving.posX;
double delY = projectile.posY - event.entityLiving.posY;
double delZ = projectile.posZ - event.entityLiving.posZ;
double angle = (delX * projectile.motionX + delY * projectile.motionY + delZ * projectile.motionZ) /
(Math.sqrt(delX * delX + delY * delY + delZ * delZ) * Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ));
angle = Math.acos(angle);
if (angle < 3 * (Math.PI / 4)) continue; //angle is < 135 degrees
if (throwingEntity != null) {
delX = -projectile.posX + throwingEntity.posX;
delY = -projectile.posY + (throwingEntity.posY + throwingEntity.getEyeHeight());
delZ = -projectile.posZ + throwingEntity.posZ;
}
double curVel = Math.sqrt(delX * delX + delY * delY + delZ * delZ);
delX /= curVel;
delY /= curVel;
delZ /= curVel;
double newVel = Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ);
projectile.motionX = newVel * delX;
projectile.motionY = newVel * delY;
projectile.motionZ = newVel * delZ;
}
}
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerDamageEvent(LivingAttackEvent event) {
if (event.entityLiving.isPotionActive(ModPotions.whirlwind) && event.isCancelable() && event.source.isProjectile())
event.setCanceled(true);
}
@SubscribeEvent
public void onEndermanTeleportEvent(EnderTeleportEvent event) {
if (event.entityLiving.isPotionActive(ModPotions.planarBinding) && event.isCancelable()) {
event.setCanceled(true);
}
}
}

View file

@ -7,31 +7,11 @@ import WayofTime.bloodmagic.ConfigHandler;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.orb.BloodOrb;
import WayofTime.bloodmagic.api.registry.OrbRegistry;
import WayofTime.bloodmagic.item.ItemActivationCrystal;
import WayofTime.bloodmagic.item.ItemAltarMaker;
import WayofTime.bloodmagic.item.ItemBloodOrb;
import WayofTime.bloodmagic.item.ItemBucketEssence;
import WayofTime.bloodmagic.item.ItemComponent;
import WayofTime.bloodmagic.item.ItemInscriptionTool;
import WayofTime.bloodmagic.item.ItemSacrificialDagger;
import WayofTime.bloodmagic.item.ItemSlate;
import WayofTime.bloodmagic.item.*;
import WayofTime.bloodmagic.item.armour.ItemLivingArmour;
import WayofTime.bloodmagic.item.gear.ItemPackSacrifice;
import WayofTime.bloodmagic.item.gear.ItemPackSelfSacrifice;
import WayofTime.bloodmagic.item.sigil.ItemSigilAir;
import WayofTime.bloodmagic.item.sigil.ItemSigilBloodLight;
import WayofTime.bloodmagic.item.sigil.ItemSigilDivination;
import WayofTime.bloodmagic.item.sigil.ItemSigilElementalAffinity;
import WayofTime.bloodmagic.item.sigil.ItemSigilFastMiner;
import WayofTime.bloodmagic.item.sigil.ItemSigilGreenGrove;
import WayofTime.bloodmagic.item.sigil.ItemSigilHaste;
import WayofTime.bloodmagic.item.sigil.ItemSigilLava;
import WayofTime.bloodmagic.item.sigil.ItemSigilMagnetism;
import WayofTime.bloodmagic.item.sigil.ItemSigilPhantomBridge;
import WayofTime.bloodmagic.item.sigil.ItemSigilSeer;
import WayofTime.bloodmagic.item.sigil.ItemSigilSuppression;
import WayofTime.bloodmagic.item.sigil.ItemSigilVoid;
import WayofTime.bloodmagic.item.sigil.ItemSigilWater;
import WayofTime.bloodmagic.item.sigil.*;
import WayofTime.bloodmagic.util.helper.InventoryRenderHelper;
public class ModItems {
@ -53,6 +33,7 @@ public class ModItems {
public static Item sacrificialDagger;
public static Item packSelfSacrifice;
public static Item packSacrifice;
public static Item daggerOfSacrifice;
public static Item sigilDivination;
public static Item sigilAir;
@ -68,7 +49,7 @@ public class ModItems {
public static Item sigilFastMiner;
public static Item sigilSeer;
public static Item sigilEnderSeverance;
public static Item sigilHurricane;
public static Item sigilWhirlwind;
public static Item sigilPhantomBridge;
public static Item sigilCompression;
@ -105,6 +86,7 @@ public class ModItems {
sacrificialDagger = registerItem(new ItemSacrificialDagger());
packSacrifice = registerItem(new ItemPackSacrifice());
packSelfSacrifice = registerItem(new ItemPackSelfSacrifice());
daggerOfSacrifice = registerItem(new ItemDaggerOfSacrifice());
sigilDivination = registerItem(new ItemSigilDivination());
sigilAir = registerItem(new ItemSigilAir());
@ -120,6 +102,9 @@ public class ModItems {
sigilFastMiner = registerItem(new ItemSigilFastMiner());
sigilSeer = registerItem(new ItemSigilSeer());
sigilPhantomBridge = registerItem(new ItemSigilPhantomBridge());
sigilWhirlwind = registerItem(new ItemSigilWhirlwind());
sigilCompression = registerItem(new ItemSigilCompression());
sigilEnderSeverance = registerItem(new ItemSigilEnderSeverance());
itemComponent = registerItem(new ItemComponent());
@ -165,6 +150,7 @@ public class ModItems {
renderHelper.itemRender(sacrificialDagger, 1);
renderHelper.itemRender(packSacrifice);
renderHelper.itemRender(packSelfSacrifice);
renderHelper.itemRender(daggerOfSacrifice);
renderHelper.itemRender(sigilDivination);
renderHelper.itemRender(sigilAir);
@ -187,6 +173,12 @@ public class ModItems {
renderHelper.itemRender(sigilSeer);
renderHelper.itemRender(sigilPhantomBridge, 0);
renderHelper.itemRender(sigilPhantomBridge, 1);
renderHelper.itemRender(sigilWhirlwind, 0);
renderHelper.itemRender(sigilWhirlwind, 1);
renderHelper.itemRender(sigilCompression, 0);
renderHelper.itemRender(sigilCompression, 1);
renderHelper.itemRender(sigilEnderSeverance, 0);
renderHelper.itemRender(sigilEnderSeverance, 1);
for(int i = 0 ; i < ItemComponent.getNames().size() ; i++)
renderHelper.itemRender(itemComponent, i);

View file

@ -14,6 +14,8 @@ public class ModPotions {
public static Potion drowning;
public static Potion boost;
public static Potion heavyHeart;
public static Potion whirlwind;
public static Potion planarBinding;
public static void init() {
if (Potion.potionTypes.length < 256) extendPortionArray();
@ -25,9 +27,11 @@ public class ModPotions {
// final String resourceLocation = Constants.Mod.MODID + ":textures/potions/";
// drowning = new PotionBloodMagic("Drowning", new ResourceLocation(resourceLocation + drowning.getName().toLowerCase()), true, 0, 0, 0);
boost = new PotionBloodMagic("Boost", new ResourceLocation("Minecraft:textures/gui/container/inventory.png")
boost = new PotionBloodMagic("Boost", new ResourceLocation("boost")
// new ResourceLocation(resourceLocation + boost.getName().toLowerCase())
, false, 0, 0, 0);
whirlwind = new PotionBloodMagic("Whirlwind", new ResourceLocation("whirlwind"), false, 0, 0, 0);
planarBinding = new PotionBloodMagic("Planar Binding", new ResourceLocation("planarBinding"), false, 0, 0, 0);
// heavyHeart = new PotionBloodMagic("Heavy Heart", new ResourceLocation(resourceLocation + heavyHeart.getName().toLowerCase()), true, 0, 0, 0);
}

View file

@ -1,6 +1,10 @@
package WayofTime.bloodmagic.registry;
import WayofTime.bloodmagic.item.ItemComponent;
import WayofTime.bloodmagic.api.compress.CompressionRegistry;
import WayofTime.bloodmagic.compress.AdvancedCompressionHandler;
import WayofTime.bloodmagic.compress.BaseCompressionHandler;
import WayofTime.bloodmagic.compress.StorageBlockCraftingManager;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
@ -61,4 +65,13 @@ public class ModRecipes {
AlchemyArrayRecipeRegistry.registerCraftingRecipe(ItemComponent.getStack(ItemComponent.REAGENT_AFFINITY), new ItemStack(ModItems.slate, 1, 2), new ItemStack(ModItems.sigilElementalAffinity), new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/ElementalAffinitySigil.png"));
AlchemyArrayRecipeRegistry.registerCraftingRecipe(ItemComponent.getStack(ItemComponent.REAGENT_SIGHT), new ItemStack(ModItems.slate, 1, 1), new ItemStack(ModItems.sigilSeer), new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/SightSigil.png"));
}
public static void addCompressionHandlers() {
StorageBlockCraftingManager.getInstance().addStorageBlockRecipes();
CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.glowstone_dust, 4, 0), new ItemStack(Blocks.glowstone), 64));
CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.snowball, 4, 0), new ItemStack(Blocks.snow), 8));
CompressionRegistry.registerHandler(new AdvancedCompressionHandler());
CompressionRegistry.registerItemThreshold(new ItemStack(Blocks.cobblestone), 64);
}
}

View file

@ -1,10 +1,5 @@
{
"variants": {
"normal": {
"model": "bloodmagic:BlockPhantom",
"textures": {
"all": "bloodmagic:blocks/PhantomBlock"
}
}
"normal": { "model": "bloodmagic:BlockPhantom" }
}
}

View file

@ -10,6 +10,7 @@ item.BloodMagic.sacrificialDagger.normal.name=Sacrificial Dagger
item.BloodMagic.sacrificialDagger.creative.name=Creative Sacrificial Dagger
item.BloodMagic.pack.selfSacrifice.name=Blood Letter's Pack
item.BloodMagic.pack.sacrifice.name=Coat of Arms
item.BloodMagic.daggerOfSacrifice.name=Dagger of Sacrifice
item.BloodMagic.bucket.lifeEssence.name=Bucket of Life
@ -83,6 +84,8 @@ item.BloodMagic.sigil.magnetism.name=Sigil of Magnetism
item.BloodMagic.sigil.fastMiner.name=Sigil of the Fast Miner
item.BloodMagic.sigil.seer.name=Seer's Sigil
item.BloodMagic.sigil.phantomBridge.name=Sigil of the Phantom Bridge
item.BloodMagic.sigil.whirlwind.name=Sigil of the Whirlwind
item.BloodMagic.sigil.enderSeverance.name=Sigil of Ender Severance
item.BloodMagic.altarMaker.name=Altar Maker
@ -129,7 +132,7 @@ tooltip.BloodMagic.deactivated=Deactivated
tooltip.BloodMagic.sigil.air.desc=&oI feel lighter already...
tooltip.BloodMagic.sigil.bloodLight.desc=&oI see a light!
tooltip.BloodMagic.sigil.compression.desc=&oHands of Diamonds
tooltip.BloodMagic.sigil.compression.desc=&oHands of diamonds
tooltip.BloodMagic.sigil.divination.desc=&oPeer into the soul
tooltip.BloodMagic.sigil.divination.currentAltarTier=Current Tier: %d
tooltip.BloodMagic.sigil.divination.currentEssence=Current Essence: %d LP
@ -149,7 +152,9 @@ tooltip.BloodMagic.sigil.seer.currentAltarConsumptionRate=Consumption Rate: %d L
tooltip.BloodMagic.sigil.seer.currentAltarTier=Current Tier: %d
tooltip.BloodMagic.sigil.seer.currentEssence=Current Essence: %d LP
tooltip.BloodMagic.sigil.seer.currentAltarCapacity=Current Capacity: %d LP
tooltip.BloodMagic.sigil.phantomBridge.desc=Walking in thin air...
tooltip.BloodMagic.sigil.phantomBridge.desc=&oWalking on thin air...
tooltip.BloodMagic.sigil.whirlwind.desc=&oBest not to wear a skirt
tooltip.BloodMagic.sigil.enderSeverance.desc=&oPutting Endermen in Dire situations!
tooltip.BloodMagic.sacrificialDagger.desc=Just a prick of the finger will suffice...
tooltip.BloodMagic.slate.desc=Infused stone inside of a Blood Altar

View file

@ -0,0 +1,6 @@
{
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/DaggerOfSacrifice"
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/SigilOfSeverance_deactivated"
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/SigilOfSeverance_activated"
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/WindSigil_deactivated"
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/WindSigil_activated"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 792 B

After

Width:  |  Height:  |  Size: 767 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 645 B