Fix crash when creating a tank stack with meta > 15 (#1057)
Also finally fixes the tanks so they properly drop themselves.
This commit is contained in:
parent
58d11dfbdc
commit
93d7efcb40
|
@ -5,6 +5,7 @@ import WayofTime.bloodmagic.api.Constants;
|
|||
import WayofTime.bloodmagic.block.base.BlockInteger;
|
||||
import WayofTime.bloodmagic.client.IVariantProvider;
|
||||
import WayofTime.bloodmagic.tile.TileBloodTank;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -29,6 +30,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -88,6 +90,17 @@ public class BlockBloodTank extends BlockInteger implements IVariantProvider
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity tile, ItemStack stack) {
|
||||
super.harvestBlock(world, player, pos, state, tile, stack);
|
||||
world.setBlockToAir(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
|
||||
return willHarvest || super.removedByPlayer(state, world, pos, player, willHarvest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
|
@ -115,17 +128,19 @@ public class BlockBloodTank extends BlockInteger implements IVariantProvider
|
|||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState blockState, int fortune)
|
||||
{
|
||||
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
||||
List<ItemStack> list = Lists.newArrayList();
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileBloodTank)
|
||||
{
|
||||
TileBloodTank bloodTank = (TileBloodTank) tile;
|
||||
ItemStack drop = new ItemStack(this);
|
||||
ItemStack drop = new ItemStack(this, 1, bloodTank.getBlockMetadata());
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
bloodTank.serialize(tag);
|
||||
|
||||
if (bloodTank.getTank().getFluid() != null)
|
||||
bloodTank.getTank().getFluid().writeToNBT(tag);
|
||||
|
||||
drop.setTagCompound(tag);
|
||||
drop.setItemDamage(getMetaFromState(blockState));
|
||||
list.add(drop);
|
||||
}
|
||||
|
||||
|
@ -138,11 +153,12 @@ public class BlockBloodTank extends BlockInteger implements IVariantProvider
|
|||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileBloodTank)
|
||||
{
|
||||
TileBloodTank bloodTank = (TileBloodTank) tile;
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
if (tag != null)
|
||||
{
|
||||
((TileBloodTank) tile).deserialize(tag);
|
||||
blockState.withProperty(getProperty(), stack.getMetadata());
|
||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
||||
bloodTank.getTank().setFluid(fluidStack);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Map;
|
|||
import javax.annotation.Nonnull;
|
||||
|
||||
import mezz.jei.api.*;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
|
@ -90,6 +89,6 @@ public class BloodMagicPlugin extends BlankModPlugin
|
|||
|
||||
@Override
|
||||
public void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) {
|
||||
subtypeRegistry.useNbtForSubtypes(Item.getItemFromBlock(ModBlocks.BLOOD_TANK));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,16 +44,15 @@ public class DataProviderBloodTank implements IWailaDataProvider
|
|||
{
|
||||
TileBloodTank bloodTank = (TileBloodTank) accessor.getTileEntity();
|
||||
NBTTagCompound tag = accessor.getNBTData();
|
||||
int capacity = tag.getInteger(Constants.NBT.ALTAR_CAPACITY);
|
||||
int capacity = accessor.getNBTData().getInteger(Constants.NBT.ALTAR_CAPACITY);
|
||||
currenttip.add(TextHelper.localizeEffect("tooltip.bloodmagic.tier", bloodTank.getBlockMetadata() + 1));
|
||||
currenttip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.capacity") + ": " + capacity + "mB");
|
||||
currenttip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.capacity", capacity));
|
||||
|
||||
tag = tag.getCompoundTag(Constants.NBT.TANK);
|
||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
||||
if (!Strings.isNullOrEmpty(tag.getString("FluidName")) && fluidStack != null)
|
||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag(Constants.NBT.TANK));
|
||||
if (fluidStack != null)
|
||||
{
|
||||
currenttip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.type") + ": " + fluidStack.getLocalizedName());
|
||||
currenttip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.amount") + ": " + tag.getInteger("Amount") + "/" + capacity + "mB");
|
||||
currenttip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.type", fluidStack.getLocalizedName()));
|
||||
currenttip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.amount", fluidStack.amount, capacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
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;
|
||||
|
@ -13,6 +11,7 @@ import net.minecraft.item.ItemBlock;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.fluids.*;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack;
|
||||
|
@ -39,10 +38,10 @@ public class ItemBlockBloodTank extends ItemBlock
|
|||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(Constants.NBT.TANK) && !stack.getTagCompound().getCompoundTag(Constants.NBT.TANK).getString("FluidName").equals(""))
|
||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(stack.getTagCompound());
|
||||
if (fluidStack != null)
|
||||
{
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(Constants.NBT.TANK);
|
||||
return super.getItemStackDisplayName(stack) + " " + TextHelper.localizeEffect("tooltip.bloodmagic.tier", stack.getItemDamage() + 1) + " (" + FluidStack.loadFluidStackFromNBT(tag).getLocalizedName() + ")";
|
||||
return super.getItemStackDisplayName(stack) + " " + TextHelper.localizeEffect("tooltip.bloodmagic.tier", stack.getItemDamage() + 1) + " (" + fluidStack.getLocalizedName() + ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -54,15 +53,15 @@ public class ItemBlockBloodTank extends ItemBlock
|
|||
public void addInformation(ItemStack stack, EntityPlayer entityPlayer, List<String> tooltip, boolean advanced)
|
||||
{
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.tier", stack.getItemDamage() + 1));
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.capacity") + ": " + getCapacity(stack) + "mB");
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.capacity", getCapacity(stack)));
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(Constants.NBT.TANK);
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
||||
if (!Strings.isNullOrEmpty(tag.getString("FluidName")) && fluidStack != null)
|
||||
if (fluidStack != null)
|
||||
{
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.type") + ": " + fluidStack.getLocalizedName());
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.amount") + ": " + tag.getInteger("Amount") + "/" + getCapacity(stack) + "mB");
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.type", fluidStack.getLocalizedName()));
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.amount", fluidStack.amount, getCapacity(stack)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +76,8 @@ public class ItemBlockBloodTank extends ItemBlock
|
|||
|
||||
public int getCapacity(ItemStack container)
|
||||
{
|
||||
return container != null && Block.getBlockFromItem(container.getItem()) instanceof BlockBloodTank ? TileBloodTank.CAPACITIES[container.getMetadata()] * Fluid.BUCKET_VOLUME : 0;
|
||||
int meta = MathHelper.clamp(container.getItemDamage(), 0, TileBloodTank.CAPACITIES.length);
|
||||
return !container.isEmpty() && Block.getBlockFromItem(container.getItem()) instanceof BlockBloodTank ? TileBloodTank.CAPACITIES[meta] * Fluid.BUCKET_VOLUME : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,14 +39,14 @@ public class SigilHoldingPacketProcessor implements IMessage, IMessageHandler<Si
|
|||
@Override
|
||||
public IMessage onMessage(SigilHoldingPacketProcessor message, MessageContext ctx)
|
||||
{
|
||||
ItemStack itemStack = null;
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
|
||||
if (message.slot > -1 && message.slot < 9)
|
||||
{
|
||||
itemStack = ctx.getServerHandler().playerEntity.inventory.getStackInSlot(message.slot);
|
||||
}
|
||||
|
||||
if (itemStack != null)
|
||||
if (!itemStack.isEmpty())
|
||||
{
|
||||
ItemSigilHolding.cycleToNextSigil(itemStack, message.mode);
|
||||
}
|
||||
|
|
|
@ -539,9 +539,9 @@ tooltip.bloodmagic.itemFilter.oreDict=Used to filter through the Ore Dictionary
|
|||
|
||||
tooltip.bloodmagic.itemFilter.exact=Filters the fluid input/output
|
||||
|
||||
tooltip.bloodmagic.fluid.type=Fluid Contained
|
||||
tooltip.bloodmagic.fluid.amount=Amount
|
||||
tooltip.bloodmagic.fluid.capacity=Capacity
|
||||
tooltip.bloodmagic.fluid.type=Fluid Contained: %s
|
||||
tooltip.bloodmagic.fluid.amount=Amount: %d / %d mB
|
||||
tooltip.bloodmagic.fluid.capacity=Capacity: %d mB
|
||||
|
||||
tooltip.bloodmagic.ghost.everything=Everything
|
||||
tooltip.bloodmagic.ghost.amount=Ghost item amount: %d
|
||||
|
|
Loading…
Reference in a new issue