Cleaned up item data fixes

This commit is contained in:
RaphiMC 2024-04-28 14:55:11 +02:00
parent d7ea2d5cde
commit 35acb36d1c
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
4 changed files with 62 additions and 131 deletions

View File

@ -1,25 +0,0 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2021-2024 RK_01/RaphiMC 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 net.raphimc.viaproxy.injection.interfaces;
public interface IBlockItemPacketRewriter1_20_5 {
void onMappingDataLoaded();
}

View File

@ -39,19 +39,20 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.Serverb
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter.BlockItemPacketRewriter1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter.BlockItemPacketRewriter1_20_5;
import com.viaversion.viaversion.rewriter.ItemRewriter; import com.viaversion.viaversion.rewriter.ItemRewriter;
import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.viaproxy.injection.interfaces.IBlockItemPacketRewriter1_20_5; import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.plugins.events.ViaLoadingEvent;
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyMappingDataLoader; import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyMappingDataLoader;
import net.raphimc.viaproxy.util.logging.Logger;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.*; import java.util.*;
@Mixin(value = BlockItemPacketRewriter1_20_5.class, remap = false) @Mixin(value = BlockItemPacketRewriter1_20_5.class, remap = false)
public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<ClientboundPacket1_20_3, ServerboundPacket1_20_5, Protocol1_20_5To1_20_3> implements IBlockItemPacketRewriter1_20_5 { public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<ClientboundPacket1_20_3, ServerboundPacket1_20_5, Protocol1_20_5To1_20_3> {
@Unique @Unique
private final Set<String> foodItems_b1_7_3 = new HashSet<>(); private final Set<String> foodItems_b1_7_3 = new HashSet<>();
@ -69,8 +70,8 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<Cl
super(null, null, null, null, null); super(null, null, null, null, null);
} }
@Override @Inject(method = "<init>", at = @At("RETURN"))
public void onMappingDataLoaded() { public void loadItemMappings(Protocol1_20_5To1_20_3 protocol, CallbackInfo ci) {
this.foodItems_b1_7_3.add("minecraft:apple"); this.foodItems_b1_7_3.add("minecraft:apple");
this.foodItems_b1_7_3.add("minecraft:mushroom_stew"); this.foodItems_b1_7_3.add("minecraft:mushroom_stew");
this.foodItems_b1_7_3.add("minecraft:bread"); this.foodItems_b1_7_3.add("minecraft:bread");
@ -81,26 +82,12 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<Cl
this.foodItems_b1_7_3.add("minecraft:cooked_cod"); this.foodItems_b1_7_3.add("minecraft:cooked_cod");
this.foodItems_b1_7_3.add("minecraft:cookie"); this.foodItems_b1_7_3.add("minecraft:cookie");
this.armorMaxDamage_b1_8_1.put("minecraft:leather_helmet", 33); final JsonObject armorMaxDamages = ViaProxyMappingDataLoader.INSTANCE.loadData("armor-damages-b1.8.1.json");
this.armorMaxDamage_b1_8_1.put("minecraft:leather_chestplate", 48); for (Map.Entry<String, JsonElement> entry : armorMaxDamages.entrySet()) {
this.armorMaxDamage_b1_8_1.put("minecraft:leather_leggings", 45); final String item = entry.getKey();
this.armorMaxDamage_b1_8_1.put("minecraft:leather_boots", 39); final int maxDamage = entry.getValue().getAsInt();
this.armorMaxDamage_b1_8_1.put("minecraft:chainmail_helmet", 66); this.armorMaxDamage_b1_8_1.put(item, maxDamage);
this.armorMaxDamage_b1_8_1.put("minecraft:chainmail_chestplate", 96); }
this.armorMaxDamage_b1_8_1.put("minecraft:chainmail_leggings", 90);
this.armorMaxDamage_b1_8_1.put("minecraft:chainmail_boots", 78);
this.armorMaxDamage_b1_8_1.put("minecraft:iron_helmet", 132);
this.armorMaxDamage_b1_8_1.put("minecraft:iron_chestplate", 192);
this.armorMaxDamage_b1_8_1.put("minecraft:iron_leggings", 180);
this.armorMaxDamage_b1_8_1.put("minecraft:iron_boots", 156);
this.armorMaxDamage_b1_8_1.put("minecraft:diamond_helmet", 264);
this.armorMaxDamage_b1_8_1.put("minecraft:diamond_chestplate", 384);
this.armorMaxDamage_b1_8_1.put("minecraft:diamond_leggings", 360);
this.armorMaxDamage_b1_8_1.put("minecraft:diamond_boots", 312);
this.armorMaxDamage_b1_8_1.put("minecraft:golden_helmet", 66);
this.armorMaxDamage_b1_8_1.put("minecraft:golden_chestplate", 96);
this.armorMaxDamage_b1_8_1.put("minecraft:golden_leggings", 90);
this.armorMaxDamage_b1_8_1.put("minecraft:golden_boots", 78);
this.swordItems1_8.add("minecraft:wooden_sword"); this.swordItems1_8.add("minecraft:wooden_sword");
this.swordItems1_8.add("minecraft:stone_sword"); this.swordItems1_8.add("minecraft:stone_sword");
@ -108,23 +95,12 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<Cl
this.swordItems1_8.add("minecraft:golden_sword"); this.swordItems1_8.add("minecraft:golden_sword");
this.swordItems1_8.add("minecraft:diamond_sword"); this.swordItems1_8.add("minecraft:diamond_sword");
ViaProxy.EVENT_MANAGER.registerRunnable(() -> {
final JsonObject itemToolComponents = ViaProxyMappingDataLoader.INSTANCE.loadData("item-tool-components.json"); final JsonObject itemToolComponents = ViaProxyMappingDataLoader.INSTANCE.loadData("item-tool-components.json");
for (Map.Entry<String, JsonElement> entry : itemToolComponents.entrySet()) { for (Map.Entry<String, JsonElement> entry : itemToolComponents.entrySet()) {
int attempts = 0;
while (ProtocolVersion.getClosest(entry.getKey()) == null) {
try {
Thread.sleep(100);
if (attempts++ > 100) { // 10 seconds
Logger.LOGGER.warn("Failed to load item-tool-components.json after 10 seconds. Skipping entry.");
break;
}
} catch (InterruptedException e) {
break;
}
}
final ProtocolVersion version = ProtocolVersion.getClosest(entry.getKey()); final ProtocolVersion version = ProtocolVersion.getClosest(entry.getKey());
if (version == null) { // Only happens if the timeout above is reached or the thread is interrupted if (version == null) {
continue; throw new IllegalStateException("Unknown protocol version: " + entry.getKey());
} }
final Map<String, ToolProperties> toolProperties = new HashMap<>(); final Map<String, ToolProperties> toolProperties = new HashMap<>();
final JsonArray toolComponents = entry.getValue().getAsJsonArray(); final JsonArray toolComponents = entry.getValue().getAsJsonArray();
@ -149,6 +125,7 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<Cl
} }
this.toolDataChanges.put(version, toolProperties); this.toolDataChanges.put(version, toolProperties);
} }
}, ViaLoadingEvent.class);
} }
@Inject(method = "toStructuredItem", at = @At("RETURN")) @Inject(method = "toStructuredItem", at = @At("RETURN"))

View File

@ -1,43 +0,0 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2021-2024 RK_01/RaphiMC 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 net.raphimc.viaproxy.injection.mixins;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter.BlockItemPacketRewriter1_20_5;
import net.raphimc.viaproxy.injection.interfaces.IBlockItemPacketRewriter1_20_5;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
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;
@Mixin(value = Protocol1_20_5To1_20_3.class, remap = false)
public abstract class MixinProtocol1_20_5To1_20_3 {
@Shadow
@Final
private BlockItemPacketRewriter1_20_5 itemRewriter;
@Inject(method = "onMappingDataLoaded", at = @At("RETURN"))
private void callOnMappingDataLoaded(CallbackInfo ci) {
((IBlockItemPacketRewriter1_20_5) (Object) this.itemRewriter).onMappingDataLoaded();
}
}

View File

@ -0,0 +1,22 @@
{
"minecraft:leather_helmet": 33,
"minecraft:leather_chestplate": 48,
"minecraft:leather_leggings": 45,
"minecraft:leather_boots": 39,
"minecraft:chainmail_helmet": 66,
"minecraft:chainmail_chestplate": 96,
"minecraft:chainmail_leggings": 90,
"minecraft:chainmail_boots": 78,
"minecraft:iron_helmet": 132,
"minecraft:iron_chestplate": 192,
"minecraft:iron_leggings": 180,
"minecraft:iron_boots": 156,
"minecraft:diamond_helmet": 264,
"minecraft:diamond_chestplate": 384,
"minecraft:diamond_leggings": 360,
"minecraft:diamond_boots": 312,
"minecraft:golden_helmet": 66,
"minecraft:golden_chestplate": 96,
"minecraft:golden_leggings": 90,
"minecraft:golden_boots": 78
}