Fluidlogged API

Fluidlogged API

356k Downloads

Problem of block harvesting with silk touch enchantment

LouisQuepierts opened this issue ยท 2 comments

commented

What's happen
Hello, I found a problem when I try to use a tool with silk touch enchantment to harvest a fluid logged block.
Mod Version: v1.6.2

If I try to harvest a fluid logged un-silk-touchable block (et. slabs), it will drops its drop item and a barrier.
And if I try to harvest a fluid logged silk-touchable block (et. glass pane), it only drops a barrier but not the silk touched drop item.

The case for shearable blocks is the same as for silk touchable blocks. (this is with out the silk touch enchantment)

I'm sorry I can't provide some screenshots here :(

To make sure I may not have been detailed enough, here're the steps what I did in the game.

  1. Get a tool with silk touch enchantment
  2. Harvest the fluid logged block (et. slabs) and fluid logged silk touchable block (et. glass pane) with that too

A solution might solve this problem
Here's some code that might solve the problem:
In class: common/block/BlockFluidloggedTE

For method getStored(@nonnull IBlockAccess world, @nonnull BlockPos pos)

    @Nonnull
    public IBlockState getStored(@Nonnull IBlockAccess world, @Nonnull BlockPos pos) {
        TileEntity te = world.getTileEntity(pos);
        return te instanceof TileEntityFluidlogged ? ((TileEntityFluidlogged)te).stored : Blocks.AIR.getDefaultState();
    }

For method removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest

    public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
        IBlockState stored = this.getStored(world, pos);
        if (!player.isCreative() && this.canHarvestBlock(stored, player, world, pos)) {
            int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
            List<ItemStack> drops = stored.getBlock().getDrops(world, pos, stored, 0);
            if (fortune > 0) {
                drops = stored.getBlock().getDrops(world, pos, stored, fortune);

            } else if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0
                    && this.canSilkHarvest(world, pos, stored, player)) {
                drops = Collections.singletonList(new ItemStack(Item.getItemFromBlock(stored.getBlock())));

            } else if (stored.getBlock() instanceof IShearable
                    && ((IShearable) stored.getBlock()).isShearable(ItemStack.EMPTY, world, pos)) {
                drops = ((IShearable) stored.getBlock()).onSheared(ItemStack.EMPTY, world, pos, 0);
            }

            Iterator<?> var9 = drops.iterator();

            while(var9.hasNext()) {
                ItemStack drop = (ItemStack)var9.next();
                spawnAsEntity(world, pos, drop);
            }
        }

        return world.setBlockState(pos, this.fluid.getBlock().getDefaultState(), world.isRemote ? 11 : 3);
    }

Hope these help with this bug :)

commented

Just tested the issue for the v1.7 rewrite (wip) and it seems to have fixed itself

commented

fixed in v1.7