Skip to content

Commit c1e08fc

Browse files
committed
Fix computer block drops not being handles
This is still not 100% perfect - we don't drop them when in creative. However, it's a notable improvement on what it was. Closes #174
1 parent b9ec6f2 commit c1e08fc

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
import net.minecraft.util.math.Direction;
2424
import net.minecraft.world.BlockView;
2525
import net.minecraft.world.World;
26+
import net.minecraft.world.loot.context.LootContext;
27+
import net.minecraft.world.loot.context.LootContextParameters;
2628

2729
import javax.annotation.Nonnull;
30+
import java.util.List;
2831

2932
public abstract class BlockComputerBase<T extends TileComputerBase> extends BlockGeneric implements IBundledRedstoneBlock
3033
{
31-
public static final Identifier COMPUTER_DROP = new Identifier( ComputerCraft.MOD_ID, "computer" );
34+
private static final Identifier COMPUTER_DROP = new Identifier( ComputerCraft.MOD_ID, "computer" );
3235

3336
private final ComputerFamily family;
3437

@@ -123,47 +126,18 @@ public ItemStack getPickStack( BlockView world, BlockPos pos, BlockState state )
123126
return super.getPickStack( world, pos, state );
124127
}
125128

126-
/*
127-
TODO: Find a way of doing creative block drops
128129
@Override
129130
@Deprecated
130-
public final void dropBlockAsItemWithChance( @Nonnull BlockState state, World world, @Nonnull BlockPos pos, float change, int fortune )
131+
public List<ItemStack> getDroppedStacks( BlockState state, LootContext.Builder builder )
131132
{
133+
// TODO: Find a way of doing creative block drops
134+
builder.putDrop( COMPUTER_DROP, ( context, consumer ) -> {
135+
BlockEntity tile = context.get( LootContextParameters.BLOCK_ENTITY );
136+
if( tile instanceof TileComputerBase ) consumer.accept( getItem( (TileComputerBase) tile ) );
137+
} );
138+
return super.getDroppedStacks( state, builder );
132139
}
133140

134-
@Override
135-
public final void getDrops( BlockState state, DefaultedList<ItemStack> drops, World world, BlockPos pos, int fortune )
136-
{
137-
BlockEntity tile = world.getBlockEntity( pos );
138-
if( tile instanceof TileComputerBase )
139-
{
140-
ItemStack stack = getItem( (TileComputerBase) tile );
141-
if( !stack.isEmpty() ) drops.add( stack );
142-
}
143-
}
144-
145-
@Override
146-
public boolean removedByPlayer( BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, FluidState fluid )
147-
{
148-
if( !world.isClient )
149-
{
150-
// We drop the item here instead of doing it in the harvest method, as we
151-
// need to drop it for creative players too.
152-
BlockEntity tile = world.getBlockEntity( pos );
153-
if( tile instanceof TileComputerBase )
154-
{
155-
TileComputerBase computer = (TileComputerBase) tile;
156-
if( !player.abilities.creativeMode || computer.getLabel() != null )
157-
{
158-
dropStack( world, pos, getItem( computer ) );
159-
}
160-
}
161-
}
162-
163-
return super.removedByPlayer( state, world, pos, player, willHarvest, fluid );
164-
}
165-
*/
166-
167141
@Override
168142
public void onPlaced( World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack )
169143
{

0 commit comments

Comments
 (0)