Skip to content

Commit

Permalink
getCommandSenderWorld() => level()
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Nov 20, 2023
1 parent fd5a744 commit 702b956
Show file tree
Hide file tree
Showing 53 changed files with 158 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class BackpackMenu extends InventoryMenu {

public BackpackMenu(int windowId, Player player) {
super(player.getInventory(), !player.getCommandSenderWorld().isClientSide, player);
super(player.getInventory(), !player.level().isClientSide, player);
this.containerId = windowId;

Inventory inventory = player.getInventory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private static ItemStack cloneStack(ItemStack stack, int size) {

public static CrateMenu fromNetwork(int windowId, Inventory playerInventory, FriendlyByteBuf buf) {
BlockPos pos = buf.readBlockPos();
CrateBlockEntity te = (CrateBlockEntity) playerInventory.player.getCommandSenderWorld().getBlockEntity(pos);
CrateBlockEntity te = (CrateBlockEntity) playerInventory.player.level().getBlockEntity(pos);
return new CrateMenu(windowId, playerInventory, te);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void onTake(@NotNull Player thePlayer, @NotNull ItemStack stack) {

public static MatrixEnchantingMenu fromNetwork(int windowId, Inventory playerInventory, FriendlyByteBuf buf) {
BlockPos pos = buf.readBlockPos();
MatrixEnchantingTableBlockEntity te = (MatrixEnchantingTableBlockEntity) playerInventory.player.getCommandSenderWorld().getBlockEntity(pos);
MatrixEnchantingTableBlockEntity te = (MatrixEnchantingTableBlockEntity) playerInventory.player.level().getBlockEntity(pos);
return new MatrixEnchantingMenu(windowId, playerInventory, te);
}

Expand All @@ -88,7 +88,7 @@ private void finish(Player player, ItemStack stack) {
MatrixEnchantingModule.influenceTrigger.trigger(serverPlayer);
}

player.getCommandSenderWorld().playSound(null, enchanter.getBlockPos(), SoundEvents.ENCHANTMENT_TABLE_USE, SoundSource.BLOCKS, 1.0F, player.getCommandSenderWorld().random.nextFloat() * 0.1F + 0.9F);
player.level().playSound(null, enchanter.getBlockPos(), SoundEvents.ENCHANTMENT_TABLE_USE, SoundSource.BLOCKS, 1.0F, player.level().random.nextFloat() * 0.1F + 0.9F);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void inventoryTick(@NotNull ItemStack stack, Level worldIn, @NotNull Enti

@Override
public boolean onEntityItemUpdateZeta(ItemStack stack, ItemEntity entityItem) {
if(BackpackModule.superOpMode || entityItem.getCommandSenderWorld().isClientSide)
if(BackpackModule.superOpMode || entityItem.level().isClientSide)
return false;

if (!ItemNBTHelper.detectNBT(stack))
Expand All @@ -190,7 +190,7 @@ public boolean onEntityItemUpdateZeta(ItemStack stack, ItemEntity entityItem) {
ItemStack stackAt = handler.getStackInSlot(i);
if(!stackAt.isEmpty()) {
ItemStack copy = stackAt.copy();
Containers.dropItemStack(entityItem.getCommandSenderWorld(), entityItem.getX(), entityItem.getY(), entityItem.getZ(), copy);
Containers.dropItemStack(entityItem.level(), entityItem.getX(), entityItem.getY(), entityItem.getZ(), copy);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ public void onDrops(ZLivingDrops event) {
chance--;
amount++;
}
if(chance > 0 && entity.getCommandSenderWorld().random.nextDouble() < chance)
if(chance > 0 && entity.level().random.nextDouble() < chance)
amount++;

event.getDrops().add(new ItemEntity(entity.getCommandSenderWorld(), entity.getX(), entity.getY(), entity.getZ(), new ItemStack(ravager_hide, amount)));
event.getDrops().add(new ItemEntity(entity.level(), entity.getX(), entity.getY(), entity.getZ(), new ItemStack(ravager_hide, amount)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DoubleDoorMessage(BlockPos pos) {
}

private Level extractWorld(ServerPlayer entity) {
return entity == null ? null : entity.getCommandSenderWorld();
return entity == null ? null : entity.level();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public boolean receive(IZetaNetworkEventContext context) {
context.enqueueWork(() -> {
Player player = context.getSender();
if(player != null) {
BlockHitResult pick = Item.getPlayerPOVHitResult(player.getCommandSenderWorld(), player, ClipContext.Fluid.ANY);
BlockHitResult pick = Item.getPlayerPOVHitResult(player.level(), player, ClipContext.Fluid.ANY);
SimpleHarvestModule.click(context.getSender(), hand, pos, pick);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ public void setChanged() {

private void addItemParticles(Entity entity, ItemStack stack, int count) {
for(int i = 0; i < count; ++i) {
Vec3 direction = new Vec3((entity.getCommandSenderWorld().random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
Vec3 direction = new Vec3((entity.level().random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
direction = direction.xRot(-entity.getXRot() * ((float)Math.PI / 180F));
direction = direction.yRot(-entity.getYRot() * ((float)Math.PI / 180F));
double yVelocity = (-entity.getCommandSenderWorld().random.nextFloat()) * 0.6D - 0.3D;
Vec3 position = new Vec3((entity.getCommandSenderWorld().random.nextFloat() - 0.5D) * 0.3D, yVelocity, 0.6D);
double yVelocity = (-entity.level().random.nextFloat()) * 0.6D - 0.3D;
Vec3 position = new Vec3((entity.level().random.nextFloat() - 0.5D) * 0.3D, yVelocity, 0.6D);
Vec3 entityPos = entity.position();
position = position.xRot(-entity.getXRot() * ((float)Math.PI / 180F));
position = position.yRot(-entity.getYRot() * ((float)Math.PI / 180F));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ public void tick() {

// vanilla copy for falling upwards stuff
BlockPos blockpos1 = this.blockPosition();
boolean aboveHasCollision = !getCommandSenderWorld().getBlockState(blockpos1.above()).getCollisionShape(getCommandSenderWorld(), blockpos1.above()).isEmpty();
if (!this.getCommandSenderWorld().isClientSide && getFallDirection() > 0 && !isRemoved() && aboveHasCollision) {
boolean aboveHasCollision = !level().getBlockState(blockpos1.above()).getCollisionShape(level(), blockpos1.above()).isEmpty();
if (!this.level().isClientSide && getFallDirection() > 0 && !isRemoved() && aboveHasCollision) {
Block block = this.blockState.getBlock();
BlockState blockstate = this.getCommandSenderWorld().getBlockState(blockpos1);
BlockState blockstate = this.level().getBlockState(blockpos1);
this.setDeltaMovement(this.getDeltaMovement().multiply(0.7D, 0.5D, 0.7D));
boolean flag2 = blockstate.canBeReplaced(new DirectionalPlaceContext(this.getCommandSenderWorld(), blockpos1, Direction.UP, ItemStack.EMPTY, Direction.DOWN));
boolean flag3 = FallingBlock.isFree(this.getCommandSenderWorld().getBlockState(blockpos1.above()));
boolean flag4 = this.blockState.canSurvive(this.getCommandSenderWorld(), blockpos1) && !flag3;
boolean flag2 = blockstate.canBeReplaced(new DirectionalPlaceContext(this.level(), blockpos1, Direction.UP, ItemStack.EMPTY, Direction.DOWN));
boolean flag3 = FallingBlock.isFree(this.level().getBlockState(blockpos1.above()));
boolean flag4 = this.blockState.canSurvive(this.level(), blockpos1) && !flag3;

if (flag2 && flag4) {
if (this.getCommandSenderWorld().setBlock(blockpos1, this.blockState, 3)) {
((ServerLevel)this.getCommandSenderWorld()).getChunkSource().chunkMap.broadcast(this, new ClientboundBlockUpdatePacket(blockpos1, this.getCommandSenderWorld().getBlockState(blockpos1)));
if (this.level().setBlock(blockpos1, this.blockState, 3)) {
((ServerLevel)this.level()).getChunkSource().chunkMap.broadcast(this, new ClientboundBlockUpdatePacket(blockpos1, this.level().getBlockState(blockpos1)));
this.discard();
} else if (this.dropItem && this.getCommandSenderWorld().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
} else if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
this.discard();
this.callOnBrokenAfterFall(block, blockpos1);
this.spawnAtLocation(block);
}
} else {
this.discard();
if (this.dropItem && this.getCommandSenderWorld().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
this.callOnBrokenAfterFall(block, blockpos1);
this.spawnAtLocation(block);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class FeedingTroughModule extends ZetaModule {

@PlayEvent
public void onBreed(ZBabyEntitySpawn.Lowest event) {
if (event.getCausedByPlayer() == null && event.getParentA().getCommandSenderWorld().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))
if (event.getCausedByPlayer() == null && event.getParentA().level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))
breedingOccurred.set(true);
}

Expand Down Expand Up @@ -135,7 +135,7 @@ public static Player temptWithTroughs(TemptGoal goal, Player found, ServerLevel
BlockPos location = pointer.pos();
Vec3 eyesPos = goal.mob.position().add(0, goal.mob.getEyeHeight(), 0);
Vec3 targetPos = new Vec3(location.getX(), location.getY(), location.getZ()).add(0.5, 0.0625, 0.5);
BlockHitResult ray = goal.mob.getCommandSenderWorld().clip(new ClipContext(eyesPos, targetPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, goal.mob));
BlockHitResult ray = goal.mob.level().clip(new ClipContext(eyesPos, targetPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, goal.mob));

if (ray.getType() == HitResult.Type.BLOCK && ray.getBlockPos().equals(location)) {
if(!cached)
Expand Down Expand Up @@ -202,7 +202,7 @@ public static TroughPointer fromEntity(Entity e, TemptGoal goal) {
int z = tag.getInt("z");

BlockPos pos = new BlockPos(x, y, z);
return getTroughFakePlayer(e.getCommandSenderWorld(), pos, goal);
return getTroughFakePlayer(e.level(), pos, goal);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected void renderNameTag(@NotNull GlassItemFrame frame, @NotNull Component t
protected void renderItemStack(GlassItemFrame itemFrame, PoseStack matrix, MultiBufferSource buff, int light, ItemStack stack) {
if (!stack.isEmpty()) {
matrix.pushPose();
MapItemSavedData mapdata = MapItem.getSavedData(stack, itemFrame.getCommandSenderWorld());
MapItemSavedData mapdata = MapItem.getSavedData(stack, itemFrame.level());

sign: if(itemFrame.isOnSign()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public InteractionResult interact(Player player, @NotNull InteractionHand hand)
ItemStack item = getItem();
if(!player.isShiftKeyDown() && !item.isEmpty() && !(item.getItem() instanceof BannerItem)) {
BlockPos behind = getBehindPos();
BlockEntity tile = getCommandSenderWorld().getBlockEntity(behind);
BlockEntity tile = level().getBlockEntity(behind);

if(tile != null && tile.getCapability(ForgeCapabilities.ITEM_HANDLER).isPresent()) {
BlockState behindState = getCommandSenderWorld().getBlockState(behind);
InteractionResult result = behindState.use(getCommandSenderWorld(), player, hand, new BlockHitResult(new Vec3(getX(), getY(), getZ()), direction, behind, true));
BlockState behindState = level().getBlockState(behind);
InteractionResult result = behindState.use(level(), player, hand, new BlockHitResult(new Vec3(getX(), getY(), getZ()), direction, behind, true));

if(result.consumesAction())
return result;
Expand All @@ -84,26 +84,26 @@ public void tick() {
super.tick();
boolean shouldUpdateMaps = GlassItemFrameModule.glassItemFramesUpdateMapsEveryTick;
//same update as normal frames
if(getCommandSenderWorld().getGameTime() % 100 == 0) {
if(level().getGameTime() % 100 == 0) {
updateIsOnSign();
//not upating every tick otherwise lag
shouldUpdateMaps = true;
}

if(!getCommandSenderWorld().isClientSide && GlassItemFrameModule.glassItemFramesUpdateMaps && shouldUpdateMaps) {
if(!level().isClientSide && GlassItemFrameModule.glassItemFramesUpdateMaps && shouldUpdateMaps) {
ItemStack stack = getItem();
if(stack.getItem() instanceof MapItem map && getCommandSenderWorld() instanceof ServerLevel sworld) {
if(stack.getItem() instanceof MapItem map && level() instanceof ServerLevel sworld) {
ItemStack clone = stack.copy();

MapItemSavedData data = MapItem.getSavedData(clone, getCommandSenderWorld());
MapItemSavedData data = MapItem.getSavedData(clone, level());
if(data != null && !data.locked) {
var fakePlayer = FakePlayerFactory.get(sworld, DUMMY_PROFILE);

clone.setEntityRepresentation(null);
fakePlayer.setPos(getX(), getY(), getZ());
fakePlayer.getInventory().setItem(0, clone);

map.update(getCommandSenderWorld(), fakePlayer, data);
map.update(level(), fakePlayer, data);
}
}
}
Expand All @@ -112,7 +112,7 @@ public void tick() {
private void updateIsOnSign() {
onSignRotation = null;
if(this.direction.getAxis() != Direction.Axis.Y){
BlockState back = getCommandSenderWorld().getBlockState(getBehindPos());
BlockState back = level().getBlockState(getBehindPos());
if(back.is(BlockTags.STANDING_SIGNS)){
onSignRotation = back.getValue(StandingSignBlock.ROTATION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void playerTick(ZPlayerTick.Start event) {
Player player = event.getPlayer();
BlockPos playerPos = player.blockPosition();
boolean isTrying = player.isVisuallyCrawling() ||
(player.isCrouching() && !player.isColliding(playerPos, player.getCommandSenderWorld().getBlockState(playerPos)));
(player.isCrouching() && !player.isColliding(playerPos, player.level().getBlockState(playerPos)));
boolean wasTrying = player.getPersistentData().getBoolean(TAG_TRYING_TO_CRAWL);

if (!player.isVisuallyCrawling()) {
Expand All @@ -86,16 +86,16 @@ public void playerTick(ZPlayerTick.Start event) {
}

private boolean tryClimb(Player player, Direction dir, BlockPos pos) {
BlockState state = player.getCommandSenderWorld().getBlockState(pos);
BlockState state = player.level().getBlockState(pos);
Block block = state.getBlock();

if(block instanceof ICrawlSpaceBlock crawlSpace) {
if(crawlSpace.canCrawl(player.getCommandSenderWorld(), state, pos, dir)) {
if(crawlSpace.canCrawl(player.level(), state, pos, dir)) {
player.setPose(Pose.SWIMMING);
player.setSwimming(true);

double x = pos.getX() + 0.5 - (dir.getStepX() * 0.3);
double y = pos.getY() + crawlSpace.crawlHeight(player.getCommandSenderWorld(), state, pos, dir);
double y = pos.getY() + crawlSpace.crawlHeight(player.level(), state, pos, dir);
double z = pos.getZ() + 0.5 - (dir.getStepZ() * 0.3);

player.setPos(x, y, z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static boolean canEntityUseElytra(LivingEntity entity, boolean prev) {
if(!staticEnabled || !enableDimensionLockedElytra)
return true;

Level level = entity.getCommandSenderWorld();
Level level = entity.level();
String dim = level.dimensionTypeId().location().toString();
return elytraAllowedDimensions.contains(dim);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private boolean crawlInventory(IItemHandler inv, int lowerBound, int upperBound,

@PlayEvent
public void onPlayerTick(ZPlayerTick.End event) {
if(!event.getPlayer().getCommandSenderWorld().isClientSide && replacements.containsKey(event.getPlayer())) {
if(!event.getPlayer().level().isClientSide && replacements.containsKey(event.getPlayer())) {
Stack<QueuedRestock> replacementStack = replacements.get(event.getPlayer());
synchronized(mutex) {
while(!replacementStack.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ public static boolean lavaBucketOverride(ItemStack stack, ItemStack incoming, Sl
if (canTrashItem(stack, incoming, slot, player)) {

incoming.setCount(0);
if (!player.getCommandSenderWorld().isClientSide)
player.getCommandSenderWorld().playSound(null, player.blockPosition(), SoundEvents.LAVA_EXTINGUISH, SoundSource.PLAYERS, 0.25F, 2F + (float) Math.random());
if (!player.level().isClientSide)
player.level().playSound(null, player.blockPosition(), SoundEvents.LAVA_EXTINGUISH, SoundSource.PLAYERS, 0.25F, 2F + (float) Math.random());

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public boolean canUse() {
if (startled || stoneling.isPlayerMade())
return false;

List<Player> playersAround = stoneling.getCommandSenderWorld().getEntitiesOfClass(Player.class, stoneling.getBoundingBox().inflate(range),
List<Player> playersAround = stoneling.level().getEntitiesOfClass(Player.class, stoneling.getBoundingBox().inflate(range),
(player) -> player != null && !player.getAbilities().instabuild && player.distanceToSqr(stoneling) < range * range);

if (playersAround.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void tick() {
if(shiba.currentHyperfocus != null) {
navigator.moveTo(navigator.createPath(shiba.currentHyperfocus, 1), 1.1);

if(shiba.getCommandSenderWorld() instanceof ServerLevel slevel && shiba.tickCount % 10 == 0) {
if(shiba.level() instanceof ServerLevel slevel && shiba.tickCount % 10 == 0) {
Vec3 pos = shiba.position();
slevel.sendParticles(ParticleTypes.ANGRY_VILLAGER, pos.x, pos.y + 0.5, pos.z, 1, 0.25F, 0.1F, 0.25F, 0);
shiba.lookAt(Anchor.EYES, new Vec3(shiba.currentHyperfocus.getX() + 0.5, shiba.currentHyperfocus.getY(), shiba.currentHyperfocus.getZ() + 0.5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void tick() {

timeTilNextJump--;
if(timeTilNextJump <= 0) {
timeTilNextJump = shiba.getCommandSenderWorld().random.nextInt(5) + 10;
timeTilNextJump = shiba.level().random.nextInt(5) + 10;

if(shiba.onGround()) {
shiba.push(0, 0.3, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean canUse() {

@Override
public boolean canContinueToUse() {
return timeoutCounter >= -maxStayTicks && timeoutCounter <= 1200 && targetBlock.test(creature.getCommandSenderWorld().getBlockState(destinationBlock));
return timeoutCounter >= -maxStayTicks && timeoutCounter <= 1200 && targetBlock.test(creature.level().getBlockState(destinationBlock));
}

@Override
Expand Down Expand Up @@ -110,7 +110,7 @@ private boolean searchForDestination() {
pos.set(xBase + xShift, yBase + yShift - 1, zBase + zShift);

if (creature.isWithinRestriction(pos) &&
targetBlock.test(creature.getCommandSenderWorld().getBlockState(pos))) {
targetBlock.test(creature.level().getBlockState(pos))) {
destinationBlock = pos;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void tick() {

timeTilNextJump--;
if(timeTilNextJump <= 0) {
timeTilNextJump = shiba.getCommandSenderWorld().random.nextInt(5) + 10;
timeTilNextJump = shiba.level().random.nextInt(5) + 10;

if(shiba.onGround()) {
shiba.push(0, 0.3, 0);
Expand All @@ -62,7 +62,7 @@ public boolean canContinueToUse() {
@Override
public boolean canUse() {
AbstractArrow fetching = shiba.getFetching();
return shiba.getMouthItem().isEmpty() && fetching != null && fetching.isAlive() && fetching.getCommandSenderWorld() == shiba.getCommandSenderWorld() && fetching.pickup != Pickup.DISALLOWED;
return shiba.getMouthItem().isEmpty() && fetching != null && fetching.isAlive() && fetching.level() == shiba.level() && fetching.pickup != Pickup.DISALLOWED;
}

}
Loading

0 comments on commit 702b956

Please sign in to comment.