Emulate recipes for 1.8 - 1.11.2

This commit is contained in:
FlorianMichael 2023-11-05 18:27:35 +01:00
parent f445ecdd9e
commit dc21828860
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
6 changed files with 221 additions and 3 deletions

View File

@ -0,0 +1,67 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.definition;
import net.minecraft.block.ConcretePowderBlock;
import net.minecraft.block.GlazedTerracottaBlock;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.recipe.*;
import net.raphimc.vialoader.util.VersionEnum;
import java.util.List;
public class RecipesPre1_12 {
public static void editRecipes(final List<Recipe<?>> recipes, final VersionEnum version) {
final var registryManager = MinecraftClient.getInstance().world.getRegistryManager();
recipes.removeIf(recipe -> {
if (recipe.getResult(registryManager).getItem() instanceof BlockItem block) {
return block.getBlock() instanceof ConcretePowderBlock || block.getBlock() instanceof GlazedTerracottaBlock;
}
return false;
});
if (version.isOlderThanOrEqualTo(VersionEnum.r1_11)) {
recipes.removeIf(recipe -> recipe.getResult(registryManager).getItem() == Items.IRON_NUGGET);
if (version.isOlderThanOrEqualTo(VersionEnum.r1_10)) {
recipes.removeIf(recipe -> {
Item item = recipe.getResult(registryManager).getItem();
if (item instanceof BlockItem blockItem) {
return blockItem.getBlock() instanceof ShulkerBoxBlock;
} else if (item == Items.OBSERVER || item == Items.IRON_NUGGET) {
return true;
} else if (item == Items.GOLD_NUGGET) {
return recipe.getSerializer() == RecipeSerializer.SMELTING;
} else {
return false;
}
});
}
if (version.isOlderThanOrEqualTo(VersionEnum.r1_9_3tor1_9_4)) {
recipes.removeIf(recipe -> recipe.getResult(registryManager).getItem() == Items.BONE_BLOCK);
}
}
}
}

View File

@ -0,0 +1,25 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.access;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
public interface IProtocol1_13To1_12_2 {
void viafabricplus_writeDeclareRecipes(final PacketWrapper recipesPacket);
}

View File

@ -19,6 +19,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.network;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.definition.RecipesPre1_12;
import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
import de.florianmichael.viafabricplus.injection.access.IBoatEntity;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
@ -29,6 +30,9 @@ import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.util.Identifier;
import net.raphimc.vialoader.util.VersionEnum;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
@ -38,8 +42,11 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@SuppressWarnings("DataFlowIssue")
@Mixin(ClientPlayNetworkHandler.class)
@ -136,4 +143,21 @@ public abstract class MixinClientPlayNetworkHandler {
ci.cancel();
}
}
@Redirect(method = "onSynchronizeRecipes", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/SynchronizeRecipesS2CPacket;getRecipes()Ljava/util/List;"))
public List<RecipeEntry<?>> rewriteRecipes(SynchronizeRecipesS2CPacket instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
final List<Recipe<?>> recipes = instance.getRecipes().stream().map(RecipeEntry::value).collect(Collectors.toList());
RecipesPre1_12.editRecipes(recipes, ProtocolHack.getTargetVersion());
final List<RecipeEntry<?>> entries = new ArrayList<>();
int recipeId = 0;
for (final Recipe<?> recipe : recipes) {
entries.add(new RecipeEntry<>(new Identifier(String.valueOf(recipeId++)), recipe));
}
return entries;
}
return instance.getRecipes();
}
}

View File

@ -0,0 +1,63 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion.protocol1_12to1_11_1;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import de.florianmichael.viafabricplus.injection.access.IProtocol1_13To1_12_2;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = Protocol1_12To1_11_1.class, remap = false)
public class MixinProtocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9_3, ClientboundPackets1_12, ServerboundPackets1_9_3, ServerboundPackets1_12> {
@Inject(method = "registerPackets", at = @At("RETURN"))
public void enforceRecipeWriting(CallbackInfo ci) {
registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketHandlers() {
@Override
public void register() {
map(Type.INT);
map(Type.UNSIGNED_BYTE);
map(Type.INT);
handler(wrapper -> {
wrapper.user().get(ClientWorld.class).setEnvironment(wrapper.get(Type.INT, 1));
final IProtocol1_13To1_12_2 protocol = (IProtocol1_13To1_12_2) wrapper.user().getProtocolInfo().getPipeline().getProtocol(Protocol1_13To1_12_2.class);
if (protocol == null) {
Via.getPlatform().getLogger().warning("Protocol1_13To1_12_2 not found!");
return;
}
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, protocol::viafabricplus_writeDeclareRecipes).scheduleSend(Protocol1_13To1_12_2.class);
});
}
});
}
}

View File

@ -0,0 +1,35 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion.protocol1_13to1_12_2;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import de.florianmichael.viafabricplus.injection.access.IProtocol1_13To1_12_2;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(value = Protocol1_13To1_12_2.class, remap = false)
public abstract class MixinProtocol1_13To1_12_2 implements IProtocol1_13To1_12_2 {
@Shadow protected abstract void writeDeclareRecipes(PacketWrapper recipesPacket);
@Override
public void viafabricplus_writeDeclareRecipes(PacketWrapper recipesPacket) {
writeDeclareRecipes(recipesPacket);
}
}

View File

@ -136,6 +136,7 @@
"fixes.minecraft.screen.merchant.MixinMerchantScreen",
"fixes.minecraft.screen.merchant.MixinMerchantScreenHandler",
"fixes.minecraft.screen.screenhandler.MixinBrewingStandScreenHandler_FuelSlot",
"fixes.minecraft.screen.screenhandler.MixinCraftingScreenHandler",
"fixes.minecraft.screen.screenhandler.MixinPlayerScreenHandler",
"fixes.minecraft.screen.screenhandler.MixinScreenHandler",
"fixes.viabedrock.MixinBedrockProtocol",
@ -169,10 +170,13 @@
"fixes.viaversion.protocol1_9to1_8.MixinEntityTracker1_9",
"fixes.viaversion.protocol1_9to1_8.MixinMetadataRewriter1_9To1_8",
"jsonwebtoken.MixinClasses",
"jsonwebtoken.MixinDefaultJwtParserBuilder",
"fixes.minecraft.screen.screenhandler.MixinCraftingScreenHandler"
"jsonwebtoken.MixinDefaultJwtParserBuilder"
],
"injectors": {
"defaultRequire": 1
}
},
"mixins": [
"fixes.viaversion.protocol1_12to1_11_1.MixinProtocol1_12To1_11_1",
"fixes.viaversion.protocol1_13to1_12_2.MixinProtocol1_13To1_12_2"
]
}