Skip to content

Commit

Permalink
[ci skip] Add changes comment
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Jan 5, 2025
1 parent d461e1e commit 42c744b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,6 @@ private void cubicChunkColumn_construct(World world, int x, int z, CallbackInfo
Arrays.fill(getBiomeArray(), (byte) -1);
}

/*
@ModifyConstant(method = "<init>(Lnet/minecraft/world/World;II)V", constant = @Constant(intValue = 16),
slice = @Slice(to = @At(
value = "FIELD",
target = "Lnet/minecraft/world/chunk/Chunk;storageArrays:[Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;",
opcode = Opcodes.PUTFIELD
)),
allow = 1, require = 1)
private int modifySectionArrayLength(int sixteen, World worldIn, int x, int z) {
if (worldIn == null) {
// Some mods construct chunks with null world, ignore them
return sixteen;
}
if (!((ICubicWorld) worldIn).isCubicWorld()) {
IMinMaxHeight y = (IMinMaxHeight) worldIn;
return Coords.blockToCube(y.getMaxHeight()) - Coords.blockToCube(y.getMinHeight());
}
return sixteen;
}
*/ // Now moved to MixinChunk_Cubes_Vanilla_Sided

@Redirect(method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/ChunkPrimer;II)V",
at = @At(
value = "FIELD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@

@Mixin(value = Chunk.class, priority = 999)
public abstract class MixinChunk_Cubes_Bukkit_Sided {

/*
* Spigot added some more constants before the storageArrays array is set, so we need to adjust the slice.
*/
@ModifyConstant(method = "<init>(Lnet/minecraft/world/World;II)V", constant = @Constant(intValue = 16),
slice = @Slice(
from = @At(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,17 @@
*/
package io.github.opencubicchunks.cubicchunks.core.asm.mixin.core.common;

import io.github.opencubicchunks.cubicchunks.api.util.Coords;
import io.github.opencubicchunks.cubicchunks.core.entity.ICubicEntityTracker;
import io.github.opencubicchunks.cubicchunks.core.server.ICubicPlayerList;
import io.github.opencubicchunks.cubicchunks.core.server.PlayerCubeMap;
import io.github.opencubicchunks.cubicchunks.api.world.ICubicWorld;
import io.github.opencubicchunks.cubicchunks.core.asm.mixin.ICubicWorldInternal;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import javax.annotation.ParametersAreNonnullByDefault;

Expand All @@ -56,18 +48,6 @@ public abstract class MixinPlayerList implements ICubicPlayerList {
@Shadow @Final private MinecraftServer server;
protected int verticalViewDistance = -1;

// @Redirect(method = "playerLoggedOut",
// at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;markDirty()V", ordinal = 0),
// require = 1)
// private void setChunkModifiedOnPlayerLoggedOut(Chunk chunkIn, EntityPlayerMP playerIn) {
// ICubicWorldInternal world = (ICubicWorldInternal) playerIn.getServerWorld();
// if (world.isCubicWorld()) {
// world.getCubeFromCubeCoords(playerIn.chunkCoordX, playerIn.chunkCoordY, playerIn.chunkCoordZ).markDirty();
// } else {
// ((World) world).getChunk(playerIn.chunkCoordX, playerIn.chunkCoordZ).markDirty();
// }
// } // Moved to MixinPlayerList_Vanilla_Sided

@Override public int getVerticalViewDistance() {
return verticalViewDistance < 0 ? viewDistance : verticalViewDistance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@
@ParametersAreNonnullByDefault
@Mixin(PlayerList.class)
public abstract class MixinPlayerList_Bukkit_Sided {

/*
* CraftBukkit has a different return value for this method comparing to vanilla.
* CB: String playerLoggedOut(EntityPlayerMP);
* Vanilla: void playerLoggedOut(EntityPlayerMP);
*/
@Redirect(method = "playerLoggedOut(Lnet/minecraft/entity/player/EntityPlayerMP;)Ljava/lang/String;",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;markDirty()V", ordinal = 0),
require = 1) // CB method has a different return value
require = 1)
private void setChunkModifiedOnPlayerLoggedOut(Chunk chunkIn, EntityPlayerMP playerIn) {
ICubicWorldInternal world = (ICubicWorldInternal) playerIn.getServerWorld();
if (world.isCubicWorld()) {
Expand All @@ -56,6 +62,12 @@ private void setChunkModifiedOnPlayerLoggedOut(Chunk chunkIn, EntityPlayerMP pla
}
}

/*
* CraftBukkit changed the logic of how Vanilla "respawns" a player.
* In vanilla, the player instance will be recreated and the player's inventory will be copied over,
* while in CB, player instance is always same while the referenced player is online,
* and they offer another method "moveToWorld" to handle this.
*/
@Inject(method = "moveToWorld(Lnet/minecraft/entity/player/EntityPlayerMP;IZLorg/bukkit/Location;Z)Lnet/minecraft/entity/player/EntityPlayerMP;", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/gen/ChunkProviderServer;provideChunk(II)Lnet/minecraft/world/chunk/Chunk;"))
private void createPlayerChunk(EntityPlayerMP playerIn, int dimension, boolean conqueredEnd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public abstract class MixinWorld_HeightLimits_Bukkit_Sided implements ICubicWorl

@Shadow public abstract boolean isBlockLoaded(BlockPos pos, boolean allowEmpty);

/*
* CraftBukkit moved the vanilla spawnEntity method logic to addEntity.
* And now in Spigot calling spawnEntity will be redirected to addEntity.
*/
// Error is fine here, disabled remap as it's a CB method.
@Redirect(method = "addEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isChunkLoaded(IIZ)Z"), remap = false)
private boolean addEntity_isChunkLoaded(World world, int chunkX, int chunkZ, boolean allowEmpty, Entity ent) {
Expand Down

0 comments on commit 42c744b

Please sign in to comment.