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.block.base.BlockInteger;
|
||||||
import WayofTime.bloodmagic.client.IVariantProvider;
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
||||||
import WayofTime.bloodmagic.tile.TileBloodTank;
|
import WayofTime.bloodmagic.tile.TileBloodTank;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import net.minecraft.block.SoundType;
|
import net.minecraft.block.SoundType;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
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.ImmutablePair;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -88,6 +90,17 @@ public class BlockBloodTank extends BlockInteger implements IVariantProvider
|
||||||
return false;
|
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
|
@Override
|
||||||
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
|
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
|
@Override
|
||||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState blockState, int fortune)
|
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);
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
if (tile instanceof TileBloodTank)
|
if (tile instanceof TileBloodTank)
|
||||||
{
|
{
|
||||||
TileBloodTank bloodTank = (TileBloodTank) tile;
|
TileBloodTank bloodTank = (TileBloodTank) tile;
|
||||||
ItemStack drop = new ItemStack(this);
|
ItemStack drop = new ItemStack(this, 1, bloodTank.getBlockMetadata());
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
bloodTank.serialize(tag);
|
|
||||||
|
if (bloodTank.getTank().getFluid() != null)
|
||||||
|
bloodTank.getTank().getFluid().writeToNBT(tag);
|
||||||
|
|
||||||
drop.setTagCompound(tag);
|
drop.setTagCompound(tag);
|
||||||
drop.setItemDamage(getMetaFromState(blockState));
|
|
||||||
list.add(drop);
|
list.add(drop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,11 +153,12 @@ public class BlockBloodTank extends BlockInteger implements IVariantProvider
|
||||||
TileEntity tile = world.getTileEntity(pos);
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
if (tile instanceof TileBloodTank)
|
if (tile instanceof TileBloodTank)
|
||||||
{
|
{
|
||||||
|
TileBloodTank bloodTank = (TileBloodTank) tile;
|
||||||
NBTTagCompound tag = stack.getTagCompound();
|
NBTTagCompound tag = stack.getTagCompound();
|
||||||
if (tag != null)
|
if (tag != null)
|
||||||
{
|
{
|
||||||
((TileBloodTank) tile).deserialize(tag);
|
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
||||||
blockState.withProperty(getProperty(), stack.getMetadata());
|
bloodTank.getTank().setFluid(fluidStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Map;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import mezz.jei.api.*;
|
import mezz.jei.api.*;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
import WayofTime.bloodmagic.api.Constants;
|
import WayofTime.bloodmagic.api.Constants;
|
||||||
|
@ -90,6 +89,6 @@ public class BloodMagicPlugin extends BlankModPlugin
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) {
|
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();
|
TileBloodTank bloodTank = (TileBloodTank) accessor.getTileEntity();
|
||||||
NBTTagCompound tag = accessor.getNBTData();
|
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.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.getCompoundTag(Constants.NBT.TANK));
|
||||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
if (fluidStack != null)
|
||||||
if (!Strings.isNullOrEmpty(tag.getString("FluidName")) && fluidStack != null)
|
|
||||||
{
|
{
|
||||||
currenttip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.type") + ": " + fluidStack.getLocalizedName());
|
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.amount", fluidStack.amount, capacity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package WayofTime.bloodmagic.item.block;
|
package WayofTime.bloodmagic.item.block;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.api.Constants;
|
|
||||||
import WayofTime.bloodmagic.block.BlockBloodTank;
|
import WayofTime.bloodmagic.block.BlockBloodTank;
|
||||||
import WayofTime.bloodmagic.tile.TileBloodTank;
|
import WayofTime.bloodmagic.tile.TileBloodTank;
|
||||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -13,6 +11,7 @@ import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||||
import net.minecraftforge.fluids.*;
|
import net.minecraftforge.fluids.*;
|
||||||
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack;
|
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack;
|
||||||
|
@ -39,10 +38,10 @@ public class ItemBlockBloodTank extends ItemBlock
|
||||||
@Override
|
@Override
|
||||||
public String getItemStackDisplayName(ItemStack stack)
|
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.getLocalizedName() + ")";
|
||||||
return super.getItemStackDisplayName(stack) + " " + TextHelper.localizeEffect("tooltip.bloodmagic.tier", stack.getItemDamage() + 1) + " (" + FluidStack.loadFluidStackFromNBT(tag).getLocalizedName() + ")";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -54,15 +53,15 @@ public class ItemBlockBloodTank extends ItemBlock
|
||||||
public void addInformation(ItemStack stack, EntityPlayer entityPlayer, List<String> tooltip, boolean advanced)
|
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.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())
|
if (stack.hasTagCompound())
|
||||||
{
|
{
|
||||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(Constants.NBT.TANK);
|
NBTTagCompound tag = stack.getTagCompound();
|
||||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
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.type", fluidStack.getLocalizedName()));
|
||||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.amount") + ": " + tag.getInteger("Amount") + "/" + getCapacity(stack) + "mB");
|
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)
|
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
|
@Override
|
||||||
|
|
|
@ -39,14 +39,14 @@ public class SigilHoldingPacketProcessor implements IMessage, IMessageHandler<Si
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(SigilHoldingPacketProcessor message, MessageContext ctx)
|
public IMessage onMessage(SigilHoldingPacketProcessor message, MessageContext ctx)
|
||||||
{
|
{
|
||||||
ItemStack itemStack = null;
|
ItemStack itemStack = ItemStack.EMPTY;
|
||||||
|
|
||||||
if (message.slot > -1 && message.slot < 9)
|
if (message.slot > -1 && message.slot < 9)
|
||||||
{
|
{
|
||||||
itemStack = ctx.getServerHandler().playerEntity.inventory.getStackInSlot(message.slot);
|
itemStack = ctx.getServerHandler().playerEntity.inventory.getStackInSlot(message.slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemStack != null)
|
if (!itemStack.isEmpty())
|
||||||
{
|
{
|
||||||
ItemSigilHolding.cycleToNextSigil(itemStack, message.mode);
|
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.itemFilter.exact=Filters the fluid input/output
|
||||||
|
|
||||||
tooltip.bloodmagic.fluid.type=Fluid Contained
|
tooltip.bloodmagic.fluid.type=Fluid Contained: %s
|
||||||
tooltip.bloodmagic.fluid.amount=Amount
|
tooltip.bloodmagic.fluid.amount=Amount: %d / %d mB
|
||||||
tooltip.bloodmagic.fluid.capacity=Capacity
|
tooltip.bloodmagic.fluid.capacity=Capacity: %d mB
|
||||||
|
|
||||||
tooltip.bloodmagic.ghost.everything=Everything
|
tooltip.bloodmagic.ghost.everything=Everything
|
||||||
tooltip.bloodmagic.ghost.amount=Ghost item amount: %d
|
tooltip.bloodmagic.ghost.amount=Ghost item amount: %d
|
||||||
|
|
Loading…
Reference in a new issue