geforkt von Mirrors/Paper
SPIGOT-7867: Merchant instanceof AbstractVillager always returns false
By: Miles Holder <mwholder2005@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
7657f347d2
Commit
ac5e815b3e
@ -1,6 +1,6 @@
|
|||||||
--- a/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
|
--- a/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
|
||||||
+++ b/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
|
+++ b/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
|
||||||
@@ -40,8 +40,24 @@
|
@@ -40,8 +40,22 @@
|
||||||
import net.minecraft.world.phys.Vec3D;
|
import net.minecraft.world.phys.Vec3D;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
@ -15,17 +15,15 @@
|
|||||||
public abstract class EntityVillagerAbstract extends EntityAgeable implements InventoryCarrier, NPC, IMerchant {
|
public abstract class EntityVillagerAbstract extends EntityAgeable implements InventoryCarrier, NPC, IMerchant {
|
||||||
|
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ private CraftMerchant craftMerchant;
|
|
||||||
+
|
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public CraftMerchant getCraftMerchant() {
|
+ public CraftMerchant getCraftMerchant() {
|
||||||
+ return (craftMerchant == null) ? craftMerchant = new CraftMerchant(this) : craftMerchant;
|
+ return (org.bukkit.craftbukkit.entity.CraftAbstractVillager) getBukkitEntity();
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
private static final DataWatcherObject<Integer> DATA_UNHAPPY_COUNTER = DataWatcher.defineId(EntityVillagerAbstract.class, DataWatcherRegistry.INT);
|
private static final DataWatcherObject<Integer> DATA_UNHAPPY_COUNTER = DataWatcher.defineId(EntityVillagerAbstract.class, DataWatcherRegistry.INT);
|
||||||
private static final Logger LOGGER = LogUtils.getLogger();
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
public static final int VILLAGER_SLOT_OFFSET = 300;
|
public static final int VILLAGER_SLOT_OFFSET = 300;
|
||||||
@@ -50,7 +66,7 @@
|
@@ -50,7 +64,7 @@
|
||||||
private EntityHuman tradingPlayer;
|
private EntityHuman tradingPlayer;
|
||||||
@Nullable
|
@Nullable
|
||||||
protected MerchantRecipeList offers;
|
protected MerchantRecipeList offers;
|
||||||
@ -34,7 +32,7 @@
|
|||||||
|
|
||||||
public EntityVillagerAbstract(EntityTypes<? extends EntityVillagerAbstract> entitytypes, World world) {
|
public EntityVillagerAbstract(EntityTypes<? extends EntityVillagerAbstract> entitytypes, World world) {
|
||||||
super(entitytypes, world);
|
super(entitytypes, world);
|
||||||
@@ -179,7 +195,7 @@
|
@@ -179,7 +193,7 @@
|
||||||
public void readAdditionalSaveData(NBTTagCompound nbttagcompound) {
|
public void readAdditionalSaveData(NBTTagCompound nbttagcompound) {
|
||||||
super.readAdditionalSaveData(nbttagcompound);
|
super.readAdditionalSaveData(nbttagcompound);
|
||||||
if (nbttagcompound.contains("Offers")) {
|
if (nbttagcompound.contains("Offers")) {
|
||||||
@ -43,7 +41,7 @@
|
|||||||
Logger logger = EntityVillagerAbstract.LOGGER;
|
Logger logger = EntityVillagerAbstract.LOGGER;
|
||||||
|
|
||||||
Objects.requireNonNull(logger);
|
Objects.requireNonNull(logger);
|
||||||
@@ -246,7 +262,16 @@
|
@@ -246,7 +260,16 @@
|
||||||
MerchantRecipe merchantrecipe = ((VillagerTrades.IMerchantRecipeOption) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random);
|
MerchantRecipe merchantrecipe = ((VillagerTrades.IMerchantRecipeOption) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random);
|
||||||
|
|
||||||
if (merchantrecipe != null) {
|
if (merchantrecipe != null) {
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
package org.bukkit.craftbukkit.entity;
|
package org.bukkit.craftbukkit.entity;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import net.minecraft.world.entity.npc.EntityVillager;
|
import net.minecraft.world.entity.npc.EntityVillager;
|
||||||
import net.minecraft.world.entity.npc.EntityVillagerAbstract;
|
import net.minecraft.world.entity.npc.EntityVillagerAbstract;
|
||||||
|
import net.minecraft.world.item.trading.IMerchant;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftMerchant;
|
import org.bukkit.craftbukkit.inventory.CraftMerchant;
|
||||||
import org.bukkit.entity.AbstractVillager;
|
import org.bukkit.entity.AbstractVillager;
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
|
||||||
|
|
||||||
public class CraftAbstractVillager extends CraftAgeable implements AbstractVillager, InventoryHolder {
|
public class CraftAbstractVillager extends CraftAgeable implements CraftMerchant, AbstractVillager, InventoryHolder {
|
||||||
|
|
||||||
public CraftAbstractVillager(CraftServer server, EntityVillagerAbstract entity) {
|
public CraftAbstractVillager(CraftServer server, EntityVillagerAbstract entity) {
|
||||||
super(server, entity);
|
super(server, entity);
|
||||||
@ -23,6 +21,11 @@ public class CraftAbstractVillager extends CraftAgeable implements AbstractVilla
|
|||||||
return (EntityVillager) entity;
|
return (EntityVillager) entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMerchant getMerchant() {
|
||||||
|
return getHandle();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CraftAbstractVillager";
|
return "CraftAbstractVillager";
|
||||||
@ -32,43 +35,4 @@ public class CraftAbstractVillager extends CraftAgeable implements AbstractVilla
|
|||||||
public Inventory getInventory() {
|
public Inventory getInventory() {
|
||||||
return new CraftInventory(getHandle().getInventory());
|
return new CraftInventory(getHandle().getInventory());
|
||||||
}
|
}
|
||||||
|
|
||||||
private CraftMerchant getMerchant() {
|
|
||||||
return getHandle().getCraftMerchant();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<MerchantRecipe> getRecipes() {
|
|
||||||
return getMerchant().getRecipes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRecipes(List<MerchantRecipe> recipes) {
|
|
||||||
this.getMerchant().setRecipes(recipes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MerchantRecipe getRecipe(int i) {
|
|
||||||
return getMerchant().getRecipe(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRecipe(int i, MerchantRecipe merchantRecipe) {
|
|
||||||
getMerchant().setRecipe(i, merchantRecipe);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRecipeCount() {
|
|
||||||
return getMerchant().getRecipeCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isTrading() {
|
|
||||||
return getTrader() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HumanEntity getTrader() {
|
|
||||||
return getMerchant().getTrader();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,21 +11,13 @@ import org.bukkit.entity.HumanEntity;
|
|||||||
import org.bukkit.inventory.Merchant;
|
import org.bukkit.inventory.Merchant;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
|
|
||||||
public class CraftMerchant implements Merchant {
|
public interface CraftMerchant extends Merchant {
|
||||||
|
|
||||||
protected final IMerchant merchant;
|
IMerchant getMerchant();
|
||||||
|
|
||||||
public CraftMerchant(IMerchant merchant) {
|
|
||||||
this.merchant = merchant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IMerchant getMerchant() {
|
|
||||||
return merchant;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MerchantRecipe> getRecipes() {
|
default List<MerchantRecipe> getRecipes() {
|
||||||
return Collections.unmodifiableList(Lists.transform(merchant.getOffers(), new Function<net.minecraft.world.item.trading.MerchantRecipe, MerchantRecipe>() {
|
return Collections.unmodifiableList(Lists.transform(getMerchant().getOffers(), new Function<net.minecraft.world.item.trading.MerchantRecipe, MerchantRecipe>() {
|
||||||
@Override
|
@Override
|
||||||
public MerchantRecipe apply(net.minecraft.world.item.trading.MerchantRecipe recipe) {
|
public MerchantRecipe apply(net.minecraft.world.item.trading.MerchantRecipe recipe) {
|
||||||
return recipe.asBukkit();
|
return recipe.asBukkit();
|
||||||
@ -34,8 +26,8 @@ public class CraftMerchant implements Merchant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRecipes(List<MerchantRecipe> recipes) {
|
default void setRecipes(List<MerchantRecipe> recipes) {
|
||||||
MerchantRecipeList recipesList = merchant.getOffers();
|
MerchantRecipeList recipesList = getMerchant().getOffers();
|
||||||
recipesList.clear();
|
recipesList.clear();
|
||||||
for (MerchantRecipe recipe : recipes) {
|
for (MerchantRecipe recipe : recipes) {
|
||||||
recipesList.add(CraftMerchantRecipe.fromBukkit(recipe).toMinecraft());
|
recipesList.add(CraftMerchantRecipe.fromBukkit(recipe).toMinecraft());
|
||||||
@ -43,38 +35,28 @@ public class CraftMerchant implements Merchant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MerchantRecipe getRecipe(int i) {
|
default MerchantRecipe getRecipe(int i) {
|
||||||
return merchant.getOffers().get(i).asBukkit();
|
return getMerchant().getOffers().get(i).asBukkit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRecipe(int i, MerchantRecipe merchantRecipe) {
|
default void setRecipe(int i, MerchantRecipe merchantRecipe) {
|
||||||
merchant.getOffers().set(i, CraftMerchantRecipe.fromBukkit(merchantRecipe).toMinecraft());
|
getMerchant().getOffers().set(i, CraftMerchantRecipe.fromBukkit(merchantRecipe).toMinecraft());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRecipeCount() {
|
default int getRecipeCount() {
|
||||||
return merchant.getOffers().size();
|
return getMerchant().getOffers().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTrading() {
|
default boolean isTrading() {
|
||||||
return getTrader() != null;
|
return getTrader() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HumanEntity getTrader() {
|
default HumanEntity getTrader() {
|
||||||
EntityHuman eh = merchant.getTradingPlayer();
|
EntityHuman eh = getMerchant().getTradingPlayer();
|
||||||
return eh == null ? null : eh.getBukkitEntity();
|
return eh == null ? null : eh.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return merchant.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(final Object obj) {
|
|
||||||
return obj instanceof CraftMerchant && ((CraftMerchant) obj).merchant.equals(this.merchant);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,12 @@ import net.minecraft.world.item.trading.MerchantRecipe;
|
|||||||
import net.minecraft.world.item.trading.MerchantRecipeList;
|
import net.minecraft.world.item.trading.MerchantRecipeList;
|
||||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||||
|
|
||||||
public class CraftMerchantCustom extends CraftMerchant {
|
public class CraftMerchantCustom implements CraftMerchant {
|
||||||
|
|
||||||
|
private MinecraftMerchant merchant;
|
||||||
|
|
||||||
public CraftMerchantCustom(String title) {
|
public CraftMerchantCustom(String title) {
|
||||||
super(new MinecraftMerchant(title));
|
this.merchant = new MinecraftMerchant(title);
|
||||||
getMerchant().craftMerchant = this;
|
getMerchant().craftMerchant = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ public class CraftMerchantCustom extends CraftMerchant {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MinecraftMerchant getMerchant() {
|
public MinecraftMerchant getMerchant() {
|
||||||
return (MinecraftMerchant) super.getMerchant();
|
return this.merchant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MinecraftMerchant implements IMerchant {
|
public static class MinecraftMerchant implements IMerchant {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren