Résolu Problème avec un item Géant !
-
Bonjour ,
J’ai essayé de creer un item géant comme dans le mod Twilight Forest mais je n’ai pas réussi , il n’y a pas de rendu de l’épée géante en mainVoici le rendu en main avec le mod Twilight Forest :
Et le rendu dans l’inventaire avec le mod TwilightForest :
Voici les classes de twilight Forest :
La giant sword : ici
L’icon Geant : ici
Et Twilight Forest en général : iciPrécision importante : dans le mod Twilight Forest la texture de l’épée est celle de minecraft , cela veut dire que si je met un texture pack , la texture de l’épée de mon pack va être utilisée.
Moi j’ai un problème : j’ai pas le rendu en main et pas le rendu dans l’inventaire
Voici mes deux classes (moi je veux faire un rendu de l’épée en bois au lieu de l’épée en stone):
GiantWoodSword class :public class GiantWoodSword extends ItemSword { private GiantItemsIcon giantIcon; public GiantWoodSword(Item.ToolMaterial par2EnumToolMaterial) { super(par2EnumToolMaterial); this.setCreativeTab(TabMod.iutilstab); } /** * Return whether this item is repairable in an anvil. */ @Override public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { // repair with wooden sword return par2ItemStack.getItem() == Items.wooden_sword ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); } /** * Properly register icon source */ @Override @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister par1IconRegister) { this.itemIcon = Items.wooden_sword.getIconFromDamage(0); this.giantIcon = new GiantItemsIcon(this.itemIcon, 0.0625F * 3F, 0.0625F * 5F); } /** * Return the correct icon for rendering based on the supplied ItemStack and render pass. * * Defers to {@link #getIconFromDamageForRenderPass(int, int)} * @param stack to render for * @param pass the multi-render pass * @return the icon */ public IIcon getIcon(ItemStack stack, int pass) { // render pass 1 gives the giant Icon if (pass == -1) { return this.giantIcon; } else { return super.getIcon(stack, pass); } } }
GiantItemsIcon class
public class GiantItemsIcon implements IIcon { private IIcon baseIcon; private float myX; private float myY; public GiantItemsIcon(IIcon blockIcon, float x, float y) { this.baseIcon = blockIcon; this.myX = x; this.myY = y; } @Override public int getIconWidth() { return this.baseIcon.getIconWidth() / 2; } @Override public int getIconHeight() { return this.baseIcon.getIconHeight() / 2; } @Override public float getMinU() { float f = this.baseIcon.getMaxU() - this.baseIcon.getMinU(); return this.baseIcon.getMinU() + (f * myX); } @Override public float getMaxU() { float f = this.baseIcon.getMaxU() - this.baseIcon.getMinU(); return this.baseIcon.getMinU() + (f * (myX + 0.5F)); } @Override public float getInterpolatedU(double par1) { float f = this.getMaxU() - this.getMinU(); return this.getMinU() + f * (float)par1 / 16.0F; } @Override public float getMinV() { float f = this.baseIcon.getMaxV() - this.baseIcon.getMinV(); return this.baseIcon.getMinV() + (f * myY); } @Override public float getMaxV() { float f = this.baseIcon.getMaxV() - this.baseIcon.getMinV(); return this.baseIcon.getMinV() + (f * (myY + 0.5F)); } @Override public float getInterpolatedV(double par1) { float f = this.getMaxV() - this.getMinV(); return this.getMinV() + f * ((float)par1 / 16.0F); } @Override public String getIconName() { return this.baseIcon.getIconName(); } }
Aidez Moi please !
Précision : je n’ai aucune erreur sur eclipse (=rien n’est souligné en rouge) ça me fait ceci :
-
Salut,
Il te manque l’IItemRenderer : https://github.com/Benimatic/twilightforest/blob/master/src/main/java/twilightforest/client/renderer/TFGiantItemRenderer.java -
Oui mais maintenant , j’ai un autre problème au niveau du register :
-
Minecraft mc = Minecraft.getMinecraft();
-
Merci !
EDIT :
ça fonctionne toujours pas , mon épée n’est pas géante et je sais pas ou j’aurai pu faire une erreur …Mes Classes :
Classe de l’épée :public class GiantWoodSword extends ItemSword { private GiantItemsIcon giantIcon; public GiantWoodSword(Item.ToolMaterial par2EnumToolMaterial) { super(par2EnumToolMaterial); this.setCreativeTab(TabMod.iutilstab); } /** * Return whether this item is repairable in an anvil. */ @Override public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { // repair with wooden sword return par2ItemStack.getItem() == Items.wooden_sword ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); } /** * Properly register icon source */ @Override @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister par1IconRegister) { this.itemIcon = Items.wooden_sword.getIconFromDamage(0); this.giantIcon = new GiantItemsIcon(this.itemIcon, 0.0625F * 3F, 0.0625F * 5F); } /** * Return the correct icon for rendering based on the supplied ItemStack and render pass. * * Defers to {@link #getIconFromDamageForRenderPass(int, int)} * @param stack to render for * @param pass the multi-render pass * @return the icon */ public IIcon getIcon(ItemStack stack, int pass) { // render pass 1 gives the giant Icon if (pass == -1) { return this.giantIcon; } else { return super.getIcon(stack, pass); } } }
Le renderer :
public class GiantItemsRenderer implements IItemRenderer { private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); private TextureManager texturemanager; public GiantItemsRenderer(GameSettings gameSettings, TextureManager textureManager) { this.texturemanager = textureManager; } /** * Checks if this renderer should handle a specific item's render type * @param item The item we are trying to render * @param type A render type to check if this renderer handles * @return true if this renderer should handle the given render type, * otherwise false */ @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { return type == ItemRenderType.ENTITY || type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON || type == ItemRenderType.INVENTORY; } /** * Checks if certain helper functionality should be executed for this renderer. * See ItemRendererHelper for more info * * @param type The render type * @param item The ItemStack being rendered * @param helper The type of helper functionality to be ran * @return True to run the helper functionality, false to not. */ @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return type == ItemRenderType.ENTITY && (helper == ItemRendererHelper.ENTITY_ROTATION || helper == ItemRendererHelper.ENTITY_BOBBING); } /** * Called to do the actual rendering, see ItemRenderType for details on when specific * types are run, and what extra data is passed into the data parameter. * * @param type The render type * @param item The ItemStack being rendered * @param data Extra Type specific data */ @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { if (type == ItemRenderType.EQUIPPED_FIRST_PERSON) { // extra scaling float scale = 4.0F; GL11.glScalef(scale, scale, scale); // move for first person GL11.glTranslatef(-0.25F, -0.2F, 0.25F); // render item IIcon iicon = ((EntityLivingBase)data[1]).getItemIcon(item, 0); renderGiantItemEquipped(iicon, item); } else if (type == ItemRenderType.EQUIPPED) { // extra scaling float scale = 4.0F; GL11.glScalef(scale, scale, scale); // move item for equipped GL11.glTranslatef(-0.625F, -0.1F, 0.03F); // render item IIcon iicon = ((EntityLivingBase)data[1]).getItemIcon(item, 0); renderGiantItemEquipped(iicon, item); } else if (type == ItemRenderType.ENTITY) { // extra scaling float scale = 4.0F; GL11.glScalef(scale, scale, scale); // move item for dropped GL11.glTranslatef(0.0F, 0.15F, 0.0F); EntityItem entityItem = (EntityItem)data[1]; this.renderDroppedItem(entityItem, item); } else if (type == ItemRenderType.INVENTORY) { this.renderInventoryItem(item, (RenderBlocks)data[0]); } } private void renderInventoryItem(ItemStack itemStack, RenderBlocks renderBlocks) { // how do we get the itemrender? //RenderManager.instance.itemRenderer. IIcon iicon = itemStack.getItem().getIcon(itemStack, -1); GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, ad renderEffect can derp them up. GL11.glEnable(GL11.GL_ALPHA_TEST); RenderItem.getInstance().renderIcon(0, 0, iicon, 16, 16); GL11.glDisable(GL11.GL_ALPHA_TEST); GL11.glEnable(GL11.GL_LIGHTING); if (itemStack.hasEffect(0)) { RenderItem.getInstance().renderEffect(this.texturemanager, 0, 0); } GL11.glEnable(GL11.GL_LIGHTING); //RenderItem.getInstance().renderItemIntoGUI(null, this.texturemanager, item, 0, 0, true); //renderItemIntoGUI } private void renderGiantItemEquipped(IIcon iicon, ItemStack par2ItemStack) { int par3 = 0; if (iicon == null) { GL11.glPopMatrix(); return; } texturemanager.bindTexture(texturemanager.getResourceLocation(par2ItemStack.getItemSpriteNumber())); TextureUtil.func_152777_a(false, false, 1.0F); Tessellator tessellator = Tessellator.instance; float f = iicon.getMinU(); float f1 = iicon.getMaxU(); float f2 = iicon.getMinV(); float f3 = iicon.getMaxV(); ItemRenderer.renderItemIn2D(tessellator, f1, f2, f, f3, iicon.getIconWidth(), iicon.getIconHeight(), 0.0625F); if (par2ItemStack.hasEffect(par3)) { GL11.glDepthFunc(GL11.GL_EQUAL); GL11.glDisable(GL11.GL_LIGHTING); texturemanager.bindTexture(RES_ITEM_GLINT); GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(768, 1, 1, 0); float f7 = 0.76F; GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F); GL11.glMatrixMode(GL11.GL_TEXTURE); GL11.glPushMatrix(); float f8 = 0.125F; GL11.glScalef(f8, f8, f8); float f9 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; GL11.glTranslatef(f9, 0.0F, 0.0F); GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F); GL11.glPopMatrix(); GL11.glPushMatrix(); GL11.glScalef(f8, f8, f8); f9 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; GL11.glTranslatef(-f9, 0.0F, 0.0F); GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDepthFunc(GL11.GL_LEQUAL); } texturemanager.bindTexture(texturemanager.getResourceLocation(par2ItemStack.getItemSpriteNumber())); TextureUtil.func_147945_b(); } private void renderDroppedItem(EntityItem entityItem, ItemStack item) { Tessellator tessellator = Tessellator.instance; float f9 = 0.5F; float f10 = 0.25F; GL11.glPushMatrix(); float f12 = 0.0625F; float f11 = 0.021875F; GL11.glTranslatef(-f9, -f10, -(f12 + f11)); GL11.glTranslatef(0f, 0f, f12 + f11); this.texturemanager.bindTexture(TextureMap.locationItemsTexture); IIcon par2Icon = item.getIconIndex(); //GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); ItemRenderer.renderItemIn2D(tessellator, par2Icon.getMaxU(), par2Icon.getMinV(), par2Icon.getMinU(), par2Icon.getMaxV(), par2Icon.getIconWidth(), par2Icon.getIconHeight(), f12); GL11.glPopMatrix(); } }
Et le proxy :
public class ClientProxy extends CommonProxy { @Override public void registerRenders() { Minecraft mc = Minecraft.getMinecraft(); GiantItemsRenderer giantRenderer = new GiantItemsRenderer(mc.gameSettings, mc.getTextureManager()); MinecraftForgeClient.registerItemRenderer(ItemMod.giant_wood_sword, giantRenderer); } }
Help !
-
La fonction registerRenders de ton proxy est bien appelé ?
-
comment ça ?
EDIT : Merci de m’avoir posé la question , après vérification j’avais mis “proxy.registerRenders()” dans le preInit au lieu du Init
Merci infiniement [size=small∞]