From 1e78ecbc746ec64e5c8494dca45bdf26b87695b9 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 2 Oct 2018 14:35:16 +0100 Subject: [PATCH 01/21] Initial 1.13.1 compile fixes, does NOT load into the game --- build.gradle | 3 +- .../rift/listener/ChunkGeneratorReplacer.java | 1 - .../dimdev/rift/listener/MessageAdder.java | 2 +- .../rift/mixin/hook/MixinDimensionType.java | 2 +- .../rift/mixin/hook/MixinMinecraftServer.java | 38 ++++++++----------- .../rift/mixin/hook/MixinTileEntityType.java | 4 +- .../java/org/dimdev/rift/network/Message.java | 2 +- .../dimdev/rift/util/ArmorMaterialImpl.java | 4 +- 8 files changed, 25 insertions(+), 31 deletions(-) diff --git a/build.gradle b/build.gradle index 5df21f1..3d79265 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,7 @@ repositories { maven { url 'https://libraries.minecraft.net/' } maven { url 'https://www.dimdev.org/maven/' } maven { url = 'https://repo.spongepowered.org/maven/' } + mavenLocal() } dependencies { @@ -43,7 +44,7 @@ dependencies { } minecraft { - version = '1.13' + version = '1.13.1' mappings = 'snapshot_20180908' runDir = 'run' tweakClass = 'org.dimdev.riftloader.launch.RiftLoaderClientTweaker' diff --git a/src/main/java/org/dimdev/rift/listener/ChunkGeneratorReplacer.java b/src/main/java/org/dimdev/rift/listener/ChunkGeneratorReplacer.java index 10f0f4c..1c1e3ef 100644 --- a/src/main/java/org/dimdev/rift/listener/ChunkGeneratorReplacer.java +++ b/src/main/java/org/dimdev/rift/listener/ChunkGeneratorReplacer.java @@ -5,7 +5,6 @@ import net.minecraft.world.gen.ChunkGeneratorType; import net.minecraft.world.gen.IChunkGenSettings; import net.minecraft.world.gen.IChunkGenerator; -import net.minecraft.world.gen.IChunkGeneratorFactory; import javax.annotation.Nullable; import java.util.function.Supplier; diff --git a/src/main/java/org/dimdev/rift/listener/MessageAdder.java b/src/main/java/org/dimdev/rift/listener/MessageAdder.java index 5e2e092..2f5d6a8 100644 --- a/src/main/java/org/dimdev/rift/listener/MessageAdder.java +++ b/src/main/java/org/dimdev/rift/listener/MessageAdder.java @@ -5,5 +5,5 @@ import org.dimdev.rift.network.Message; public interface MessageAdder { - void registerMessages(RegistryNamespaced> registry); + void registerMessages(RegistryNamespaced> registry); } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinDimensionType.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinDimensionType.java index efd1860..4ab47a1 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinDimensionType.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinDimensionType.java @@ -14,7 +14,7 @@ public class MixinDimensionType { private static HashMap dimensionTypes = new HashMap<>(); static { - for (DimensionType dimensionType : DimensionType.values()) { + for (DimensionType dimensionType : DimensionType.func_212681_b()) { dimensionTypes.put(dimensionType.getId(), dimensionType); } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java index 3ed6aa7..b918ce5 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java @@ -15,6 +15,7 @@ import net.minecraft.world.storage.ISaveFormat; import net.minecraft.world.storage.ISaveHandler; import net.minecraft.world.storage.WorldInfo; +import net.minecraft.world.storage.WorldSavedDataStorage; import org.dimdev.rift.listener.DataPackFinderAdder; import org.dimdev.rift.listener.ServerTickable; import org.dimdev.riftloader.RiftLoader; @@ -33,14 +34,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Consumer; @Mixin(MinecraftServer.class) public abstract class MixinMinecraftServer { @Shadow @Final private ResourcePackList resourcePacks; @Shadow @Final public Profiler profiler; @Shadow public abstract void convertMapIfNeeded(String p_convertMapIfNeeded_1_); - @Shadow public WorldServer[] worlds; - @Shadow public long[][] timeOfLastDimensionTick; + @Shadow public Map worlds; + @Shadow public Map timeOfLastDimensionTick; @Shadow public abstract ISaveFormat getActiveAnvilConverter(); @Shadow public abstract void setResourcePackFromWorld(String p_setResourcePackFromWorld_1_, ISaveHandler p_setResourcePackFromWorld_2_); @Shadow public abstract String getFolderName(); @@ -49,7 +51,6 @@ public abstract class MixinMinecraftServer { @Shadow public abstract boolean canStructuresSpawn(); @Shadow public abstract boolean isHardcore(); @Shadow public abstract void func_195560_a(File p_195560_1_, WorldInfo p_195560_2_); - @Shadow public abstract void initialWorldChunkLoad(); @Shadow public abstract void setDifficultyForAllWorlds(EnumDifficulty p_setDifficultyForAllWorlds_1_); @Shadow public abstract CustomBossEvents getCustomBossEvents(); @Shadow public abstract PlayerList getPlayerList(); @@ -101,9 +102,9 @@ public void loadAllWorlds(String saveName, String worldName, long seed, WorldTyp func_195560_a(saveHandler.getWorldDirectory(), worldInfo); // Create overworld - WorldServer overworld = isDemo() ? new WorldServerDemo((MinecraftServer) (Object) this, saveHandler, worldInfo, 0, profiler) - : new WorldServer((MinecraftServer) (Object) this, saveHandler, worldInfo, 0, profiler); - overworld.init(); + WorldServer overworld = isDemo() ? new WorldServerDemo((MinecraftServer) (Object) this, saveHandler, new WorldSavedDataStorage(saveHandler), worldInfo, DimensionType.OVERWORLD, profiler) + : new WorldServer((MinecraftServer) (Object) this, saveHandler, new WorldSavedDataStorage(saveHandler), worldInfo, DimensionType.OVERWORLD, profiler); + overworld.func_212251_i__(); overworld.initialize(worldSettings); overworld.addEventListener(new ServerWorldEventHandler((MinecraftServer) (Object) this, overworld)); @@ -132,8 +133,8 @@ public void loadAllWorlds(String saveName, String worldName, long seed, WorldTyp for (DimensionType dimensionType : dimensionTypes) { dimensionIdToWorldIndex.put(dimensionType.getId(), worldList.size()); dimensionTypeToWorldIndex.put(dimensionType, worldList.size()); - WorldServerMulti world = new WorldServerMulti((MinecraftServer) (Object) this, saveHandler, dimensionType.getId(), overworld, profiler); - world.init(); + WorldServerMulti world = new WorldServerMulti((MinecraftServer) (Object) this, saveHandler, dimensionType, overworld, profiler); + world.func_212251_i__(); world.addEventListener(new ServerWorldEventHandler((MinecraftServer) (Object) this, world)); if (!isSinglePlayer()) { world.getWorldInfo().setGameType(getGameType()); @@ -143,10 +144,13 @@ public void loadAllWorlds(String saveName, String worldName, long seed, WorldTyp } // Initialize other things - worlds = worldList.toArray(new WorldServer[0]); - timeOfLastDimensionTick = new long[worlds.length][100]; + worlds = new HashMap<>(); + worldList.forEach(worldServer -> worlds.put(worldServer.dimension.getType(), worldServer)); - getPlayerList().setPlayerManager(worlds); + timeOfLastDimensionTick = new HashMap<>(); + worldList.forEach(worldServer -> timeOfLastDimensionTick.put(worldServer.dimension.getType(), new long[100])); + + getPlayerList().func_212504_a(worlds.get(DimensionType.OVERWORLD)); if (worldInfo.getCustomBossEvents() != null) { getCustomBossEvents().read(worldInfo.getCustomBossEvents()); } @@ -154,8 +158,6 @@ public void loadAllWorlds(String saveName, String worldName, long seed, WorldTyp if (overworld.getWorldInfo().getDifficulty() == null) { setDifficultyForAllWorlds(getInitialDifficulty()); } - - // initialWorldChunkLoad(); } protected WorldSettings getWorldSettings(@Nullable WorldInfo worldInfo, long seed, WorldType worldType, JsonElement generatorOptions) { @@ -178,14 +180,4 @@ protected WorldSettings getWorldSettings(@Nullable WorldInfo worldInfo, long see protected EnumDifficulty getInitialDifficulty() { return getDifficulty(); } - - @Overwrite - public WorldServer getWorld(DimensionType dimensionType) { - return worlds[dimensionTypeToWorldIndex.get(dimensionType)]; - } - - @Overwrite - public WorldServer getWorld(int dimensionId) { - return worlds[dimensionIdToWorldIndex.get(dimensionId)]; - } } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java index 0c152bd..3b0b163 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java @@ -7,6 +7,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.datafix.DataFixesManager; import net.minecraft.util.datafix.TypeReferences; +import net.minecraft.util.registry.IRegistry; import net.minecraft.util.registry.RegistryNamespaced; import org.apache.logging.log4j.Logger; import org.dimdev.rift.listener.TileEntityTypeAdder; @@ -22,7 +23,6 @@ @Mixin(TileEntityType.class) public abstract class MixinTileEntityType { @Shadow @Final private static Logger LOGGER; - @Shadow @Final public static RegistryNamespaced> REGISTRY; @Overwrite public static TileEntityType registerTileEntityType(String id, TileEntityType.Builder builder) { @@ -35,7 +35,7 @@ public static TileEntityType registerTileEntityType(St } TileEntityType tileEntityType = builder.build(dataFixerType); - REGISTRY.put(new ResourceLocation(id), tileEntityType); + IRegistry.field_212626_o.put(new ResourceLocation(id), tileEntityType); return tileEntityType; } diff --git a/src/main/java/org/dimdev/rift/network/Message.java b/src/main/java/org/dimdev/rift/network/Message.java index 04222e1..0b2ae20 100644 --- a/src/main/java/org/dimdev/rift/network/Message.java +++ b/src/main/java/org/dimdev/rift/network/Message.java @@ -19,7 +19,7 @@ import java.util.function.Predicate; public abstract class Message { - public static final RegistryNamespaced> REGISTRY = new RegistryNamespaced<>(); + public static final RegistryNamespaced> REGISTRY = new RegistryNamespaced<>(); public abstract void write(PacketBuffer buffer); diff --git a/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java b/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java index ecab276..6dc7905 100644 --- a/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java +++ b/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java @@ -30,7 +30,9 @@ public ArmorMaterialImpl(String name, int maxDamageFactor, int[] damageReduction @Override public int getDurability(EntityEquipmentSlot slot) { - return ArmorMaterial.MAX_DAMAGE_ARRAY[slot.getIndex()] * maxDamageFactor; + return 0; + //TODO at + // return ArmorMaterial.MAX_DAMAGE_ARRAY[slot.getIndex()] * maxDamageFactor; } @Override From 1b889d9e32704be042acac818c2e48b583c40458 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 2 Oct 2018 14:47:10 +0100 Subject: [PATCH 02/21] Fix crash when loading the world --- src/main/java/org/dimdev/rift/listener/MessageAdder.java | 5 ++--- .../dimdev/rift/mixin/hook/MixinNetHandlerPlayServer.java | 4 ++++ .../rift/mixin/hook/client/MixinNetHandlerPlayClient.java | 4 ++++ src/main/java/org/dimdev/rift/network/Message.java | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/dimdev/rift/listener/MessageAdder.java b/src/main/java/org/dimdev/rift/listener/MessageAdder.java index 2f5d6a8..6fe81e0 100644 --- a/src/main/java/org/dimdev/rift/listener/MessageAdder.java +++ b/src/main/java/org/dimdev/rift/listener/MessageAdder.java @@ -1,9 +1,8 @@ package org.dimdev.rift.listener; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.registry.RegistryNamespaced; +import net.minecraft.util.registry.IRegistry; import org.dimdev.rift.network.Message; public interface MessageAdder { - void registerMessages(RegistryNamespaced> registry); + void registerMessages(IRegistry> registry); } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinNetHandlerPlayServer.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinNetHandlerPlayServer.java index c5d029e..90e6f07 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinNetHandlerPlayServer.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinNetHandlerPlayServer.java @@ -37,6 +37,10 @@ private void handleModCustomPayload(CPacketCustomPayload packet, CallbackInfo ci } } + if(Message.REGISTRY.isEmpty()){ + return; + } + Class messageClass = Message.REGISTRY.get(channelName); if (messageClass != null) { try { diff --git a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java index d185b6c..5f7ff4e 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java @@ -55,6 +55,10 @@ private void handleModCustomPayload(SPacketCustomPayload packet, CallbackInfo ci } } + if(Message.REGISTRY.isEmpty()){ + return; + } + Class messageClass = Message.REGISTRY.get(channelName); if (messageClass != null) { try { diff --git a/src/main/java/org/dimdev/rift/network/Message.java b/src/main/java/org/dimdev/rift/network/Message.java index 0b2ae20..82e7e10 100644 --- a/src/main/java/org/dimdev/rift/network/Message.java +++ b/src/main/java/org/dimdev/rift/network/Message.java @@ -13,13 +13,14 @@ import net.minecraft.network.play.server.SPacketCustomPayload; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; import net.minecraft.util.registry.RegistryNamespaced; import net.minecraft.world.WorldServer; import java.util.function.Predicate; public abstract class Message { - public static final RegistryNamespaced> REGISTRY = new RegistryNamespaced<>(); + public static final IRegistry> REGISTRY = IRegistry.func_212610_a("message", new RegistryNamespaced()); public abstract void write(PacketBuffer buffer); From fad4dfdab3333caa9a770b8ea3a563383870c5d3 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 2 Oct 2018 14:48:29 +0100 Subject: [PATCH 03/21] Fix TODO --- src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java b/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java index 6dc7905..b9dcb75 100644 --- a/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java +++ b/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java @@ -30,9 +30,7 @@ public ArmorMaterialImpl(String name, int maxDamageFactor, int[] damageReduction @Override public int getDurability(EntityEquipmentSlot slot) { - return 0; - //TODO at - // return ArmorMaterial.MAX_DAMAGE_ARRAY[slot.getIndex()] * maxDamageFactor; + return getDurability(slot) * maxDamageFactor; } @Override From 99f8cfa3978001f0923c33fc0d9b79832543598e Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 2 Oct 2018 14:55:51 +0100 Subject: [PATCH 04/21] Fix ArmorMaterialImpl --- src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java | 2 +- src/main/resources/access_transformations.at | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java b/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java index b9dcb75..ecab276 100644 --- a/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java +++ b/src/main/java/org/dimdev/rift/util/ArmorMaterialImpl.java @@ -30,7 +30,7 @@ public ArmorMaterialImpl(String name, int maxDamageFactor, int[] damageReduction @Override public int getDurability(EntityEquipmentSlot slot) { - return getDurability(slot) * maxDamageFactor; + return ArmorMaterial.MAX_DAMAGE_ARRAY[slot.getIndex()] * maxDamageFactor; } @Override diff --git a/src/main/resources/access_transformations.at b/src/main/resources/access_transformations.at index aabb8ef..4503949 100644 --- a/src/main/resources/access_transformations.at +++ b/src/main/resources/access_transformations.at @@ -31,4 +31,4 @@ public class bms$a # net.minecraft.world.gen.ChunkGeneratorType$Settings public class bmu # net.minecraft.world.chunk.ChunkStatus public method bwp b (Ljava/lang/Class;Ljava/lang/String;)V registerStructure # net.minecraft.world.gen.feature.structure.StructureIO/registerStructure public method bwp a (Ljava/lang/Class;Ljava/lang/String;)V # net.minecraft.world.gen.feature.structure.StructureIO/registerStructure -public field aqz g [I # net.minecraft.item.ArmorMaterial/MAX_DAMAGE_ARRAY +public field arc g [I # net.minecraft.item.ArmorMaterial/MAX_DAMAGE_ARRAY From d2d26ceda25e11d199c27a59519cc6e22c3e9d06 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 2 Oct 2018 15:00:47 +0100 Subject: [PATCH 05/21] Added RegistryUtil.createRegistry that adds takes a ResourceLocation --- src/main/java/org/dimdev/rift/network/Message.java | 3 ++- .../java/org/dimdev/rift/util/RegistryUtil.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/dimdev/rift/util/RegistryUtil.java diff --git a/src/main/java/org/dimdev/rift/network/Message.java b/src/main/java/org/dimdev/rift/network/Message.java index 82e7e10..0e46455 100644 --- a/src/main/java/org/dimdev/rift/network/Message.java +++ b/src/main/java/org/dimdev/rift/network/Message.java @@ -16,11 +16,12 @@ import net.minecraft.util.registry.IRegistry; import net.minecraft.util.registry.RegistryNamespaced; import net.minecraft.world.WorldServer; +import org.dimdev.rift.util.RegistryUtil; import java.util.function.Predicate; public abstract class Message { - public static final IRegistry> REGISTRY = IRegistry.func_212610_a("message", new RegistryNamespaced()); + public static final IRegistry> REGISTRY = RegistryUtil.createRegistry(new ResourceLocation("rift", "message"), new RegistryNamespaced()); public abstract void write(PacketBuffer buffer); diff --git a/src/main/java/org/dimdev/rift/util/RegistryUtil.java b/src/main/java/org/dimdev/rift/util/RegistryUtil.java new file mode 100644 index 0000000..c9a1db7 --- /dev/null +++ b/src/main/java/org/dimdev/rift/util/RegistryUtil.java @@ -0,0 +1,13 @@ +package org.dimdev.rift.util; + +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; + +public class RegistryUtil { + + public static IRegistry createRegistry(ResourceLocation resourceLocation, IRegistry registry) { + IRegistry.field_212617_f.put(resourceLocation, registry); + return registry; + } + +} From ffdcc8ee8caae7a7d3821b56df77982e53eb9b31 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 6 Nov 2018 14:50:33 +0000 Subject: [PATCH 06/21] Update mappings to 20181023 No more compile errors, but there are definitely some Mixins that don't work (or make sense) with 1.13 --- build.gradle | 2 +- .../org/dimdev/rift/mixin/core/client/MixinLavaFluid.java | 2 +- .../dimdev/rift/mixin/core/client/MixinWaterFluid.java | 6 +++--- .../java/org/dimdev/rift/mixin/hook/MixinItemTool.java | 2 +- .../org/dimdev/rift/mixin/hook/MixinMinecraftServer.java | 3 +-- .../org/dimdev/rift/mixin/hook/MixinTileEntityType.java | 8 ++++---- .../java/org/dimdev/rift/mixin/hook/MixinWorldServer.java | 4 ++-- .../dimdev/rift/mixin/hook/client/MixinModelBakery.java | 2 +- .../rift/mixin/hook/client/MixinNetHandlerPlayClient.java | 4 ++-- src/main/java/org/dimdev/rift/network/Message.java | 2 +- src/main/java/org/dimdev/rift/util/RegistryUtil.java | 2 +- 11 files changed, 18 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index 3d79265..7096570 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ dependencies { minecraft { version = '1.13.1' - mappings = 'snapshot_20180908' + mappings = 'snapshot_20181023' runDir = 'run' tweakClass = 'org.dimdev.riftloader.launch.RiftLoaderClientTweaker' makeObfSourceJar = false diff --git a/src/main/java/org/dimdev/rift/mixin/core/client/MixinLavaFluid.java b/src/main/java/org/dimdev/rift/mixin/core/client/MixinLavaFluid.java index 86d1ac9..ea5396d 100644 --- a/src/main/java/org/dimdev/rift/mixin/core/client/MixinLavaFluid.java +++ b/src/main/java/org/dimdev/rift/mixin/core/client/MixinLavaFluid.java @@ -1,7 +1,7 @@ package org.dimdev.rift.mixin.core.client; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.block.model.ModelBakery; +import net.minecraft.client.renderer.model.ModelBakery; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.fluid.LavaFluid; import net.minecraft.init.Blocks; diff --git a/src/main/java/org/dimdev/rift/mixin/core/client/MixinWaterFluid.java b/src/main/java/org/dimdev/rift/mixin/core/client/MixinWaterFluid.java index 6745e4b..d3fe126 100644 --- a/src/main/java/org/dimdev/rift/mixin/core/client/MixinWaterFluid.java +++ b/src/main/java/org/dimdev/rift/mixin/core/client/MixinWaterFluid.java @@ -1,13 +1,13 @@ package org.dimdev.rift.mixin.core.client; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.block.model.ModelBakery; +import net.minecraft.client.renderer.model.ModelBakery; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.fluid.WaterFluid; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorldReader; -import net.minecraft.world.biome.BiomeColorHelper; +import net.minecraft.world.biome.BiomeColors; import org.dimdev.rift.injectedmethods.RiftFluid; import org.spongepowered.asm.mixin.Mixin; @@ -25,6 +25,6 @@ public TextureAtlasSprite getFlowingTexture() { @Override public int getColorMultiplier(IWorldReader world, BlockPos pos) { - return BiomeColorHelper.getWaterColor(world, pos); + return BiomeColors.getWaterColor(world, pos); } } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinItemTool.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinItemTool.java index 257e348..c615a62 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinItemTool.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinItemTool.java @@ -22,7 +22,7 @@ public class MixinItemTool { @Shadow @Mutable @Final private Set effectiveBlocks; @Inject(method = "", at = @At("RETURN")) - private void onInit(float attackDamage, float attackSpeed, IItemTier tier, Set effectiveBlocks, Item.Builder builder, CallbackInfo ci) { + private void onInit(float attackDamage, float attackSpeed, IItemTier tier, Set effectiveBlocks, Item.Properties builder, CallbackInfo ci) { this.effectiveBlocks = new HashSet<>(effectiveBlocks); for (ToolEfficiencyProvider toolEfficiencyProvider : RiftLoader.instance.getListeners(ToolEfficiencyProvider.class)) { diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java index b918ce5..2d5aa72 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java @@ -34,7 +34,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Consumer; @Mixin(MinecraftServer.class) public abstract class MixinMinecraftServer { @@ -166,7 +165,7 @@ protected WorldSettings getWorldSettings(@Nullable WorldInfo worldInfo, long see return WorldServerDemo.DEMO_WORLD_SETTINGS; } else { WorldSettings worldSettings = new WorldSettings(seed, getGameType(), canStructuresSpawn(), isHardcore(), worldType); - worldSettings.func_205390_a(generatorOptions); + worldSettings.setGeneratorOptions(generatorOptions); if (enableBonusChest) { worldSettings.enableBonusChest(); } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java index 3b0b163..e89c6ab 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java @@ -8,7 +8,6 @@ import net.minecraft.util.datafix.DataFixesManager; import net.minecraft.util.datafix.TypeReferences; import net.minecraft.util.registry.IRegistry; -import net.minecraft.util.registry.RegistryNamespaced; import org.apache.logging.log4j.Logger; import org.dimdev.rift.listener.TileEntityTypeAdder; import org.dimdev.riftloader.RiftLoader; @@ -25,17 +24,18 @@ public abstract class MixinTileEntityType { @Shadow @Final private static Logger LOGGER; @Overwrite - public static TileEntityType registerTileEntityType(String id, TileEntityType.Builder builder) { - Type dataFixerType = null; + public static TileEntityType register(String id, TileEntityType.Builder builder) { + Type dataFixerType = null; try { + //Schema#getChoiceType can throw an IAE that vanilla won't catch, so we catch that too dataFixerType = DataFixesManager.getDataFixer().getSchema(DataFixUtils.makeKey(1519)).getChoiceType(TypeReferences.BLOCK_ENTITY, id); } catch (IllegalStateException | IllegalArgumentException e) { LOGGER.debug("No data fixer registered for block entity {}", id); } TileEntityType tileEntityType = builder.build(dataFixerType); - IRegistry.field_212626_o.put(new ResourceLocation(id), tileEntityType); + IRegistry.BLOCK_ENTITY_TYPE.put(new ResourceLocation(id), tileEntityType); return tileEntityType; } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinWorldServer.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinWorldServer.java index 05bb601..72eaa59 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinWorldServer.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinWorldServer.java @@ -16,9 +16,9 @@ public class MixinWorldServer { @SuppressWarnings("ConstantConditions") @Redirect(method = "createChunkProvider", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;createChunkGenerator()Lnet/minecraft/world/gen/IChunkGenerator;")) - protected IChunkGenerator onCreateChunkGenerator(Dimension dimension) { + protected IChunkGenerator onCreateChunkGenerator(Dimension dimension) { WorldServer world = (WorldServer) (Object) this; - WorldType type = world.getWorldInfo().getTerrainType(); + WorldType type = world.getWorldInfo().getGenerator(); IChunkGenerator generator = null; for(ChunkGeneratorReplacer adder : RiftLoader.instance.getListeners(ChunkGeneratorReplacer.class)) { IChunkGenerator value = adder.createChunkGenerator(world, type, dimension.getType().getId()); diff --git a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinModelBakery.java b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinModelBakery.java index 42ae7e0..947edc3 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinModelBakery.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinModelBakery.java @@ -1,6 +1,6 @@ package org.dimdev.rift.mixin.hook.client; -import net.minecraft.client.renderer.block.model.ModelBakery; +import net.minecraft.client.renderer.model.ModelBakery; import net.minecraft.util.ResourceLocation; import org.dimdev.rift.listener.client.TextureAdder; import org.dimdev.riftloader.RiftLoader; diff --git a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java index 5f7ff4e..33e6eeb 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java @@ -85,14 +85,14 @@ private void handleModCustomPayload(SPacketCustomPayload packet, CallbackInfo ci @Inject(method = "handleUpdateTileEntity", at = @At("RETURN")) private void handleUpdateModTileEntity(SPacketUpdateTileEntity packet, CallbackInfo ci) { TileEntity tileEntity = world.getTileEntity(packet.getPos()); - if (tileEntity == null || packet.getNbtCompound() == null || !packet.getNbtCompound().hasKey("id", 8)) { + if (tileEntity == null || packet.getNbtCompound() == null || !packet.getNbtCompound().contains("id", 8)) { return; } ResourceLocation tileEntityId = TileEntityType.getId(tileEntity.getType()); ResourceLocation packetId = new ResourceLocation(packet.getNbtCompound().getString("id")); if (packetId != null && !packetId.getNamespace().equals("minecraft") && packetId.equals(tileEntityId)) { - tileEntity.readFromNBT(packet.getNbtCompound()); + tileEntity.read(packet.getNbtCompound()); } } } diff --git a/src/main/java/org/dimdev/rift/network/Message.java b/src/main/java/org/dimdev/rift/network/Message.java index 0e46455..7121a3b 100644 --- a/src/main/java/org/dimdev/rift/network/Message.java +++ b/src/main/java/org/dimdev/rift/network/Message.java @@ -21,7 +21,7 @@ import java.util.function.Predicate; public abstract class Message { - public static final IRegistry> REGISTRY = RegistryUtil.createRegistry(new ResourceLocation("rift", "message"), new RegistryNamespaced()); + public static final IRegistry> REGISTRY = RegistryUtil.createRegistry(new ResourceLocation("rift", "message"), new RegistryNamespaced<>()); public abstract void write(PacketBuffer buffer); diff --git a/src/main/java/org/dimdev/rift/util/RegistryUtil.java b/src/main/java/org/dimdev/rift/util/RegistryUtil.java index c9a1db7..488d401 100644 --- a/src/main/java/org/dimdev/rift/util/RegistryUtil.java +++ b/src/main/java/org/dimdev/rift/util/RegistryUtil.java @@ -6,7 +6,7 @@ public class RegistryUtil { public static IRegistry createRegistry(ResourceLocation resourceLocation, IRegistry registry) { - IRegistry.field_212617_f.put(resourceLocation, registry); + IRegistry.REGISTRY.put(resourceLocation, registry); return registry; } From b65258a849150c9d6e11fbaa3927de089963e10c Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 6 Nov 2018 15:21:47 +0000 Subject: [PATCH 07/21] Update test mod mappings Now it compiles too --- .../testmod/ChangeDimensionCommand.java | 6 +++--- .../org/dimdev/testmod/ItemPacketTester.java | 4 ++-- .../java/org/dimdev/testmod/TestMod.java | 19 +++++++++-------- .../java/org/dimdev/testmod/WhiteFluid.java | 21 ++++++++++--------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/debug/java/org/dimdev/testmod/ChangeDimensionCommand.java b/src/debug/java/org/dimdev/testmod/ChangeDimensionCommand.java index 9868ac7..9a75ca1 100644 --- a/src/debug/java/org/dimdev/testmod/ChangeDimensionCommand.java +++ b/src/debug/java/org/dimdev/testmod/ChangeDimensionCommand.java @@ -2,19 +2,19 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import net.minecraft.command.CommandSource; +import net.minecraft.command.arguments.DimensionArgument; import net.minecraft.entity.Entity; public class ChangeDimensionCommand { public static void register(CommandDispatcher dispatcher) { LiteralArgumentBuilder builder = literalArgument("changedimension") - .then(requiredArgument("dimension", IntegerArgumentType.integer(0)) + .then(requiredArgument("dimension", DimensionArgument.getDimension()) .executes(context -> { Entity entity = context.getSource().getEntity(); - entity.changeDimension(context.getArgument("dimension", Integer.class)); + entity.func_212321_a(DimensionArgument.func_212592_a(context, "dimension")); return 0; })); dispatcher.register(builder); diff --git a/src/debug/java/org/dimdev/testmod/ItemPacketTester.java b/src/debug/java/org/dimdev/testmod/ItemPacketTester.java index 5fdac20..01a4d56 100644 --- a/src/debug/java/org/dimdev/testmod/ItemPacketTester.java +++ b/src/debug/java/org/dimdev/testmod/ItemPacketTester.java @@ -10,7 +10,7 @@ public class ItemPacketTester extends Item { private static final Logger log = LogManager.getLogger(); - public ItemPacketTester(Builder builder) { + public ItemPacketTester(Properties builder) { super(builder); } @@ -22,7 +22,7 @@ public EnumActionResult onItemUse(ItemUseContext context) { int data = (int) (Math.random() * 1000); log.info("Sending test packet and message to server: " + data); - Minecraft.getMinecraft().getConnection().sendPacket(new CPacketTest(data)); + Minecraft.getInstance().getConnection().sendPacket(new CPacketTest(data)); new TestMessage(data).sendToServer(); diff --git a/src/debug/java/org/dimdev/testmod/TestMod.java b/src/debug/java/org/dimdev/testmod/TestMod.java index 343944b..ed4937f 100644 --- a/src/debug/java/org/dimdev/testmod/TestMod.java +++ b/src/debug/java/org/dimdev/testmod/TestMod.java @@ -15,6 +15,7 @@ import net.minecraft.item.ItemGroup; import net.minecraft.network.EnumPacketDirection; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; import net.minecraft.util.registry.RegistryNamespaced; import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.EndDimension; @@ -34,12 +35,12 @@ public class TestMod implements BlockAdder, ItemAdder, FluidAdder, TextureAdder, PacketAdder, CommandAdder, ClientTickable, /*AmbientMusicTypeProvider,*/ DimensionTypeAdder, MessageAdder { private static final Logger LOGGER = LogManager.getLogger(); - public static final Block WHITE_BLOCK = new Block(Block.Builder.create(Material.ROCK)); - public static final Block TRANSLUCENT_WHITE_BLOCK = new BlockStainedGlass(EnumDyeColor.WHITE, Block.Builder.create(Material.GLASS)); + public static final Block WHITE_BLOCK = new Block(Block.Properties.create(Material.ROCK)); + public static final Block TRANSLUCENT_WHITE_BLOCK = new BlockStainedGlass(EnumDyeColor.WHITE, Block.Properties.create(Material.GLASS)); public static final FlowingFluid WHITE_FLUID = new WhiteFluid.Source(); public static final FlowingFluid FLOWING_WHITE_FLUID = new WhiteFluid.Flowing(); - public static final BlockFlowingFluid BLOCK_WHITE_FLUID = new BlockFlowingFluid(WHITE_FLUID, Block.Builder.create(Material.WATER).doesNotBlockMovement().hardnessAndResistance(100F, 100F).variableOpacity()); - public static final Item PACKET_TESTER = new ItemPacketTester(new Item.Builder()); + public static final BlockFlowingFluid BLOCK_WHITE_FLUID = new BlockFlowingFluid(WHITE_FLUID, Block.Properties.create(Material.WATER).doesNotBlockMovement().hardnessAndResistance(100F, 100F).variableOpacity()); + public static final Item PACKET_TESTER = new ItemPacketTester(new Item.Properties()); public static final MusicTicker.MusicType TEST_MUSIC = AmbientMusicTypeProvider.newMusicType("test", ENTITY_EXPERIENCE_ORB_PICKUP, 0, 0); private int clientTickCount = 0; @@ -52,9 +53,9 @@ public void registerBlocks() { @Override public void registerItems() { - Item.registerItemBlock(WHITE_BLOCK, ItemGroup.BUILDING_BLOCKS); - Item.registerItemBlock(TRANSLUCENT_WHITE_BLOCK, ItemGroup.BUILDING_BLOCKS); - Item.registerItem(new ResourceLocation("testmod", "packet_tester"), PACKET_TESTER); + Item.register(WHITE_BLOCK, ItemGroup.BUILDING_BLOCKS); + Item.register(TRANSLUCENT_WHITE_BLOCK, ItemGroup.BUILDING_BLOCKS); + Item.register(new ResourceLocation("testmod", "packet_tester"), PACKET_TESTER); } @Override @@ -106,7 +107,7 @@ public Set getDimensionTypes() { } @Override - public void registerMessages(RegistryNamespaced> registry) { - registry.putObject(new ResourceLocation("testmod", "test_message"), TestMessage.class); + public void registerMessages(IRegistry> registry) { + registry.put(new ResourceLocation("testmod", "test_message"), TestMessage.class); } } diff --git a/src/debug/java/org/dimdev/testmod/WhiteFluid.java b/src/debug/java/org/dimdev/testmod/WhiteFluid.java index 1f12472..9a72ec2 100644 --- a/src/debug/java/org/dimdev/testmod/WhiteFluid.java +++ b/src/debug/java/org/dimdev/testmod/WhiteFluid.java @@ -50,7 +50,8 @@ public Item getFilledBucket() { } @Override - public void randomDisplayTick(World world, BlockPos pos, IFluidState state, Random random) {} + protected void randomTick(World world, BlockPos pos, IFluidState state, Random random) { + } @Override @Nullable public IParticleData getDripParticleData() { @@ -74,12 +75,12 @@ public int getSlopeFindDistance(IWorldReaderBase worldIn) { @Override public IBlockState getBlockState(IFluidState state) { - return TestMod.BLOCK_WHITE_FLUID.getDefaultState().withProperty(BlockFlowingFluid.LEVEL, getLevelFromState(state)); + return TestMod.BLOCK_WHITE_FLUID.getDefaultState().with(BlockFlowingFluid.LEVEL, getLevelFromState(state)); } @Override - public boolean isSameAs(Fluid fluid) { - return fluid == TestMod.WHITE_FLUID || fluid == TestMod.FLOWING_WHITE_FLUID; + public boolean isEquivalentTo(Fluid fluid) { + return fluid == TestMod.WHITE_FLUID || fluid == TestMod.FLOWING_WHITE_FLUID; } @Override @@ -104,12 +105,12 @@ protected float getExplosionResistance() { @Override public TextureAtlasSprite getStillTexture() { - return Minecraft.getMinecraft().getModelManager().getBlockModelShapes().getModelForState(TestMod.BLOCK_WHITE_FLUID.getDefaultState()).getParticleTexture(); + return Minecraft.getInstance().getModelManager().getBlockModelShapes().getModel(TestMod.BLOCK_WHITE_FLUID.getDefaultState()).getParticleTexture(); } @Override public TextureAtlasSprite getFlowingTexture() { - return Minecraft.getMinecraft().getTextureMapBlocks().getSprite(new ResourceLocation("testmod", "block/white_fluid_flow")); + return Minecraft.getInstance().getTextureMap().getSprite(new ResourceLocation("testmod", "block/white_fluid_flow")); } @Override @@ -122,14 +123,14 @@ public static class Flowing extends WhiteFluid { public Flowing() {} @Override - protected void buildStateContainer(StateContainer.Builder builder) { - super.buildStateContainer(builder); - builder.add(LEVEL_1_TO_8); + protected void fillStateContainer(StateContainer.Builder builder) { + super.fillStateContainer(builder); + builder.add(LEVEL_1_8); } @Override public int getLevel(IFluidState getLevel) { - return getLevel.getValue(LEVEL_1_TO_8); + return getLevel.get(LEVEL_1_8); } @Override From bccd4d78ed715c208b7a18b07eada7ee88382222 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 7 Nov 2018 17:51:42 +0000 Subject: [PATCH 08/21] Update access transformations Bundled the updating script designed to do MCP methods to Notch names too, fields and classes are comparatively easier (and faster) --- .../rift/AccessTransformerUpdater.java | 323 ++++++++++++++++++ src/main/resources/access_transformations.at | 67 ++-- 2 files changed, 359 insertions(+), 31 deletions(-) create mode 100644 src/debug/java/com/chocohead/rift/AccessTransformerUpdater.java diff --git a/src/debug/java/com/chocohead/rift/AccessTransformerUpdater.java b/src/debug/java/com/chocohead/rift/AccessTransformerUpdater.java new file mode 100644 index 0000000..fb2b81b --- /dev/null +++ b/src/debug/java/com/chocohead/rift/AccessTransformerUpdater.java @@ -0,0 +1,323 @@ +package com.chocohead.rift; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipInputStream; + +import org.apache.commons.io.IOUtils; + +import com.google.common.base.Charsets; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + +public class AccessTransformerUpdater { + public static class ClassMapping { + public final Set constructors = new HashSet<>(); + public final Map methods = new HashMap<>(); + public final Map fields = new HashMap<>(); + public final String notchName, mcpName; + + public ClassMapping(String notchName, String mcpName) { + this.notchName = notchName; + this.mcpName = mcpName; + } + } + + public static void main(String[] args) throws InterruptedException, ExecutionException { + ExecutorService executor = Executors.newFixedThreadPool(2); + + Future> srgTask = executor.submit(() -> { + Map files = download("http://files.minecraftforge.net/maven/de/oceanlabs/mcp/mcp_config/1.13.1-20180929.143449/mcp_config-1.13.1-20180929.143449.zip", Sets.newHashSet("config/joined.tsrg", "config/constructors.txt")); + try (BufferedReader contents = new BufferedReader(new StringReader(files.get("config/joined.tsrg"))); BufferedReader constructors = new BufferedReader(new StringReader(files.get("config/constructors.txt")))) { + Map classes = new HashMap<>(); + + ClassMapping current = null; + for (String line = contents.readLine(); line != null; line = contents.readLine()) { + if (line.charAt(0) != '\t') { + String[] parts = line.split(" "); + if (parts.length != 2) + throw new IllegalStateException("Unexpected line split: " + Arrays.toString(parts) + " from " + line); + + classes.put(parts[1], current = new ClassMapping(parts[0], parts[1])); + } else { + String[] parts = line.substring(1).split(" "); + switch (parts.length) { + case 2: //Field + current.fields.put(parts[1], parts[0]); + break; + + case 3: //Method + current.methods.put(parts[2], parts[0] + ' ' + parts[1]); + break; + + default: + throw new IllegalStateException("Unexpected line split: " + Arrays.toString(parts) + " from " + line); + } + } + } + + Pattern classFinder = Pattern.compile("L([^;]+);"); + for (String line = constructors.readLine(); line != null; line = constructors.readLine()) { + if (line.startsWith("#")) continue; + String[] parts = line.split(" "); + + if (parts.length != 3) + throw new IllegalStateException("Unexpected line length: " + Arrays.toString(parts) + " from " + line); + + current = classes.get(parts[1]); + if (current == null) { + //Anonymous classes will often not have mappings, ATing them would be pointless as they're inaccessible anyway + //System.err.println("Unable to find " + parts[1] + " for constructor"); + continue; + } + + String desc = parts[2]; + StringBuffer buf = new StringBuffer(" "); + + Matcher matcher = classFinder.matcher(desc); + while (matcher.find()) { + ClassMapping type = classes.get(matcher.group(1)); + matcher.appendReplacement(buf, Matcher.quoteReplacement('L' + (type == null ? matcher.group(1) : type.notchName) + ';')); + } + matcher.appendTail(buf); + + current.constructors.add(buf.toString()); + } + + return classes; + } catch (IOException e) { + throw new RuntimeException("Error processing SRG mappings", e); + } + }); + Future> mcpTask = executor.submit(() -> { + Map files = download(String.format("http://export.mcpbot.bspk.rs/mcp_snapshot_nodoc/%1$s/mcp_snapshot_nodoc-%1$s.zip", "20181106-1.13.1"), Sets.newHashSet("methods.csv", "fields.csv")); + try (BufferedReader methodList = new BufferedReader(new StringReader(files.get("methods.csv"))); BufferedReader fieldList = new BufferedReader(new StringReader(files.get("fields.csv")))) { + Map mappings = new HashMap<>(); + + readMcpMappings(methodList, mappings); + readMcpMappings(fieldList, mappings); + + return mappings; + } catch (IOException e) { + throw new RuntimeException("Error unjoining SRG names", e); + } + }); + + Map srg = srgTask.get(); + Map mcp = mcpTask.get(); + executor.shutdown(); + + List transforms = new ArrayList<>(); + Set seenTransforms = new HashSet<>(); + for (String line : new String[] { + "public method bcr a (Ljava/lang/String;Lbcr;)V # net.minecraft.block.Block/register\r\n", + "public method bcr a (Lpc;Lbcr;)V # net.minecraft.block.Block/register\r\n", + "public method bcr$c a (Lbhq;)Lbcr$c; # net.minecraft.block.Block$Properties/sound\r\n", + "public method bcr$c a (I)Lbcr$c; # net.minecraft.block.Block$Properties/lightValue\r\n", + "public method bcr$c b ()Lbcr$c; # net.minecraft.block.Block$Properties/zeroHardnessAndResistance\r\n", + "public method bcr$c c ()Lbcr$c; # net.minecraft.block.Block$Properties/needsRandomTick\r\n", + "public method bcr$c d ()Lbcr$c; # net.minecraft.block.Block$Properties/variableOpacity\r\n", + "\r\n", + "public method asz a (Lari;)V # net.minecraft.item.Item/register\r\n", + "public method asz a (Lbcr;Larx;)V # net.minecraft.item.Item/register\r\n", + "public method asz a (Lbcr;Lasw;)V # net.minecraft.item.Item/register\r\n", + "public method asz a (Ljava/lang/String;Lasz;)V # net.minecraft.item.Item/register\r\n", + "public method asz a (Lpc;Lasz;)V # net.minecraft.item.Item/register\r\n", + "public method asz b (Lbcj;)V # net.minecraft.item.Item/register\r\n", + "\r\n", + "public method bym a (Ljava/lang/String;Lbym;)V # net.minecraft.fluid.Fluid/register\r\n", + "public method bym a (Lpc;Lbym;)V # net.minecraft.fluid.Fluid/register\r\n", + "public method bfl (Lbyl;Lbcj$c;)V # net.minecraft.block.BlockFlowingFluid/", + "\r\n", + "public method ayt a (ILjava/lang/String;Layt;)V # net.minecraft.world.biome.Biome/register", + "\r\n", + "public method fl (Lpc;ZLfk$a;)V # net.minecraft.particles.ParticleType/", + "public method fl a (Ljava/lang/String;Z)V # net.minecraft.particles.ParticleType/register", + "public method fl a (Ljava/lang/String;ZLfk$a;)V # net.minecraft.particles.ParticleType/register", + "public class fn # net.minecraft.particles.BasicParticleType", + "public method fn (Lpc;Z)V # net.minecraft.particles.BasicParticleType/", + "\r\n", + "public method awa a (Ljava/lang/String;Lawa;)V # net.minecraft.enchantment.Enchantment/func_210770_a", + "public method aeg a (ILjava/lang/String;Laeg;)V # net.minecraft.potion.Potion/func_210759_a", + "\r\n", + "public method wh a (Ljava/lang/String;)V # net.minecraft.util.SoundEvent/register", + "\r\n", + "public method axz (ILjava/lang/String;)V # net.minecraft.world.WorldType/", + "public method axz (ILjava/lang/String;I)V # net.minecraft.world.WorldType/", + "public method axz (ILjava/lang/String;Ljava/lang/String;I)V # net.minecraft.world.WorldType/", + "public class bmz # net.minecraft.world.gen.IChunkGeneratorFactory", + "public class bnc # net.minecraft.world.chunk.ChunkStatus", + "public method bwp b (Ljava/lang/Class;Ljava/lang/String;)V registerStructure # net.minecraft.world.gen.feature.structure.StructureIO/registerStructure", + "public method bwp a (Ljava/lang/Class;Ljava/lang/String;)V # net.minecraft.world.gen.feature.structure.StructureIO/registerStructure" + }) { + line = line.trim(); + if (line.isEmpty()) { + transforms.add(""); + continue; + } + + String name = line.substring(line.lastIndexOf(' ') + 1); + int split = name.lastIndexOf('/'); + if (split <= 0) { + transforms.add("#??? " + line); + System.err.println("Bad line: " + line); + continue; + } + String targetClass = name.substring(0, split++).replace('.', '/'); + String targetMethod = name.substring(split); + + ClassMapping mappings = srg.get(targetClass); + if (mappings == null) { + transforms.add("#??? " + line); + System.err.println("Unable to find mapping for " + targetClass + " (from " + line + ')'); + continue; + } + + String[] result; + if ("".equals(targetMethod)) { + //We're looking for constructors (which are inherently ambiguous without parameters) + switch (mappings.constructors.size()) { + case 0: + System.err.println("Unable to find any constructors for " + targetClass); + continue; + + case 1: { + System.out.println("Found constructor for " + targetClass); + String match = Iterables.getOnlyElement(mappings.constructors); + result = new String[] {match}; + } + + default: + System.out.println("Fuzzing " + targetClass + " constructors, found " + mappings.constructors.size()); + result = mappings.constructors.toArray(new String[0]); + } + } else { + //Find all the possible SRG -> MCP mappings for the target class + Set> options = mcp.entrySet().stream().filter(entry -> mappings.methods.containsKey(entry.getKey())).collect(Collectors.toSet()); + + Set matches; + if (!targetMethod.startsWith("func_")) { + //Find all the matching MCP names for the target + matches = options.stream().filter(entry -> entry.getValue().equals(targetMethod)).map(Entry::getKey).collect(Collectors.toSet()); + } else { + //Looks like there isn't an MCP name for the target, search by SRG instead + matches = options.stream().map(Entry::getKey).filter(entry -> entry.equals(targetMethod)).collect(Collectors.toSet()); + } + + switch (matches.size()) { + case 0: + System.err.println("Unable to find any matching method names for " + targetMethod + " (did find " + options + ')'); + continue; + + case 1: { + System.out.println("Found mapping for " + targetMethod); + String match = Iterables.getOnlyElement(matches); + result = new String[] {mappings.methods.get(match)}; + break; + } + + default: + System.out.println("Fuzzing " + targetMethod + ", found " + matches.size() + " matches"); + result = matches.stream().map(mappings.methods::get).toArray(String[]::new); + } + } + + //System.out.println(Arrays.toString(result)); + List written = new ArrayList<>(); + + for (String transform : result) { + transform = mappings.notchName + ' ' + transform; + + //Fuzzed mappings can result in already transforming some methods + if (!seenTransforms.contains(transform)) { + seenTransforms.add(transform); + transforms.add(transform + " # " + line); + + written.add(transform); + } + } + + System.out.println(written); + } + + System.out.println(); + System.out.println(); + transforms.forEach(System.out::println); + } + + static void readMcpMappings(BufferedReader contents, Map mappings) throws IOException { + contents.readLine(); //Skip the header line + + for (String line = contents.readLine(); line != null; line = contents.readLine()) { + int first = line.indexOf(','); + + String srg = line.substring(0, first++); + String mcp = line.substring(first, line.indexOf(',', first)); + + mappings.put(srg, mcp); + } + } + + private static Map download(String url, Set files) { + HttpURLConnection connection = null; + try { + URL target = new URL(url); + connection = (HttpURLConnection) target.openConnection(); + + try (InputStream in = connection.getInputStream(); ZipInputStream zip = new ZipInputStream(in)) { + Map out = new HashMap<>(); + + for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { + //System.out.println(entry.getName()); + + if (!entry.isDirectory()) { + if (files.remove(entry.getName())) { + byte[] content = new byte[4096]; + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + + int read; + while ((read = zip.read(content)) != -1) { + bytes.write(content, 0, read); + } + + out.put(entry.getName(), new String(bytes.toByteArray(), Charsets.UTF_8)); + if (files.isEmpty()) return out; + } + } + + zip.closeEntry(); + } + } + + throw new RuntimeException("Unable to find targets in " + url + " (missed " + files + ')'); + } catch (ZipException e) { + throw new SecurityException("Invalid (non?) zip response from " + url, e); + } catch (IOException e) { + throw new RuntimeException("Error downloading mappings from " + url, e); + } finally { + IOUtils.close(connection); + } + } +} \ No newline at end of file diff --git a/src/main/resources/access_transformations.at b/src/main/resources/access_transformations.at index 4503949..cc8372e 100644 --- a/src/main/resources/access_transformations.at +++ b/src/main/resources/access_transformations.at @@ -1,34 +1,39 @@ -public method bcj a (Ljava/lang/String;Lbcj;)V # net.minecraft.block.Block/registerBlock -public method bcj a (Lpc;Lbcj;)V # net.minecraft.block.Block/registerBlock -public method bcj$c a (Lbhi;)Lbcj$c; # net.minecraft.block.Block$Builder/soundType -public method bcj$c a (I)Lbcj$c; # net.minecraft.block.Block$Builder/lightValue -public method bcj$c b ()Lbcj$c; # net.minecraft.block.Block$Builder/zeroHardnessAndResistance -public method bcj$c c ()Lbcj$c; # net.minecraft.block.Block$Builder/needsRandomTick -public method bcj$c d ()Lbcj$c; # net.minecraft.block.Block$Builder/variableOpacity -public method asw a (Larf;)V # net.minecraft.item.Item/registerItemBlock -public method asw a (Lbcj;Laru;)V # net.minecraft.item.Item/registerItemBlock -public method asw a (Lbcj;Lasw;)V # net.minecraft.item.Item/registerItemBlock -public method asw a (Ljava/lang/String;Lasw;)V # net.minecraft.item.Item/registerItemBlock -public method asw a (Lpc;Lasw;)V # net.minecraft.item.Item/registerItemBlock -public method asw b (Lbcj;)V # net.minecraft.item.Item/registerItemBlock -public method bym a (Ljava/lang/String;Lbym;)V # net.minecraft.fluid.Fluid/registerFluid -public method bym a (Lpc;Lbym;)V # net.minecraft.fluid.Fluid/registerFluid -public method ayn a (ILjava/lang/String;Layn;)V # net.minecraft.world.biome.Biome/registerBiome -public method fl a (Ljava/lang/String;Z)V # net.minecraft.particles.ParticleType/registerParticleType -public method fl a (Ljava/lang/String;ZLfk$a;)V # net.minecraft.particles.ParticleType/registerParticleType +public method bcr a (Ljava/lang/String;Lbcr;)V # net.minecraft.block.Block/register +public method bcr a (Lpc;Lbcr;)V # net.minecraft.block.Block/register +public method bcr$c a (Lbhq;)Lbcr$c; # net.minecraft.block.Block$Properties/sound +public method bcr$c a (I)Lbcr$c; # net.minecraft.block.Block$Properties/lightValue +public method bcr$c b ()Lbcr$c; # net.minecraft.block.Block$Properties/zeroHardnessAndResistance +public method bcr$c c ()Lbcr$c; # net.minecraft.block.Block$Properties/needsRandomTick +public method bcr$c d ()Lbcr$c; # net.minecraft.block.Block$Properties/variableOpacity + +public method asz a (Lari;)V # net.minecraft.item.Item/register +public method asz a (Lbcr;Larx;)V # net.minecraft.item.Item/register +public method asz a (Lbcr;Lasz;)V # net.minecraft.item.Item/register +public method asz a (Ljava/lang/String;Lasz;)V # net.minecraft.item.Item/register +public method asz a (Lpc;Lasz;)V # net.minecraft.item.Item/register +public method asz b (Lbcr;)V # net.minecraft.item.Item/register + +public method byu a (Ljava/lang/String;Lbyu;)V # net.minecraft.fluid.Fluid/register +public method byu a (Lpc;Lbyu;)V # net.minecraft.fluid.Fluid/register +public method bft (Lbyt;Lbcr$c;)V # net.minecraft.block.BlockFlowingFluid/ + +public method ayt a (ILjava/lang/String;Layt;)V # net.minecraft.world.biome.Biome/register + public method fl (Lpc;ZLfk$a;)V # net.minecraft.particles.ParticleType/ -public class fn # net.minecraft.particles.BasicParticleType +public method fl a (Ljava/lang/String;Z)V # net.minecraft.particles.ParticleType/register +public method fl a (Ljava/lang/String;ZLfk$a;)V # net.minecraft.particles.ParticleType/register public method fn (Lpc;Z)V # net.minecraft.particles.BasicParticleType/ -public method awa a (Ljava/lang/String;Lawa;)V # net.minecraft.enchantment.Enchantment/func_210770_a -public method aeg a (ILjava/lang/String;Laeg;)V # net.minecraft.potion.Potion/func_210759_a -public method bfl (Lbyl;Lbcj$c;)V # net.minecraft.block.BlockFlowingFluid -public method wh a (Ljava/lang/String;)V # net.minecraft.util.SoundEvent -public method axz (ILjava/lang/String;)V # net.minecraft.world.WorldType/ -public method axz (ILjava/lang/String;I)V # net.minecraft.world.WorldType/ -public method axz (ILjava/lang/String;Ljava/lang/String;I)V # net.minecraft.world.WorldType/ -public class bmr # net.minecraft.world.gen.IChunkGeneratorFactory -public class bms$a # net.minecraft.world.gen.ChunkGeneratorType$Settings -public class bmu # net.minecraft.world.chunk.ChunkStatus -public method bwp b (Ljava/lang/Class;Ljava/lang/String;)V registerStructure # net.minecraft.world.gen.feature.structure.StructureIO/registerStructure -public method bwp a (Ljava/lang/Class;Ljava/lang/String;)V # net.minecraft.world.gen.feature.structure.StructureIO/registerStructure + +public method awd a (Ljava/lang/String;Lawd;)V # net.minecraft.enchantment.Enchantment/func_210770_a +public method aej a (ILjava/lang/String;Laej;)V # net.minecraft.potion.Potion/func_210759_a + +public method wi a (Ljava/lang/String;)V # net.minecraft.util.SoundEvent/register + +public method ayf (ILjava/lang/String;)V # net.minecraft.world.WorldType/ +public method ayf (ILjava/lang/String;I)V # net.minecraft.world.WorldType/ +public method ayf (ILjava/lang/String;Ljava/lang/String;I)V # net.minecraft.world.WorldType/ +public class bmz # net.minecraft.world.gen.IChunkGeneratorFactory +public class bnc # net.minecraft.world.chunk.ChunkStatus +public method bwx b (Ljava/lang/Class;Ljava/lang/String;)V # net.minecraft.world.gen.feature.structure.StructureIO/registerStructure + public field arc g [I # net.minecraft.item.ArmorMaterial/MAX_DAMAGE_ARRAY From a6e672b30b911a1ce67ffb9e63284eabe0da8fde Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 7 Nov 2018 18:57:19 +0000 Subject: [PATCH 09/21] Update some Mixin shadow mappings Game can now load to the world --- .../java/org/dimdev/testmod/TestMod.java | 2 +- .../rift/mixin/core/MixinVanillaPack.java | 8 ++++---- .../core/client/MixinBlockFluidRenderer.java | 20 +++++++++---------- .../dimdev/rift/mixin/hook/MixinBiome.java | 2 +- .../rift/mixin/hook/MixinMinecraftServer.java | 6 +++--- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/debug/java/org/dimdev/testmod/TestMod.java b/src/debug/java/org/dimdev/testmod/TestMod.java index ed4937f..d1a277d 100644 --- a/src/debug/java/org/dimdev/testmod/TestMod.java +++ b/src/debug/java/org/dimdev/testmod/TestMod.java @@ -16,11 +16,11 @@ import net.minecraft.network.EnumPacketDirection; import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.IRegistry; -import net.minecraft.util.registry.RegistryNamespaced; import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.EndDimension; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; + import org.dimdev.rift.listener.*; import org.dimdev.rift.listener.client.AmbientMusicTypeProvider; import org.dimdev.rift.listener.client.ClientTickable; diff --git a/src/main/java/org/dimdev/rift/mixin/core/MixinVanillaPack.java b/src/main/java/org/dimdev/rift/mixin/core/MixinVanillaPack.java index 4b9d83d..ae7e280 100644 --- a/src/main/java/org/dimdev/rift/mixin/core/MixinVanillaPack.java +++ b/src/main/java/org/dimdev/rift/mixin/core/MixinVanillaPack.java @@ -16,7 +16,7 @@ @Mixin(VanillaPack.class) public class MixinVanillaPack { - @Shadow public static Path field_199754_a; + @Shadow public static Path basePath; /** * @reason Give priority to resources in the Minecraft jar to avoid them @@ -24,11 +24,11 @@ public class MixinVanillaPack { */ @Overwrite @Nullable - protected InputStream func_195782_c(ResourcePackType type, ResourceLocation location) { + protected InputStream getInputStreamVanilla(ResourcePackType type, ResourceLocation location) { String pathString = type.getDirectoryName() + "/" + location.getNamespace() + "/" + location.getPath(); - if (field_199754_a != null) { - Path path = field_199754_a.resolve(pathString); + if (basePath != null) { + Path path = basePath.resolve(pathString); if (Files.exists(path)) { try { return Files.newInputStream(path); diff --git a/src/main/java/org/dimdev/rift/mixin/core/client/MixinBlockFluidRenderer.java b/src/main/java/org/dimdev/rift/mixin/core/client/MixinBlockFluidRenderer.java index 2638d64..88eef2c 100644 --- a/src/main/java/org/dimdev/rift/mixin/core/client/MixinBlockFluidRenderer.java +++ b/src/main/java/org/dimdev/rift/mixin/core/client/MixinBlockFluidRenderer.java @@ -25,9 +25,9 @@ @Mixin(BlockFluidRenderer.class) public abstract class MixinBlockFluidRenderer { @Shadow private static boolean isAdjacentFluidSameAs(IBlockReader world, BlockPos pos, EnumFacing side, IFluidState state) { return false; } - @Shadow private static boolean func_209556_a(IBlockReader p_209556_0_, BlockPos p_209556_1_, EnumFacing p_209556_2_, float p_209556_3_) { return false; } - @Shadow protected abstract float func_204504_a(IWorldReaderBase p_204504_1_, BlockPos p_204504_2_, Fluid p_204504_3_); - @Shadow protected abstract int func_204835_a(IWorldReader p_204835_1_, BlockPos p_204835_2_); + @Shadow private static boolean func_209556_a(IBlockReader world, BlockPos pos, EnumFacing side, float height) { return false; } + @Shadow protected abstract float getFluidHeight(IWorldReaderBase world, BlockPos pos, Fluid fluid); + @Shadow protected abstract int getCombinedLightUpMax(IWorldReader world, BlockPos pos); @Shadow private TextureAtlasSprite atlasSpriteWaterOverlay; @Overwrite @@ -62,10 +62,10 @@ public boolean render(IWorldReader world, BlockPos pos, BufferBuilder buffer, IF boolean rendered = false; - float var17 = func_204504_a(world, pos, state.getFluid()); - float var18 = func_204504_a(world, pos.south(), state.getFluid()); - float var19 = func_204504_a(world, pos.east().south(), state.getFluid()); - float var20 = func_204504_a(world, pos.east(), state.getFluid()); + float var17 = getFluidHeight(world, pos, state.getFluid()); + float var18 = getFluidHeight(world, pos.south(), state.getFluid()); + float var19 = getFluidHeight(world, pos.east().south(), state.getFluid()); + float var20 = getFluidHeight(world, pos.east(), state.getFluid()); double x = pos.getX(); double y = pos.getY(); @@ -115,7 +115,7 @@ public boolean render(IWorldReader world, BlockPos pos, BufferBuilder buffer, IF var34 = texture.getInterpolatedV(8 + (-var37 - var36) * 16); } - int blockLight = func_204835_a(world, pos); + int blockLight = getCombinedLightUpMax(world, pos); int skyLight = blockLight >> 16; buffer.pos(x, y + var17, z).color(redMultiplier, greenMultiplier, blueMultiplier, 1).tex(minU, var28).lightmap(skyLight, blockLight).endVertex(); @@ -136,7 +136,7 @@ public boolean render(IWorldReader world, BlockPos pos, BufferBuilder buffer, IF minV = stillTexture.getMinV(); maxV = stillTexture.getMaxV(); - int blockLight = func_204835_a(world, pos.down()); + int blockLight = getCombinedLightUpMax(world, pos.down()); int skyLight = blockLight >> 16; float darkerRedMultiplier = 0.5F * redMultiplier; @@ -212,7 +212,7 @@ public boolean render(IWorldReader world, BlockPos pos, BufferBuilder buffer, IF float var60 = texture.getInterpolatedV((1 - maxU) * 16 * 0.5); float var61 = texture.getInterpolatedV((1 - minV) * 16 * 0.5); float var62 = texture.getInterpolatedV(8); - int var63 = func_204835_a(world, var55); + int var63 = getCombinedLightUpMax(world, var55); int var64 = var63 >> 16; float colorDarkness = direction < 2 ? 0.8F : 0.6F; float var67 = colorDarkness * redMultiplier; diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinBiome.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinBiome.java index e3da3d4..c4b3d76 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinBiome.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinBiome.java @@ -18,7 +18,7 @@ private static void onRegisterBiomes(CallbackInfo ci) { } } - @Inject(method = "registerBiome", at = @At(value = "RETURN")) + @Inject(method = "register", at = @At(value = "RETURN")) private static void onRegisterBiome(int biomeId, String biomeName, Biome biome, CallbackInfo ci) { for (WorldChanger worldChanger : RiftLoader.instance.getListeners(WorldChanger.class)) { worldChanger.modifyBiome(biomeId, biomeName, biome); diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java index 2d5aa72..2b0fe5d 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java @@ -49,7 +49,7 @@ public abstract class MixinMinecraftServer { @Shadow public abstract GameType getGameType(); @Shadow public abstract boolean canStructuresSpawn(); @Shadow public abstract boolean isHardcore(); - @Shadow public abstract void func_195560_a(File p_195560_1_, WorldInfo p_195560_2_); + @Shadow public abstract void loadDataPacks(File p_195560_1_, WorldInfo p_195560_2_); @Shadow public abstract void setDifficultyForAllWorlds(EnumDifficulty p_setDifficultyForAllWorlds_1_); @Shadow public abstract CustomBossEvents getCustomBossEvents(); @Shadow public abstract PlayerList getPlayerList(); @@ -61,7 +61,7 @@ public abstract class MixinMinecraftServer { private Map dimensionTypeToWorldIndex = new HashMap<>(); private Map dimensionIdToWorldIndex = new HashMap<>(); - @Inject(method = "func_195560_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourcePackList;addPackFinder(Lnet/minecraft/resources/IPackFinder;)V", shift = At.Shift.AFTER)) + @Inject(method = "loadDataPacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourcePackList;addPackFinder(Lnet/minecraft/resources/IPackFinder;)V", shift = At.Shift.AFTER)) private void afterAddVanillaPackFinder(File serverDirectory, WorldInfo worldInfo, CallbackInfo ci) { for (DataPackFinderAdder resourcePackFinderAdder : RiftLoader.instance.getListeners(DataPackFinderAdder.class)) { for (IPackFinder packFinder : resourcePackFinderAdder.getDataPackFinders()) { @@ -98,7 +98,7 @@ public void loadAllWorlds(String saveName, String worldName, long seed, WorldTyp worldInfo.setWorldName(worldName); } - func_195560_a(saveHandler.getWorldDirectory(), worldInfo); + loadDataPacks(saveHandler.getWorldDirectory(), worldInfo); // Create overworld WorldServer overworld = isDemo() ? new WorldServerDemo((MinecraftServer) (Object) this, saveHandler, new WorldSavedDataStorage(saveHandler), worldInfo, DimensionType.OVERWORLD, profiler) From 3dfe7269ee77f46ffc917318de731825cbba17b0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 7 Nov 2018 19:07:16 +0000 Subject: [PATCH 10/21] Bump the mappings to match what the ATs used Don't think anything changed that was being used, but that's what I was using Also updates the profile to extend from 1.13.1 --- build.gradle | 2 +- src/main/resources/profile.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 7096570..31d4294 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ dependencies { minecraft { version = '1.13.1' - mappings = 'snapshot_20181023' + mappings = 'snapshot_20181106' runDir = 'run' tweakClass = 'org.dimdev.riftloader.launch.RiftLoaderClientTweaker' makeObfSourceJar = false diff --git a/src/main/resources/profile.json b/src/main/resources/profile.json index 6e8ed19..8a22eda 100644 --- a/src/main/resources/profile.json +++ b/src/main/resources/profile.json @@ -1,6 +1,6 @@ { - "inheritsFrom": "1.13", - "id": "1.13-rift-${version}", + "inheritsFrom": "1.13.1", + "id": "1.13.1-rift-${version}", "releaseTime": "2018-07-18T15:11:46+00:00", "time": "2018-07-18T15:11:46+00:00", "type": "release", From 30ec670f6d1915915bdc535bf4f19ad5779e6e9b Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 8 Nov 2018 15:17:00 +0000 Subject: [PATCH 11/21] Fix block and fluid listeners not firing --- src/main/java/org/dimdev/rift/mixin/hook/MixinBlock.java | 6 +++++- src/main/java/org/dimdev/rift/mixin/hook/MixinFluid.java | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinBlock.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinBlock.java index d39ffa9..d21f5a0 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinBlock.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinBlock.java @@ -1,8 +1,12 @@ package org.dimdev.rift.mixin.hook; import net.minecraft.block.Block; + import org.dimdev.rift.listener.BlockAdder; import org.dimdev.riftloader.RiftLoader; + +import org.objectweb.asm.Opcodes; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -10,7 +14,7 @@ @Mixin(Block.class) public abstract class MixinBlock { - @Inject(method = "registerBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/RegistryNamespacedDefaultedByKey;validateKey()V")) + @Inject(method = "registerBlocks", at = @At(value = "FIELD", target = "Lnet/minecraft/util/registry/IRegistry;BLOCK:Lnet/minecraft/util/registry/IRegistry;", opcode = Opcodes.GETSTATIC, ordinal = 1)) private static void onRegisterBlocks(CallbackInfo ci) { for (BlockAdder blockAdder : RiftLoader.instance.getListeners(BlockAdder.class)) { blockAdder.registerBlocks(); diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinFluid.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinFluid.java index a56c4e1..e460885 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinFluid.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinFluid.java @@ -3,6 +3,7 @@ import net.minecraft.fluid.Fluid; import org.dimdev.rift.listener.FluidAdder; import org.dimdev.riftloader.RiftLoader; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -10,7 +11,7 @@ @Mixin(Fluid.class) public abstract class MixinFluid { - @Inject(method = "registerAll", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/RegistryNamespacedDefaultedByKey;validateKey()V")) + @Inject(method = "registerAll", at = @At(value = "FIELD", target = "Lnet/minecraft/util/registry/IRegistry;FLUID:Lnet/minecraft/util/registry/IRegistry;", opcode = Opcodes.GETSTATIC, ordinal = 1)) private static void onRegisterFluids(CallbackInfo ci) { for (FluidAdder fluidAdder : RiftLoader.instance.getListeners(FluidAdder.class)) { fluidAdder.registerFluids(); From fbfe23492d8977cfcf2528735f538496a362dd31 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 8 Nov 2018 15:19:35 +0000 Subject: [PATCH 12/21] Protect against items with a null name `ItemRenderer` will cause `ModelResourceLocation` to crash unhelpfully if an item is registered with a null resource location This doesn't fix the fact it crashes, just allows for the item to be found --- .../mixin/core/client/MixinItemRenderer.java | 25 +++++++++++++++++++ src/main/resources/mixins.rift.core.json | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/dimdev/rift/mixin/core/client/MixinItemRenderer.java diff --git a/src/main/java/org/dimdev/rift/mixin/core/client/MixinItemRenderer.java b/src/main/java/org/dimdev/rift/mixin/core/client/MixinItemRenderer.java new file mode 100644 index 0000000..7cb00dc --- /dev/null +++ b/src/main/java/org/dimdev/rift/mixin/core/client/MixinItemRenderer.java @@ -0,0 +1,25 @@ +package org.dimdev.rift.mixin.core.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.item.Item; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; + +@Mixin(ItemRenderer.class) +public class MixinItemRenderer { + @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/IRegistry;getKey(Ljava/lang/Object;)Lnet/minecraft/util/ResourceLocation;")) + private ResourceLocation onGetItem(IRegistry registry, Object item) { + ResourceLocation key = registry.getKey(item); + + if (key == null) { + //Guard against unregistered items to avoid throwing unhelpful NPEs in ModelResourceLocation's constructor + throw new IllegalStateException("Item registered with null key: " + item + " - " + ((Item) item).getName() + " (" + item.getClass() + ')'); + } else { + return key; + } + } +} \ No newline at end of file diff --git a/src/main/resources/mixins.rift.core.json b/src/main/resources/mixins.rift.core.json index e268b54..9a29976 100644 --- a/src/main/resources/mixins.rift.core.json +++ b/src/main/resources/mixins.rift.core.json @@ -14,6 +14,7 @@ "client.MixinLayerArmorBase", "client.MixinBlockFluidRenderer", "client.MixinWaterFluid", - "client.MixinLavaFluid" + "client.MixinLavaFluid", + "client.MixinItemRenderer" ] } From b9f0998e4f0150162aa2b59af1d87a1ffc002b91 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 8 Nov 2018 17:26:18 +0000 Subject: [PATCH 13/21] Fix DimensionTypeAdder Now there is a proper dimension registry the old hacks can start to be removed Breaks the test mod loading into the world from `MixinMinecraftServer` needing updating too Removes ATing string registering methods when there are resource location versions instead --- .../rift/AccessTransformerUpdater.java | 2 +- .../java/org/dimdev/testmod/TestMod.java | 8 +++--- .../rift/listener/DimensionTypeAdder.java | 9 +++---- .../rift/mixin/hook/MixinDimensionType.java | 26 +++---------------- src/main/resources/access_transformations.at | 6 ++--- 5 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/debug/java/com/chocohead/rift/AccessTransformerUpdater.java b/src/debug/java/com/chocohead/rift/AccessTransformerUpdater.java index fb2b81b..fdaf6c2 100644 --- a/src/debug/java/com/chocohead/rift/AccessTransformerUpdater.java +++ b/src/debug/java/com/chocohead/rift/AccessTransformerUpdater.java @@ -180,7 +180,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc String name = line.substring(line.lastIndexOf(' ') + 1); int split = name.lastIndexOf('/'); - if (split <= 0) { + if (split < 0) { transforms.add("#??? " + line); System.err.println("Bad line: " + line); continue; diff --git a/src/debug/java/org/dimdev/testmod/TestMod.java b/src/debug/java/org/dimdev/testmod/TestMod.java index d1a277d..669acb6 100644 --- a/src/debug/java/org/dimdev/testmod/TestMod.java +++ b/src/debug/java/org/dimdev/testmod/TestMod.java @@ -1,6 +1,7 @@ package org.dimdev.testmod; import com.mojang.brigadier.CommandDispatcher; + import net.minecraft.block.Block; import net.minecraft.block.BlockFlowingFluid; import net.minecraft.block.BlockStainedGlass; @@ -16,8 +17,8 @@ import net.minecraft.network.EnumPacketDirection; import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.IRegistry; -import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.EndDimension; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -29,7 +30,6 @@ import java.util.Collection; import java.util.Collections; -import java.util.Set; import static net.minecraft.init.SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP; @@ -102,8 +102,8 @@ public MusicTicker.MusicType getAmbientMusicType(Minecraft client) { } @Override - public Set getDimensionTypes() { - return Collections.singleton(DimensionTypeAdder.newDimensionType(555, "test_dimension", "_test", EndDimension::new)); + public void registerDimensionTypes() { + DimensionTypeAdder.addDimensionType(555, new ResourceLocation("testmod", "test_dimension"), "_test", EndDimension::new); } @Override diff --git a/src/main/java/org/dimdev/rift/listener/DimensionTypeAdder.java b/src/main/java/org/dimdev/rift/listener/DimensionTypeAdder.java index cd6757a..bfbc55b 100644 --- a/src/main/java/org/dimdev/rift/listener/DimensionTypeAdder.java +++ b/src/main/java/org/dimdev/rift/listener/DimensionTypeAdder.java @@ -1,16 +1,15 @@ package org.dimdev.rift.listener; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.dimension.Dimension; import net.minecraft.world.dimension.DimensionType; -import org.dimdev.utils.ReflectionUtils; -import java.util.Set; import java.util.function.Supplier; public interface DimensionTypeAdder { - static DimensionType newDimensionType(int id, String name, String suffix, Supplier dimensionSupplier) { - return ReflectionUtils.makeEnumInstance(DimensionType.class, name.toUpperCase(), -1, id, name, suffix, dimensionSupplier); + static DimensionType addDimensionType(int id, ResourceLocation name, String suffix, Supplier dimensionSupplier) { + return DimensionType.register(name.toString(), new DimensionType(id, suffix, name.getPath(), dimensionSupplier)); } - Set getDimensionTypes(); + void registerDimensionTypes(); } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinDimensionType.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinDimensionType.java index 4ab47a1..f3524e8 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinDimensionType.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinDimensionType.java @@ -1,37 +1,17 @@ package org.dimdev.rift.mixin.hook; import net.minecraft.world.dimension.DimensionType; + import org.dimdev.rift.listener.DimensionTypeAdder; import org.dimdev.riftloader.RiftLoader; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import java.util.HashMap; +import org.spongepowered.asm.mixin.Mixin; @Mixin(DimensionType.class) public class MixinDimensionType { - @SuppressWarnings("PublicStaticMixinMember") // accessed using reflection - private static HashMap dimensionTypes = new HashMap<>(); - static { - for (DimensionType dimensionType : DimensionType.func_212681_b()) { - dimensionTypes.put(dimensionType.getId(), dimensionType); - } - for (DimensionTypeAdder dimensionTypeAdder : RiftLoader.instance.getListeners(DimensionTypeAdder.class)) { - for (DimensionType dimensionType : dimensionTypeAdder.getDimensionTypes()) { - dimensionTypes.put(dimensionType.getId(), dimensionType); - } + dimensionTypeAdder.registerDimensionTypes(); } } - - @Overwrite - public static DimensionType getById(int id) { - DimensionType dimensionType = dimensionTypes.get(id); - if (dimensionType == null) { - throw new IllegalArgumentException("Invalid dimension id " + id); - } - - return dimensionType; - } } diff --git a/src/main/resources/access_transformations.at b/src/main/resources/access_transformations.at index cc8372e..a659b9b 100644 --- a/src/main/resources/access_transformations.at +++ b/src/main/resources/access_transformations.at @@ -1,4 +1,3 @@ -public method bcr a (Ljava/lang/String;Lbcr;)V # net.minecraft.block.Block/register public method bcr a (Lpc;Lbcr;)V # net.minecraft.block.Block/register public method bcr$c a (Lbhq;)Lbcr$c; # net.minecraft.block.Block$Properties/sound public method bcr$c a (I)Lbcr$c; # net.minecraft.block.Block$Properties/lightValue @@ -9,14 +8,15 @@ public method bcr$c d ()Lbcr$c; # net.minecraft.block.Block$Properties/variableO public method asz a (Lari;)V # net.minecraft.item.Item/register public method asz a (Lbcr;Larx;)V # net.minecraft.item.Item/register public method asz a (Lbcr;Lasz;)V # net.minecraft.item.Item/register -public method asz a (Ljava/lang/String;Lasz;)V # net.minecraft.item.Item/register public method asz a (Lpc;Lasz;)V # net.minecraft.item.Item/register public method asz b (Lbcr;)V # net.minecraft.item.Item/register -public method byu a (Ljava/lang/String;Lbyu;)V # net.minecraft.fluid.Fluid/register public method byu a (Lpc;Lbyu;)V # net.minecraft.fluid.Fluid/register public method bft (Lbyt;Lbcr$c;)V # net.minecraft.block.BlockFlowingFluid/ +public method boc (ILjava/lang/String;Ljava/lang/String;Ljava/util/function/Supplier;)V # net.minecraft.world.dimension.DimensionType/ +public method boc a (Ljava/lang/String;Lboc;)Lboc; # net.minecraft.world.dimension.DimensionType/register + public method ayt a (ILjava/lang/String;Layt;)V # net.minecraft.world.biome.Biome/register public method fl (Lpc;ZLfk$a;)V # net.minecraft.particles.ParticleType/ From 1008e55c8f2a5b2ce213428400b80e02fcece8d6 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 12 Nov 2018 20:39:16 +0000 Subject: [PATCH 14/21] Fix MixinMinecraftServer Mojang now has a `DimensionType` -> `World` map instead of the old `World[]` array so most of the old hacks can go --- .../org/dimdev/testmod/TestDimension.java | 109 +++++++++++++ .../java/org/dimdev/testmod/TestMod.java | 3 +- .../rift/mixin/hook/MixinMinecraftServer.java | 153 +++--------------- .../hook/client/MixinIntegratedServer.java | 38 ----- src/main/resources/mixins.rift.hooks.json | 3 +- 5 files changed, 137 insertions(+), 169 deletions(-) create mode 100644 src/debug/java/org/dimdev/testmod/TestDimension.java delete mode 100644 src/main/java/org/dimdev/rift/mixin/hook/client/MixinIntegratedServer.java diff --git a/src/debug/java/org/dimdev/testmod/TestDimension.java b/src/debug/java/org/dimdev/testmod/TestDimension.java new file mode 100644 index 0000000..03708e6 --- /dev/null +++ b/src/debug/java/org/dimdev/testmod/TestDimension.java @@ -0,0 +1,109 @@ +package org.dimdev.testmod; + +import java.util.Random; + +import net.minecraft.init.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.biome.provider.BiomeProviderType; +import net.minecraft.world.dimension.Dimension; +import net.minecraft.world.dimension.DimensionType; +import net.minecraft.world.dimension.EndDimension; +import net.minecraft.world.gen.ChunkGeneratorType; +import net.minecraft.world.gen.EndGenSettings; +import net.minecraft.world.gen.IChunkGenerator; + +/** Loose clone of {@link EndDimension} */ +public class TestDimension extends Dimension { + private static DimensionType type; + + @Override + protected void init() { + hasSkyLight = false; + } + + @Override + public IChunkGenerator createChunkGenerator() { + EndGenSettings endGenerator = ChunkGeneratorType.FLOATING_ISLANDS.createSettings(); + + endGenerator.setDefautBlock(Blocks.WHITE_CONCRETE.getDefaultState()); + endGenerator.setDefaultFluid(Blocks.AIR.getDefaultState()); + endGenerator.setSpawnPos(getSpawnCoordinate()); + + return ChunkGeneratorType.FLOATING_ISLANDS.create(world, BiomeProviderType.THE_END.create(BiomeProviderType.THE_END.createSettings().setSeed(world.getSeed())), endGenerator); + } + + @Override + public BlockPos getSpawnCoordinate() { + return EndDimension.SPAWN; + } + + @Override + public BlockPos findSpawn(ChunkPos chunk, boolean checkValid) { + Random random = new Random(world.getSeed()); + BlockPos pos = new BlockPos(chunk.getXStart() + random.nextInt(15), 0, chunk.getZEnd() + random.nextInt(15)); + return world.getGroundAboveSeaLevel(pos).getMaterial().blocksMovement() ? pos : null; + } + + @Override + public BlockPos findSpawn(int x, int z, boolean checkValid) { + return findSpawn(new ChunkPos(x >> 4, z >> 4), checkValid); + } + + @Override + public boolean isSurfaceWorld() { + return false; + } + + @Override + public float calculateCelestialAngle(long worldTime, float partialTicks) { + return 0F; + } + + @Override + public float[] calcSunriseSunsetColors(float celestialAngle, float partialTicks) { + return null; + } + + @Override + public boolean doesXZShowFog(int x, int z) { + return false; + } + + @Override + public Vec3d getFogColor(float celestialAngle, float partialTicks) { + float sun = MathHelper.cos(celestialAngle * ((float)Math.PI * 2F)) * 2F + 0.5F; + sun = MathHelper.clamp(sun, 0F, 1F); + + float r = 0.627451F; + float g = 0.5019608F; + float b = 0.627451F; + r = r * (sun * 0.0F + 0.15F); + g = g * (sun * 0.0F + 0.15F); + b = b * (sun * 0.0F + 0.15F); + + return new Vec3d((double)r, (double)g, (double)b); + } + + @Override + public boolean canRespawnHere() { + return false; + } + + @Override + public float getCloudHeight() { + return 8F; + } + + static void giveType(DimensionType type) { + TestDimension.type = type; + } + + @Override + public DimensionType getType() { + if (type == null) throw new IllegalStateException("Null type?"); + return type; + } +} \ No newline at end of file diff --git a/src/debug/java/org/dimdev/testmod/TestMod.java b/src/debug/java/org/dimdev/testmod/TestMod.java index 669acb6..c67041f 100644 --- a/src/debug/java/org/dimdev/testmod/TestMod.java +++ b/src/debug/java/org/dimdev/testmod/TestMod.java @@ -17,7 +17,6 @@ import net.minecraft.network.EnumPacketDirection; import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.IRegistry; -import net.minecraft.world.dimension.EndDimension; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -103,7 +102,7 @@ public MusicTicker.MusicType getAmbientMusicType(Minecraft client) { @Override public void registerDimensionTypes() { - DimensionTypeAdder.addDimensionType(555, new ResourceLocation("testmod", "test_dimension"), "_test", EndDimension::new); + TestDimension.giveType(DimensionTypeAdder.addDimensionType(555, new ResourceLocation("testmod", "test_dimension"), "_test", TestDimension::new)); } @Override diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java index 2b0fe5d..05ccb5a 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinMinecraftServer.java @@ -1,67 +1,45 @@ package org.dimdev.rift.mixin.hook; -import com.google.gson.JsonElement; import net.minecraft.profiler.Profiler; import net.minecraft.resources.IPackFinder; import net.minecraft.resources.ResourcePackInfo; import net.minecraft.resources.ResourcePackList; -import net.minecraft.server.CustomBossEvents; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.management.PlayerList; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.world.*; +import net.minecraft.world.GameType; +import net.minecraft.world.ServerWorldEventHandler; +import net.minecraft.world.WorldServer; +import net.minecraft.world.WorldServerMulti; +import net.minecraft.world.WorldSettings; import net.minecraft.world.dimension.DimensionType; -import net.minecraft.world.storage.ISaveFormat; import net.minecraft.world.storage.ISaveHandler; import net.minecraft.world.storage.WorldInfo; import net.minecraft.world.storage.WorldSavedDataStorage; + import org.dimdev.rift.listener.DataPackFinderAdder; import org.dimdev.rift.listener.ServerTickable; import org.dimdev.riftloader.RiftLoader; + import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import javax.annotation.Nullable; import java.io.File; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Map; @Mixin(MinecraftServer.class) public abstract class MixinMinecraftServer { @Shadow @Final private ResourcePackList resourcePacks; @Shadow @Final public Profiler profiler; - @Shadow public abstract void convertMapIfNeeded(String p_convertMapIfNeeded_1_); - @Shadow public Map worlds; - @Shadow public Map timeOfLastDimensionTick; - @Shadow public abstract ISaveFormat getActiveAnvilConverter(); - @Shadow public abstract void setResourcePackFromWorld(String p_setResourcePackFromWorld_1_, ISaveHandler p_setResourcePackFromWorld_2_); - @Shadow public abstract String getFolderName(); - @Shadow protected abstract void setUserMessage(ITextComponent p_200245_1_); + + @Shadow @Final public Map worlds; + @Shadow public abstract WorldServer getWorld(DimensionType dimension); @Shadow public abstract GameType getGameType(); - @Shadow public abstract boolean canStructuresSpawn(); - @Shadow public abstract boolean isHardcore(); - @Shadow public abstract void loadDataPacks(File p_195560_1_, WorldInfo p_195560_2_); - @Shadow public abstract void setDifficultyForAllWorlds(EnumDifficulty p_setDifficultyForAllWorlds_1_); - @Shadow public abstract CustomBossEvents getCustomBossEvents(); - @Shadow public abstract PlayerList getPlayerList(); - @Shadow public abstract boolean isDemo(); @Shadow public abstract boolean isSinglePlayer(); - @Shadow public abstract EnumDifficulty getDifficulty(); - @Shadow private boolean enableBonusChest; - - private Map dimensionTypeToWorldIndex = new HashMap<>(); - private Map dimensionIdToWorldIndex = new HashMap<>(); - @Inject(method = "loadDataPacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourcePackList;addPackFinder(Lnet/minecraft/resources/IPackFinder;)V", shift = At.Shift.AFTER)) + @Inject(method = "loadDataPacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourcePackList;reloadPacksFromFinders()V")) private void afterAddVanillaPackFinder(File serverDirectory, WorldInfo worldInfo, CallbackInfo ci) { for (DataPackFinderAdder resourcePackFinderAdder : RiftLoader.instance.getListeners(DataPackFinderAdder.class)) { for (IPackFinder packFinder : resourcePackFinderAdder.getDataPackFinders()) { @@ -81,102 +59,23 @@ private void onTick(CallbackInfo ci) { profiler.endSection(); } - @Overwrite - public void loadAllWorlds(String saveName, String worldName, long seed, WorldType type, JsonElement generatorOptions) { - convertMapIfNeeded(saveName); - - setUserMessage(new TextComponentTranslation("menu.loadingLevel")); - - ISaveHandler saveHandler = getActiveAnvilConverter().getSaveLoader(saveName, (MinecraftServer) (Object) this); - setResourcePackFromWorld(getFolderName(), saveHandler); - WorldInfo worldInfo = saveHandler.loadWorldInfo(); - WorldSettings worldSettings = getWorldSettings(worldInfo, seed, type, generatorOptions); - - if (worldInfo == null) { - worldInfo = new WorldInfo(worldSettings, worldName); - } else { - worldInfo.setWorldName(worldName); - } - - loadDataPacks(saveHandler.getWorldDirectory(), worldInfo); - - // Create overworld - WorldServer overworld = isDemo() ? new WorldServerDemo((MinecraftServer) (Object) this, saveHandler, new WorldSavedDataStorage(saveHandler), worldInfo, DimensionType.OVERWORLD, profiler) - : new WorldServer((MinecraftServer) (Object) this, saveHandler, new WorldSavedDataStorage(saveHandler), worldInfo, DimensionType.OVERWORLD, profiler); - overworld.func_212251_i__(); - - overworld.initialize(worldSettings); - overworld.addEventListener(new ServerWorldEventHandler((MinecraftServer) (Object) this, overworld)); - if (!isSinglePlayer()) { - overworld.getWorldInfo().setGameType(getGameType()); - } - - List worldList = new ArrayList<>(); - worldList.add(overworld); - dimensionIdToWorldIndex.put(0, 0); - dimensionTypeToWorldIndex.put(DimensionType.OVERWORLD, 0); - - // Create other worlds - List dimensionTypes; - try { - @SuppressWarnings("JavaReflectionMemberAccess") - Field dimensionTypesField = DimensionType.class.getDeclaredField("dimensionTypes"); - dimensionTypesField.setAccessible(true); - //noinspection unchecked - dimensionTypes = new ArrayList<>(((Map) dimensionTypesField.get(null)).values()); - dimensionTypes.remove(DimensionType.OVERWORLD); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - - for (DimensionType dimensionType : dimensionTypes) { - dimensionIdToWorldIndex.put(dimensionType.getId(), worldList.size()); - dimensionTypeToWorldIndex.put(dimensionType, worldList.size()); - WorldServerMulti world = new WorldServerMulti((MinecraftServer) (Object) this, saveHandler, dimensionType, overworld, profiler); - world.func_212251_i__(); - world.addEventListener(new ServerWorldEventHandler((MinecraftServer) (Object) this, world)); - if (!isSinglePlayer()) { - world.getWorldInfo().setGameType(getGameType()); - } - - worldList.add(world); - } - - // Initialize other things - worlds = new HashMap<>(); - worldList.forEach(worldServer -> worlds.put(worldServer.dimension.getType(), worldServer)); - - timeOfLastDimensionTick = new HashMap<>(); - worldList.forEach(worldServer -> timeOfLastDimensionTick.put(worldServer.dimension.getType(), new long[100])); + @Inject(method = "func_212369_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;func_212504_a(Lnet/minecraft/world/WorldServer;)V")) + private void onWorldLoad(ISaveHandler saveHandler, WorldSavedDataStorage savedDataStorage, WorldInfo info, WorldSettings settings, CallbackInfo ci) { + WorldServer overworld = getWorld(DimensionType.OVERWORLD); - getPlayerList().func_212504_a(worlds.get(DimensionType.OVERWORLD)); - if (worldInfo.getCustomBossEvents() != null) { - getCustomBossEvents().read(worldInfo.getCustomBossEvents()); - } - - if (overworld.getWorldInfo().getDifficulty() == null) { - setDifficultyForAllWorlds(getInitialDifficulty()); - } - } + for (DimensionType type : DimensionType.func_212681_b()) { + //Skip around existing types (the Overworld, Nether and End) + if (!worlds.containsKey(type)) { + WorldServerMulti world = new WorldServerMulti((MinecraftServer) (Object) this, saveHandler, type, overworld, profiler); + world.func_212251_i__(); - protected WorldSettings getWorldSettings(@Nullable WorldInfo worldInfo, long seed, WorldType worldType, JsonElement generatorOptions) { - if (worldInfo == null) { - if (isDemo()) { - return WorldServerDemo.DEMO_WORLD_SETTINGS; - } else { - WorldSettings worldSettings = new WorldSettings(seed, getGameType(), canStructuresSpawn(), isHardcore(), worldType); - worldSettings.setGeneratorOptions(generatorOptions); - if (enableBonusChest) { - worldSettings.enableBonusChest(); - } - return worldSettings; - } - } else { - return new WorldSettings(worldInfo); - } - } + worlds.put(type, world); - protected EnumDifficulty getInitialDifficulty() { - return getDifficulty(); + world.addEventListener(new ServerWorldEventHandler((MinecraftServer) (Object) this, world)); + if (!isSinglePlayer()) { + world.getWorldInfo().setGameType(getGameType()); + } + } + } } } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinIntegratedServer.java b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinIntegratedServer.java deleted file mode 100644 index 627f89d..0000000 --- a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinIntegratedServer.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.dimdev.rift.mixin.hook.client; - -import com.google.gson.JsonElement; -import net.minecraft.client.Minecraft; -import net.minecraft.server.integrated.IntegratedServer; -import net.minecraft.world.EnumDifficulty; -import net.minecraft.world.WorldSettings; -import net.minecraft.world.WorldType; -import net.minecraft.world.storage.WorldInfo; -import org.dimdev.rift.mixin.hook.MixinMinecraftServer; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import javax.annotation.Nullable; - -@Mixin(IntegratedServer.class) -public abstract class MixinIntegratedServer extends MixinMinecraftServer { - @Shadow @Final private Minecraft mc; - @Shadow @Final private WorldSettings worldSettings; - - @Override - protected WorldSettings getWorldSettings(@Nullable WorldInfo worldInfo, long seed, WorldType worldType, JsonElement generatorOptions) { - return worldSettings; - } - - @Override - protected EnumDifficulty getInitialDifficulty() { - return mc.gameSettings.difficulty; - } - - @Overwrite - @Override - public void loadAllWorlds(String saveName, String worldName, long seed, WorldType type, JsonElement generatorOptions) { - super.loadAllWorlds(saveName, worldName, seed, type, generatorOptions); - } -} diff --git a/src/main/resources/mixins.rift.hooks.json b/src/main/resources/mixins.rift.hooks.json index f8a6ae0..45db5f0 100644 --- a/src/main/resources/mixins.rift.hooks.json +++ b/src/main/resources/mixins.rift.hooks.json @@ -48,7 +48,6 @@ "client.MixinRenderManager", "client.MixinEntityPlayerSP", "client.MixinGameSettings", - "client.MixinGuiIngame", - "client.MixinIntegratedServer" + "client.MixinGuiIngame" ] } From 539a03d4d91a6219c47f208af789888b605a9225 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 12 Nov 2018 20:39:52 +0000 Subject: [PATCH 15/21] Update the EntityType and TileEntityType DataFix keys --- src/main/java/org/dimdev/rift/mixin/hook/MixinEntityType.java | 2 +- .../java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinEntityType.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinEntityType.java index 4528aae..9ebb62a 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinEntityType.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinEntityType.java @@ -41,7 +41,7 @@ public EntityType build(String id) { if (serializable) { try { - dataFixerType = DataFixesManager.getDataFixer().getSchema(DataFixUtils.makeKey(1519)).getChoiceType(TypeReferences.ENTITY_TYPE, id); + dataFixerType = DataFixesManager.getDataFixer().getSchema(DataFixUtils.makeKey(1628)).getChoiceType(TypeReferences.ENTITY_TYPE, id); } catch (IllegalStateException | IllegalArgumentException ignored) { LOGGER.debug("No data fixer registered for entity {}", id); } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java index e89c6ab..15f6d87 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinTileEntityType.java @@ -29,7 +29,7 @@ public static TileEntityType register(String id, TileE try { //Schema#getChoiceType can throw an IAE that vanilla won't catch, so we catch that too - dataFixerType = DataFixesManager.getDataFixer().getSchema(DataFixUtils.makeKey(1519)).getChoiceType(TypeReferences.BLOCK_ENTITY, id); + dataFixerType = DataFixesManager.getDataFixer().getSchema(DataFixUtils.makeKey(1628)).getChoiceType(TypeReferences.BLOCK_ENTITY, id); } catch (IllegalStateException | IllegalArgumentException e) { LOGGER.debug("No data fixer registered for block entity {}", id); } From a61b09c2e8800aeb414f75427ad18c64cf79ee68 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 13 Nov 2018 19:09:15 +0000 Subject: [PATCH 16/21] Pass the client instance to ClientTickables Most `ClientTickable`s will need it anyway, so might as well make it as convenient as `ServerTickable` is --- src/debug/java/org/dimdev/testmod/TestMod.java | 2 +- .../java/org/dimdev/rift/listener/client/ClientTickable.java | 4 +++- .../org/dimdev/rift/mixin/hook/client/MixinMinecraft.java | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/debug/java/org/dimdev/testmod/TestMod.java b/src/debug/java/org/dimdev/testmod/TestMod.java index c67041f..be95a43 100644 --- a/src/debug/java/org/dimdev/testmod/TestMod.java +++ b/src/debug/java/org/dimdev/testmod/TestMod.java @@ -89,7 +89,7 @@ public void registerCommands(CommandDispatcher dispatcher) { } @Override - public void clientTick() { + public void clientTick(Minecraft client) { if (clientTickCount++ == 100) { LOGGER.info("100 ticks have passed"); } diff --git a/src/main/java/org/dimdev/rift/listener/client/ClientTickable.java b/src/main/java/org/dimdev/rift/listener/client/ClientTickable.java index 6e4cbcf..82922cd 100644 --- a/src/main/java/org/dimdev/rift/listener/client/ClientTickable.java +++ b/src/main/java/org/dimdev/rift/listener/client/ClientTickable.java @@ -1,5 +1,7 @@ package org.dimdev.rift.listener.client; +import net.minecraft.client.Minecraft; + public interface ClientTickable { - void clientTick(); + void clientTick(Minecraft client); } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinMinecraft.java b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinMinecraft.java index 5b2d77b..4c8e568 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinMinecraft.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinMinecraft.java @@ -26,7 +26,7 @@ public class MixinMinecraft { @Shadow @Final public Profiler profiler; @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourcePackList;addPackFinder(Lnet/minecraft/resources/IPackFinder;)V", ordinal = 1)) - private void onAddResourcePacks(ResourcePackList resourcePackList, IPackFinder minecraftPackFinder) { + private void onAddResourcePacks(ResourcePackList resourcePackList, IPackFinder minecraftPackFinder) { resourcePackList.addPackFinder(minecraftPackFinder); for (ResourcePackFinderAdder resourcePackFinderAdder : RiftLoader.instance.getListeners(ResourcePackFinderAdder.class)) { @@ -41,7 +41,7 @@ private void onTick(CallbackInfo ci) { profiler.startSection("mods"); for (ClientTickable tickable : RiftLoader.instance.getListeners(ClientTickable.class)) { profiler.startSection(() -> tickable.getClass().getCanonicalName().replace('.', '/')); - tickable.clientTick(); + tickable.clientTick((Minecraft) (Object) this); profiler.endSection(); } profiler.endSection(); From 1cf2af57bf542ea26837dcb103f8f71800b7f6df Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 20 Nov 2018 17:41:41 +0000 Subject: [PATCH 17/21] Finally fix the changedimension command Technically `func_212321_a` is the proper portal teleport, but it has a whole load of expectations that makes it break too easily So we just jump on the TeleportCommand which is actually designed for what we're using it for --- .../testmod/ChangeDimensionCommand.java | 49 +++++++++++++++++-- .../org/dimdev/utils/ReflectionUtils.java | 12 +++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/debug/java/org/dimdev/testmod/ChangeDimensionCommand.java b/src/debug/java/org/dimdev/testmod/ChangeDimensionCommand.java index 9a75ca1..cd96d69 100644 --- a/src/debug/java/org/dimdev/testmod/ChangeDimensionCommand.java +++ b/src/debug/java/org/dimdev/testmod/ChangeDimensionCommand.java @@ -1,22 +1,48 @@ package org.dimdev.testmod; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.dimdev.utils.ReflectionUtils; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + import net.minecraft.command.CommandSource; import net.minecraft.command.arguments.DimensionArgument; +import net.minecraft.command.arguments.ILocationArgument; +import net.minecraft.command.arguments.LocationInput; +import net.minecraft.command.arguments.LocationPart; +import net.minecraft.command.arguments.Vec3Argument; +import net.minecraft.command.impl.TeleportCommand; import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.WorldServer; +import net.minecraft.world.dimension.DimensionType; public class ChangeDimensionCommand { public static void register(CommandDispatcher dispatcher) { LiteralArgumentBuilder builder = literalArgument("changedimension") .then(requiredArgument("dimension", DimensionArgument.getDimension()) .executes(context -> { - Entity entity = context.getSource().getEntity(); - entity.func_212321_a(DimensionArgument.func_212592_a(context, "dimension")); - return 0; - })); + WorldServer world = context.getSource().getServer().getWorld(DimensionArgument.func_212592_a(context, "dimension")); + + BlockPos pos = world.getSpawnCoordinate(); + if (pos == null) pos = world.getSpawnPoint(); + + return teleport(context, new LocationInput(new LocationPart(false, pos.getX()), new LocationPart(false, pos.getY()), new LocationPart(false, pos.getZ()))); + })) + .then(requiredArgument("dimension", DimensionArgument.getDimension()) + .then(requiredArgument("location", Vec3Argument.vec3()) + .executes(context -> teleport(context, Vec3Argument.getLocation(context, "location")) + ))); dispatcher.register(builder); } @@ -27,4 +53,19 @@ private static LiteralArgumentBuilder literalArgument(String name private static RequiredArgumentBuilder requiredArgument(String name, ArgumentType type) { return RequiredArgumentBuilder.argument(name, type); } + + static int teleport(CommandContext context, ILocationArgument location) throws CommandSyntaxException { + Entity entity = context.getSource().assertIsEntity(); + DimensionType type = DimensionArgument.func_212592_a(context, "dimension"); + + try { + Class facing = Arrays.stream(TeleportCommand.class.getDeclaredClasses()).filter(Class::isMemberClass).findFirst().get(); //Grab TeleportCommand.Facing, only need it to pass null in + Method m = ReflectionUtils.findMethod(TeleportCommand.class, int.class, CommandSource.class, Collection.class, WorldServer.class, ILocationArgument.class, ILocationArgument.class, facing); + MethodHandles.lookup().unreflect(m).invokeWithArguments(context.getSource(), Collections.singleton(entity), context.getSource().getServer().getWorld(type), location, LocationInput.current(), null); + } catch (Throwable t) { + throw new RuntimeException("Error teleporting " + entity + " to " + type, t); + } + + return 1; + } } diff --git a/src/main/java/org/dimdev/utils/ReflectionUtils.java b/src/main/java/org/dimdev/utils/ReflectionUtils.java index c295451..90429c9 100644 --- a/src/main/java/org/dimdev/utils/ReflectionUtils.java +++ b/src/main/java/org/dimdev/utils/ReflectionUtils.java @@ -6,6 +6,7 @@ import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; +import java.util.Arrays; public class ReflectionUtils { private static final MethodHandle addURLHandle; @@ -32,6 +33,17 @@ public static T makeEnumInstance(Class enumClass, Object... constructorAr } } + public static Method findMethod(Class target, Class returnType, Class... params) throws NoSuchMethodException { + for (Method method : target.getDeclaredMethods()) { + if (method.getReturnType() == returnType && Arrays.equals(method.getParameterTypes(), params)) { + method.setAccessible(true); + return method; + } + } + + throw new NoSuchMethodException("Cannot find method in " + target + '(' + Arrays.toString(params) + ") " + returnType); + } + public static void addURLToClasspath(URL url) { try { addURLHandle.invoke(ClassLoader.getSystemClassLoader(), url); From 145bec2712f1886af6f1b76591dbbc08b8afe00f Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 20 Nov 2018 20:00:23 +0000 Subject: [PATCH 18/21] Add the AmbientMusic test back again It's less annoying now, but still worth testing to make sure enum extending is fine --- .../java/org/dimdev/testmod/TestMod.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/debug/java/org/dimdev/testmod/TestMod.java b/src/debug/java/org/dimdev/testmod/TestMod.java index be95a43..7b068b0 100644 --- a/src/debug/java/org/dimdev/testmod/TestMod.java +++ b/src/debug/java/org/dimdev/testmod/TestMod.java @@ -7,7 +7,7 @@ import net.minecraft.block.BlockStainedGlass; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.MusicTicker; +import net.minecraft.client.audio.MusicTicker.MusicType; import net.minecraft.command.CommandSource; import net.minecraft.fluid.FlowingFluid; import net.minecraft.fluid.Fluid; @@ -32,7 +32,7 @@ import static net.minecraft.init.SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP; -public class TestMod implements BlockAdder, ItemAdder, FluidAdder, TextureAdder, PacketAdder, CommandAdder, ClientTickable, /*AmbientMusicTypeProvider,*/ DimensionTypeAdder, MessageAdder { +public class TestMod implements BlockAdder, ItemAdder, FluidAdder, TextureAdder, PacketAdder, CommandAdder, ClientTickable, AmbientMusicTypeProvider, DimensionTypeAdder, MessageAdder { private static final Logger LOGGER = LogManager.getLogger(); public static final Block WHITE_BLOCK = new Block(Block.Properties.create(Material.ROCK)); public static final Block TRANSLUCENT_WHITE_BLOCK = new BlockStainedGlass(EnumDyeColor.WHITE, Block.Properties.create(Material.GLASS)); @@ -40,8 +40,8 @@ public class TestMod implements BlockAdder, ItemAdder, FluidAdder, TextureAdder, public static final FlowingFluid FLOWING_WHITE_FLUID = new WhiteFluid.Flowing(); public static final BlockFlowingFluid BLOCK_WHITE_FLUID = new BlockFlowingFluid(WHITE_FLUID, Block.Properties.create(Material.WATER).doesNotBlockMovement().hardnessAndResistance(100F, 100F).variableOpacity()); public static final Item PACKET_TESTER = new ItemPacketTester(new Item.Properties()); - public static final MusicTicker.MusicType TEST_MUSIC = AmbientMusicTypeProvider.newMusicType("test", ENTITY_EXPERIENCE_ORB_PICKUP, 0, 0); - private int clientTickCount = 0; + public static final MusicType TEST_MUSIC = AmbientMusicTypeProvider.newMusicType("test", ENTITY_EXPERIENCE_ORB_PICKUP, 0, 0); + private int clientTickCount = 0, inWorldTicks = 0; @Override public void registerBlocks() { @@ -93,11 +93,17 @@ public void clientTick(Minecraft client) { if (clientTickCount++ == 100) { LOGGER.info("100 ticks have passed"); } + if (client.world != null) { + inWorldTicks++; + } else if (inWorldTicks > 0) { + inWorldTicks = 0; + } } -// @Override - public MusicTicker.MusicType getAmbientMusicType(Minecraft client) { - return TEST_MUSIC; + @Override + public MusicType getAmbientMusicType(Minecraft client) { + //Make some experience noises for 100 ticks but then stop because they are very annoying + return inWorldTicks < 100 ? TEST_MUSIC : null; } @Override From 2abd4de7137eceb49d503ae22bd4a3252f9dc70a Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 23 Nov 2018 19:17:04 +0000 Subject: [PATCH 19/21] Removed CustomPayloadHandler It's been replaced in favour of the `Message` system for a while now --- .../rift/listener/CustomPayloadHandler.java | 17 ----------------- .../mixin/hook/MixinNetHandlerPlayServer.java | 18 ++++-------------- .../hook/client/MixinNetHandlerPlayClient.java | 18 ++++-------------- 3 files changed, 8 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/org/dimdev/rift/listener/CustomPayloadHandler.java diff --git a/src/main/java/org/dimdev/rift/listener/CustomPayloadHandler.java b/src/main/java/org/dimdev/rift/listener/CustomPayloadHandler.java deleted file mode 100644 index 48b4a08..0000000 --- a/src/main/java/org/dimdev/rift/listener/CustomPayloadHandler.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.dimdev.rift.listener; - -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; - -/** - * @deprecated Use {@link MessageAdder} instead. - */ -@Deprecated -@SuppressWarnings("DeprecatedIsStillUsed") -public interface CustomPayloadHandler { - boolean clientHandlesChannel(ResourceLocation channelName); - void clientHandleCustomPayload(ResourceLocation channelName, PacketBuffer bufferData); - - boolean serverHandlesChannel(ResourceLocation channelName); - void serverHandleCustomPayload(ResourceLocation channelName, PacketBuffer bufferData); -} diff --git a/src/main/java/org/dimdev/rift/mixin/hook/MixinNetHandlerPlayServer.java b/src/main/java/org/dimdev/rift/mixin/hook/MixinNetHandlerPlayServer.java index 90e6f07..3d97522 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/MixinNetHandlerPlayServer.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/MixinNetHandlerPlayServer.java @@ -8,7 +8,6 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.ResourceLocation; import org.dimdev.rift.injectedmethods.RiftCPacketCustomPayload; -import org.dimdev.rift.listener.CustomPayloadHandler; import org.dimdev.rift.network.Message; import org.dimdev.rift.network.ServerMessageContext; import org.dimdev.riftloader.RiftLoader; @@ -25,24 +24,15 @@ public class MixinNetHandlerPlayServer { @Shadow public EntityPlayerMP player; @Shadow @Final public NetworkManager netManager; - @SuppressWarnings("deprecation") @Inject(method = "processCustomPayload", at = @At("HEAD"), cancellable = true) private void handleModCustomPayload(CPacketCustomPayload packet, CallbackInfo ci) { - ResourceLocation channelName = ((RiftCPacketCustomPayload) packet).getChannelName(); - PacketBuffer data = ((RiftCPacketCustomPayload) packet).getData(); - - for (CustomPayloadHandler customPayloadHandler : RiftLoader.instance.getListeners(CustomPayloadHandler.class)) { - if (customPayloadHandler.serverHandlesChannel(channelName)) { - customPayloadHandler.serverHandleCustomPayload(channelName, data); - } - } - - if(Message.REGISTRY.isEmpty()){ - return; - } + if (Message.REGISTRY.isEmpty()) return; + ResourceLocation channelName = ((RiftCPacketCustomPayload) packet).getChannelName(); Class messageClass = Message.REGISTRY.get(channelName); if (messageClass != null) { + PacketBuffer data = ((RiftCPacketCustomPayload) packet).getData(); + try { Message message = RiftLoader.instance.newInstance(messageClass); message.read(data); diff --git a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java index 33e6eeb..1459430 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java @@ -18,7 +18,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.ResourceLocation; -import org.dimdev.rift.listener.CustomPayloadHandler; import org.dimdev.rift.network.ClientMessageContext; import org.dimdev.rift.network.Message; import org.dimdev.riftloader.RiftLoader; @@ -43,24 +42,15 @@ public class MixinNetHandlerPlayClient { @Shadow private NetworkTagManager networkTagManager; @Shadow private NBTQueryManager nbtQueryManager; - @SuppressWarnings("deprecation") @Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true) private void handleModCustomPayload(SPacketCustomPayload packet, CallbackInfo ci) { - ResourceLocation channelName = packet.getChannelName(); - PacketBuffer data = packet.getBufferData(); - - for (CustomPayloadHandler customPayloadHandler : RiftLoader.instance.getListeners(CustomPayloadHandler.class)) { - if (customPayloadHandler.clientHandlesChannel(channelName)) { - customPayloadHandler.clientHandleCustomPayload(channelName, data); - } - } - - if(Message.REGISTRY.isEmpty()){ - return; - } + if (Message.REGISTRY.isEmpty()) return; + ResourceLocation channelName = packet.getChannelName(); Class messageClass = Message.REGISTRY.get(channelName); if (messageClass != null) { + PacketBuffer data = packet.getBufferData(); + try { Message message = RiftLoader.instance.newInstance(messageClass); message.read(data); From cb0989bf0029756897843c83d1c93301b997cab8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 23 Nov 2018 19:19:15 +0000 Subject: [PATCH 20/21] Fix a couple of warnings --- .../rift/mixin/hook/client/MixinNetHandlerPlayClient.java | 2 +- .../mixin/hook/client/MixinTileEntityRendererDispatcher.java | 2 +- src/main/java/org/dimdev/riftloader/DuplicateModException.java | 3 +++ .../org/dimdev/riftloader/launch/RiftLoaderClientTweaker.java | 2 -- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java index 1459430..a6bd959 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinNetHandlerPlayClient.java @@ -81,7 +81,7 @@ private void handleUpdateModTileEntity(SPacketUpdateTileEntity packet, CallbackI ResourceLocation tileEntityId = TileEntityType.getId(tileEntity.getType()); ResourceLocation packetId = new ResourceLocation(packet.getNbtCompound().getString("id")); - if (packetId != null && !packetId.getNamespace().equals("minecraft") && packetId.equals(tileEntityId)) { + if (!packetId.getNamespace().equals("minecraft") && packetId.equals(tileEntityId)) { tileEntity.read(packet.getNbtCompound()); } } diff --git a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinTileEntityRendererDispatcher.java b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinTileEntityRendererDispatcher.java index d2a7b1c..f6c2faf 100644 --- a/src/main/java/org/dimdev/rift/mixin/hook/client/MixinTileEntityRendererDispatcher.java +++ b/src/main/java/org/dimdev/rift/mixin/hook/client/MixinTileEntityRendererDispatcher.java @@ -24,7 +24,7 @@ private void onRegisterTileEntityRenderDispatcher(CallbackInfo ci) { tileEntityRendererAdder.addTileEntityRenderers(renderers); } - for (TileEntityRenderer renderer : renderers.values()) { + for (TileEntityRenderer renderer : renderers.values()) { renderer.setRendererDispatcher((TileEntityRendererDispatcher) (Object) this); } } diff --git a/src/main/java/org/dimdev/riftloader/DuplicateModException.java b/src/main/java/org/dimdev/riftloader/DuplicateModException.java index 52d575f..3914852 100644 --- a/src/main/java/org/dimdev/riftloader/DuplicateModException.java +++ b/src/main/java/org/dimdev/riftloader/DuplicateModException.java @@ -1,6 +1,8 @@ package org.dimdev.riftloader; public class DuplicateModException extends RuntimeException { + private static final long serialVersionUID = 8227628664058325482L; + private final ModInfo mod1; private final ModInfo mod2; @@ -13,6 +15,7 @@ public DuplicateModException(ModInfo mod1, ModInfo mod2) { this.mod2 = mod2; } + @Override public String getMessage() { return "Duplicate mod " + mod1.id + ":\r\n - " + mod1.source + "\r\n - " + mod2.source; } diff --git a/src/main/java/org/dimdev/riftloader/launch/RiftLoaderClientTweaker.java b/src/main/java/org/dimdev/riftloader/launch/RiftLoaderClientTweaker.java index 33b51a4..bc96cde 100644 --- a/src/main/java/org/dimdev/riftloader/launch/RiftLoaderClientTweaker.java +++ b/src/main/java/org/dimdev/riftloader/launch/RiftLoaderClientTweaker.java @@ -1,7 +1,5 @@ package org.dimdev.riftloader.launch; -import org.spongepowered.asm.mixin.MixinEnvironment; - import java.io.File; import java.util.ArrayList; import java.util.List; From a29b027f0c0b001ae9b0a734d18cc3d566abf2d8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 24 Nov 2018 20:52:12 +0000 Subject: [PATCH 21/21] Remove unnecessary casts --- src/debug/java/org/dimdev/testmod/TestDimension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debug/java/org/dimdev/testmod/TestDimension.java b/src/debug/java/org/dimdev/testmod/TestDimension.java index 03708e6..b223549 100644 --- a/src/debug/java/org/dimdev/testmod/TestDimension.java +++ b/src/debug/java/org/dimdev/testmod/TestDimension.java @@ -84,7 +84,7 @@ public Vec3d getFogColor(float celestialAngle, float partialTicks) { g = g * (sun * 0.0F + 0.15F); b = b * (sun * 0.0F + 0.15F); - return new Vec3d((double)r, (double)g, (double)b); + return new Vec3d(r, g, b); } @Override