use of mcmultipart.api.slot.IPartSlot in project LogisticsPipes by RS485.
the class LPMicroblockBlock method removedByPlayer.
@Override
@ModDependentMethod(modId = LPConstants.mcmpModID)
public boolean removedByPlayer(@Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest) {
Pair<Vec3d, Vec3d> vectors = RayTraceHelper.getRayTraceVectors(player);
RayTraceResult hit = collisionRayTrace(state, world, pos, vectors.getLeft(), vectors.getRight());
Optional<TileMultipartContainer> tile = getTile(world, pos);
if (hit != null && tile.isPresent() && hit.subHit >= 0) {
if (!world.isRemote) {
IPartSlot slot = MCMultiPart.slotRegistry.getValue(hit.subHit);
boolean canRemove = tile.get().get(slot).map(i -> {
if (i.getPart().canPlayerDestroy(i, player)) {
i.getPart().onPartHarvested(i, player);
if (player == null || !player.capabilities.isCreativeMode) {
i.getPart().getDrops(i.getPartWorld(), pos, i, 0).forEach(s -> spawnAsEntity(world, pos, s));
}
return true;
} else {
return false;
}
}).orElse(true);
if (canRemove)
tile.get().removePart(slot);
}
}
if (hit != null && hit.subHit == -1) {
return super.removedByPlayer(state, world, pos, player, willHarvest);
}
return false;
}
Aggregations