diff --git a/changelog.txt b/changelog.txt index 94e7b910..33c2f1e4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +------------------------------------------------------ +Version 2.0.0-36 +------------------------------------------------------ + + ------------------------------------------------------ Version 2.0.0-35 ------------------------------------------------------ diff --git a/src/main/java/WayofTime/bloodmagic/client/gui/GuiAlchemyTable.java b/src/main/java/WayofTime/bloodmagic/client/gui/GuiAlchemyTable.java index a66fd555..a9c3d23d 100644 --- a/src/main/java/WayofTime/bloodmagic/client/gui/GuiAlchemyTable.java +++ b/src/main/java/WayofTime/bloodmagic/client/gui/GuiAlchemyTable.java @@ -8,6 +8,7 @@ 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.TileAlchemyTable; import WayofTime.bloodmagic.tile.container.ContainerAlchemyTable; import WayofTime.bloodmagic.util.helper.TextHelper; @@ -47,8 +48,7 @@ public class GuiAlchemyTable extends GuiContainer public int getCookProgressScaled(int scale) { -// double progress = ((TileAlchemyTable) tileTable).getProgressForGui(); -// return (int) (progress * scale); - return scale / 2; + double progress = ((TileAlchemyTable) tileTable).getProgressForGui(); + return (int) (progress * scale); } } diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java index 24ebd972..f855ba91 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java @@ -8,6 +8,7 @@ import WayofTime.bloodmagic.api.compress.CompressionRegistry; import WayofTime.bloodmagic.api.recipe.ShapedBloodOrbRecipe; import WayofTime.bloodmagic.api.recipe.ShapelessBloodOrbRecipe; import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry; +import WayofTime.bloodmagic.api.registry.AlchemyTableRecipeRegistry; import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry; import WayofTime.bloodmagic.api.registry.OrbRegistry; import WayofTime.bloodmagic.api.registry.TartaricForgeRecipeRegistry; @@ -20,7 +21,9 @@ import WayofTime.bloodmagic.compress.StorageBlockCraftingManager; import WayofTime.bloodmagic.item.ItemComponent; import WayofTime.bloodmagic.item.ItemDemonCrystal; import WayofTime.bloodmagic.item.soul.ItemSoulGem; + import com.google.common.base.Stopwatch; + import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -41,6 +44,7 @@ public class ModRecipes addAltarRecipes(); addAlchemyArrayRecipes(); addSoulForgeRecipes(); + addAlchemyTableRecipes(); } public static void addCraftingRecipes() @@ -252,4 +256,9 @@ public class ModRecipes TartaricForgeRecipeRegistry.registerRecipe(new ItemStack(ModBlocks.demonPylon), 400, 50, "blockIron", "stone", "gemLapis", ModItems.itemDemonCrystal); TartaricForgeRecipeRegistry.registerRecipe(new ItemStack(ModBlocks.demonCrystallizer), 500, 100, ModBlocks.soulForge, "stone", "gemLapis", "blockGlass"); } + + public static void addAlchemyTableRecipes() + { + AlchemyTableRecipeRegistry.registerRecipe(new ItemStack(Items.STRING, 4), 0, 100, 0, Blocks.WOOL); + } } diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java b/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java index 049287a4..afb8cca8 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java @@ -1,13 +1,28 @@ package WayofTime.bloodmagic.tile; +import java.util.ArrayList; +import java.util.List; + import lombok.Getter; +import net.minecraft.block.state.IBlockState; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.wrapper.SidedInvWrapper; import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.network.SoulNetwork; +import WayofTime.bloodmagic.api.orb.IBloodOrb; +import WayofTime.bloodmagic.api.recipe.AlchemyTableRecipe; +import WayofTime.bloodmagic.api.registry.AlchemyTableRecipeRegistry; +import WayofTime.bloodmagic.api.util.helper.NetworkHelper; + +import com.google.common.base.Strings; @Getter public class TileAlchemyTable extends TileInventory implements ISidedInventory, ITickable @@ -18,6 +33,8 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, public EnumFacing direction = EnumFacing.NORTH; public boolean isSlave = false; + public int burnTime = 0; + public int ticksRequired = 1; public BlockPos connectedPos = BlockPos.ORIGIN; @@ -50,6 +67,9 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, isSlave = tag.getBoolean("isSlave"); direction = EnumFacing.getFront(tag.getInteger(Constants.NBT.DIRECTION)); connectedPos = new BlockPos(tag.getInteger(Constants.NBT.X_COORD), tag.getInteger(Constants.NBT.Y_COORD), tag.getInteger(Constants.NBT.Z_COORD)); + + burnTime = tag.getInteger("burnTime"); + ticksRequired = tag.getInteger("ticksRequired"); } @Override @@ -62,6 +82,31 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, tag.setInteger(Constants.NBT.X_COORD, connectedPos.getX()); tag.setInteger(Constants.NBT.Y_COORD, connectedPos.getY()); tag.setInteger(Constants.NBT.Z_COORD, connectedPos.getZ()); + + tag.setInteger("burnTime", burnTime); + tag.setInteger("ticksRequired", ticksRequired); + } + + @SuppressWarnings("unchecked") + @Override + public T getCapability(Capability capability, EnumFacing facing) + { + if (facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) + { + if (this.isSlave()) + { + TileEntity tile = worldObj.getTileEntity(connectedPos); + if (tile instanceof TileAlchemyTable) + { + return (T) new SidedInvWrapper((TileAlchemyTable) tile, facing); + } + } else + { + return (T) new SidedInvWrapper(this, facing); + } + } + + return super.getCapability(capability, facing); } @Override @@ -71,20 +116,237 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, } @Override - public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) + public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction) { + switch (direction) + { + case DOWN: + return index != outputSlot && index != orbSlot && index != toolSlot; + default: + break; + } return false; } @Override public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) { - return false; + switch (direction) + { + case DOWN: + return index == outputSlot; +// case EAST: +// break; +// case NORTH: +// break; +// case SOUTH: +// break; +// case UP: +// break; +// case WEST: +// break; + default: + return false; + } } @Override public void update() { - //TODO: Stuff and things + if (isSlave()) + { + return; + } + + List inputList = new ArrayList(); + + for (int i = 0; i < 6; i++) + { + if (getStackInSlot(i) != null) + { + inputList.add(getStackInSlot(i)); + } + } + + int tier = getTierOfOrb(); + + AlchemyTableRecipe recipe = AlchemyTableRecipeRegistry.getMatchingRecipe(inputList, getWorld(), getPos()); + if (recipe != null && (burnTime > 0 || (!worldObj.isRemote && tier >= recipe.getTierRequired() && this.getContainedLp() >= recipe.getLpDrained()))) + { + if (burnTime == 1) + { + IBlockState state = worldObj.getBlockState(pos); + worldObj.notifyBlockUpdate(getPos(), state, state, 3); + } + + if (canCraft(recipe)) + { + ticksRequired = recipe.getTicksRequired(); + burnTime++; + + if (burnTime == ticksRequired) + { + if (!worldObj.isRemote) + { + int requiredLp = recipe.getLpDrained(); + if (requiredLp > 0) + { + if (!worldObj.isRemote) + { + consumeLp(requiredLp); + } + } + + if (!worldObj.isRemote) + { + craftItem(recipe); + } + } + + burnTime = 0; + + IBlockState state = worldObj.getBlockState(pos); + worldObj.notifyBlockUpdate(getPos(), state, state, 3); + } else if (burnTime > ticksRequired + 10) + { + burnTime = 0; + } + } else + { + burnTime = 0; + } + } else + { + burnTime = 0; + } + } + + public double getProgressForGui() + { + return ((double) burnTime) / ticksRequired; + } + + private boolean canCraft(AlchemyTableRecipe 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 int getTierOfOrb() + { + ItemStack orbStack = getStackInSlot(orbSlot); + if (orbStack != null) + { + if (orbStack.getItem() instanceof IBloodOrb) + { + return ((IBloodOrb) orbStack.getItem()).getOrbLevel(orbStack.getMetadata()); + } + } + + return 0; + } + + public int getContainedLp() + { + ItemStack orbStack = getStackInSlot(orbSlot); + if (orbStack != null) + { + if (orbStack.getItem() instanceof IBloodOrb) + { + NBTTagCompound itemTag = orbStack.getTagCompound(); + + if (itemTag == null) + { + return 0; + } + + String ownerUUID = itemTag.getString(Constants.NBT.OWNER_UUID); + + if (Strings.isNullOrEmpty(ownerUUID)) + { + return 0; + } + + SoulNetwork network = NetworkHelper.getSoulNetwork(ownerUUID); + + return network.getCurrentEssence(); + } + } + + return 0; + } + + public void craftItem(AlchemyTableRecipe 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 int consumeLp(int requested) + { + ItemStack orbStack = getStackInSlot(orbSlot); + + if (orbStack != null) + { + if (orbStack.getItem() instanceof IBloodOrb) + { + if (NetworkHelper.syphonFromContainer(orbStack, requested)) + { + return requested; + } + } + } + + return 0; + } + + public void consumeInventory() + { + for (int i = 0; i < 6; i++) + { + ItemStack inputStack = getStackInSlot(i); + if (inputStack != null) + { + if (inputStack.getItem().hasContainerItem(inputStack)) + { + setInventorySlotContents(i, inputStack.getItem().getContainerItem(inputStack)); + continue; + } + + inputStack.stackSize--; + if (inputStack.stackSize <= 0) + { + setInventorySlotContents(i, null); + continue; + } + } + } } }