Fix inventory not syncing after death (#64)

Expose modded materials to legacy plugins.
This commit is contained in:
IzzelAliz 2020-10-31 11:03:57 +08:00
parent e537455453
commit 5ee2cfaad6
5 changed files with 130 additions and 4 deletions

View File

@ -0,0 +1,33 @@
package io.izzel.arclight.common.mixin.bukkit;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftEntity;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v.inventory.CraftInventory;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryPlayer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(value = CraftHumanEntity.class, remap = false)
public abstract class CraftHumanEntityMixin extends CraftEntity {
// @formatter:off
@Shadow private CraftInventoryPlayer inventory;
@Shadow @Final @Mutable private CraftInventory enderChest;
// @formatter:on
public CraftHumanEntityMixin(CraftServer server, Entity entity) {
super(server, entity);
}
@Override
public void setHandle(Entity entity) {
super.setHandle(entity);
this.inventory = new CraftInventoryPlayer(((PlayerEntity) entity).inventory);
this.enderChest = new CraftInventory(((PlayerEntity) entity).getInventoryEnderChest());
}
}

View File

@ -0,0 +1,91 @@
package io.izzel.arclight.common.mixin.bukkit;
import io.izzel.arclight.common.bridge.bukkit.MaterialBridge;
import io.izzel.arclight.i18n.conf.MaterialPropertySpec;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v.legacy.CraftLegacy;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(value = CraftLegacy.class, remap = false)
public class CraftLegacyLegacyMixin {
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static Material valueOf(String name) {
if (name.startsWith("LEGACY_")) {
return Material.valueOf(name);
} else {
try {
Material material = Material.valueOf(name);
if (((MaterialBridge) (Object) material).bridge$getType() == MaterialPropertySpec.MaterialType.FORGE) {
return material;
} else {
return Material.valueOf("LEGACY_" + name);
}
} catch (IllegalArgumentException e) {
return Material.valueOf("LEGACY_" + name);
}
}
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static Material getMaterial(String name) {
if (name.startsWith("LEGACY_")) {
return Material.getMaterial(name);
} else {
try {
Material material = Material.getMaterial(name);
if (((MaterialBridge) (Object) material).bridge$getType() == MaterialPropertySpec.MaterialType.FORGE) {
return material;
} else {
return Material.getMaterial("LEGACY_" + name);
}
} catch (IllegalArgumentException e) {
return Material.getMaterial("LEGACY_" + name);
}
}
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static Material matchMaterial(String name) {
if (name.startsWith("LEGACY_")) {
return Material.matchMaterial(name);
} else {
try {
Material material = Material.matchMaterial(name);
if (((MaterialBridge) (Object) material).bridge$getType() == MaterialPropertySpec.MaterialType.FORGE) {
return material;
} else {
return Material.matchMaterial("LEGACY_" + name);
}
} catch (IllegalArgumentException e) {
return Material.matchMaterial("LEGACY_" + name);
}
}
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static String name(Material material) {
if (((MaterialBridge) (Object) material).bridge$getType() == MaterialPropertySpec.MaterialType.FORGE) {
return material.name();
} else {
return material.name().substring("LEGACY_".length());
}
}
}

View File

@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.Overwrite;
import java.util.Arrays;
@Mixin(value = CraftLegacy.class, remap = false)
public class CraftLegacyMixin {
public class CraftLegacyUtilMixin {
private static Material[] moddedMaterials;
private static int offset;

View File

@ -440,11 +440,11 @@ public abstract class PlayerListMixin implements PlayerListBridge {
((InternalEntityBridge) playerIn).internal$getBukkitEntity().setHandle(serverplayerentity);
((EntityBridge) serverplayerentity).bridge$setBukkitEntity(((InternalEntityBridge) playerIn).internal$getBukkitEntity());
if ((Object) serverplayerentity instanceof MobEntity) {
((MobEntity) (Object) serverplayerentity).clearLeashed(true, false);
((MobEntity) (Object) playerIn).clearLeashed(true, false);
}
serverplayerentity.connection = playerIn.connection;
serverplayerentity.copyFrom(playerIn, conqueredEnd);
serverplayerentity.copyFrom(playerIn, true); // keep inventory here since inventory dropped at ServerPlayerEntity#onDeath
playerIn.remove(false); // Forge: clone event had a chance to see old data, now discard it
serverplayerentity.setEntityId(playerIn.getEntityId());
serverplayerentity.setPrimaryHand(playerIn.getPrimaryHand());

View File

@ -15,9 +15,11 @@
"CraftConsoleCommandSenderMixin",
"CraftEntityMixin",
"CraftEventFactoryMixin",
"CraftHumanEntityMixin",
"CraftInventoryMixin",
"CraftItemFactoryMixin",
"CraftLegacyMixin",
"CraftLegacyLegacyMixin",
"CraftLegacyUtilMixin",
"CraftMagicNumbersMixin",
"CraftServerMixin",
"CraftVillagerMixin",