Bonjour , j’ai un soucis depuis un bon moment , j’ai fais une barre d’XP custom avec des
métiers que j’ai ajouté dans mon mod ,mais le soucis c’est que cette barre ne reçoit pas l’XP tandis que dans ma class d’Item de test reçoit bien l’XP ! J’ai l’impression que le soucis vient du fait que la fonction OnItemRightClick dans ma class ItemSword à un paramètre EntityPlayer et que ma fonction drawScreen n’en as pas , j’ai essayé de le mettre dans
drawScreen mais le jeu n’affiche plus le GUI ! Malgré des recherches je n’ai rien trouvé d’utile ! Merci de prendre la penne de m’aidé
Cordialement Gael62 !
Class GuiJobs
public class Guijobs extends GuiScreen {
final ResourceLocation bg = new ResourceLocation("megamod", "textures/gui/XPJob.png");
final ResourceLocation bg2 = new ResourceLocation("megamod", "textures/gui/Cadre.png");
private static final ResourceLocation texture = new ResourceLocation("textures/gui/demo_background.png");
public Guijobs()
{
}
public boolean doesGuiPauseGame()
{
return false;
}
@Override
public void initGui()
{
super.initGui();
}
@Override
protected void keyTyped(char typedChar, int keyCode)
{
super.keyTyped(typedChar, keyCode);
}
@Override
protected void actionPerformed(GuiButton button)
{
if (button.id == 0) {
}
if (button.id == 1) {
}
}
@Override
public void updateScreen()
{
super.updateScreen();
}
public void drawScreen(int mouseX, int mouseY, float partialTick)
{
jobHandler props = jobHandler.get(mc.thePlayer);
mc.getTextureManager().bindTexture(texture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.width / 2 - 115, this.height / 2 - 105, 0, 0, 256, 250);
mc.renderEngine.bindTexture(this.bg2);
DisplayHelper.drawTexturedQuadFit(this.width/ 2.0D - 112.0D, this.height/ 2.0D - 50.5D, 50.0D, 9.0D, 0.0D);
super.drawScreen(mouseX, mouseY, partialTick);
mc.renderEngine.bindTexture(this.bg);
DisplayHelper.drawTexturedQuadFit(this.width/ 2.0D - 110.0D, this.height/ 2.0D - 50.0D, props.getMoney(), 8.0D, 0.0D);
}
}
Class JobHandler
public class jobHandler implements IExtendedEntityProperties{
public final static String EXT_PROP_NAME = "ExtPropTuto";
private final EntityPlayer player;
public long money;
public long maxMoney;
protected DataWatcher dataWatcher;
public jobHandler(EntityPlayer player) {
this.player = player;
this.money = 0;
this.maxMoney = 200;
}
public static final void register(EntityPlayer player) {
player.registerExtendedProperties(jobHandler.EXT_PROP_NAME,
new jobHandler(player));
}
public static final jobHandler get(EntityPlayer player) {
return (jobHandler) player.getExtendedProperties(EXT_PROP_NAME);
}
@Override
public void saveNBTData(NBTTagCompound compound) {
NBTTagCompound properties = new NBTTagCompound();
properties.setLong("Money", this.money);
properties.setLong("MaxMoney", this.maxMoney);
compound.setTag(EXT_PROP_NAME, properties);
}
@Override
public void loadNBTData(NBTTagCompound compound) {
NBTTagCompound properties = (NBTTagCompound) compound
.getTag(EXT_PROP_NAME);
this.money = properties.getLong("Money");
this.maxMoney = properties.getLong("MaxMoney");
}
@Override
public void init(Entity entity, World world) {
}
public final void sync()
{
if (!player.worldObj.isRemote)
{
EntityPlayerMP player1 = (EntityPlayerMP) player;
MegaMod.d.sendTo((IMessage)new PacketMoney(), player1);
}
else
{
PacketMoney packetcaracteristique = new PacketMoney(this.maxMoney , this.money);
MegaMod.d.sendToServer((IMessage)new PacketMoney());
}
}
private static String getSaveKey(EntityPlayer player) {
return player.getDisplayName() + ":" + EXT_PROP_NAME;
}
public static void saveProxyData(EntityPlayer player) {
jobHandler playerData = jobHandler.get(player);
NBTTagCompound savedData = new NBTTagCompound();
playerData.saveNBTData(savedData);
CommonProxy.storeEntityData(getSaveKey(player), savedData);
}
public static void loadProxyData(EntityPlayer player) {
jobHandler playerData = jobHandler.get(player);
NBTTagCompound savedData = CommonProxy
.getEntityData(getSaveKey(player));
if (savedData != null) {
playerData.loadNBTData(savedData);
}
playerData.sync();
}
public boolean pay(long amount) {
boolean sufficient = amount <= this.money;
if (sufficient) {
this.money -= amount;
this.sync();
} else {
return false;
}
return sufficient;
}
public void addMoney(long amount) {
this.money += amount;
this.sync();
}
public long getMoney() {
return this.money;
}
public void setMoney(long newMoney) {
this.money = newMoney;
this.sync();
}
public void update(long money, long maxMoney){
}
public long getMaxMoney(long money2) {
return this.maxMoney;
}
}
Class ItemSword ( pour tester l’XP)
public class ItemSwords extends ItemSword {
public ItemSwords(ToolMaterial p_i45356_1_) {
super(p_i45356_1_);
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
{
if (!world.isRemote)
{
jobHandler metier = jobHandler.get(player);
ChatComponentTranslation comp = new ChatComponentTranslation("tu as " + metier.money +" XP");
player.addChatComponentMessage(comp);
}
return itemstack;
}
}