Reorganized the AlchemyArrayEffects so it is easier to make more unique arrays. Also fixed an NPE when crafting sigils.

This commit is contained in:
WayofTime 2016-06-27 11:21:37 -04:00
parent 587e94d197
commit c5f0333aac
6 changed files with 138 additions and 25 deletions

View file

@ -6,6 +6,7 @@ import lombok.Getter;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -15,8 +16,9 @@ public class AlchemyArrayEffectBinding extends AlchemyArrayEffect
@Getter
public final ItemStack outputStack;
public AlchemyArrayEffectBinding(ItemStack outputStack)
public AlchemyArrayEffectBinding(String key, ItemStack outputStack)
{
super(key);
this.outputStack = outputStack;
}
@ -65,4 +67,22 @@ public class AlchemyArrayEffectBinding extends AlchemyArrayEffect
world.spawnEntityInWorld(lightning);
}
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
//EMPTY
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
//EMPTY
}
@Override
public AlchemyArrayEffect getNewCopy()
{
return new AlchemyArrayEffectBinding(key, outputStack);
}
}

View file

@ -1,8 +1,21 @@
package WayofTime.bloodmagic.api.alchemyCrafting;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@RequiredArgsConstructor
public abstract class AlchemyArrayEffect
{
@Getter
public final String key;
public abstract boolean update(TileEntity tile, int ticksActive);
public abstract void writeToNBT(NBTTagCompound tag);
public abstract void readFromNBT(NBTTagCompound tag);
public abstract AlchemyArrayEffect getNewCopy();
}

View file

@ -3,6 +3,7 @@ package WayofTime.bloodmagic.api.alchemyCrafting;
import lombok.Getter;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
@ -19,6 +20,12 @@ public class AlchemyArrayEffectCrafting extends AlchemyArrayEffect
public AlchemyArrayEffectCrafting(ItemStack outputStack, int tickLimit)
{
this(outputStack.toString() + tickLimit, outputStack, tickLimit);
}
public AlchemyArrayEffectCrafting(String key, ItemStack outputStack, int tickLimit)
{
super(key);
this.outputStack = outputStack;
this.tickLimit = tickLimit;
}
@ -37,7 +44,7 @@ public class AlchemyArrayEffectCrafting extends AlchemyArrayEffect
BlockPos pos = tile.getPos();
ItemStack output = outputStack.copy();
output.onCrafting(tile.getWorld(), null, output.stackSize);
EntityItem outputEntity = new EntityItem(tile.getWorld(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, output);
tile.getWorld().spawnEntityInWorld(outputEntity);
@ -47,4 +54,22 @@ public class AlchemyArrayEffectCrafting extends AlchemyArrayEffect
return false;
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
}
@Override
public AlchemyArrayEffect getNewCopy()
{
return new AlchemyArrayEffectCrafting(key, outputStack, tickLimit);
}
}

View file

@ -1,28 +1,32 @@
package WayofTime.bloodmagic.api.registry;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffectCrafting;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyCircleRenderer;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.oredict.OreDictionary;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffectCrafting;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyCircleRenderer;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
public class AlchemyArrayRecipeRegistry
{
public static final AlchemyCircleRenderer defaultRenderer = new AlchemyCircleRenderer(new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/BaseArray.png"));
private static BiMap<List<ItemStack>, AlchemyArrayRecipe> recipes = HashBiMap.create();
private static HashMap<String, AlchemyArrayEffect> effectMap = new HashMap<String, AlchemyArrayEffect>();
/**
* General case for creating an AlchemyArrayEffect for a given input.
@ -41,6 +45,8 @@ public class AlchemyArrayRecipeRegistry
*/
public static void registerRecipe(List<ItemStack> input, @Nullable ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer)
{
effectMap.put(arrayEffect.getKey(), arrayEffect);
for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet())
{
AlchemyArrayRecipe arrayRecipe = entry.getValue();
@ -67,8 +73,11 @@ public class AlchemyArrayRecipeRegistry
{
recipes.put(input, new AlchemyArrayRecipe(input, catalystStack, arrayEffect, circleRenderer));
}
}
recipes.put(input, new AlchemyArrayRecipe(input, catalystStack, arrayEffect, circleRenderer));
public static AlchemyArrayEffect getAlchemyArrayEffect(String key)
{
return effectMap.get(key);
}
public static void registerCraftingRecipe(ItemStack input, ItemStack catalystStack, ItemStack outputStack, ResourceLocation arrayResource)

View file

@ -194,14 +194,14 @@ public class ModRecipes
public static void addAlchemyArrayRecipes()
{
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.DIAMOND_SWORD), new AlchemyArrayEffectBinding(Utils.setUnbreakable(new ItemStack(ModItems.boundSword))), new BindingAlchemyCircleRenderer());
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.DIAMOND_AXE), new AlchemyArrayEffectBinding(Utils.setUnbreakable(new ItemStack(ModItems.boundAxe))));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.DIAMOND_PICKAXE), new AlchemyArrayEffectBinding(Utils.setUnbreakable(new ItemStack(ModItems.boundPickaxe))));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.DIAMOND_SHOVEL), new AlchemyArrayEffectBinding(Utils.setUnbreakable(new ItemStack(ModItems.boundShovel))));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.IRON_HELMET), new AlchemyArrayEffectBinding(new ItemStack(ModItems.livingArmourHelmet)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.IRON_CHESTPLATE), new AlchemyArrayEffectBinding(new ItemStack(ModItems.livingArmourChest)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.IRON_LEGGINGS), new AlchemyArrayEffectBinding(new ItemStack(ModItems.livingArmourLegs)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.IRON_BOOTS), new AlchemyArrayEffectBinding(new ItemStack(ModItems.livingArmourBoots)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.DIAMOND_SWORD), new AlchemyArrayEffectBinding("boundSword", Utils.setUnbreakable(new ItemStack(ModItems.boundSword))), new BindingAlchemyCircleRenderer());
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.DIAMOND_AXE), new AlchemyArrayEffectBinding("boundAxe", Utils.setUnbreakable(new ItemStack(ModItems.boundAxe))));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.DIAMOND_PICKAXE), new AlchemyArrayEffectBinding("boundPickaxe", Utils.setUnbreakable(new ItemStack(ModItems.boundPickaxe))));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.DIAMOND_SHOVEL), new AlchemyArrayEffectBinding("boundShovel", Utils.setUnbreakable(new ItemStack(ModItems.boundShovel))));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.IRON_HELMET), new AlchemyArrayEffectBinding("livingHelmet", new ItemStack(ModItems.livingArmourHelmet)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.IRON_CHESTPLATE), new AlchemyArrayEffectBinding("livingChest", new ItemStack(ModItems.livingArmourChest)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.IRON_LEGGINGS), new AlchemyArrayEffectBinding("livingLegs", new ItemStack(ModItems.livingArmourLegs)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.IRON_BOOTS), new AlchemyArrayEffectBinding("livingBoots", new ItemStack(ModItems.livingArmourBoots)));
AlchemyArrayRecipeRegistry.registerCraftingRecipe(new ItemStack(Items.REDSTONE), new ItemStack(ModItems.slate), new ItemStack(ModItems.sigilDivination), new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/DivinationSigil.png"));

View file

@ -1,18 +1,20 @@
package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.util.ITickable;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
public class TileAlchemyArray extends TileInventory implements ITickable
{
public boolean isActive = false;
public int activeCounter = 0;
private String key = "";
private AlchemyArrayEffect arrayEffect;
public TileAlchemyArray()
{
super(2, "alchemyArray");
@ -24,6 +26,14 @@ public class TileAlchemyArray extends TileInventory implements ITickable
super.readFromNBT(tagCompound);
this.isActive = tagCompound.getBoolean("isActive");
this.activeCounter = tagCompound.getInteger("activeCounter");
this.key = tagCompound.getString("key");
NBTTagCompound arrayTag = tagCompound.getCompoundTag("arrayTag");
arrayEffect = AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(key);
if (arrayEffect != null)
{
arrayEffect.readFromNBT(arrayTag);
}
}
@Override
@ -32,6 +42,15 @@ public class TileAlchemyArray extends TileInventory implements ITickable
super.writeToNBT(tagCompound);
tagCompound.setBoolean("isActive", isActive);
tagCompound.setInteger("activeCounter", activeCounter);
tagCompound.setString("key", key);
NBTTagCompound arrayTag = new NBTTagCompound();
if (arrayEffect != null)
{
arrayEffect.writeToNBT(arrayTag);
}
tagCompound.setTag("arrayTag", arrayTag);
return tagCompound;
}
@ -51,6 +70,8 @@ public class TileAlchemyArray extends TileInventory implements ITickable
{
isActive = false;
activeCounter = 0;
arrayEffect = null;
key = null;
}
}
@ -58,10 +79,35 @@ public class TileAlchemyArray extends TileInventory implements ITickable
{
AlchemyArrayEffect effect = AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(this.getStackInSlot(0), this.getStackInSlot(1));
if (effect != null)
{
if (arrayEffect == null)
{
arrayEffect = effect;
key = effect.getKey();
} else
{
String effectKey = effect.getKey();
if (effectKey.equals(key))
{
//Good! Moving on.
} else
{
//Something has changed, therefore we have to move our stuffs.
//TODO: Add an AlchemyArrayEffect.onBreak(); ?
arrayEffect = effect;
key = effect.getKey();
}
}
} else
{
return false;
}
if (arrayEffect != null)
{
isActive = true;
if (effect.update(this, this.activeCounter))
if (arrayEffect.update(this, this.activeCounter))
{
this.decrStackSize(0, 1);
this.decrStackSize(1, 1);