Skip to content

Commit

Permalink
Blood Amulet can be filled in machines
Browse files Browse the repository at this point in the history
  • Loading branch information
Tombenpotter committed Nov 16, 2014
1 parent 9b94753 commit b0e0a96
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 42 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Fixed portal orientations.
Added a sanguimancy folder to the world save.
Improved the Quarry ritual a lot. It is instant, but it works a lot better and costs a lot more. By default you don't get the items mined.
Fixed the Chunkloading log not getting generated if the sanguimancy folder already existed.
Modifications to the Blood Amulet. Can now be filled in machines.

Version 1.1.8-Pre9:
Fixed a world crashing bug with portals.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidContainerRegistry;
import tombenpotter.sanguimancy.Sanguimancy;
import tombenpotter.sanguimancy.tile.TileLumpCleaner;
import tombenpotter.sanguimancy.tile.TileBloodCleaner;
import tombenpotter.sanguimancy.util.RandomUtils;

public class BlockLumpCleaner extends BlockContainer {
Expand All @@ -41,7 +41,7 @@ public void registerBlockIcons(IIconRegister ir) {

@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileLumpCleaner();
return new TileBloodCleaner();
}

@Override
Expand All @@ -53,7 +53,7 @@ public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
TileLumpCleaner fluidHandler = (TileLumpCleaner) world.getTileEntity(x, y, z);
TileBloodCleaner fluidHandler = (TileBloodCleaner) world.getTileEntity(x, y, z);
if (RandomUtils.fillHandlerWithContainer(world, fluidHandler, player)) {
world.markBlockForUpdate(x, y, z);
return true;
Expand Down Expand Up @@ -89,8 +89,8 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase e
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess access, int x, int y, int z, int side) {
int meta = access.getBlockMetadata(x, y, z);
if (access.getTileEntity(x, y, z) != null && access.getTileEntity(x, y, z) instanceof TileLumpCleaner) {
TileLumpCleaner tile = (TileLumpCleaner) access.getTileEntity(x, y, z);
if (access.getTileEntity(x, y, z) != null && access.getTileEntity(x, y, z) instanceof TileBloodCleaner) {
TileBloodCleaner tile = (TileBloodCleaner) access.getTileEntity(x, y, z);
if (tile.isActive) {
return side == 1 ? this.topIcon : (side == 0 ? this.bottomIcon : (side != meta ? this.blockIcon : this.frontOnIcon));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import tombenpotter.sanguimancy.registry.ItemsRegistry;
import tombenpotter.sanguimancy.tile.TileLumpCleaner;
import tombenpotter.sanguimancy.tile.TileBloodCleaner;

public class ContainerLumpCleaner extends Container {

TileLumpCleaner tile;
TileBloodCleaner tile;

public ContainerLumpCleaner(EntityPlayer player, TileLumpCleaner entity) {
public ContainerLumpCleaner(EntityPlayer player, TileBloodCleaner entity) {
this.tile = entity;
createSlots(entity, player);
bindPlayerInventory(player.inventory);
Expand All @@ -30,7 +30,7 @@ public void bindPlayerInventory(InventoryPlayer inv) {
}
}

public void createSlots(TileLumpCleaner tile, EntityPlayer player) {
public void createSlots(TileBloodCleaner tile, EntityPlayer player) {
addSlotToContainer(new Slot(tile, 0, 52, 16));
addSlotToContainer(new SlotFurnace(player, tile, 1, 129, 34));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.lwjgl.opengl.GL11;
import tombenpotter.sanguimancy.Sanguimancy;
import tombenpotter.sanguimancy.container.ContainerLumpCleaner;
import tombenpotter.sanguimancy.tile.TileLumpCleaner;
import tombenpotter.sanguimancy.tile.TileBloodCleaner;

import java.util.ArrayList;

Expand All @@ -17,10 +17,10 @@ public class GuiLumpCleaner extends GuiContainer {
public static final ResourceLocation gui = new ResourceLocation(Sanguimancy.texturePath, "textures/gui/LumpCleaner.png");
@SuppressWarnings("unused")
public ContainerLumpCleaner container;
public TileLumpCleaner te;
public TileBloodCleaner te;
String containerName = "Ore Lump Cleaner";

public GuiLumpCleaner(EntityPlayer player, TileLumpCleaner tile) {
public GuiLumpCleaner(EntityPlayer player, TileBloodCleaner tile) {
super(new ContainerLumpCleaner(player, tile));
this.container = (ContainerLumpCleaner) this.inventorySlots;
this.te = tile;
Expand Down
104 changes: 83 additions & 21 deletions src/main/java/tombenpotter/sanguimancy/items/ItemBloodAmulet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tombenpotter.sanguimancy.items;

import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
Expand All @@ -9,20 +10,23 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import tombenpotter.sanguimancy.Sanguimancy;
import tombenpotter.sanguimancy.tile.TileBloodTank;
import tombenpotter.sanguimancy.util.RandomUtils;

import java.util.List;

public class ItemBloodAmulet extends Item {
public class ItemBloodAmulet extends Item implements IFluidContainerItem {

public int bloodLoss = 1200;

Expand Down Expand Up @@ -50,28 +54,20 @@ public void onUpdate(ItemStack stack, World world, Entity entity, int par4, bool
livingBase.motionY = 0;
livingBase.motionZ = 0;
livingBase.addPotionEffect(new PotionEffect(Potion.blindness.id, 100, 1));
stack.stackTagCompound.setInteger("blood", stack.stackTagCompound.getInteger("blood") - bloodLoss);
if (drain(stack, bloodLoss, false) != null) {
drain(stack, bloodLoss, true);
}
}
}
}
}

public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) {
if (!world.isRemote && addBloodAndDrainTank(stack, world, x, y, z)) {
return true;
}
return super.onItemUse(stack, player, world, x, y, z, par7, par8, par9, par10);
}

public boolean addBloodAndDrainTank(ItemStack stack, World world, int x, int y, int z) {
RandomUtils.checkAndSetCompound(stack);
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) {
if (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileBloodTank) {
TileBloodTank tile = (TileBloodTank) world.getTileEntity(x, y, z);
if (tile.tank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME) {
if (tile.tank.getFluid() != null && tile.tank.getFluid().fluidID == AlchemicalWizardry.lifeEssenceFluid.getID()) {
tile.drain(ForgeDirection.UNKNOWN, FluidContainerRegistry.BUCKET_VOLUME, true);
RandomUtils.checkAndSetCompound(stack);
stack.stackTagCompound.setInteger("blood", stack.stackTagCompound.getInteger("blood") + FluidContainerRegistry.BUCKET_VOLUME);
world.markBlockForUpdate(x, y, z);
fill(stack, new FluidStack(AlchemicalWizardry.lifeEssenceFluid, FluidContainerRegistry.BUCKET_VOLUME), true);
return true;
}
}
Expand All @@ -81,14 +77,80 @@ public boolean addBloodAndDrainTank(ItemStack stack, World world, int x, int y,
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean p_77624_4_) {
if (!GuiScreen.isShiftKeyDown()) {
list.add(StatCollector.translateToLocal("info.Sanguimancy.tooltip.shift.info"));
if (stack.hasTagCompound()) {
if (!GuiScreen.isShiftKeyDown())
list.add(StatCollector.translateToLocal("info.Sanguimancy.tooltip.shift.info"));
else {
NBTTagCompound tag = stack.stackTagCompound.getCompoundTag("tank");
if (stack.hasTagCompound() && tag.getString("FluidName") != "") {
list.add(StatCollector.translateToLocal("info.Sanguimancy.tooltip.fluid") + ": " + RandomUtils.capitalizeFirstLetter(tag.getString("FluidName")));
list.add(StatCollector.translateToLocal("info.Sanguimancy.tooltip.amount") + ": " + tag.getInteger("Amount") + "/" + getCapacity(stack) + "mB");
}
}
}
if (GuiScreen.isShiftKeyDown()) {
if (stack.hasTagCompound() && stack.stackTagCompound.hasKey("blood")) {
list.add(StatCollector.translateToLocal("info.Sanguimancy.tooltip.amount") + ": " + stack.stackTagCompound.getInteger("blood") + " mB");
list.add(bloodLoss + " mB " + StatCollector.translateToLocal("info.Sanguimancy.toolitp.per.point"));
}

@Override
public FluidStack getFluid(ItemStack stack) {
if (stack.hasTagCompound() && stack.stackTagCompound.hasKey("tank") && stack.stackTagCompound.getCompoundTag("tank").getString("FluidName") != "") {
NBTTagCompound tag = stack.stackTagCompound.getCompoundTag("tank");
return FluidStack.loadFluidStackFromNBT(tag);
}
return null;
}

@Override
public int getCapacity(ItemStack container) {
return Integer.MAX_VALUE;
}

@Override
public int fill(ItemStack stack, FluidStack resource, boolean doFill) {
if (resource == null || stack.stackSize != 1) return 0;
if (resource.fluidID != AlchemicalWizardry.lifeEssenceFluid.getID()) {
return 0;
}
int fillAmount = 0, capacity = getCapacity(stack);
NBTTagCompound tag = stack.stackTagCompound, fluidTag = null;
FluidStack fluid = null;
if (tag == null || !tag.hasKey("tank") || (fluidTag = tag.getCompoundTag("tank")) == null || (fluid = FluidStack.loadFluidStackFromNBT(fluidTag)) == null)
fillAmount = Math.min(capacity, resource.amount);
if (fluid == null) {
if (doFill) {
fluid = resource.copy();
fluid.amount = 0;
}
} else if (!fluid.isFluidEqual(resource))
return 0;
else
fillAmount = Math.min(capacity - fluid.amount, resource.amount);
fillAmount = Math.max(fillAmount, 0);
if (doFill) {
if (tag == null)
tag = stack.stackTagCompound = new NBTTagCompound();
fluid.amount += fillAmount;
tag.setTag("tank", fluid.writeToNBT(fluidTag == null ? new NBTTagCompound() : fluidTag));
}
return fillAmount;
}

@Override
public FluidStack drain(ItemStack stack, int maxDrain, boolean doDrain) {
NBTTagCompound tag = stack.stackTagCompound, fluidTag = null;
FluidStack fluid = null;
if (tag == null || !tag.hasKey("tank") || (fluidTag = tag.getCompoundTag("tank")) == null || (fluid = FluidStack.loadFluidStackFromNBT(fluidTag)) == null) {
if (fluidTag != null)
tag.removeTag("tank");
return null;
}
int drainAmount = Math.min(maxDrain, fluid.amount);
if (doDrain) {
tag.removeTag("tank");
fluid.amount -= drainAmount;
if (fluid.amount > 0)
fill(stack, fluid, true);
}
fluid.amount = drainAmount;
return fluid;
}
}
10 changes: 5 additions & 5 deletions src/main/java/tombenpotter/sanguimancy/proxies/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.world.World;
import tombenpotter.sanguimancy.container.ContainerLumpCleaner;
import tombenpotter.sanguimancy.gui.GuiLumpCleaner;
import tombenpotter.sanguimancy.tile.TileLumpCleaner;
import tombenpotter.sanguimancy.tile.TileBloodCleaner;

public class CommonProxy implements IGuiHandler {

Expand All @@ -22,8 +22,8 @@ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int
TileEntity tile = world.getTileEntity(x, y, z);
switch (ID) {
case 0:
if (tile != null && tile instanceof TileLumpCleaner) {
return new ContainerLumpCleaner(player, (TileLumpCleaner) tile);
if (tile != null && tile instanceof TileBloodCleaner) {
return new ContainerLumpCleaner(player, (TileBloodCleaner) tile);
}
default:
return null;
Expand All @@ -35,8 +35,8 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int
TileEntity tile = world.getTileEntity(x, y, z);
switch (ID) {
case 0:
if (tile != null && tile instanceof TileLumpCleaner) {
return new GuiLumpCleaner(player, (TileLumpCleaner) tile);
if (tile != null && tile instanceof TileBloodCleaner) {
return new GuiLumpCleaner(player, (TileBloodCleaner) tile);
}
default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class RecipesRegistry {

public static IRecipe altarEmitter, sacrificeTransferrer, corruptionReader, unattunedPlayerSacrificer, corruptionCrystallizer, bloodTank, lumpCleaner;
public static IRecipe altarEmitter, sacrificeTransferrer, corruptionReader, unattunedPlayerSacrificer, corruptionCrystallizer, bloodTank, lumpCleaner, bloodAmulet;
public static AltarRecipe altarDiviner, attunedPlayerSacrificer, corruptionCatalyst;
public static RecipeCorruptedInfusion poisonousPotato, rottenFlesh, crackedStoneBricks, bonemeal, soulSand, corruptedDemonShard, cobblestone, gravel, sand, dirt;

Expand Down Expand Up @@ -46,6 +46,8 @@ public static void registerOrbRecipes() {
bloodTank = RecipeRegistry.getLatestCraftingRecipe();
GameRegistry.addRecipe(new ShapedBloodOrbRecipe(RandomUtils.SanguimancyItemStacks.lumpCleaner, "XXX", "YZY", "ABA", 'X', RandomUtils.SanguimancyItemStacks.oreLump, 'Y', RandomUtils.SanguimancyItemStacks.bloodTank, 'Z', new ItemStack(ModItems.masterBloodOrb), 'A', new ItemStack(Blocks.iron_block), 'B', new ItemStack(Blocks.diamond_block)));
lumpCleaner = RecipeRegistry.getLatestCraftingRecipe();
GameRegistry.addRecipe(new ShapedBloodOrbRecipe(RandomUtils.SanguimancyItemStacks.bloodAmulet, "XYX", "ZAZ", "BCB", 'X', new ItemStack(Items.string), 'Y', new ItemStack(Items.bucket), 'Z', new ItemStack(ModItems.demonicSlate), 'A', new ItemStack(Items.clock), 'B', RandomUtils.SanguimancyItemStacks.bloodTank, 'C', new ItemStack(ModItems.magicianBloodOrb)));
bloodAmulet = RecipeRegistry.getLatestCraftingRecipe();
}

public static void registerCustomModRecipes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void registerTEs() {
GameRegistry.registerTileEntity(TileSacrificeTransfer.class, "TileSacrificeTransfer");
GameRegistry.registerTileEntity(TileIllusion.class, "TileIllusion");
GameRegistry.registerTileEntity(TileCorruptionCrystallizer.class, "TileCorruptionCrystallizer");
GameRegistry.registerTileEntity(TileLumpCleaner.class, "TileLumpCleaner");
GameRegistry.registerTileEntity(TileBloodCleaner.class, "TileBloodCleaner");
GameRegistry.registerTileEntity(TileBloodTank.class, "TileBloodTank");
GameRegistry.registerTileEntity(TileDimensionalPortal.class, "TileDimensionalPortal");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.minecraftforge.fluids.*;
import tombenpotter.sanguimancy.recipes.RecipeBloodCleanser;

public class TileLumpCleaner extends TileEntity implements ISidedInventory, IFluidHandler {
public class TileBloodCleaner extends TileEntity implements ISidedInventory, IFluidHandler {

public ItemStack[] inventory;
public int capacity;
Expand All @@ -23,7 +23,7 @@ public class TileLumpCleaner extends TileEntity implements ISidedInventory, IFlu
public FluidTank tank;
public boolean isActive;

public TileLumpCleaner() {
public TileBloodCleaner() {
inventory = new ItemStack[2];
capacity = FluidContainerRegistry.BUCKET_VOLUME * 16;
maxTicks = 150;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public static class SanguimancyItemStacks {
public static ItemStack corruptedDemonShard = new ItemStack(ItemsRegistry.corruptedDemonShard);
public static ItemStack corruptionCatalist = new ItemStack(ItemsRegistry.corruptionCatalyst);
public static ItemStack oreLump = new ItemStack(ItemsRegistry.oreLump);
public static ItemStack bloodAmulet = new ItemStack(ItemsRegistry.bloodAmulet);

// Blocks
public static ItemStack altarEmitter = new ItemStack(BlocksRegistry.altarEmitter);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b0e0a96

Please sign in to comment.