Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CactusCoffee

Members
  • Joined

  • Last visited

Everything posted by CactusCoffee

  1. Here's the relevant code for the renderer. [...] public class RenderMagicOrb extends Render { private int element; public RenderMagicOrb(int data) { this.element = data; } public RenderMagicOrb() { this(0); } public void doRender(Entity entity, double x, double y, double z, float f, float f1) { IIcon iicon = getIcon(((EntityMagicOrb)entity).getElement()); GL11.glPushMatrix(); GL11.glTranslatef((float)x, (float)y, (float)z); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glScalef(0.5F, 0.5F, 0.5F); bindEntityTexture(entity); Tessellator tessellator = Tessellator.instance; func_77026_a(tessellator, iicon); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); } private void func_77026_a(Tessellator t, IIcon iicon) { (Same as RenderSnowball) } private IIcon getIcon(int e) //Returns the icon based on the element value { Item t = Items.nether_star; switch(e) { case 1: t = Items.fire_charge; case 2: t = Items.magma_cream; case 3: t = Items.slime_ball; case 4: t = Items.clay_ball; case 5: t = Items.ender_pearl; case 6: t = Items.snowball; } return t.getIconFromDamage(0); } @Override protected ResourceLocation getEntityTexture(Entity p_110775_1_) { return TextureMap.locationItemsTexture; } } All it requires from the entity is the element, which is an integer from 1-6. Here's the relevant bits of the entity class: [...] public class EntityMagicOrb extends EntityThrowable { public int spell; public int element; public EntityMagicOrb(World world) { super(world); } public EntityMagicOrb(World world, int sp, int e) { super(world); spell = sp; element = e; } public EntityMagicOrb(World world, EntityLivingBase entity, int sp, int e) { super(world, entity); spell = sp; element = e; } [...] public int getElement() { return element; } }
  2. In my project I have an entity that behaves like a thrown item, a magic spell entity created using a staff (the entity itself is not an item). I also want to have the entity's texture reflect the spell's type (a red projectile for fire, blue for water, etc.). Currently I have the rendering class set up to use default icons for each type, eventually I'll use my own textures. I have a couple questions regarding how to implement these behaviors. 1) - I would like to avoid creating an item class for the entity, as it is not created by throwing an item. I have looked at the code in RenderSnowball and similar classes and have been unable to find an IIcon that does not require a base item. Is it possible to get an IIcon for an entity without an item to go with it? Is there any way to register the icons in the entity/render classes? 2) - I have a switch statement set up to get an icon based on the rendered entity's type. This takes place in the doRender method, by casting the Entity parameter to my custom entity class and using a getter for the type, then performing a switch on that value. This should return a unique icon for each type, or a default for a null type. Looking at the code for getting potion damage, this should work, but it doesn't, it returns the icon indicating the null type instead. I have considered creating a subclass for entities of each type, but I am confident there is a more practical way to accomplish this goal. While the only differences between the entity textures I have set up are the colors, I would rather not use a coloration of a single texture (like thrown potions use). Is it possible to do this? If so, how?
  3. That makes sense. Will start researching how to do stuff with packets. Thanks.
  4. Just tried adding a world parameter and an if (!world.isRemote) to the charge method. That prevents the display from changing, so you seem to be right. I suspect that the reason is that the method is only activated on the client side, as it's called by a keyboard press. I've just started experimenting with keyboard bindings, so I probably did something wrong in my key handler. This is the relevant method in the keyboard handler: @SubscribeEvent public void onKeyInput(KeyInputEvent event) { if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) { if (keys[CUSTOM_INV].isPressed()) { Minecraft mcInstance = Minecraft.getMinecraft(); EntityPlayer player = (EntityPlayer)mcInstance.thePlayer; ItemStack inHand = player.inventory.getCurrentItem(); if (inHand != null) { Item itemInUse = inHand.getItem(); if (itemInUse instanceof ItemStaff) { ((ItemStaff)itemInUse).charge(inHand, mcInstance.theWorld, player); } } } } } Not sure what I need to do in order to fix this.
  5. I'm a novice modder, so what I'm missing/doing wrong is probably rather obvious. I've done some looking around for tutorials / other support requests for relevant tips but couldn't find that either. Anyway, part of the mod I'm making is an item which uses damage values as a charge: pretty basic, starts at 0 damage, using the item adds damage, item doesn't break at max damage, etc. That all works fine. But I also want to have another item used as fuel to recharge this item. I've got it so it consumes fuel on a button press when holding the item, depletes fuel, that also works as expected. However, when using the item after recharging, it acts as if it was not recharged. Example: I use the item until it reaches a damage of, say, 34. On charging the item, it removes up to 10 damage points. So the item is now at 24 damage. When I use the item again, instead of going to 25 damage as expected, it goes to 35, as if the recharge didn't actually do anything. It's not that it doesn't recharge; the damage meter appears properly, refilling as the item is recharged and disappearing at full charge. The item also uses addInformation() to display the charge as a tooltip, and that refills properly as well. So I'm proper confused. I've tried using both the setDamage(itemstack, value) and itemstack.damageItem(value) methods, both have the same result. I've also tried replacing the item with a new item with a lower damage value, but that prevented it from charging at all. I've seen mods like EE do this properly, what am I doing wrong? Relevant code bits: package [...] import [...] public class ItemStaff extends Item { protected ItemStaff(int l) { [...] } [...] //Method for recharging public void charge(ItemStack itemStack, EntityPlayer player) { if (itemStack.stackTagCompound != null && getDamage(itemStack) > 0) { boolean flag = player.capabilities.isCreativeMode; if (!flag && player.inventory.hasItem(SimplyMagicMod.manaCrystal)) { player.inventory.consumeInventoryItem(SimplyMagicMod.manaCrystal); itemStack.damageItem(-20, player); } } } [...] //Item use if not targeting block @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (itemStack.stackTagCompound != null && canDoSpell(itemStack)) { [...] itemStack.damageItem(itemStack.stackTagCompound.getInteger("Cost"), player); } [...] } //Item use if targeting block @Override public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) { if (itemStack.stackTagCompound != null && canDoSpell(itemStack)) { itemStack.damageItem(itemStack.stackTagCompound.getInteger("Cost"), player); [...] } else return false; } //Add tooltip @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack itemStack, EntityPlayer player, List dataList, boolean b) { [...] dataList.add("Charge: " + (getMaxDamage() - getDamage(itemStack)) + "/" + (getMaxDamage())); [...] } [...] //Can execute special function (current charge - action cost >= 0 charge) public boolean canDoSpell(ItemStack itemStack) { return getDamage(itemStack) + itemStack.stackTagCompound.getInteger("Cost") <= getMaxDamage(); } }

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.