compatibility improvements for Bukkit environments

This commit is contained in:
Adrian Siekierka 2019-05-26 14:30:57 +02:00
parent b02b567de3
commit 25fd0c5267
20 changed files with 111 additions and 45 deletions
build.gradle
fabric-commands-v0
build.gradle
src/main
java/net/fabricmc/fabric/mixin/registrycommands
resources
fabric-containers-v0
fabric-networking-blockentity-v0
build.gradle
src/main/java/net/fabricmc/fabric/mixin/networkingblockentity
fabric-registry-sync-v0
fabric-textures-v0
build.gradle
src/main/java/net/fabricmc/fabric/mixin/client/texture

View file

@ -12,8 +12,8 @@ plugins {
def ENV = System.getenv()
def baseVersion = "0.3.0-pre"
def mcVersion = "1.14.2 Pre-Release 2"
def yarnVersion = "+build.2"
def mcVersion = "1.14.2 Pre-Release 4"
def yarnVersion = "+build.1"
def getSubprojectVersion(project, version) {
if (grgit == null) {
@ -40,7 +40,7 @@ allprojects {
dependencies {
minecraft "com.mojang:minecraft:$mcVersion"
mappings "net.fabricmc:yarn:${mcVersion}${yarnVersion}"
modCompile "net.fabricmc:fabric-loader:0.4.6+build.144"
modCompile "net.fabricmc:fabric-loader:0.4.8+build.154"
}
configurations {
@ -171,9 +171,6 @@ dependencies {
include project("${it.name}:")
}
}
// workaround linux segfault
// compile "org.lwjgl:lwjgl-jemalloc:3.2.1"
}
version = baseVersion + "+" + (ENV.BUILD_NUMBER ? ("build." + ENV.BUILD_NUMBER) : "local")

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-commands-v0"
version = getSubprojectVersion(project, "0.1.0")
version = getSubprojectVersion(project, "0.1.1")
dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -20,17 +20,17 @@ import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.fabric.impl.registry.CommandRegistryImpl;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(CommandManager.class)
public class MixinServerCommandManager {
@Shadow
private static Logger LOGGER;
public class MixinCommandManagerIntegrated {
@Shadow
private CommandDispatcher<ServerCommandSource> dispatcher;

View file

@ -3,8 +3,10 @@
"package": "net.fabricmc.fabric.mixin.registrycommands",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinMinecraftDedicatedServer",
"MixinServerCommandManager"
"MixinMinecraftDedicatedServer"
],
"client": [
"MixinCommandManagerIntegrated"
],
"injectors": {
"defaultRequire": 1

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-containers-v0"
version = getSubprojectVersion(project, "0.1.1")
version = getSubprojectVersion(project, "0.1.2")
dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -20,6 +20,7 @@ import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.container.ContainerFactory;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.fabricmc.fabric.impl.network.PacketTypes;
import net.fabricmc.fabric.mixin.container.ServerPlayerEntityAccessor;
import net.minecraft.client.network.packet.CustomPayloadS2CPacket;
import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerEntity;
@ -62,10 +63,27 @@ public class ContainerProviderImpl implements ContainerProviderRegistry {
openContainer(identifier, (ServerPlayerEntity) player, writer);
}
private boolean emittedNoSyncHookWarning = false;
@Override
public void openContainer(Identifier identifier, ServerPlayerEntity player, Consumer<PacketByteBuf> writer) {
SyncIdProvider syncIDProvider = (SyncIdProvider) player;
int syncId = syncIDProvider.fabric_incrementSyncId();
int syncId;
if (player instanceof ServerPlayerEntitySyncHook) {
ServerPlayerEntitySyncHook serverPlayerEntitySyncHook = (ServerPlayerEntitySyncHook) player;
syncId = serverPlayerEntitySyncHook.fabric_incrementSyncId();
} else if (player instanceof ServerPlayerEntityAccessor) {
if (!emittedNoSyncHookWarning) {
LOGGER.warn("ServerPlayerEntitySyncHook could not be applied - fabric-containers is using a hack!");
emittedNoSyncHookWarning = true;
}
syncId = (((ServerPlayerEntityAccessor) player).getContainerSyncId() + 1) % 100;
((ServerPlayerEntityAccessor) player).setContainerSyncId(syncId);
} else {
throw new RuntimeException("Neither ServerPlayerEntitySyncHook nor Accessor present! This should not happen!");
}
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeIdentifier(identifier);
buf.writeByte(syncId);

View file

@ -19,7 +19,7 @@ package net.fabricmc.fabric.impl.container;
/**
* This is a interface that is present on a ServerPlayerEntity, it allows access to the sync id.
*/
public interface SyncIdProvider {
public interface ServerPlayerEntitySyncHook {
/**
* gets and sets the new player sync id, and returns the new value

View file

@ -16,13 +16,13 @@
package net.fabricmc.fabric.mixin.container;
import net.fabricmc.fabric.impl.container.SyncIdProvider;
import net.fabricmc.fabric.impl.container.ServerPlayerEntitySyncHook;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(ServerPlayerEntity.class)
public abstract class MixinServerPlayerEntity implements SyncIdProvider {
public abstract class MixinServerPlayerEntity implements ServerPlayerEntitySyncHook {
@Shadow
private int containerSyncId;

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.mixin.container;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(ServerPlayerEntity.class)
public interface ServerPlayerEntityAccessor {
@Accessor
int getContainerSyncId();
@Accessor
void setContainerSyncId(int syncId);
}

View file

@ -0,0 +1,11 @@
{
"required": false,
"package": "net.fabricmc.fabric.mixin.container",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinServerPlayerEntity"
],
"injectors": {
"defaultRequire": 1
}
}

View file

@ -1,9 +1,9 @@
{
"required": true,
"required": false,
"package": "net.fabricmc.fabric.mixin.container",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinServerPlayerEntity"
"ServerPlayerEntityAccessor"
],
"injectors": {
"defaultRequire": 1

View file

@ -9,7 +9,8 @@
"fabric-networking-v0": "*"
},
"mixins": [
"fabric-containers-v0.mixins.json"
"fabric-containers-v0.mixins.json",
"fabric-containers-v0.accurate.mixins.json"
],
"entrypoints": {
"client": [

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-networking-blockentity-v0"
version = getSubprojectVersion(project, "0.1.0")
version = getSubprojectVersion(project, "0.1.1")
dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -23,9 +23,11 @@ import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.packet.BlockEntityUpdateS2CPacket;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
@ -34,8 +36,8 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(ClientPlayNetworkHandler.class)
public class MixinClientPlayNetworkHandler {
@Shadow
private static Logger LOGGER;
@Unique
private static Logger FABRIC_LOGGER = LogManager.getLogger();
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/packet/BlockEntityUpdateS2CPacket;getActionId()I", ordinal = 0), method = "onBlockEntityUpdate", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void onBlockEntityUpdate(BlockEntityUpdateS2CPacket packet, CallbackInfo info, BlockEntity entity) {
@ -47,7 +49,7 @@ public class MixinClientPlayNetworkHandler {
Identifier otherIdObj = BlockEntityType.getId(entity.getType());
;
if (otherIdObj == null) {
LOGGER.error(entity.getClass() + " is missing a mapping! This is a bug!");
FABRIC_LOGGER.error(entity.getClass() + " is missing a mapping! This is a bug!");
info.cancel();
return;
}

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-registry-sync-v0"
version = getSubprojectVersion(project, "0.1.1")
version = getSubprojectVersion(project, "0.1.2")
dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -31,9 +31,11 @@ import net.fabricmc.fabric.impl.registry.callbacks.RegistryPreRegisterCallback;
import net.minecraft.util.Identifier;
import net.minecraft.util.Int2ObjectBiMap;
import net.minecraft.util.registry.SimpleRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@ -42,14 +44,14 @@ import java.util.*;
@Mixin(SimpleRegistry.class)
public abstract class MixinIdRegistry<T> implements RemappableRegistry, ListenableRegistry<T> {
@Shadow
protected static Logger LOGGER;
@Shadow
protected Int2ObjectBiMap<T> indexedEntries;
@Shadow
protected BiMap<Identifier, T> entries;
@Shadow
private int nextId;
@Unique
private static Logger FABRIC_LOGGER = LogManager.getLogger();
private final Event<RegistryPreClearCallback> fabric_preClearEvent = EventFactory.createArrayBacked(RegistryPreClearCallback.class,
(callbacks) -> () -> {
@ -191,7 +193,7 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
for (Identifier id : registry.getIds()) {
if (!remoteIndexedEntries.containsKey(id)) {
LOGGER.warn("Adding " + id + " to registry.");
FABRIC_LOGGER.warn("Adding " + id + " to registry.");
remoteIndexedEntries.put(id, ++maxValue);
}
}
@ -229,7 +231,7 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
if (mode != RemapMode.AUTHORITATIVE) {
throw new RemapException(identifier + " missing from registry, but requested!");
} else {
LOGGER.warn(identifier + " missing from registry, but requested!");
FABRIC_LOGGER.warn(identifier + " missing from registry, but requested!");
}
continue;
}

View file

@ -23,9 +23,11 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.world.WorldSaveHandler;
import net.minecraft.world.level.LevelProperties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@ -38,8 +40,8 @@ import java.io.IOException;
@Mixin(WorldSaveHandler.class)
public class MixinWorldSaveHandler {
private static final int FABRIC_ID_REGISTRY_BACKUPS = 3;
@Shadow
private static Logger LOGGER;
@Unique
private static Logger FABRIC_LOGGER = LogManager.getLogger();
@Shadow
public File worldDir;
@ -68,7 +70,7 @@ public class MixinWorldSaveHandler {
public void readWorldProperties(CallbackInfoReturnable<LevelProperties> callbackInfo) {
// Load
for (int i = 0; i < FABRIC_ID_REGISTRY_BACKUPS; i++) {
LOGGER.info("Loading Fabric registry [file " + (i + 1) + "/" + (FABRIC_ID_REGISTRY_BACKUPS + 1) + "]");
FABRIC_LOGGER.info("Loading Fabric registry [file " + (i + 1) + "/" + (FABRIC_ID_REGISTRY_BACKUPS + 1) + "]");
try {
if (fabric_readIdMapFile(getWorldIdMapFile(i))) {
break;
@ -77,7 +79,7 @@ public class MixinWorldSaveHandler {
if (i >= FABRIC_ID_REGISTRY_BACKUPS - 1) {
throw new RuntimeException(e);
} else {
LOGGER.warn("Reading registry file failed!", e);
FABRIC_LOGGER.warn("Reading registry file failed!", e);
}
} catch (RemapException e) {
throw new RuntimeException("Remapping world failed!", e);
@ -103,7 +105,7 @@ public class MixinWorldSaveHandler {
NbtIo.writeCompressed(newIdMap, fileOutputStream);
fileOutputStream.close();
} catch (IOException e) {
LOGGER.warn("Failed to save registry file!", e);
FABRIC_LOGGER.warn("Failed to save registry file!", e);
}
fabric_lastSavedIdMap = newIdMap;

View file

@ -16,22 +16,22 @@
package net.fabricmc.fabric.mixin.registry.client;
import net.fabricmc.fabric.impl.network.ClientSidePacketRegistryImpl;
import net.fabricmc.fabric.impl.registry.RegistrySyncManager;
import net.fabricmc.fabric.impl.registry.RemapException;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MinecraftClient.class)
public class MixinMinecraftClient {
@Shadow
private static Logger LOGGER;
@Unique
private static Logger FABRIC_LOGGER = LogManager.getLogger();
// Unmap the registry before loading a new SP/MP setup.
@Inject(at = @At("RETURN"), method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V")
@ -39,7 +39,7 @@ public class MixinMinecraftClient {
try {
RegistrySyncManager.unmap();
} catch (RemapException e) {
LOGGER.warn("Failed to unmap Fabric registries!", e);
FABRIC_LOGGER.warn("Failed to unmap Fabric registries!", e);
}
}
}

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-textures-v0"
version = getSubprojectVersion(project, "0.1.1")
version = getSubprojectVersion(project, "0.1.2")
dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -31,9 +31,11 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.crash.CrashException;
import net.minecraft.util.crash.CrashReport;
import net.minecraft.util.crash.CrashReportSection;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
@ -45,8 +47,8 @@ import java.util.*;
@Mixin(SpriteAtlasTexture.class)
public abstract class MixinSpriteAtlasTexture implements SpriteAtlasTextureHooks {
@Shadow
private static Logger LOGGER;
@Unique
private static Logger FABRIC_LOGGER = LogManager.getLogger();
@Shadow
private int mipLevel;
@ -163,7 +165,7 @@ public abstract class MixinSpriteAtlasTexture implements SpriteAtlasTextureHooks
return;
}
} catch (RuntimeException | IOException e) {
LOGGER.error("Unable to load custom sprite {}: {}", sprite.getId(), e);
FABRIC_LOGGER.error("Unable to load custom sprite {}: {}", sprite.getId(), e);
info.setReturnValue(false);
return;
}
@ -172,7 +174,7 @@ public abstract class MixinSpriteAtlasTexture implements SpriteAtlasTextureHooks
sprite.generateMipmaps(this.mipLevel);
info.setReturnValue(true);
} catch (Throwable e) {
LOGGER.error("Unable to apply mipmap to custom sprite {}: {}", sprite.getId(), e);
FABRIC_LOGGER.error("Unable to apply mipmap to custom sprite {}: {}", sprite.getId(), e);
info.setReturnValue(false);
}
}