Finished non-rendering components for the Soul Forge.

This commit is contained in:
WayofTime 2016-01-08 10:27:26 -05:00
parent 7b8646659a
commit 16a50f7144
6 changed files with 131 additions and 15 deletions

View file

@ -78,6 +78,9 @@ public class Constants
public static final String SOULS = "souls";
public static final String SOUL_SWORD_DAMAGE = "soulSwordDamage";
public static final String SOUL_SWORD_ACTIVE_DRAIN = "soulSwordActiveDrain";
public static final String SOUL_FORGE_BURN = "burnTime";
public static final String SOUL_FORGE_CONSUMED = "consumedSouls";
}
public static class Mod

View file

@ -34,6 +34,8 @@ public class SoulForgeRecipe
public SoulForgeRecipe(ItemStack result, double minSouls, double drain, Object... recipe)
{
output = result.copy();
this.minimumSouls = minSouls;
this.soulsDrained = drain;
for (Object in : recipe)
{
if (in instanceof ItemStack)
@ -71,7 +73,7 @@ public class SoulForgeRecipe
public ItemStack getRecipeOutput()
{
return output;
return output.copy();
}
/**

View file

@ -8,15 +8,19 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.tile.TileSoulForge;
import WayofTime.bloodmagic.tile.container.ContainerSoulForge;
import WayofTime.bloodmagic.util.helper.TextHelper;
@SideOnly(Side.CLIENT)
public class GuiSoulForge extends GuiContainer
{
public GuiSoulForge(InventoryPlayer playerInventory, IInventory tileTeleposer)
public IInventory tileSoulForge;
public GuiSoulForge(InventoryPlayer playerInventory, IInventory tileSoulForge)
{
super(new ContainerSoulForge(playerInventory, tileTeleposer));
super(new ContainerSoulForge(playerInventory, tileSoulForge));
this.tileSoulForge = tileSoulForge;
this.xSize = 176;
this.ySize = 205;
}
@ -44,7 +48,7 @@ public class GuiSoulForge extends GuiContainer
public int getCookProgressScaled(int scale)
{
double progress = 0.5;
double progress = ((TileSoulForge) tileSoulForge).getProgressForGui();
return (int) (progress * scale);
}
}

View file

@ -17,6 +17,7 @@ import WayofTime.bloodmagic.api.recipe.ShapelessBloodOrbRecipe;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry;
import WayofTime.bloodmagic.api.registry.OrbRegistry;
import WayofTime.bloodmagic.api.registry.SoulForgeRecipeRegistry;
import WayofTime.bloodmagic.api.ritual.EnumRuneType;
import WayofTime.bloodmagic.client.render.alchemyArray.BindingAlchemyCircleRenderer;
import WayofTime.bloodmagic.compress.AdvancedCompressionHandler;
@ -34,6 +35,7 @@ public class ModRecipes
addCraftingRecipes();
addAltarRecipes();
addAlchemyArrayRecipes();
addSoulForgeRecipes();
}
public static void addCraftingRecipes()
@ -155,4 +157,9 @@ public class ModRecipes
CompressionRegistry.registerItemThreshold(new ItemStack(Blocks.cobblestone), 64);
}
public static void addSoulForgeRecipes()
{
SoulForgeRecipeRegistry.registerRecipe(new ItemStack(Items.diamond), 1, 0.5, new ItemStack(Items.redstone), new ItemStack(Items.redstone), new ItemStack(Items.redstone));
}
}

View file

@ -6,6 +6,7 @@ import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ITickable;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.recipe.SoulForgeRecipe;
import WayofTime.bloodmagic.api.registry.SoulForgeRecipeRegistry;
import WayofTime.bloodmagic.api.soul.ISoul;
@ -13,26 +14,34 @@ import WayofTime.bloodmagic.api.soul.ISoulGem;
public class TileSoulForge extends TileInventory implements ITickable
{
public static final int ticksRequired = 100;
public static final int soulSlot = 4;
public static final int outputSlot = 5;
//Input slots are from 0 to 3.
public int burnTime = 0;
public TileSoulForge()
{
super(6, "soulForge");
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tagCompound);
super.readFromNBT(tag);
burnTime = tag.getInteger(Constants.NBT.SOUL_FORGE_BURN);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tagCompound);
super.writeToNBT(tag);
tag.setInteger(Constants.NBT.SOUL_FORGE_BURN, burnTime);
}
@Override
@ -40,6 +49,7 @@ public class TileSoulForge extends TileInventory implements ITickable
{
if (!hasSoulGemOrSoul())
{
burnTime = 0;
return;
}
@ -56,20 +66,82 @@ public class TileSoulForge extends TileInventory implements ITickable
}
SoulForgeRecipe recipe = SoulForgeRecipeRegistry.getMatchingRecipe(inputList, getWorld(), getPos());
if (recipe != null && recipe.getMinimumSouls() <= soulsInGem)
if (recipe != null && (soulsInGem >= recipe.getMinimumSouls() || burnTime > 0))
{
ItemStack outputStack = recipe.getRecipeOutput();
if (getStackInSlot(outputSlot) == null)
if (canCraft(recipe))
{
setInventorySlotContents(outputSlot, outputStack);
consumeInventory();
burnTime++;
if (burnTime == ticksRequired)
{
if (!worldObj.isRemote)
{
double requiredSouls = recipe.getSoulsDrained();
if (requiredSouls > 0)
{
consumeSouls(requiredSouls);
}
craftItem(recipe);
}
burnTime = 0;
} else if (burnTime > ticksRequired + 10)
{
burnTime = 0;
}
} else
{
burnTime = 0;
}
}
}
public double getProgressForGui()
{
return ((double) burnTime) / ticksRequired;
}
private boolean canCraft(SoulForgeRecipe recipe)
{
if (recipe == null)
{
return false;
}
ItemStack outputStack = recipe.getRecipeOutput();
ItemStack currentOutputStack = getStackInSlot(outputSlot);
if (outputStack == null)
return false;
if (currentOutputStack == null)
return true;
if (!currentOutputStack.isItemEqual(outputStack))
return false;
int result = currentOutputStack.stackSize + outputStack.stackSize;
return result <= getInventoryStackLimit() && result <= currentOutputStack.getMaxStackSize();
}
public void craftItem(SoulForgeRecipe recipe)
{
if (this.canCraft(recipe))
{
ItemStack outputStack = recipe.getRecipeOutput();
ItemStack currentOutputStack = getStackInSlot(outputSlot);
if (currentOutputStack == null)
{
setInventorySlotContents(outputSlot, outputStack);
} else if (currentOutputStack.getItem() == currentOutputStack.getItem())
{
currentOutputStack.stackSize += outputStack.stackSize;
}
consumeInventory();
}
}
public boolean hasSoulGemOrSoul()
{
ItemStack soulStack = getStackInSlot(soulSlot);
@ -107,6 +179,34 @@ public class TileSoulForge extends TileInventory implements ITickable
return 0;
}
public double consumeSouls(double requested)
{
ItemStack soulStack = getStackInSlot(soulSlot);
if (soulStack != null)
{
if (soulStack.getItem() instanceof ISoul)
{
ISoul soul = (ISoul) soulStack.getItem();
double souls = soul.drainSouls(soulStack, requested);
if (soul.getSouls(soulStack) <= 0)
{
setInventorySlotContents(soulSlot, null);
}
return souls;
}
if (soulStack.getItem() instanceof ISoulGem)
{
System.out.println("Test");
ISoulGem soul = (ISoulGem) soulStack.getItem();
return soul.drainSouls(soulStack, requested);
}
}
return 0;
}
public void consumeInventory()
{
for (int i = 0; i < 4; i++)

View file

@ -149,7 +149,7 @@ tile.BloodMagic.spectralBlock.name=Spectral Block
tile.BloodMagic.phantomBlock.name=Phantom Block
tile.BloodMagic.teleposer.name=Teleposer
tile.BloodMagic.soulforge.name=Soul Forge
tile.BloodMagic.soulForge.name=Soul Forge
# Tooltips
tooltip.BloodMagic.orb.desc=Stores raw Life Essence