Implement a functioning Blood Tank (#969)
Added a search bar to the Upgrade Tomes Creative Tab Updated some Altar fluid code (remove deprecated stuff) Moved Rendering classes into appropriate package Fix the localization errors on the Demon Crystals A few cleanups here and there
This commit is contained in:
parent
d1f4e95a7e
commit
aac2623440
40 changed files with 929 additions and 249 deletions
|
@ -1,14 +1,22 @@
|
|||
package WayofTime.bloodmagic.item.block;
|
||||
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.block.BlockBloodTank;
|
||||
import WayofTime.bloodmagic.tile.TileBloodTank;
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.fluids.*;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -17,53 +25,71 @@ public class ItemBlockBloodTank extends ItemBlock implements IFluidContainerItem
|
|||
public ItemBlockBloodTank(Block block)
|
||||
{
|
||||
super(block);
|
||||
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int meta)
|
||||
{
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("tank") && !stack.getTagCompound().getCompoundTag("tank").getString("FluidName").equals(""))
|
||||
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(Constants.NBT.TANK) && !stack.getTagCompound().getCompoundTag(Constants.NBT.TANK).getString("FluidName").equals(""))
|
||||
{
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("tank");
|
||||
return super.getItemStackDisplayName(stack) + " (" + tag.getString("FluidName") + ")";
|
||||
} else
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(Constants.NBT.TANK);
|
||||
return super.getItemStackDisplayName(stack) + " " + TextHelper.localizeEffect("tooltip.BloodMagic.tier", stack.getItemDamage() + 1) + " (" + FluidStack.loadFluidStackFromNBT(tag).getLocalizedName() + ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.getItemStackDisplayName(stack);
|
||||
return super.getItemStackDisplayName(stack) + " " + TextHelper.localizeEffect("tooltip.BloodMagic.tier", stack.getItemDamage() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - Correctly localize these strings
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer entityPlayer, List<String> tooltip, boolean advanced)
|
||||
{
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.fluid.capacity") + ": " + String.valueOf(getCapacity(stack)) + "mB");
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.tier", stack.getItemDamage() + 1));
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.fluid.capacity") + ": " + getCapacity(stack) + "mB");
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("tank");
|
||||
if (!tag.getString("FluidName").equals(""))
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(Constants.NBT.TANK);
|
||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
||||
if (!Strings.isNullOrEmpty(tag.getString("FluidName")) && fluidStack != null)
|
||||
{
|
||||
tooltip.add(" ");
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.fluid.type") + ": " + tag.getString("FluidName"));
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.fluid.type") + ": " + fluidStack.getLocalizedName());
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.fluid.amount") + ": " + tag.getInteger("Amount") + "/" + getCapacity(stack) + "mB");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item id, CreativeTabs creativeTab, List<ItemStack> list)
|
||||
{
|
||||
for (int i = 0; i < TileBloodTank.capacities.length; i++)
|
||||
list.add(new ItemStack(id, 1, i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid(ItemStack stack)
|
||||
{
|
||||
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("tank") && !stack.getTagCompound().getCompoundTag("tank").getString("FluidName").equals(""))
|
||||
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(Constants.NBT.TANK) && !stack.getTagCompound().getCompoundTag(Constants.NBT.TANK).getString("FluidName").equals(""))
|
||||
{
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("tank");
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(Constants.NBT.TANK);
|
||||
return FluidStack.loadFluidStackFromNBT(tag);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity(ItemStack container)
|
||||
{
|
||||
return TileBloodTank.capacity;
|
||||
return container != null && Block.getBlockFromItem(container.getItem()) instanceof BlockBloodTank ? TileBloodTank.capacities[container.getMetadata()] * Fluid.BUCKET_VOLUME : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,11 +97,14 @@ public class ItemBlockBloodTank extends ItemBlock implements IFluidContainerItem
|
|||
{
|
||||
if (resource == null || stack.stackSize != 1)
|
||||
return 0;
|
||||
|
||||
int fillAmount = 0, capacity = getCapacity(stack);
|
||||
NBTTagCompound tag = stack.getTagCompound(), fluidTag = null;
|
||||
FluidStack fluid = null;
|
||||
if (tag == null || !tag.hasKey("tank") || (fluidTag = tag.getCompoundTag("tank")) == null || (fluid = FluidStack.loadFluidStackFromNBT(fluidTag)) == null)
|
||||
|
||||
if (tag == null || !tag.hasKey(Constants.NBT.TANK) || (fluidTag = tag.getCompoundTag(Constants.NBT.TANK)) == null || (fluid = FluidStack.loadFluidStackFromNBT(fluidTag)) == null)
|
||||
fillAmount = Math.min(capacity, resource.amount);
|
||||
|
||||
if (fluid == null)
|
||||
{
|
||||
if (doFill)
|
||||
|
@ -83,19 +112,24 @@ public class ItemBlockBloodTank extends ItemBlock implements IFluidContainerItem
|
|||
fluid = resource.copy();
|
||||
fluid.amount = 0;
|
||||
}
|
||||
} else if (!fluid.isFluidEqual(resource))
|
||||
}
|
||||
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)
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
|
||||
tag = stack.getTagCompound();
|
||||
fluid.amount += fillAmount;
|
||||
tag.setTag("tank", fluid.writeToNBT(fluidTag == null ? new NBTTagCompound() : fluidTag));
|
||||
tag.setTag(Constants.NBT.TANK, fluid.writeToNBT(fluidTag == null ? new NBTTagCompound() : fluidTag));
|
||||
}
|
||||
|
||||
return fillAmount;
|
||||
}
|
||||
|
||||
|
@ -103,22 +137,32 @@ public class ItemBlockBloodTank extends ItemBlock implements IFluidContainerItem
|
|||
public FluidStack drain(ItemStack stack, int maxDrain, boolean doDrain)
|
||||
{
|
||||
NBTTagCompound tag = stack.getTagCompound(), fluidTag = null;
|
||||
FluidStack fluid = null;
|
||||
if (tag == null || !tag.hasKey("tank") || (fluidTag = tag.getCompoundTag("tank")) == null || (fluid = FluidStack.loadFluidStackFromNBT(fluidTag)) == null)
|
||||
FluidStack fluid;
|
||||
|
||||
if (tag == null || !tag.hasKey(Constants.NBT.TANK) || (fluidTag = tag.getCompoundTag(Constants.NBT.TANK)) == null || (fluid = FluidStack.loadFluidStackFromNBT(fluidTag)) == null)
|
||||
{
|
||||
if (fluidTag != null)
|
||||
tag.removeTag("tank");
|
||||
tag.removeTag(Constants.NBT.TANK);
|
||||
return null;
|
||||
}
|
||||
|
||||
int drainAmount = Math.min(maxDrain, fluid.amount);
|
||||
|
||||
if (doDrain)
|
||||
{
|
||||
tag.removeTag("tank");
|
||||
tag.removeTag(Constants.NBT.TANK);
|
||||
fluid.amount -= drainAmount;
|
||||
if (fluid.amount > 0)
|
||||
fill(stack, fluid, true);
|
||||
}
|
||||
|
||||
fluid.amount = drainAmount;
|
||||
return fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt)
|
||||
{
|
||||
return new FluidHandlerItemStack(stack, getCapacity(stack));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import net.minecraft.util.EnumFacing;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class ItemBlockDemonCrystal extends ItemBlock
|
||||
{
|
||||
public ItemBlockDemonCrystal(Block block)
|
||||
|
@ -23,7 +25,7 @@ public class ItemBlockDemonCrystal extends ItemBlock
|
|||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return super.getUnlocalizedName(stack) + EnumDemonWillType.values()[stack.getItemDamage()];
|
||||
return super.getUnlocalizedName(stack) + EnumDemonWillType.values()[stack.getItemDamage()].toString().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue