Jump to content

[1.8] Rendering Projectile? [Solved]


Ms_Raven

Recommended Posts

In a 1.7.10 mod I made a bomb that could be thrown and explodes on impact, and it worked.

However, I'm having trouble updating it to 1.8.

 

When I throw the item after trying to update the code it crashes.

(With this if it matters)

 

I can't find anything about rendering simple thrown projectiles in 1.8 or about updating it to 1.8, and there are still pretty much no YouTube tutorials at all for 1.8 except for simple blocks and items. So I'm kind of at a loss here.

 

Main class:

 

@Mod(modid = Main.MODID, name = Main.NAME, version = Main.VERSION)

public class Main

{

@SidedProxy(clientSide = "apocalypse.publicraft.network.ClientProxy", serverSide = "apocalypse.publicraft.network.CommonProxy")

public static CommonProxy proxy;

 

    public static final String MODID = "publicraft";

    public static final String NAME = "PubliCraft";

    public static final String VERSION = "0.1";

 

    public static final Tabs tabPubliCraft = new Tabs("tabPubliCraft");

   

    public static Generation generation = new Generation();

   

   

   

    @EventHandler

    public void preInit(FMLPreInitializationEvent event)

    {

    PubliConfig.init(event);

    ItemReg.register();

    BlockReg.register();

    }

    @EventHandler

    public void init(FMLInitializationEvent event)

    {

    proxy.registerRenders();

    proxy.renderProjectiles();

 

    EntityRegistry.registerModEntity(EntityBomb.class, "Bomb", PubliConfig.bombID(), this, 64, 10, true);

   

    }

    @EventHandler

    public void postInit(FMLPostInitializationEvent event)

    {

   

    }

}

 

 

 

Bomb item:

 

public class Bomb extends Item

{

 

public Bomb()

{

super();

setMaxStackSize(1);

 

}

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)

{

if (!player.capabilities.isCreativeMode)

{

--stack.stackSize;

}

 

world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

 

if (!world.isRemote)

{

world.spawnEntityInWorld(new EntityBomb(world, player));

}

 

return stack;

}

 

}

 

 

 

 

ClientProxy:

 

public class ClientProxy extends CommonProxy

{

@Override

public void registerRenders()

{

ItemReg.render();

BlockReg.render();

}

 

@SideOnly(Side.CLIENT)

@Override

public void renderProjectiles()

{

    RenderingRegistry.registerEntityRenderingHandler(EntityBomb.class, new RenderSnowball(Minecraft.getMinecraft().getRenderManager(), ItemReg.bomb, null));

 

}

}

 

 

 

Item registry:

 

 

public class ItemReg

{

public static Item bomb;

public static void register()

{

bomb = new Bomb().setUnlocalizedName("bomb").setCreativeTab(Main.tabPubliCraft);

GameRegistry.registerItem(bomb, bomb.getUnlocalizedName().substring(5));

}

public static void render()

{

registerRender(bomb);

}

public static void registerRender(Item item)

{

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Main.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));

}

}

 

 

 

Could someone please shed some light on why this isn't working?

 

Link to comment
Share on other sites

 

package net.minecraft.client.renderer.entity;

 

import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.client.renderer.texture.TextureMap;

import net.minecraft.entity.Entity;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

@SideOnly(Side.CLIENT)

public class RenderSnowball extends Render

{

    protected final Item field_177084_a;

    private final RenderItem field_177083_e;

    private static final String __OBFID = "CL_00001008";

 

    public RenderSnowball(RenderManager p_i46137_1_, Item p_i46137_2_, RenderItem p_i46137_3_)

    {

        super(p_i46137_1_);

        this.field_177084_a = p_i46137_2_;

        this.field_177083_e = p_i46137_3_;

    }

 

    /**

    * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then

    * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic

    * (Render<T extends Entity>) and this method has signature public void func_76986_a(T entity, double d, double d1,

    * double d2, float f, float f1). But JAD is pre 1.5 so doe

    */

    public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float partialTicks)

    {

        GlStateManager.pushMatrix();

        GlStateManager.translate((float)x, (float)y, (float)z);

        GlStateManager.enableRescaleNormal();

        GlStateManager.scale(0.5F, 0.5F, 0.5F);

        GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);

        GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);

        this.bindTexture(TextureMap.locationBlocksTexture);

        this.field_177083_e.renderItemModel(this.func_177082_d(entity));                                    //      <------------------ Line 41

        GlStateManager.disableRescaleNormal();

        GlStateManager.popMatrix();

        super.doRender(entity, x, y, z, p_76986_8_, partialTicks);

    }

 

    public ItemStack func_177082_d(Entity p_177082_1_)

    {

        return new ItemStack(this.field_177084_a, 1, 0);

    }

 

    /**

    * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.

    */

    protected ResourceLocation getEntityTexture(Entity entity)

    {

        return TextureMap.locationBlocksTexture;

    }

}

 

Link to comment
Share on other sites

Firstly remove __OBFID, that's vanilla classes only (From what I've heard)

Secondly I suggest naming your variables to something other than srg names, rather than private final RenderItem field_177083_e; you can call it renderItem or something more understandable. Same with the methods.

 

Lastly either field_177083_e, field_177084_a, or entity is null on line 41. My best guess is that it is entity, add these 3 lines above line 41 to find out which one it is

 

System.out.println("RenderItem " + (field_177083_e == null));
System.out.println("Item " + (field_177084_a == null));
System.out.println("entity " + (entity == null));

Link to comment
Share on other sites

No wonder if you are putting NULL to RenderItem:

Code:

public RenderSnowball(RenderManager p_i46137_1_, Item p_i46137_2_, RenderItem p_i46137_3_)

 

You:

new RenderSnowball(Minecraft.getMinecraft().getRenderManager(), ItemReg.bomb, null)

 

You need to Minecraft.getMinecraft().getRenderItem()

 

 

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried removed Sodium and iris but didn't help
    • same issue, crash on ubuntu 24 and stable on WIndows GraalVM 17 on 1.20.1 fabric Prominence II [RPG] modpack
    • look my mod-pack with 300+ plus mods is crashing and I'm not sure what mod is causing this it was working fine not that long ago... and if no one knows then my question would be is how do you read crash logs Crash Log https://pastebin.com/tak3uuEm 
    • I try to play with better combat, I install its dependency but it tells me that it needs version 1.0.2 and I already have it, what do I do? the dependency is player animator
    • I think my save file was potentially corrupted (based on what I have been reading online). The world has loaded and saved perfectly fine for weeks. Today I added about 6 new mods and updated 3 mod libraries, and then encountered the following error: "Errors in currently selected data packs prevented the world from loading. You can either try to load it with only the vanilla data pack ("safe mode"), or go back to the title screen and fix it manually." I have tried changing to a newer Forge version, reverting the updated mods back to original versions, removing the new mods, removing and readding all mods, removing my world file and loading the forge profile and adding it back, renaming the level.dat_old file as level.dat... Nothing has worked yet. Forge loads fine and I don't want to risk trying to reload the world in "safe mode" in case I end up losing mod-related content. Not sure how that works. I am having trouble reading the output log to determine what is causing the error. Any advice is better than none!! Thank you!     Info: Minecraft 1.20.1 Forge 47.1.3 Mod list (includes which mods are disabled, newly added before this error, and any changes I found after the error) : https://pastebin.com/nquXY1Hj Latest log: https://pastebin.com/U4fD0kAt
  • Topics

×
×
  • Create New...

Important Information

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