mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-06 02:42:14 +01:00
SPIGOT-4223: Fix inventories using the same TileEntity instance.
This commit is contained in:
parent
671581e33f
commit
ec2095d9c6
@ -2,9 +2,6 @@ package org.bukkit.craftbukkit.inventory.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.server.TileEntityDispenser;
|
||||
import net.minecraft.server.TileEntityDropper;
|
||||
import net.minecraft.server.TileEntityHopper;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
@ -18,9 +15,8 @@ public final class CraftInventoryCreator {
|
||||
|
||||
private CraftInventoryCreator() {
|
||||
converterMap.put(InventoryType.CHEST, DEFAULT_CONVERTER);
|
||||
converterMap.put(InventoryType.DISPENSER, new CraftTileInventoryConverter(new TileEntityDispenser()));
|
||||
converterMap.put(InventoryType.DROPPER, new CraftTileInventoryConverter(new TileEntityDropper()));
|
||||
// furnace needs a world
|
||||
converterMap.put(InventoryType.DISPENSER, new CraftTileInventoryConverter.Dispenser());
|
||||
converterMap.put(InventoryType.DROPPER, new CraftTileInventoryConverter.Dropper());
|
||||
converterMap.put(InventoryType.FURNACE, new CraftTileInventoryConverter.Furnace());
|
||||
converterMap.put(InventoryType.WORKBENCH, DEFAULT_CONVERTER);
|
||||
converterMap.put(InventoryType.ENCHANTING, DEFAULT_CONVERTER);
|
||||
@ -30,7 +26,7 @@ public final class CraftInventoryCreator {
|
||||
converterMap.put(InventoryType.ENDER_CHEST, DEFAULT_CONVERTER);
|
||||
converterMap.put(InventoryType.ANVIL, DEFAULT_CONVERTER);
|
||||
converterMap.put(InventoryType.BEACON, new CraftTileInventoryConverter.Beacon());
|
||||
converterMap.put(InventoryType.HOPPER, new CraftTileInventoryConverter(new TileEntityHopper()));
|
||||
converterMap.put(InventoryType.HOPPER, new CraftTileInventoryConverter.Hopper());
|
||||
converterMap.put(InventoryType.SHULKER_BOX, DEFAULT_CONVERTER);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,10 @@ import net.minecraft.server.ITileInventory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.TileEntityBeacon;
|
||||
import net.minecraft.server.TileEntityBrewingStand;
|
||||
import net.minecraft.server.TileEntityDispenser;
|
||||
import net.minecraft.server.TileEntityDropper;
|
||||
import net.minecraft.server.TileEntityFurnace;
|
||||
import net.minecraft.server.TileEntityHopper;
|
||||
import net.minecraft.server.TileEntityLootable;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryBeacon;
|
||||
@ -15,26 +18,23 @@ import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class CraftTileInventoryConverter implements CraftInventoryCreator.InventoryConverter {
|
||||
public abstract class CraftTileInventoryConverter implements CraftInventoryCreator.InventoryConverter {
|
||||
|
||||
protected final ITileInventory tileEntity;
|
||||
|
||||
public CraftTileInventoryConverter(ITileInventory tileEntity) {
|
||||
this.tileEntity = tileEntity;
|
||||
}
|
||||
public abstract ITileInventory getTileEntity();
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder holder, InventoryType type) {
|
||||
return getInventory(tileEntity);
|
||||
return getInventory(getTileEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
|
||||
if (tileEntity instanceof TileEntityLootable) {
|
||||
((TileEntityLootable) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title));
|
||||
ITileInventory te = getTileEntity();
|
||||
if (te instanceof TileEntityLootable) {
|
||||
((TileEntityLootable) te).setCustomName(CraftChatMessage.fromStringOrNull(title));
|
||||
}
|
||||
|
||||
return getInventory(tileEntity);
|
||||
return getInventory(te);
|
||||
}
|
||||
|
||||
public Inventory getInventory(ITileInventory tileEntity) {
|
||||
@ -43,37 +43,37 @@ public class CraftTileInventoryConverter implements CraftInventoryCreator.Invent
|
||||
|
||||
public static class Furnace extends CraftTileInventoryConverter {
|
||||
|
||||
public Furnace() {
|
||||
super(new TileEntityFurnace());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type) {
|
||||
return getInventory(tileEntity);
|
||||
public ITileInventory getTileEntity() {
|
||||
TileEntityFurnace furnace = new TileEntityFurnace();
|
||||
furnace.setWorld(MinecraftServer.getServer().getWorldServer(0)); // TODO: customize this if required
|
||||
return furnace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
|
||||
ITileInventory tileEntity = getTileEntity();
|
||||
((TileEntityFurnace) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title));
|
||||
return getInventory(tileEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory(ITileInventory tileEntity) {
|
||||
((TileEntityFurnace) tileEntity).setWorld(MinecraftServer.getServer().getWorldServer(0)); // TODO: customize this if required
|
||||
return new CraftInventoryFurnace((TileEntityFurnace) tileEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BrewingStand extends CraftTileInventoryConverter {
|
||||
|
||||
public BrewingStand() {
|
||||
super(new TileEntityBrewingStand());
|
||||
@Override
|
||||
public ITileInventory getTileEntity() {
|
||||
return new TileEntityBrewingStand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
|
||||
// BrewingStand does not extend TileEntityLootable
|
||||
ITileInventory tileEntity = getTileEntity();
|
||||
if (tileEntity instanceof TileEntityBrewingStand) {
|
||||
((TileEntityBrewingStand) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title));
|
||||
}
|
||||
@ -88,8 +88,9 @@ public class CraftTileInventoryConverter implements CraftInventoryCreator.Invent
|
||||
|
||||
public static class Beacon extends CraftTileInventoryConverter {
|
||||
|
||||
public Beacon() {
|
||||
super(new TileEntityBeacon());
|
||||
@Override
|
||||
public ITileInventory getTileEntity() {
|
||||
return new TileEntityBeacon();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -97,4 +98,28 @@ public class CraftTileInventoryConverter implements CraftInventoryCreator.Invent
|
||||
return new CraftInventoryBeacon((TileEntityBeacon) tileInventory);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Dispenser extends CraftTileInventoryConverter {
|
||||
|
||||
@Override
|
||||
public ITileInventory getTileEntity() {
|
||||
return new TileEntityDispenser();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Dropper extends CraftTileInventoryConverter {
|
||||
|
||||
@Override
|
||||
public ITileInventory getTileEntity() {
|
||||
return new TileEntityDropper();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Hopper extends CraftTileInventoryConverter {
|
||||
|
||||
@Override
|
||||
public ITileInventory getTileEntity() {
|
||||
return new TileEntityHopper();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user