Non résolu Problème stick et problème Unclaim Finder
-
Hey j’ai rajouté un Stick donnant des effets mais le problème c’est que je n’arrive pas à lui faire perdre de la durabilité
Voici ma classe :
package com.hypala.hypalacore.common; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; public class PowerStick extends Item { public PowerStick() { this.maxStackSize = 1; // on lui met un stack de 1 this.setMaxDamage(3); // on met 15 de durabilité } @Override public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { return super.getIsRepairable(p_82789_1_, p_82789_2_); } @Override public void onUpdate(ItemStack item, World world, Entity player, int slotIndex, boolean inHand) { if(item.hasTagCompound())//Si ton item n'a pas de tag alors on ne fait rien { if(item.stackTagCompound.getInteger("timer") > 0)//si ton timer est supérieur à 0 (après un clic droit logiquement) { item.stackTagCompound.setInteger("timer", (int) (item.stackTagCompound.getInteger("timer") + 1));//On l'incrémente de 1 à chaque tick } if(item.stackTagCompound.getInteger("timer") >= (int) (30*20))//Remplace 6 par le nombre de secondes du timer souhaité { item.stackTagCompound.setInteger("timer", 0);//On remet à 0 si le timer est arrivé à la limite souhaitée } } super.onUpdate(item, world, player, slotIndex, inHand); } public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { if(!item.hasTagCompound())//Même condition, si ton item n'a pas de tag on lui en ajoute avec l'int timer en + { item.setTagCompound(new NBTTagCompound()); item.stackTagCompound.setInteger("timer", 0); } if(item.stackTagCompound.getInteger("timer") == 0) { player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 400, 2)); player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 300, 2)); player.addPotionEffect(new PotionEffect(Potion.resistance.id, 300, 2)); player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 300, 2)); item.stackTagCompound.setInteger("timer", 1);//On le met à 1 pour pouvoir rentrer dans la condition de onUpdate() } else { if(world.isRemote); } return item; } @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack item) { return item.hasTagCompound() ? (item.stackTagCompound.getInteger("timer") == 0 ? true : false) : true; } public boolean isFull3D() // on met de la 3D a l'item { return true; } }
J’ai également un Unclaim Finder qui n’affiche pas les pourcents :
Classe DisplayHelperBaseTracker :
package com.hypala.hypalacore.common; import net.minecraft.client.Minecraft ; import net.minecraft.client.gui.FontRenderer ; import net.minecraft.client.renderer.OpenGlHelper ; import net.minecraft.client.renderer.Tessellator ; import net.minecraft.client.renderer.entity.RenderManager ; import net.minecraft.entity.EntityLivingBase ; import org.lwjgl.opengl.GL11 ; public class DisplayHelperBaseTracker { static Minecraft mc ; public static void drawTexturedModalRect(int par1, int par2, float z, int par3, int par4, int par5, int par6) { drawTexturedModalRect(par1, par2, z, par3, par4, par5, par6, 0.00390625F, 0.00390625F); } public static void drawTexturedModalRect(int par1, int par2, float z, int par3, int par4, int par5, int par6, float f, float f1) { Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV(par1 + 0, par2 + par6, z, (par3 + 0) * f, (par4 + par6) * f1); tessellator.addVertexWithUV(par1 + par5, par2 + par6, z, (par3 + par5) * f, (par4 + par6) * f1); tessellator.addVertexWithUV(par1 + par5, par2 + 0, z, (par3 + par5) * f, (par4 + 0) * f1); tessellator.addVertexWithUV(par1 + 0, par2 + 0, z, (par3 + 0) * f, (par4 + 0) * f1); tessellator.draw(); } public static void renderEntity(int x, int y, int scale, float rotX, float rotY, EntityLivingBase entity, boolean nametag) { GL11.glEnable(2903); GL11.glPushMatrix(); GL11.glTranslatef(x, y, 50.0F); GL11.glScalef(-scale, scale, scale); GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); float f2 = entity.renderYawOffset; float f3 = entity.rotationYaw; float f4 = entity.rotationPitch; float f5 = entity.prevRotationYawHead; float f6 = entity.rotationYawHead; GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); GL11.glRotatef(-(float) Math.atan(rotY / 40.0F) * 20.0F, 1.0F, 0.0F, 0.0F); entity.renderYawOffset = ((float) Math.atan(rotX / 40.0F) * 20.0F); entity.rotationYaw = ((float) Math.atan(rotX / 40.0F) * 40.0F); entity.rotationPitch = (-(float) Math.atan(rotY / 40.0F) * 20.0F); entity.rotationYawHead = entity.rotationYaw; entity.prevRotationYawHead = entity.rotationYaw; GL11.glTranslatef(0.0F, entity.yOffset, 0.0F); RenderManager.instance.playerViewY = 180.0F; RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); entity.renderYawOffset = f2; entity.rotationYaw = f3; entity.rotationPitch = f4; entity.prevRotationYawHead = f5; entity.rotationYawHead = f6; GL11.glPopMatrix(); GL11.glDisable(32826); OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); GL11.glDisable(3553); OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); } public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel) { Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV(x + 0.0D, y + height, zLevel, 0.0D, 1.0D); tessellator.addVertexWithUV(x + width, y + height, zLevel, 1.0D, 1.0D); tessellator.addVertexWithUV(x + width, y + 0.0D, zLevel, 1.0D, 0.0D); tessellator.addVertexWithUV(x + 0.0D, y + 0.0D, zLevel, 0.0D, 0.0D); tessellator.draw(); } public static void renderFloatingText(String text, float x, float y, float z, int color) { RenderManager renderManager = RenderManager.instance; FontRenderer fontRenderer = mc.fontRenderer; float scale = 0.027F; GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5F); GL11.glPushMatrix(); GL11.glTranslatef(x + 0.0F, y + 2.3F, z); GL11.glNormal3f(0.0F, 1.0F, 0.0F); GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GL11.glRotatef(renderManager.playerViewX, 1.0F, 0.0F, 0.0F); GL11.glScalef(-scale, -scale, scale); GL11.glDisable(2896); GL11.glDepthMask(false); GL11.glDisable(2929); GL11.glEnable(3042); GL11.glBlendFunc(770, 771); Tessellator tessellator = Tessellator.instance; int yOffset = 0; GL11.glDisable(3553); tessellator.startDrawingQuads(); int stringMiddle = fontRenderer.getStringWidth(text) / 2; tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.5F); tessellator.addVertex(-stringMiddle - 1, -1 + yOffset, 0.0D); tessellator.addVertex(-stringMiddle - 1, 8 + yOffset, 0.0D); tessellator.addVertex(stringMiddle + 1, 8 + yOffset, 0.0D); tessellator.addVertex(stringMiddle + 1, -1 + yOffset, 0.0D); tessellator.draw(); GL11.glEnable(3553); GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5F); fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, color); GL11.glEnable(2929); GL11.glDepthMask(true); fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, color); GL11.glEnable(2896); GL11.glDisable(3042); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPopMatrix(); } }
Classe ItemBaseTracker:
package com.hypala.hypalacore.common; import net.minecraft.item.Item; import java.util.List; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; public class ItemBaseTracker extends Item { private String[] type = {"base_tracker"}; private IIcon[] iconArray; public ItemBaseTracker() { setMaxStackSize(1); } public void registerIcons(IIconRegister iconregister) { this.iconArray = new IIcon[this.type.length]; for (int i = 0; i < this.type.length; i++) { this.iconArray[i] = iconregister.registerIcon("HypalaCore:" + this.type[i]); } } @SideOnly(Side.CLIENT) public void getSubItems(Item Item, CreativeTabs creativeTabs, List list) { for (int metadata = 0; metadata < this.type.length; metadata++) { list.add(new ItemStack(Item, 1, metadata)); } } @SideOnly(Side.CLIENT) public IIcon getIconFromDamage(int metadata) { return (metadata < this.type.length) && (metadata >= 0) ? this.iconArray[metadata] : this.iconArray[0]; } }
Et classe OverlayBaseTracker :
package com.hypala.hypalacore.common; import java.util.Iterator; import java.util.Map; import org.lwjgl.opengl.GL11; import com.hypala.hypalacore.common.ItemBaseTracker; import com.hypala.hypalacore.common.HypalaCore; import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderGameOverlayEvent; public class OverlayBaseTracker extends Gui { private Minecraft mc; private String show; final ResourceLocation bg = new ResourceLocation("base_tracker.png"); FontRenderer fontRender; RenderItem itemRenderer = new RenderItem(); public OverlayBaseTracker() { this.mc = Minecraft.getMinecraft(); this.show = "0%"; this.fontRender = this.mc.fontRenderer; } @SubscribeEvent(priority = EventPriority.NORMAL) public void onRender(RenderGameOverlayEvent.Post event) { if (event.type != RenderGameOverlayEvent.ElementType.HOTBAR) { return; } if ((this.mc.thePlayer.getHeldItem() != null) && ((this.mc.thePlayer.getHeldItem().getItem() instanceof ItemBaseTracker)) && (this.mc.theWorld.isRemote)) { this.mc.renderEngine.bindTexture(this.bg); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(2896); GL11.glEnable(3042); GL11.glBlendFunc(770, 771); DisplayHelperBaseTracker.drawTexturedQuadFit(5.0D, 5.0D, 32.0D, 32.0D, 0.0D); int amountTiles = this.mc.theWorld.getChunkFromChunkCoords(this.mc.thePlayer.chunkCoordX + 0, this.mc.thePlayer.chunkCoordZ + 0).chunkTileEntityMap.values().size(); amountTiles = amountTiles + this.mc.theWorld.getChunkFromChunkCoords(this.mc.thePlayer.chunkCoordX + 0, this.mc.thePlayer.chunkCoordZ + 1).chunkTileEntityMap.values().size(); amountTiles = amountTiles + this.mc.theWorld.getChunkFromChunkCoords(this.mc.thePlayer.chunkCoordX + 0, this.mc.thePlayer.chunkCoordZ - 1).chunkTileEntityMap.values().size(); amountTiles = amountTiles + this.mc.theWorld.getChunkFromChunkCoords(this.mc.thePlayer.chunkCoordX + 1, this.mc.thePlayer.chunkCoordZ).chunkTileEntityMap.values().size(); amountTiles = amountTiles + this.mc.theWorld.getChunkFromChunkCoords(this.mc.thePlayer.chunkCoordX - 1, this.mc.thePlayer.chunkCoordZ).chunkTileEntityMap.values().size(); if (this.mc.thePlayer.getHeldItem().getItemDamage() >= 1) { int[] y = { -2, -1, 0, 1, 2, -2, 2, -2, 2, -2, 2, -2, -1, 0, 1, 2 }; int[] x = { -2, -2, -2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2 }; for (int i = 0; i < y.length; i++) { amountTiles = amountTiles + this.mc.theWorld.getChunkFromChunkCoords(this.mc.thePlayer.chunkCoordX + x[i], this.mc.thePlayer.chunkCoordZ + y[i]).chunkTileEntityMap.values().size(); } } if (this.mc.thePlayer.getHeldItem().getItemDamage() >= 2) { int[] y = { -3, -2, -1, 0, 1, 2, 0, 3, -3, 3, -3, 3, -3, 3, -3, 3, -3, -2, -1, 0, 1, 2, 3 }; int[] x = { -3, -3, -3, -3, -3, -3, -5, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3 }; for (int i = 0; i < y.length; i++) { amountTiles = amountTiles + this.mc.theWorld.getChunkFromChunkCoords(this.mc.thePlayer.chunkCoordX + x[i], this.mc.thePlayer.chunkCoordZ + y[i]).chunkTileEntityMap.values().size(); } } if (this.mc.thePlayer.getHeldItem().getItemDamage() >= 0) { int tileAmmount = 0; int items = 0; int chests = 0; int moddedChests = 0; for (int x = -3; x < 3; x++) { for (int z = -3; z < 3; z++) { Map tileMap = this.mc.theWorld.getChunkFromChunkCoords(this.mc.thePlayer.chunkCoordX + x, this.mc.thePlayer.chunkCoordZ + z).chunkTileEntityMap; Iterator entries = tileMap.entrySet().iterator(); while (entries.hasNext()) { Map.Entry e = (Map.Entry) entries.next(); TileEntity te = (TileEntity) e.getValue(); if (te != null) { if (te.getClass().toString().contains("net.minecraft.tileentity.TileEntityChest")) { chests++; } else if ((te.getClass().toString().contains("Chest")) || (te.getClass().toString().contains("chest"))) { moddedChests++; } } } } } ItemStack stackChest = new ItemStack(Blocks.chest); GL11.glPushMatrix(); GL11.glEnable(2929); GL11.glScaled(1.5D, 1.5D, 1.5D); this.itemRenderer.renderItemAndEffectIntoGUI(this.mc.fontRenderer, this.mc.renderEngine, stackChest, 30, 5); GL11.glDisable(2929); GL11.glDisable(2896); GL11.glPopMatrix(); int xChests = 53; if (chests > 100) { chests = 100; } if (moddedChests > 100) { moddedChests = 100; } String showChests = chests + "%"; if (chests > 9) { xChests -= 3; } if (moddedChests > 9) { } this.fontRender.drawStringWithShadow(showChests, xChests, 37, -1); } if (amountTiles > 100) { amountTiles = 100; } this.show = (amountTiles + "%"); int x = 0; if (amountTiles > 9) { x = 12; } else { x = 15; } this.fontRender.drawStringWithShadow(this.show, x, 37, -1); } } }
J’aimerais également mettre un cooldown sur cet item avant qu’il affiche les pourcents Ex: Il fait pendant 2-3 secondes “Scan en cours” puis il affiche les pourcents
Merci pour votre aide et votre temps
-
yo, pour retirer de la durabilité a un stack tu dois utiliser la fonction
ItemStack#damageItem(int, EntityPlayer)
Pour ton unclaim finder, je t’invite a demander de l’aide a fuze, lui sera sans doute le plus apte a te repondre ou faire des recherches par toi mm, vu le nombre de fois que ce genre de demandes a été effectué sur le forum
-
Ca ne marche toujours pas par quoi je remplace int ?
-
ok alors on va mettre les choses au point si tu n’a jamais fait de java dans ta vie alors arrete toi mtn, et commence par les bases
-
J’ai déjà fait les bases mais la fonction elle ne marche pas après peut-être que je la met au mauvais endroit
-
montre moi le code avec la fonction stp x)
-
Le voici
package com.hypala.hypalacore.common; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; public class PowerStick extends Item { public PowerStick() { this.maxStackSize = 1; // on lui met un stack de 1 this.setMaxDamage(3); // on met 15 de durabilité } @Override public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { return super.getIsRepairable(p_82789_1_, p_82789_2_); } @Override public void onUpdate(ItemStack item, World world, Entity player, int slotIndex, boolean inHand) { if(item.hasTagCompound()) { if(item.stackTagCompound.getInteger("timer") > 0) { item.stackTagCompound.setInteger("timer", (int) (item.stackTagCompound.getInteger("timer") + 1)); } if(item.stackTagCompound.getInteger("timer") >= (int) (30*20)) { item.stackTagCompound.setInteger("timer", 0); } } super.onUpdate(item, world, player, slotIndex, inHand); } public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { item.damageItem(world, player); if(!item.hasTagCompound()) { item.setTagCompound(new NBTTagCompound()); item.stackTagCompound.setInteger("timer", 0); } if(item.stackTagCompound.getInteger("timer") == 0) { player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 400, 2)); player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 300, 2)); player.addPotionEffect(new PotionEffect(Potion.resistance.id, 300, 2)); player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 300, 2)); item.stackTagCompound.setInteger("timer", 1); } else { if(world.isRemote); } return item; } @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack item) { return item.hasTagCompound() ? (item.stackTagCompound.getInteger("timer") == 0 ? true : false) : true; } public boolean isFull3D() { return true; } }
A mon avis je ne dois pas placer la fonction au bon endroit
-
item.damageItem(world, player);
nan mais je reve
quand on markItemStack#damageItem(int, EntityPlayer)
on indique la signature de la methodedamageItem
se trouvant dans la classItemStack
, ensuite leint
et leEntityPlayer
sont les parametres requis, donc si tu ne sais pas que qu’est unint
ALORS ARRETE TOUT DE SUITE ET VAS APPRENDRE LES BASES DE LA PROGRAMMATION EN JAVAun
int
est un nombre entier signé d’une taille de 32 bitsCe nombre indique le nombre de points de durabilité a retirer a l’itemstack en question
c’est a dire que si tu faitstack.damageItem(6, player)
alors tu retire 6 points de durabilité a ton itemstack, donc si ton item a 20 points de durabilité par exemple alors il lui en restera plus que 14