Skip to content

Commit

Permalink
Fix InventoryView casting error. (Closes #1518)
Browse files Browse the repository at this point in the history
Signed-off-by: 秋雨落 <[email protected]>
  • Loading branch information
qyl27 committed Oct 8, 2024
1 parent d0dda85 commit 83d8eff
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryFurnace;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.view.CraftFurnaceView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -29,7 +30,7 @@ public abstract class AbstractFurnaceContainerMixin extends AbstractContainerMen
@Shadow @Final private Container container;
// @formatter:on

private CraftInventoryView bukkitEntity = null;
private CraftFurnaceView bukkitEntity = null;
private Inventory playerInventory;

@Inject(method = "<init>(Lnet/minecraft/world/inventory/MenuType;Lnet/minecraft/world/item/crafting/RecipeType;Lnet/minecraft/world/inventory/RecipeBookType;ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/Container;Lnet/minecraft/world/inventory/ContainerData;)V", at = @At("RETURN"))
Expand All @@ -43,13 +44,13 @@ public abstract class AbstractFurnaceContainerMixin extends AbstractContainerMen
}

@Override
public CraftInventoryView getBukkitView() {
public CraftFurnaceView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}

CraftInventoryFurnace inventory = new CraftInventoryFurnace((AbstractFurnaceBlockEntity) this.container);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this);
bukkitEntity = new CraftFurnaceView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractFurnaceMenu) (Object) this);
return bukkitEntity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.craftbukkit.v.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v.inventory.view.CraftAnvilView;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.view.AnvilView;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -41,7 +42,7 @@ public abstract class AnvilMenuMixin extends ItemCombinerMixin implements AnvilM
public int maximumAllowedRenameCost = 39;
public int maximumRepairCost = 40;

private CraftInventoryView bukkitEntity;
private CraftAnvilView bukkitEntity;

@Decorate(method = "createResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/ResultContainer;setItem(ILnet/minecraft/world/item/ItemStack;)V"))
private void arclight$prepareAnvilEvent(ResultContainer instance, int i, ItemStack itemStack) throws Throwable {
Expand All @@ -66,14 +67,14 @@ public abstract class AnvilMenuMixin extends ItemCombinerMixin implements AnvilM
}

@Override
public CraftInventoryView getBukkitView() {
public CraftAnvilView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}

CraftInventory inventory = new CraftInventoryAnvil(
((IWorldPosCallableBridge) this.access).bridge$getLocation(), this.inputSlots, this.resultSlots);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this);
bukkitEntity = new CraftAnvilView(((PlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (AnvilMenu) (Object) this);
return bukkitEntity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.craftbukkit.v.inventory.CraftInventory;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryBeacon;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.view.CraftBeaconView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -26,7 +27,7 @@ public abstract class BeaconContainerMixin extends AbstractContainerMenuMixin {
@Shadow @Final private Container beacon;
// @formatter:on

private CraftInventoryView bukkitEntity;
private CraftBeaconView bukkitEntity;
private Inventory playerInventory;

@Inject(method = "<init>(ILnet/minecraft/world/Container;Lnet/minecraft/world/inventory/ContainerData;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN"))
Expand All @@ -40,13 +41,13 @@ public abstract class BeaconContainerMixin extends AbstractContainerMenuMixin {
}

@Override
public CraftInventoryView getBukkitView() {
public CraftBeaconView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}

CraftInventory inventory = new CraftInventoryBeacon(this.beacon);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this);
bukkitEntity = new CraftBeaconView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (BeaconMenu) (Object) this);
return bukkitEntity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.world.inventory.ContainerData;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryBrewer;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.view.CraftBrewingStandView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -24,7 +25,7 @@ public abstract class BrewingStandContainerMixin extends AbstractContainerMenuMi
@Shadow @Final private Container brewingStand;
// @formatter:on

private CraftInventoryView bukkitEntity = null;
private CraftBrewingStandView bukkitEntity = null;
private Inventory playerInventory;

@Inject(method = "<init>(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/Container;Lnet/minecraft/world/inventory/ContainerData;)V", at = @At("RETURN"))
Expand All @@ -38,13 +39,13 @@ public abstract class BrewingStandContainerMixin extends AbstractContainerMenuMi
}

@Override
public CraftInventoryView getBukkitView() {
public CraftBrewingStandView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}

CraftInventoryBrewer inventory = new CraftInventoryBrewer(this.brewingStand);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this);
bukkitEntity = new CraftBrewingStandView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (BrewingStandMenu) (Object) this);
return bukkitEntity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.world.inventory.CrafterMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.ResultContainer;
import org.bukkit.craftbukkit.v.inventory.view.CraftCrafterView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryCrafter;
Expand All @@ -21,16 +22,16 @@ public abstract class CrafterMenuMixin extends AbstractContainerMenuMixin {
@Shadow @Final private ResultContainer resultContainer;
@Shadow @Final private Player player;

private CraftInventoryView bukkitEntity;
private CraftCrafterView bukkitEntity;

@Override
public CraftInventoryView getBukkitView() {
public CraftCrafterView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}

CraftInventoryCrafter inventory = new CraftInventoryCrafter(this.container, this.resultContainer);
bukkitEntity = new CraftInventoryView(((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (CrafterMenu) (Object) this);
bukkitEntity = new CraftCrafterView(((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (CrafterMenu) (Object) this);
return bukkitEntity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bukkit.craftbukkit.v.inventory.CraftInventoryEnchanting;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v.inventory.view.CraftEnchantmentView;
import org.bukkit.craftbukkit.v.util.CraftNamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentOffer;
Expand Down Expand Up @@ -58,7 +59,7 @@ public abstract class EnchantmentContainerMixin extends AbstractContainerMenuMix
@Shadow @Final public int[] levelClue;
// @formatter:on

private CraftInventoryView bukkitEntity = null;
private CraftEnchantmentView bukkitEntity = null;
private Inventory playerInventory;

@Inject(method = "<init>(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN"))
Expand Down Expand Up @@ -162,13 +163,13 @@ public abstract class EnchantmentContainerMixin extends AbstractContainerMenuMix
}

@Override
public CraftInventoryView getBukkitView() {
public CraftEnchantmentView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}

CraftInventoryEnchanting inventory = new CraftInventoryEnchanting(this.enchantSlots);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this);
bukkitEntity = new CraftEnchantmentView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (EnchantmentMenu) (Object) this);
return bukkitEntity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryLectern;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.view.CraftLecternView;
import org.bukkit.event.player.PlayerTakeLecternBookEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -28,7 +29,7 @@ public abstract class LecternContainerMixin extends AbstractContainerMenuMixin i
@Shadow @Final private Container lectern;
// @formatter:on

private CraftInventoryView bukkitEntity;
private CraftLecternView bukkitEntity;
private Inventory playerInventory;

@ShadowConstructor
Expand Down Expand Up @@ -68,12 +69,12 @@ public abstract class LecternContainerMixin extends AbstractContainerMenuMixin i
}

@Override
public CraftInventoryView getBukkitView() {
public CraftLecternView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}
CraftInventoryLectern inventory = new CraftInventoryLectern(this.lectern);
bukkitEntity = new CraftInventoryView(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this);
bukkitEntity = new CraftLecternView(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (LecternMenu) (Object) this);
return bukkitEntity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.inventory.LoomMenu;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryLoom;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.view.CraftLoomView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -27,7 +28,7 @@ public abstract class LoomContainerMixin extends AbstractContainerMenuMixin impl
@Shadow @Final private ContainerLevelAccess access;
// @formatter:on

private CraftInventoryView bukkitEntity;
private CraftLoomView bukkitEntity;
private Inventory playerInventory;

@Inject(method = "<init>(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN"))
Expand All @@ -43,13 +44,13 @@ public abstract class LoomContainerMixin extends AbstractContainerMenuMixin impl
}

@Override
public CraftInventoryView getBukkitView() {
public CraftLoomView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}

CraftInventoryLoom inventory = new CraftInventoryLoom(this.inputContainer, this.outputContainer);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this);
bukkitEntity = new CraftLoomView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (LoomMenu) (Object) this);
return bukkitEntity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.world.item.trading.Merchant;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryMerchant;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.view.CraftMerchantView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -24,7 +25,7 @@ public abstract class MerchantContainerMixin extends AbstractContainerMenuMixin
@Shadow @Final private MerchantContainer tradeContainer;
// @formatter:on

private CraftInventoryView bukkitEntity = null;
private CraftMerchantView bukkitEntity = null;
private Inventory playerInventory;

@Inject(method = "<init>(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/item/trading/Merchant;)V", at = @At("RETURN"))
Expand All @@ -40,9 +41,9 @@ public abstract class MerchantContainerMixin extends AbstractContainerMenuMixin
}

@Override
public CraftInventoryView getBukkitView() {
public CraftMerchantView getBukkitView() {
if (bukkitEntity == null) {
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), new CraftInventoryMerchant(this.trader, this.tradeContainer), (AbstractContainerMenu) (Object) this);
bukkitEntity = new CraftMerchantView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), new CraftInventoryMerchant(this.trader, this.tradeContainer), (MerchantMenu) (Object) this, trader);
}
return bukkitEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.inventory.StonecutterMenu;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryStonecutter;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.view.CraftStonecutterView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -26,7 +27,7 @@ public abstract class StonecutterContainerMixin extends AbstractContainerMenuMix
@Shadow @Final private ContainerLevelAccess access;
// @formatter:on

private CraftInventoryView bukkitEntity = null;
private CraftStonecutterView bukkitEntity = null;
private Inventory playerInventory;

@Inject(method = "<init>(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN"))
Expand All @@ -35,13 +36,13 @@ public abstract class StonecutterContainerMixin extends AbstractContainerMenuMix
}

@Override
public CraftInventoryView getBukkitView() {
public CraftStonecutterView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}

CraftInventoryStonecutter inventory = new CraftInventoryStonecutter(this.container, this.resultContainer);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this);
bukkitEntity = new CraftStonecutterView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (StonecutterMenu) (Object) this);
return bukkitEntity;
}

Expand Down

0 comments on commit 83d8eff

Please sign in to comment.