Skip to content

Commit

Permalink
1.18 part 6: reflection mappings and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 30, 2021
1 parent adec0d8 commit 02fbd09
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 36 deletions.
10 changes: 4 additions & 6 deletions plugin/src/main/java/com/denizenscript/denizen/Denizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,18 @@ public void onEnable() {
String javaVersion = System.getProperty("java.version");
getLogger().info("Running on java version: " + javaVersion);
if (javaVersion.startsWith("8") || javaVersion.startsWith("1.8")) {
getLogger().info("Running on fully supported Java 8.");
}
else if (javaVersion.startsWith("11")) {
getLogger().info("Running on mostly supported Java 11. Some warnings may show or limitations may apply due to Java 11. If these limits become problems, switch to Java 8 or Java 16.");
getLogger().info("Running on fully supported Java 8. Updating to Java 17+ is recommended.");
}
else if (javaVersion.startsWith("9") || javaVersion.startsWith("1.9") || javaVersion.startsWith("10") || javaVersion.startsWith("1.10")
|| javaVersion.startsWith("11")
|| javaVersion.startsWith("12") || javaVersion.startsWith("13") || javaVersion.startsWith("14") || javaVersion.startsWith("15")) {
getLogger().warning("Running unreliable Java version. Old Minecraft is built for Java 8, modern Minecraft is built for Java 16. Other Java versions are not guaranteed to function properly.");
getLogger().warning("Running unreliable Java version. Old Minecraft is built for Java 8, modern Minecraft is built for Java 17. Other Java versions are not guaranteed to function properly.");
}
else if (javaVersion.startsWith("16")) {
getLogger().info("Running on fully supported Java 16.");
}
else if (javaVersion.startsWith("17")) {
getLogger().info("Running on probably(?) supported Java 17. Denizen is primarily tested against Java 16, not 17. If something breaks, try Java 16 instead.");
getLogger().info("Running on fully supported Java 17.");
}
else {
getLogger().info("Running on unrecognized (future?) Java version. May or may not work.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void undisableAsyncCatcher() {

@Override
public boolean isCorrectMappingsCode() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals("f0e3dfc7390de285a4693518dd5bd126");
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals("9e9fe6961a80f3e586c25601590b51ec");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,106 @@

public class ReflectionMappingsInfo {

// Contents gathered via https://minidigger.github.io/MiniMappingViewer/#/mojang/server/1.17.1
// Contents gathered via https://minidigger.github.io/MiniMappingViewer/#/mojang/server/1.18

// net.minecraft.advancements.AdvancementList
public static String AdvancementList_roots = "c";
public static String AdvancementList_tasks = "d";

// net.minecraft.world.level.block.state.BlockBehaviour
public static String BlockBehaviour_explosionResistance = "aI";

// net.minecraft.stats.RecipeBook
public static String RecipeBook_known = "a";

// net.minecraft.world.entity.Entity
public static String Entity_onGround = "z";
public static String Entity_DATA_SHARED_FLAGS_ID = "Z";
public static String Entity_DATA_CUSTOM_NAME = "aJ";
public static String Entity_DATA_CUSTOM_NAME_VISIBLE = "aK";
public static String Entity_DATA_SHARED_FLAGS_ID = "aa";
public static String Entity_DATA_CUSTOM_NAME = "aL";
public static String Entity_DATA_CUSTOM_NAME_VISIBLE = "aM";

public static String LivingEntity_attackStrengthTicker = "aQ";
// net.minecraft.world.entity.LivingEntity
public static String LivingEntity_attackStrengthTicker = "aR";

// net.minecraft.world.entity.player.Player
public static String Player_DATA_PLAYER_ABSORPTION_ID = "d";
public static String Player_DATA_PLAYER_MODE_CUSTOMISATION = "bP";
public static String Player_DATA_PLAYER_MODE_CUSTOMISATION = "bQ";

public static String ServerPlayer_respawnForced = "cS";
// net.minecraft.server.level.ServerPlayer
public static String ServerPlayer_respawnForced = "cV";

public static String EnderMan_DATA_CREEPY = "bU";
// net.minecraft.world.entity.monster.EnderMan
public static String EnderMan_DATA_CREEPY = "bY";

// net.minecraft.world.item.Item
public static String Item_maxStackSize = "c";

// net.minecraft.world.level.Level
public static String Level_isClientSide = "y";

// net.minecraft.server.level.ThreadedLevelLightEngine
public static String ThreadedLevelLightEngine_addTask = "a";
// net.minecraft.server.level.ThreadedLevelLightEngine$TaskType
public static String ThreadedLevelLightEngine_TaskType_PRE_UPDATE = "a";

// net.minecraft.world.entity.item.ItemEntity
public static String ItemEntity_DATA_ITEM = "c";

// net.minecraft.world.level.biome.Biome
public static String Biome_climateSettings = "k";
// net.minecraft.world.level.biome.Biome$ClimateSettings
public static String Biome_ClimateSettings_temperature = "c";
public static String Biome_ClimateSettings_downfall = "e";
public static String Biome_ClimateSettings_precipitation = "b";

public static String ThreadedLevelLightEngine_Update_PRE_UPDATE = "a";

// net.minecraft.network.Connection
public static String Connection_receiving = "i";

// net.minecraft.server.network.ServerGamePacketListenerImpl
public static String ServerGamePacketListenerImpl_aboveGroundTickCount = "C";
public static String ServerGamePacketListenerImpl_aboveGroundVehicleTickCount = "E";
public static String ServerGamePacketListenerImpl_connection = "a";

// net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket
public static String ClientboundPlayerAbilitiesPacket_walkingSpeed = "j";

// net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket
public static String ClientboundSetEntityDataPacket_packedItems = "b";

public static String ClientboundBlockBreakAckPacket_state = "c";
// net.minecraft.network.protocol.game.ClientboundBlockBreakAckPacket
public static String ClientboundBlockBreakAckPacket_state = "b";

// net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket
public static String ClientboundSectionBlocksUpdatePacket_sectionPos = "b";
public static String ClientboundSectionBlocksUpdatePacket_states = "d";
public static String ClientboundSectionBlocksUpdatePacket_positions = "c";

// net.minecraft.network.protocol.game.ClientboundMoveEntityPacket
public static String ClientboundMoveEntityPacket_xa = "b";
public static String ClientboundMoveEntityPacket_ya = "c";
public static String ClientboundMoveEntityPacket_za = "d";
public static String ClientboundMoveEntityPacket_yRot = "e";
public static String ClientboundMoveEntityPacket_xRot = "f";

// net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket
public static String ClientboundSetEntityMotionPacket_id = "a";

// net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket
public static String ClientboundTeleportEntityPacket_id = "a";
public static String ClientboundTeleportEntityPacket_x = "b";
public static String ClientboundTeleportEntityPacket_y = "c";
public static String ClientboundTeleportEntityPacket_z = "d";
public static String ClientboundTeleportEntityPacket_yRot = "e";
public static String ClientboundTeleportEntityPacket_xRot = "f";

/*
public static String ClientboundLevelChunkPacket_buffer = "g";
public static String ClientboundLevelChunkPacket_blockEntitiesTags = "h";
public static String ClientboundMerchantOffersPacket_containerId = "a";
public static String ClientboundMerchantOffersPacket_containerId = "a";*/

public static String FishingHook_nibble = "aq";
public static String FishingHook_timeUntilLured = "ar";
public static String FishingHook_timeUntilHooked = "as";
// net.minecraft.world.entity.projectile.FishingHook
public static String FishingHook_nibble = "ar";
public static String FishingHook_timeUntilLured = "as";
public static String FishingHook_timeUntilHooked = "at";
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ public void setBlockStrength(Material mat, float strength) {
// This is to debork Spigot's class remapper mishandling 'getFluidState' which remaps 'FluidState' to 'material.FluidType' (incorrectly) in the call and thus errors out.
// TODO: 1.18: This might be fixed by Spigot and can be switched to raw method calls
// Relevant issue: https://hub.spigotmc.org/jira/browse/SPIGOT-6696
public static MethodHandle BLOCKSTATEBASE_GETFLUIDSTATE = ReflectionHelper.getMethodHandle(BlockBehaviour.BlockStateBase.class, "getFluid");
public static MethodHandle BLOCKSTATEBASE_GETFLUIDSTATE = ReflectionHelper.getMethodHandle(BlockBehaviour.BlockStateBase.class, "n");
public static MethodHandle FLUIDSTATE_ISRANDOMLYTICKING = ReflectionHelper.getMethodHandle(BLOCKSTATEBASE_GETFLUIDSTATE.type().returnType(), "f");
public static MethodHandle FLUIDSTATE_ISEMPTY = ReflectionHelper.getMethodHandle(BLOCKSTATEBASE_GETFLUIDSTATE.type().returnType(), "isEmpty");
public static MethodHandle FLUIDSTATE_CREATELEGACYBLOCK = ReflectionHelper.getMethodHandle(BLOCKSTATEBASE_GETFLUIDSTATE.type().returnType(), "getBlockData");
public static MethodHandle FLUIDSTATE_ISEMPTY = ReflectionHelper.getMethodHandle(BLOCKSTATEBASE_GETFLUIDSTATE.type().returnType(), "c");
public static MethodHandle FLUIDSTATE_CREATELEGACYBLOCK = ReflectionHelper.getMethodHandle(BLOCKSTATEBASE_GETFLUIDSTATE.type().returnType(), "g");
public static MethodHandle FLUIDSTATE_ANIMATETICK = ReflectionHelper.getMethodHandle(BLOCKSTATEBASE_GETFLUIDSTATE.type().returnType(), "a", Level.class, BlockPos.class, Random.class);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public static BlockState getCorrectStateForFluidBlock(Level world, BlockState ib

public static boolean blockStateFluidIsEmpty(BlockState iblockdata) {
try {
// return iblockdata.getFluidState().isEmpty();
Object fluid = BlockHelperImpl.BLOCKSTATEBASE_GETFLUIDSTATE.invoke(iblockdata);
return (boolean) BlockHelperImpl.FLUIDSTATE_ISEMPTY.invoke(fluid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@

public class BlockLightImpl extends BlockLight {

public static final Class LIGHTENGINETHREADED_UPDATE = ThreadedLevelLightEngine.class.getDeclaredClasses()[0]; // TaskType
public static final Object LIGHTENGINETHREADED_UPDATE_PRE;
public static final Class LIGHTENGINETHREADED_TASKTYPE = ThreadedLevelLightEngine.class.getDeclaredClasses()[0]; // TaskType
public static final Object LIGHTENGINETHREADED_TASKTYPE_PRE;

static {
Object preObj = null;
try {
preObj = ReflectionHelper.getFields(LIGHTENGINETHREADED_UPDATE).get(ReflectionMappingsInfo.ThreadedLevelLightEngine_Update_PRE_UPDATE).get(null);
preObj = ReflectionHelper.getFields(LIGHTENGINETHREADED_TASKTYPE).get(ReflectionMappingsInfo.ThreadedLevelLightEngine_TaskType_PRE_UPDATE).get(null);
}
catch (Throwable ex) {
ex.printStackTrace();
}
LIGHTENGINETHREADED_UPDATE_PRE = preObj;
LIGHTENGINETHREADED_TASKTYPE_PRE = preObj;
}

public static final MethodHandle LIGHTENGINETHREADED_QUEUERUNNABLE = ReflectionHelper.getMethodHandle(ThreadedLevelLightEngine.class, ReflectionMappingsInfo.ThreadedLevelLightEngine_addTask,
int.class, int.class, LIGHTENGINETHREADED_UPDATE, Runnable.class);
int.class, int.class, LIGHTENGINETHREADED_TASKTYPE, Runnable.class);

public static void enqueueRunnable(LevelChunk chunk, Runnable runnable) {
LevelLightEngine lightEngine = chunk.getLevel().getChunkSource().getLightEngine();
if (lightEngine instanceof ThreadedLevelLightEngine) {
ChunkPos coord = chunk.getPos();
try {
LIGHTENGINETHREADED_QUEUERUNNABLE.invoke(lightEngine, coord.x, coord.z, LIGHTENGINETHREADED_UPDATE_PRE, runnable);
LIGHTENGINETHREADED_QUEUERUNNABLE.invoke(lightEngine, coord.x, coord.z, LIGHTENGINETHREADED_TASKTYPE_PRE, runnable);
}
catch (Throwable ex) {
Debug.echoError(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ public void setListener(PacketListener packetlistener) {
public static Field SECTIONPOS_MULTIBLOCKCHANGE = ReflectionHelper.getFields(ClientboundSectionBlocksUpdatePacket.class).get(ReflectionMappingsInfo.ClientboundSectionBlocksUpdatePacket_sectionPos);
public static Field OFFSETARRAY_MULTIBLOCKCHANGE = ReflectionHelper.getFields(ClientboundSectionBlocksUpdatePacket.class).get(ReflectionMappingsInfo.ClientboundSectionBlocksUpdatePacket_positions);
public static Field BLOCKARRAY_MULTIBLOCKCHANGE = ReflectionHelper.getFields(ClientboundSectionBlocksUpdatePacket.class).get(ReflectionMappingsInfo.ClientboundSectionBlocksUpdatePacket_states);
public static Field BLOCKDATA_BLOCKBREAK = ReflectionHelper.getFields(ClientboundBlockBreakAckPacket.class).get(ReflectionMappingsInfo.ClientboundBlockBreakAckPacket_state);
public static Field ENTITY_METADATA_LIST = ReflectionHelper.getFields(ClientboundSetEntityDataPacket.class).get(ReflectionMappingsInfo.ClientboundSetEntityDataPacket_packedItems);

@Override
Expand Down Expand Up @@ -962,18 +961,18 @@ else if (packet instanceof ClientboundBlockUpdatePacket) {
}
}
else if (packet instanceof ClientboundBlockBreakAckPacket) {
BlockPos pos = ((ClientboundBlockBreakAckPacket) packet).pos();
ClientboundBlockBreakAckPacket origPack = (ClientboundBlockBreakAckPacket) packet;
BlockPos pos = origPack.pos();
LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
if (block != null) {
ClientboundBlockBreakAckPacket newPacket = new ClientboundBlockBreakAckPacket(copyPacket(packet));
BLOCKDATA_BLOCKBREAK.set(newPacket, FakeBlockHelper.getNMSState(block));
ClientboundBlockBreakAckPacket newPacket = new ClientboundBlockBreakAckPacket(origPack.pos(), FakeBlockHelper.getNMSState(block), origPack.action(), false);
oldManager.send(newPacket, genericfuturelistener);
return true;
}
}
}
catch (Exception ex) {
catch (Throwable ex) {
Debug.echoError(ex);
}
return false;
Expand Down

0 comments on commit 02fbd09

Please sign in to comment.