1

[HELP] Entity not rendering correctly when thrown

Celo44's Avatar Celo4412/21/14 7:34 pm
1 emeralds 303 1
12/21/2014 8:08 pm
10Andrew's Avatar 10Andrew
Im trying to make a grenade. However when i throw it, it blows stuff up but you cant see it flying through the air

heres my code:
Click to reveal
package com.celo44.main;

import com.celo44.blocks.MBlocks;
import com.celo44.item.MItems;
import com.celo44.lib.RefStrings;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = RefStrings.MODID, name = RefStrings.NAME, version = RefStrings.VERSION)
public class MainRegistry
{
@SidedProxy(clientSide = RefStrings.CLIENTSIDE, serverSide = RefStrings.SERVERSIDE)

public static ServerProxy proxy;

@EventHandler
public static void PreLoad(FMLPreInitializationEvent PreEvent)
{ //Put all items and blocks here
MItems.mainRegistry();
MBlocks.mainRegistry();
CraftingManager.mainRegistry();
proxy.registerRenderInfo();
proxy.registerRenderThings();
proxy.registerSounds();
}


@EventHandler
public static void Load(FMLInitializationEvent event)
{

}


@EventHandler
public static void PostLoad(FMLPostInitializationEvent PostEvent)
{

}
















}


Click to reveal
ClientProxy:
package com.celo44.main;
import net.minecraft.client.renderer.entity.RenderSnowball;

import com.celo.entities.EntityFragGrenade;
import com.celo44.item.MItems;

import cpw.mods.fml.client.registry.RenderingRegistry;
//grenade client = client proxy
public class ClientProxy extends ServerProxy {

public void registerRenderInfo(){

}

@Override
public void registerRenderThings()
{
RenderingRegistry.registerEntityRenderingHandler(EntityFragGrenade.class, new RenderSnowball(MItems.fragGrenade));
}

@Override
public void registerSounds() {}
}


Click to reveal
Item Class:
package com.celo44.item;

import com.celo.entities.EntityFragGrenade;
import com.celo44.lib.RefStrings;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class ItemFragGrenade extends Item {
public ItemFragGrenade() {
this.setUnlocalizedName("fragGrenade"); // Sets the name of this item, Has to be unique!
this.setCreativeTab(CreativeTabs.tabCombat); // This Item will be in the Combat Creative Tab!
this.setTextureName(RefStrings.MODID + ":" + "FragGrenade"); // texture
}

/**
* Called whenever this item is equipped and the right mouse button is
* pressed. Args: itemStack, world, entityPlayer
*/
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,
EntityPlayer par3EntityPlayer) {
// This if statement is here to check that the Server is working
if (!par2World.isRemote) {
/*
* This method in World spawn in an entity, You can use with
* anything that extends the Entity class, in this case it's the
* EntityGrenade class
*/
par2World.spawnEntityInWorld(new EntityFragGrenade(par2World,
par3EntityPlayer));
// Decrease an item from the stack because you used it!
--par1ItemStack.stackSize;
}
return par1ItemStack;
}

/**
* Render Pass sensitive version of hasEffect()
*/
public boolean hasEffect(ItemStack par1ItemStack, int pass) {
// This means it will look "special" in the inventory
return true;
}
}


Click to reveal
Server proxy:
package com.celo44.main;
//server proxy = grenade common
public class ServerProxy {

public void registerRenderInfo(){

}

public void registerRenderThings() {

}

public void registerSounds() {

}
}


Click to reveal
Item Manager Class:
package com.celo44.item;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

import com.celo44.lib.RefStrings;

import cpw.mods.fml.common.registry.GameRegistry;

public class MItems {

public static void mainRegistry(){
initializeItem();
registerItem();
}

public static Item oStick;
public static Item topazGem;
public static Item fragGrenade;

public static void initializeItem(){
//declare items here > refrence them back to class

oStick = new ItemObsidianStick();
topazGem = new ItemTopazGem();
fragGrenade = new ItemFragGrenade();

}

public static void registerItem(){
GameRegistry.registerItem(oStick, oStick.getUnlocalizedName());
GameRegistry.registerItem(topazGem, topazGem.getUnlocalizedName());
GameRegistry.registerItem(fragGrenade, fragGrenade.getUnlocalizedName());
}


}


Click to reveal
Entity Class:
package com.celo.entities;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.world.World;

public class EntityFragGrenade extends EntityThrowable {
/*
* If you're wondering why I have all of these constructors for no reason,
* It's used by Forge to use this class, If you don't have these, your
* minecraft is going to crash!
*/
public EntityFragGrenade(World par1World, double par2, double par4, double par6) {
super(par1World, par2, par4, par6);
}

public EntityFragGrenade(World par1World, EntityLivingBase par2EntityLivingBase) {
super(par1World, par2EntityLivingBase);
}

public EntityFragGrenade(World par1World) {
super(par1World);
}

@Override
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(MovingObjectPosition mop) {
// If this hit's a block, continue
if (mop.typeOfHit == MovingObjectType.BLOCK) {
/*
* You might be wondering what all these case and break are These
* are use to switch the number mop.sideHit
*
* Example: If mop.sideHit == 3 whatever is in case 3 Happens!
*/
switch (mop.sideHit) {
case 0: // BOTTOM
mop.blockY--;
break;
case 1: // TOP
mop.blockY++;
break;
case 2: // EAST
mop.blockZ--;
break;
case 3: // WEST
mop.blockZ++;
break;
case 4: // NORTH
mop.blockX--;
break;
case 5: // SOUTH
mop.blockX++;
break;
}
/*
* This method creates the explosion! It uses the entity (Can be
* null) the three coordinates, the strength and if it should spawn
* smoke particles around after exploding, the last parameter is if
* it should set neighboring blocks on fire
*/
this.worldObj.newExplosion(this, mop.blockX, mop.blockY,
mop.blockZ, 2.0F, true, true);
} // If the Server is online and works, kill this entity
if (!this.worldObj.isRemote) {
this.setDead();
}
}
}
Posted by Celo44's Avatar
Celo44
Level 1 : New Miner
0

Create an account or sign in to comment.

1

1
12/21/2014 8:08 pm
Level 42 : Master Nether Knight
10Andrew
10Andrew's Avatar
I took a look at your code and saw something interesting...

GameRegistry.registerItem(oStick, oStick.getUnlocalizedName());
GameRegistry.registerItem(topazGem, topazGem.getUnlocalizedName());

You can see from in the middle of this that... oh wait... I am not a coder! I have not idea what I am doing!!!

Sorry, cant help good luck though. Maybe you should take a look at the code for a arrow and compare it to what you have done? That is just advice from someone who does not have a clue and has never coded though :/
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome