Replace getCommandSenderWorld with direct field access.

This commit is contained in:
Florian Nücke
2021-08-05 01:54:49 +02:00
parent c1c9026fbe
commit a4042b1911
8 changed files with 27 additions and 29 deletions

View File

@@ -35,7 +35,7 @@ public enum BusInterfaceNameRenderer {
public void handleRenderLastEvent(final RenderWorldLastEvent event) {
final Minecraft mc = Minecraft.getInstance();
final PlayerEntity player = mc.player;
final World world = player.getCommandSenderWorld();
final World level = player.level;
if (!Wrenches.isHoldingWrench(player)) {
return;
@@ -47,14 +47,14 @@ public enum BusInterfaceNameRenderer {
final BlockRayTraceResult hit = (BlockRayTraceResult) mc.hitResult;
final BlockPos blockPos = hit.getBlockPos();
final TileEntity tileEntity = world.getBlockEntity(blockPos);
final TileEntity tileEntity = level.getBlockEntity(blockPos);
if (!(tileEntity instanceof BusCableTileEntity)) {
return;
}
final BusCableTileEntity busCable = (BusCableTileEntity) tileEntity;
final Direction side = BusCableBlock.getHitSide(blockPos, hit);
if (BusCableBlock.getConnectionType(world.getBlockState(blockPos), side) != BusCableBlock.ConnectionType.INTERFACE) {
if (BusCableBlock.getConnectionType(level.getBlockState(blockPos), side) != BusCableBlock.ConnectionType.INTERFACE) {
return;
}

View File

@@ -62,7 +62,7 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
@Override
public void deserializeNBT(final CompoundNBT tag) {
lastOperation = MathHelper.clamp(tag.getLong(LAST_OPERATION_TAG_NAME), 0, entity.getCommandSenderWorld().getGameTime());
lastOperation = MathHelper.clamp(tag.getLong(LAST_OPERATION_TAG_NAME), 0, entity.level.getGameTime());
}
@Callback
@@ -73,8 +73,8 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
beginCooldown();
final World world = entity.getCommandSenderWorld();
if (!(world instanceof ServerWorld)) {
final World level = entity.level;
if (!(level instanceof ServerWorld)) {
return false;
}
@@ -84,7 +84,7 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
final List<ItemEntity> oldItems = getItemsInRange();
final Direction direction = RobotOperationSide.getAdjustedDirection(side, entity);
if (!tryHarvestBlock(world, entity.blockPosition().relative(direction))) {
if (!tryHarvestBlock(level, entity.blockPosition().relative(direction))) {
return false;
}
@@ -108,8 +108,8 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
beginCooldown();
final World world = entity.getCommandSenderWorld();
if (!(world instanceof ServerWorld)) {
final World level = entity.level;
if (!(level instanceof ServerWorld)) {
return false;
}
@@ -132,7 +132,7 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
final ItemStack itemStack = extracted.copy();
final BlockItem blockItem = (BlockItem) itemStack.getItem();
final ServerPlayerEntity player = FakePlayerUtils.getFakePlayer((ServerWorld) world, entity);
final ServerPlayerEntity player = FakePlayerUtils.getFakePlayer((ServerWorld) level, entity);
final BlockItemUseContext context = new BlockItemUseContext(player, Hand.MAIN_HAND, itemStack, hit);
final ActionResultType result = blockItem.place(context);
@@ -192,15 +192,15 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
///////////////////////////////////////////////////////////////////
private void beginCooldown() {
lastOperation = entity.getCommandSenderWorld().getGameTime();
lastOperation = entity.level.getGameTime();
}
private boolean isOnCooldown() {
return entity.getCommandSenderWorld().getGameTime() - lastOperation < COOLDOWN;
return entity.level.getGameTime() - lastOperation < COOLDOWN;
}
private List<ItemEntity> getItemsInRange() {
return entity.getCommandSenderWorld().getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(2));
return entity.level.getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(2));
}
private boolean tryHarvestBlock(final World world, final BlockPos blockPos) {

View File

@@ -196,7 +196,7 @@ public final class InventoryOperationsModuleDevice extends AbstractItemRPCDevice
private Stream<IItemHandler> getEntityItemHandlersAt(final Vector3d position, final Direction side) {
final AxisAlignedBB bounds = AxisAlignedBB.unitCubeFromLowerCorner(position.subtract(0.5, 0.5, 0.5));
return entity.getCommandSenderWorld().getEntities(entity, bounds).stream()
return entity.level.getEntities(entity, bounds).stream()
.map(e -> e.getCapability(Capabilities.ITEM_HANDLER, side))
.filter(LazyOptional::isPresent)
.map(c -> c.orElseThrow(AssertionError::new));
@@ -204,7 +204,7 @@ public final class InventoryOperationsModuleDevice extends AbstractItemRPCDevice
private Stream<IItemHandler> getBlockItemHandlersAt(final Vector3d position, final Direction side) {
final BlockPos pos = new BlockPos(position);
final TileEntity tileEntity = entity.getCommandSenderWorld().getBlockEntity(pos);
final TileEntity tileEntity = entity.level.getBlockEntity(pos);
if (tileEntity == null) {
return Stream.empty();
}
@@ -218,7 +218,7 @@ public final class InventoryOperationsModuleDevice extends AbstractItemRPCDevice
}
private List<ItemEntity> getItemsInRange() {
return entity.getCommandSenderWorld().getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(1));
return entity.level.getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(1));
}
private int takeFromWorld(final int count) {

View File

@@ -35,7 +35,7 @@ public final class ComputerInventoryContainer extends AbstractComputerContainer
public static ComputerInventoryContainer createClient(final int id, final PlayerInventory playerInventory, final PacketBuffer data) {
final BlockPos pos = data.readBlockPos();
final TileEntity tileEntity = playerInventory.player.getCommandSenderWorld().getBlockEntity(pos);
final TileEntity tileEntity = playerInventory.player.level.getBlockEntity(pos);
if (!(tileEntity instanceof ComputerTileEntity)) {
throw new IllegalArgumentException();
}

View File

@@ -33,7 +33,7 @@ public final class ComputerTerminalContainer extends AbstractComputerContainer {
public static ComputerTerminalContainer createClient(final int id, final PlayerInventory playerInventory, final PacketBuffer data) {
final BlockPos pos = data.readBlockPos();
final TileEntity tileEntity = playerInventory.player.getCommandSenderWorld().getBlockEntity(pos);
final TileEntity tileEntity = playerInventory.player.level.getBlockEntity(pos);
if (!(tileEntity instanceof ComputerTileEntity)) {
throw new IllegalArgumentException();
}

View File

@@ -35,7 +35,7 @@ public final class RobotInventoryContainer extends AbstractRobotContainer {
public static RobotInventoryContainer createClient(final int id, final PlayerInventory inventory, final PacketBuffer data) {
final int entityId = data.readVarInt();
final Entity entity = inventory.player.getCommandSenderWorld().getEntity(entityId);
final Entity entity = inventory.player.level.getEntity(entityId);
if (!(entity instanceof RobotEntity)) {
throw new IllegalArgumentException();
}

View File

@@ -34,7 +34,7 @@ public final class RobotTerminalContainer extends AbstractRobotContainer {
public static RobotTerminalContainer createClient(final int id, final PlayerInventory inventory, final PacketBuffer data) {
final int entityId = data.readVarInt();
final Entity entity = inventory.player.getCommandSenderWorld().getEntity(entityId);
final Entity entity = inventory.player.level.getEntity(entityId);
if (!(entity instanceof RobotEntity)) {
throw new IllegalArgumentException();
}

View File

@@ -197,8 +197,7 @@ public final class RobotEntity extends Entity implements Robot {
}
public void start() {
final World world = getCommandSenderWorld();
if (world.isClientSide) {
if (level.isClientSide()) {
return;
}
@@ -206,8 +205,7 @@ public final class RobotEntity extends Entity implements Robot {
}
public void stop() {
final World world = getCommandSenderWorld();
if (world.isClientSide) {
if (level.isClientSide()) {
return;
}
@@ -420,7 +418,7 @@ public final class RobotEntity extends Entity implements Robot {
@Override
protected Vector3d limitPistonMovement(final Vector3d pos) {
lastPistonMovement = getCommandSenderWorld().getGameTime();
lastPistonMovement = level.getGameTime();
return super.limitPistonMovement(pos);
}
@@ -442,7 +440,7 @@ public final class RobotEntity extends Entity implements Robot {
}
private void handleChunkUnload(final ChunkEvent.Unload event) {
if (event.getWorld() != getCommandSenderWorld()) {
if (event.getWorld() != level) {
return;
}
@@ -456,7 +454,7 @@ public final class RobotEntity extends Entity implements Robot {
}
private void handleWorldUnload(final WorldEvent.Unload event) {
if (event.getWorld() != getCommandSenderWorld()) {
if (event.getWorld() != level) {
return;
}
@@ -592,7 +590,7 @@ public final class RobotEntity extends Entity implements Robot {
}
public void tick() {
if (getCommandSenderWorld().isClientSide) {
if (level.isClientSide()) {
RobotActions.performClient(RobotEntity.this);
} else {
if (action != null) {
@@ -675,7 +673,7 @@ public final class RobotEntity extends Entity implements Robot {
}
private boolean addAction(final AbstractRobotAction action) {
if (getCommandSenderWorld().isClientSide) {
if (level.isClientSide()) {
return false;
}