Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #131 #132

Merged
merged 1 commit into from
Jun 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,40 @@ public int damageDropped(IBlockState state)
return state.getValue(VARIANT_PROP).ordinal();
}

/**
* Called when a player removes a block. This is responsible for
* actually destroying the block, and the block is intact at time of call.
* This is called regardless of whether the player can harvest the block or
* not.
*
* Return true if the block is actually destroyed.
*
* Note: When used in multiplayer, this is called on both client and
* server sides!
*
* @param state The current state.
* @param world The current world
* @param player The player damaging the block, may be null
* @param pos Block position in world
* @param willHarvest True if Block.harvestBlock will be called after this, if the return in true.
* Can be useful to delay the destruction of tile entities till after harvestBlock
* @return True if the block is actually destroyed.
*/
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
return willHarvest || super.removedByPlayer(state, world, pos, player, false);
}

/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
super.harvestBlock(worldIn, player, pos, state, te, stack);
worldIn.setBlockToAir(pos);
}

@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
Expand All @@ -271,11 +305,26 @@ public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, Ent
}

/**
* Spawns this Block's drops into the World as EntityItems.
* This gets a complete list of items dropped from this block.
*
* @param drops add all items this block drops to this drops list
* @param world The current world
* @param pos Block position in world
* @param state Current state
* @param fortune Breakers fortune level
*/
@Override
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
TileEntity tileentity = world.getTileEntity(pos);

if (tileentity instanceof TileEntityIronShulkerBox)
{
ItemStack itemstack = ((TileEntityIronShulkerBox) tileentity).getDrop(state, false);
if(!itemstack.isEmpty())
{
drops.add(itemstack);
}
}
}

/**
Expand All @@ -288,28 +337,10 @@ public void breakBlock(World worldIn, BlockPos pos, IBlockState state)

if (tileentity instanceof TileEntityIronShulkerBox)
{
TileEntityIronShulkerBox tileentityironshulkerbox = (TileEntityIronShulkerBox) tileentity;

if (!tileentityironshulkerbox.isCleared() && tileentityironshulkerbox.shouldDrop())
ItemStack itemstack = ((TileEntityIronShulkerBox) tileentity).getDrop(state, true);
if(!itemstack.isEmpty())
{
if (!tileentityironshulkerbox.beenUpgraded())
{
ItemStack itemstack = new ItemStack(Item.getItemFromBlock(this), 1, state.getValue(VARIANT_PROP).ordinal());
NBTTagCompound nbttagcompound = new NBTTagCompound();
NBTTagCompound nbttagcompound1 = new NBTTagCompound();

nbttagcompound.setTag("BlockEntityTag", ((TileEntityIronShulkerBox) tileentity).saveToNbt(nbttagcompound1));
itemstack.setTagCompound(nbttagcompound);

if (tileentityironshulkerbox.hasCustomName())
{
itemstack.setStackDisplayName(tileentityironshulkerbox.getName());

tileentityironshulkerbox.setCustomName("");
}

spawnAsEntity(worldIn, pos, itemstack);
}
spawnAsEntity(worldIn, pos, itemstack);
}

worldIn.updateComparatorOutputLevel(pos, state.getBlock());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
Expand Down Expand Up @@ -775,9 +776,35 @@ public void setDestroyedByCreativePlayer(boolean destoryedByCreativeUser)
this.destroyedByCreativePlayer = destoryedByCreativeUser;
}

public boolean shouldDrop()
public boolean shouldDropInBreakBlock()
{
return !this.isDestroyedByCreativePlayer() || !this.isEmpty() || this.hasCustomName() || this.lootTable != null;
return this.isDestroyedByCreativePlayer() && (!this.isEmpty() || this.hasCustomName() || this.lootTable != null);
}

public ItemStack getDrop(IBlockState state, boolean inBreakBlock) {
BlockIronShulkerBox block = (BlockIronShulkerBox) state.getBlock();
if (!isCleared() && (!inBreakBlock || shouldDropInBreakBlock()))
{
if (!beenUpgraded())
{
ItemStack itemstack = new ItemStack(Item.getItemFromBlock(block), 1, state.getValue(BlockIronShulkerBox.VARIANT_PROP).ordinal());
NBTTagCompound nbttagcompound = new NBTTagCompound();
NBTTagCompound nbttagcompound1 = new NBTTagCompound();

nbttagcompound.setTag("BlockEntityTag", saveToNbt(nbttagcompound1));
itemstack.setTagCompound(nbttagcompound);

if (hasCustomName())
{
itemstack.setStackDisplayName(getName());

setCustomName("");
}

return itemstack;
}
}
return ItemStack.EMPTY;
}

protected void sendTopStacksPacket()
Expand Down