mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-22 11:56:21 +01:00
Small code cleanup
This commit is contained in:
parent
dc21828860
commit
3f4b586328
@ -44,7 +44,6 @@ import java.io.File;
|
||||
* - Check if relevant for protocol translation: TakeItemEntityPacket isEmpty case (1.20 -> 1.20.1 change)
|
||||
* - Window interactions in <= 1.16.5 has changed and can be detected by the server
|
||||
* - Entity hit boxes and eye heights has changed in almost all versions
|
||||
* - Crafting Recipes are missing in ViaVersion (see https://github.com/ViaVersion/ViaFabricPlus/issues/60)
|
||||
* - Most CTS protocol features aren't supported (see https://github.com/ViaVersion/ViaFabricPlus/issues/181)
|
||||
* - Most CPE features aren't implemented correctly (see https://github.com/ViaVersion/ViaFabricPlus/issues/152)
|
||||
* - Bedrock scaffolding should be added as soon as ViaBedrock supports block placement (see https://github.com/ViaVersion/ViaFabricPlus/issues/204)
|
||||
|
@ -28,16 +28,11 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.FontStorage;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.inventory.RecipeInputInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
import net.raphimc.vialoader.util.VersionRange;
|
||||
@ -180,30 +175,6 @@ public class ClientsideFixes {
|
||||
return LEGACY_ARMOR_POINTS.get(itemStack.getItem());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the result slot of a crafting screen handler to the correct item stack. In MC <= 1.11.2 the result slot
|
||||
* is not updated when the input slots change, so we need to update it manually, Spigot and Paper re-syncs the slot,
|
||||
* so we don't notice this bug on servers that use Spigot or Paper
|
||||
*
|
||||
* @param syncId The sync id of the screen handler
|
||||
* @param screenHandler The screen handler
|
||||
* @param inventory The inventory of the screen handler
|
||||
*/
|
||||
public static void setCraftingResultSlot(final int syncId, final ScreenHandler screenHandler, final RecipeInputInventory inventory) {
|
||||
final var network = MinecraftClient.getInstance().getNetworkHandler();
|
||||
if (network == null) return;
|
||||
|
||||
final var world = MinecraftClient.getInstance().world;
|
||||
|
||||
final var result = network.getRecipeManager().
|
||||
getFirstMatch(RecipeType.CRAFTING, inventory, world). // Get the first matching recipe
|
||||
map(recipe -> recipe.value().craft(inventory, world.getRegistryManager())). // Craft the recipe to get the result
|
||||
orElse(ItemStack.EMPTY); // If there is no recipe, set the result to air
|
||||
|
||||
// Update the result slot
|
||||
network.onScreenHandlerSlotUpdate(new ScreenHandlerSlotUpdateS2CPacket(syncId, screenHandler.getRevision(), 0, result));
|
||||
}
|
||||
|
||||
public static int getCurrentChatLimit() {
|
||||
return currentChatLimit;
|
||||
}
|
||||
|
@ -21,16 +21,29 @@ import net.minecraft.block.ConcretePowderBlock;
|
||||
import net.minecraft.block.GlazedTerracottaBlock;
|
||||
import net.minecraft.block.ShulkerBoxBlock;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.inventory.RecipeInputInventory;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
|
||||
import net.minecraft.recipe.*;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Handles all recipe related stuff for versions older than 1.12.
|
||||
*/
|
||||
public class RecipesPre1_12 {
|
||||
|
||||
/**
|
||||
* Removes recipes that are not supported in 1.11 and older versions.
|
||||
*
|
||||
* @param recipes List of recipes
|
||||
* @param version Version of the client
|
||||
*/
|
||||
public static void editRecipes(final List<Recipe<?>> recipes, final VersionEnum version) {
|
||||
final var registryManager = MinecraftClient.getInstance().world.getRegistryManager();
|
||||
|
||||
@ -64,4 +77,28 @@ public class RecipesPre1_12 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the result slot of a crafting screen handler to the correct item stack. In MC <= 1.11.2 the result slot
|
||||
* is not updated when the input slots change, so we need to update it manually, Spigot and Paper re-syncs the slot,
|
||||
* so we don't notice this bug on servers that use Spigot or Paper
|
||||
*
|
||||
* @param syncId The sync id of the screen handler
|
||||
* @param screenHandler The screen handler
|
||||
* @param inventory The inventory of the screen handler
|
||||
*/
|
||||
public static void setCraftingResultSlot(final int syncId, final ScreenHandler screenHandler, final RecipeInputInventory inventory) {
|
||||
final var network = MinecraftClient.getInstance().getNetworkHandler();
|
||||
if (network == null) return;
|
||||
|
||||
final var world = MinecraftClient.getInstance().world;
|
||||
|
||||
final var result = network.getRecipeManager().
|
||||
getFirstMatch(RecipeType.CRAFTING, inventory, world). // Get the first matching recipe
|
||||
map(recipe -> recipe.value().craft(inventory, world.getRegistryManager())). // Craft the recipe to get the result
|
||||
orElse(ItemStack.EMPTY); // If there is no recipe, set the result to air
|
||||
|
||||
// Update the result slot
|
||||
network.onScreenHandlerSlotUpdate(new ScreenHandlerSlotUpdateS2CPacket(syncId, screenHandler.getRevision(), 0, result));
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen.screenhandler;
|
||||
|
||||
import de.florianmichael.viafabricplus.definition.ClientsideFixes;
|
||||
import de.florianmichael.viafabricplus.definition.RecipesPre1_12;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.RecipeInputInventory;
|
||||
@ -44,7 +44,7 @@ public abstract class MixinCraftingScreenHandler extends AbstractRecipeScreenHan
|
||||
@Inject(method = "onContentChanged", at = @At("HEAD"))
|
||||
public void updateResultSlot(Inventory inventory, CallbackInfo ci) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
|
||||
ClientsideFixes.setCraftingResultSlot(syncId, this, input);
|
||||
RecipesPre1_12.setCraftingResultSlot(syncId, this, input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen.screenhandler;
|
||||
|
||||
import de.florianmichael.viafabricplus.definition.ClientsideFixes;
|
||||
import de.florianmichael.viafabricplus.definition.RecipesPre1_12;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.RecipeInputInventory;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
@ -65,7 +65,7 @@ public abstract class MixinPlayerScreenHandler extends AbstractRecipeScreenHandl
|
||||
@Inject(method = "onContentChanged", at = @At("HEAD"))
|
||||
public void updateResultSlot(Inventory inventory, CallbackInfo ci) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
|
||||
ClientsideFixes.setCraftingResultSlot(syncId, this, craftingInput);
|
||||
RecipesPre1_12.setCraftingResultSlot(syncId, this, craftingInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user