Bonsoir !
J’ai résolu mon problème. 🙂 Et je ne sais pas trop comment …
Après avoir fait plusieurs tests, il s’avère que je n’utilise plus d’Iterable<itemstack> mais j’appelle directement les méthodes EntityLiving#getItemStackFromSlot et EntityLiving#setItemStackFromSlot pour mettre à jour correctement l’InventoryBasic et mon Entity (pour faire la passerelle correctement entre les deux quoi).
Voici le code qui fonctionne, si jamais quelqu’un passe après moi.
EntityNPCDialog:
public class EntityNPCDialog extends EntityLiving {
// private static final DataParameter <integer>TEXTURE_INDEX = EntityDataManager.<integer>createKey(EntityNPCDialog.class, DataSerializers.VARINT);
public EntityNPCDialog(World worldIn) {
super(worldIn);
}
@Override
protected void initEntityAI() {
super.initEntityAI();
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 16.0F, 42.0F));
this.tasks.addTask(2, new EntityAILookIdle(this));
}
@Override
public boolean canBePushed() {
return (false);
}
@Override
public boolean isPushedByWater() {
return (false);
}
@Override
protected boolean canDespawn() {
return(false);
}
@Override
public void addVelocity(double x, double y, double z) {}
@Override
public boolean canRiderInteract() {
return (false);
}
@Override
public boolean isEntityInvulnerable(DamageSource source) {
return (false);
}
@Override
public boolean isPotionApplicable(PotionEffect potioneffectIn) {
return (false);
}
@Override
public boolean isImmuneToExplosions() {
return (false);
}
@Nullable
@Override
protected SoundEvent getAmbientSound() {
return (CraftAndConquerSounds.NPCDialogSoundEvent);
}
@Nullable
@Override
protected SoundEvent getHurtSound() {
return (CraftAndConquerSounds.NPCDialogSoundEvent);
}
@Nullable
@Override
protected SoundEvent getDeathSound() {
return (CraftAndConquerSounds.NPCDialogSoundEvent);
}
@Override
protected SoundEvent getFallSound(int heightIn) {
return (CraftAndConquerSounds.NPCDialogSoundEvent);
}
@Override
protected SoundEvent getSwimSound() {
return (CraftAndConquerSounds.NPCDialogSoundEvent);
}
@Override
protected SoundEvent getSplashSound() {
return (CraftAndConquerSounds.NPCDialogSoundEvent);
}
// public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn) {
// TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
// ThreadDownloadImageData threadDownloadImageData;
//
// threadDownloadImageData = new ThreadDownloadImageData(null, "http://imgur.com/Z0pbA3P.png", DefaultNPCSkin.getDefaultSkin(), new ImageBufferDownload() {
//
// @Override
// public BufferedImage parseUserSkin(BufferedImage image) {
// return (image);
// }
//
// });
//
// textureManager.loadTexture(resourceLocationIn, threadDownloadImageData);
//
// return (threadDownloadImageData);
// }
}
ContainerNPCInventory:
public class ContainerNPCInventory extends Container {
public static final EntityEquipmentSlot[] VALID_EQUIPMENT_SLOTS = new EntityEquipmentSlot[] {
EntityEquipmentSlot.HEAD,
EntityEquipmentSlot.CHEST,
EntityEquipmentSlot.LEGS,
EntityEquipmentSlot.FEET,
EntityEquipmentSlot.MAINHAND,
EntityEquipmentSlot.OFFHAND
};
private EntityNPCDialog entityNPC;
private final InventoryPlayer playerInventory;
private InventoryBasic entityInventory;
public ContainerNPCInventory(EntityPlayer playerIn, EntityNPCDialog entityNPC) {
this.entityNPC = entityNPC;
this.playerInventory = playerIn.inventory;
this.entityInventory = new InventoryBasic("NPC Inventory", true, ContainerNPCInventory.VALID_EQUIPMENT_SLOTS.length);
for (int index = 0; index < ContainerNPCInventory.VALID_EQUIPMENT_SLOTS.length; ++index) {
this.entityInventory.setInventorySlotContents(index, entityNPC.getItemStackFromSlot(ContainerNPCInventory.VALID_EQUIPMENT_SLOTS[index]));
}
for (int index = 0; index < 4; ++index) {
final EntityEquipmentSlot equipmentSlot = ContainerNPCInventory.VALID_EQUIPMENT_SLOTS[index];
this.addSlotToContainer(new Slot(this.entityInventory, index, 8, 8 + index * 18) {
@Override
public void onSlotChanged() {
entityNPC.setItemStackToSlot(equipmentSlot, this.getStack());
super.onSlotChanged();
}
@Override
public boolean isItemValid(@Nullable ItemStack stack) {
return (stack != null && stack.getItem().isValidArmor(stack, equipmentSlot, entityNPC));
}
@Override
public int getSlotStackLimit() {
return (1);
}
@Nullable
@Override
public String getSlotTexture() {
return (ItemArmor.EMPTY_SLOT_NAMES[equipmentSlot.getIndex()]);
}
});
}
this.addSlotToContainer(new Slot(this.entityInventory, 4, 77, 8) {
@Override
public void onSlotChanged() {
entityNPC.setItemStackToSlot(ContainerNPCInventory.VALID_EQUIPMENT_SLOTS[4], this.getStack());
super.onSlotChanged();
}
});
this.addSlotToContainer(new Slot(this.entityInventory, 5, 95, 8) {
@Override
public void onSlotChanged() {
entityNPC.setItemStackToSlot(ContainerNPCInventory.VALID_EQUIPMENT_SLOTS[5], this.getStack());
super.onSlotChanged();
}
@SideOnly(Side.CLIENT)
@Nullable
@Override
public String getSlotTexture() {
return ("minecraft:items/empty_armor_slot_shield");
}
});
for (int index = 0; index < 9; ++index) {
this.addSlotToContainer(new Slot(this.playerInventory, index, 9 + index * 18, 112));
}
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return (true);
}
}
Cela fonctionne également en multiplayer. :D</integer></integer></itemstack>