Jump to content

[1.7.2] [Unsolved] Custom Entities Not Rendering For Other Players Multiplayer


Recommended Posts

Posted

I just tried running 2 instances of minecraft and a server to test multiplayer and found out that my projectiles don't render for the player who isnt firing them.

(Ex. - I Fired A Shot From The Railgun at Another guy, and it renders for me, but not for him)

 

I suspect that this is being caused by the entity to exist server side, but not client side, for the player who didnt spawn the entity, because the entity still does damage

 

Item Class:

 

 

package lazerman47.weaponsplus.Item.Gun;

import java.util.List;

import lazerman47.weaponsplus.Core.WeaponsPlus;
import lazerman47.weaponsplus.Entity.EntityRailgunRound;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemRailgun extends Item
{
public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};

@SideOnly(Side.CLIENT)
public void registerIcons (IIconRegister par1IconRegister)
{
	this.itemIcon = par1IconRegister.registerIcon( "weaponsplus:" + this.getUnlocalizedName().substring(5));
}
public ItemRailgun()
{
	super();
	this.setFull3D();
	this.maxStackSize = 1;
	this.setMaxStackSize(1);
	this.setMaxDamage(384);
	this.setCreativeTab(WeaponsPlus.theTab);
}

/**
 * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
 */
public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
{
	if (par1ItemStack.stackTagCompound == null) 
	{
		par1ItemStack.setTagCompound(new NBTTagCompound());
	}
	int j = this.getMaxItemUseDuration(par1ItemStack) - par4;

	ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j);
	MinecraftForge.EVENT_BUS.post(event);
	if (event.isCanceled())
	{
		return;
	}
	j = event.charge;

	boolean flag = par3EntityPlayer.capabilities.isCreativeMode;

	float f = (float)j / 20.0F;
	f = (f * f + f * 2.0F) / 3.0F;

	if ((double)f < 0.1D)
	{
		return;
	}
	if (f > 1.5F)
	{
		f = 1.5F;
	}
}
@Override
public ItemStack onEaten /*Not Really "Eaten"*/(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
	if (par1ItemStack.stackTagCompound == null) 
	{
		par1ItemStack.setTagCompound(new NBTTagCompound());
	}
	//Creates And Fires The Entity
	EntityRailgunRound entityRailgunRound = new EntityRailgunRound(par2World, par3EntityPlayer);
	par2World.spawnEntityInWorld(entityRailgunRound);

	//Plays The Sound
	par2World.playSoundAtEntity(par3EntityPlayer, "weaponsplus:railgunFire", 4, 1);

	//Recoil Simulation
	par3EntityPlayer.cameraYaw += 0.8F;

	//Reloads
	if(par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo) && !par3EntityPlayer.capabilities.isCreativeMode)
	{
		par3EntityPlayer.inventory.consumeInventoryItem(WeaponsPlus.railAmmo);
	}

	//Reset Cooldown
	par1ItemStack.stackTagCompound.setInteger("coolDown", 80);

	return par1ItemStack;
}

/**
 * How long it takes to use or consume an item
 */
@Override
public int getMaxItemUseDuration(ItemStack par1ItemStack)
{
	return 20;
}

/**
 * returns the action that specifies what animation to play when the items is being used
 */
public EnumAction getItemUseAction(ItemStack par1ItemStack)
{
	return EnumAction.bow;
}

/**
 * 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)
{
	if (par1ItemStack.stackTagCompound == null) 
	{
		par1ItemStack.setTagCompound(new NBTTagCompound());
	}
	if(par1ItemStack.stackTagCompound.getInteger("coolDown") ==  0 && par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo) || par1ItemStack.stackTagCompound.getInteger("coolDown") ==  0 && par3EntityPlayer.capabilities.isCreativeMode)
	{
		par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
		par2World.playSoundAtEntity(par3EntityPlayer, "weaponsplus:railgunCharge", 4, 1);
	}
	return par1ItemStack;
}

/**
 * Return the enchantability factor of the item, most of the time is based on material.
 */
public int getItemEnchantability()
{
	return 1;
}
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
	par3List.add("A Weapon That Uses Magnetic Energy To Shoot A Projectile");
	if (par1ItemStack.stackTagCompound == null) 
	{
		par1ItemStack.setTagCompound(new NBTTagCompound());
	}
	if(par1ItemStack.stackTagCompound.hasKey("coolDown"))
	if(par1ItemStack.stackTagCompound.getInteger("coolDown") ==  0)
	{
		par3List.add("Status: " + "\u00A72Armed");
	}
	else
	{
		par3List.add("Status: \u00A74Reloading");
	}
}

@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) 
{
	if (par1ItemStack.stackTagCompound == null) 
	{
		par1ItemStack.setTagCompound(new NBTTagCompound());
	}
	if(!par1ItemStack.stackTagCompound.hasKey("coolDown"))
		par1ItemStack.stackTagCompound.setInteger("coolDown", 0);
	if(par1ItemStack.stackTagCompound.getInteger("coolDown") != 0)
	{
		par1ItemStack.stackTagCompound.setInteger("coolDown", par1ItemStack.stackTagCompound.getInteger("coolDown") - 1);
	}
}
	@Override
	public EnumRarity getRarity(ItemStack par1ItemStack) 
	{
		return EnumRarity.uncommon;
	}
}

 

 

 

Entity Class:

 

 

package lazerman47.weaponsplus.Entity;

import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class EntityRailgunRound extends EntityThrowable
{
public EntityRailgunRound(World par1World)
{
	super(par1World);
	setThrowableHeading(this.motionX, this.motionY, this.motionZ, 2.2F, 1.3F);
}

public EntityRailgunRound(World par1World, EntityLivingBase par2EntityLivingBase)
{
	super(par1World, par2EntityLivingBase);
	setThrowableHeading(this.motionX, this.motionY, this.motionZ, 2.2F, 1.3F);
}

public EntityRailgunRound(World par1World, double par2, double par4, double par6)
{
	super(par1World, par2, par4, par6);
	setThrowableHeading(this.motionX, this.motionY, this.motionZ, 2.2F, 1.3F);
}

/**
 * Called when this EntityThrowable hits a block or entity.
 */
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
{
	if(!worldObj.isRemote)
		worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 0.1F, true);
	for (int i = 0; i < 8; ++i)
	{
		this.worldObj.spawnParticle("flame", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
	}
	int i = MathHelper.floor_double(this.posX);
	int j = MathHelper.floor_double(this.posZ);
	if (this.worldObj.getBiomeGenForCoords(i, j).getFloatTemperature(j, j, j) > 1.0F)
	{

	}
	this.attackEntityFrom(DamageSource.generic, 20.0F);
	if(par1MovingObjectPosition.entityHit != null)
		par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 28.0F); //EntityTNTAPrimed
	this.setDead();
}
public void onUpdate()
{
	super.onUpdate();
	this.worldObj.spawnParticle("smoke", this.posX + 0.2, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
	this.worldObj.spawnParticle("smoke", this.posX - 0.2, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
	this.worldObj.spawnParticle("smoke", this.posX + 0.1, this.posY, this.posZ + 0.1, 0.0D, 0.0D, 0.0D);
	this.worldObj.spawnParticle("smoke", this.posX - 0.1, this.posY, this.posZ - 0.1, 0.0D, 0.0D, 0.0D);
}
protected float getGravityVelocity()
{
	return 0.01F;
}
}

 

 

 

Entity Render  Class:

 

 

package lazerman47.weaponsplus.Render;

import lazerman47.weaponsplus.Entity.EntityRailgunRound;
import lazerman47.weaponsplus.Model.ModelRPGRound;
import lazerman47.weaponsplus.Model.ModelRailgunRound;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class RenderRailgunRound extends Render
{

protected ModelRailgunRound base;

float scale;
public RenderRailgunRound(float scalef)
{
	this.base = new ModelRailgunRound();
	scale = scalef;
}

public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
{
	this.renderEntityModel((EntityRailgunRound)par1Entity, par2, par4, par6, par8, par9);
}


public void renderEntityModel(EntityRailgunRound par1Entity, double par2, double par4, double par6, float par8, float par9)
{
	this.bindEntityTexture(par1Entity);
	GL11.glPushMatrix();
	GL11.glTranslatef((float)par2, (float)par4, (float)par6);
	GL11.glRotatef(par1Entity.prevRotationYaw + (par1Entity.rotationYaw - par1Entity.prevRotationYaw) * par9 - 90.0F, 0.0F, 1.0F, 0.0F);
	GL11.glRotatef(par1Entity.prevRotationPitch + (par1Entity.rotationPitch - par1Entity.prevRotationPitch) * par9, 0.0F, 0.0F, 1.0F);
	float f10 = 0.01F;
	GL11.glEnable(GL12.GL_RESCALE_NORMAL);

	GL11.glScalef(scale, scale, scale);
	GL11.glRotatef(270, 0 ,20, 0);
	GL11.glRotatef(88, -40 ,0, 0);//Did you know that cashews come from a fruit
	GL11.glTranslated(15F, 1.5, 0);
	this.base.render(par1Entity, 1, 2, 3, 4, 5, 6);
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	GL11.glPopMatrix();
}

@Override
protected ResourceLocation getEntityTexture(Entity entity) 
{
	return new ResourceLocation("weaponsplus:textures/model/railGun.png");
}
}

 

 

Creator Of Weapons+ Mod & Sword Art Online HUD Mod

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



×
×
  • Create New...

Important Information

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