|
23 | 23 | import net.minecraft.util.math.Direction; |
24 | 24 | import net.minecraft.world.BlockView; |
25 | 25 | import net.minecraft.world.World; |
| 26 | +import net.minecraft.world.loot.context.LootContext; |
| 27 | +import net.minecraft.world.loot.context.LootContextParameters; |
26 | 28 |
|
27 | 29 | import javax.annotation.Nonnull; |
| 30 | +import java.util.List; |
28 | 31 |
|
29 | 32 | public abstract class BlockComputerBase<T extends TileComputerBase> extends BlockGeneric implements IBundledRedstoneBlock |
30 | 33 | { |
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" ); |
32 | 35 |
|
33 | 36 | private final ComputerFamily family; |
34 | 37 |
|
@@ -123,47 +126,18 @@ public ItemStack getPickStack( BlockView world, BlockPos pos, BlockState state ) |
123 | 126 | return super.getPickStack( world, pos, state ); |
124 | 127 | } |
125 | 128 |
|
126 | | - /* |
127 | | - TODO: Find a way of doing creative block drops |
128 | 129 | @Override |
129 | 130 | @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 ) |
131 | 132 | { |
| 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 ); |
132 | 139 | } |
133 | 140 |
|
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 | | - |
167 | 141 | @Override |
168 | 142 | public void onPlaced( World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack ) |
169 | 143 | { |
|
0 commit comments