Mark136 Posted March 12, 2017 Posted March 12, 2017 (edited) Hello, I created a custom firebal projectile but it doest render well. the particles renders and the entity exist, only the projectile does'nt render. I think it is something stupid but can't find it. so here you can see my renderOpalShot Class, and I already checked that the doRender and the getEntityTexture both got called: @SideOnly(Side.CLIENT) public class RenderOpalShot extends Render<EntityOpalShot>{ private ResourceLocation location = new ResourceLocation("mark13695","textures/entity/Opal1.png"); public RenderOpalShot(RenderManager renderManager) { super(renderManager); } @Override public void doRender(EntityOpalShot entity, double x, double y, double z, float entityYaw, float partialTicks) { GlStateManager.pushMatrix(); this.bindEntityTexture(entity); GlStateManager.translate((float)x, (float)y, (float)z); GlStateManager.enableRescaleNormal(); GlStateManager.scale(0.5F, 0.5F, 0.5F); TextureAtlasSprite textureatlassprite = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getParticleIcon(MarkItems.OpalShotIcon); Tessellator tessellator = Tessellator.getInstance(); VertexBuffer vertexbuffer = tessellator.getBuffer(); float f = textureatlassprite.getMinU(); float f1 = textureatlassprite.getMaxU(); float f2 = textureatlassprite.getMinV(); float f3 = textureatlassprite.getMaxV(); GlStateManager.rotate(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GlStateManager.rotate((float)(this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * -this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); if (this.renderOutlines) { GlStateManager.enableColorMaterial(); GlStateManager.enableOutlineMode(this.getTeamColor(entity)); } vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_NORMAL); vertexbuffer.pos(-0.5D, -0.25D, 0.0D).tex((double)f, (double)f3).normal(0.0F, 1.0F, 0.0F).endVertex(); vertexbuffer.pos(0.5D, -0.25D, 0.0D).tex((double)f1, (double)f3).normal(0.0F, 1.0F, 0.0F).endVertex(); vertexbuffer.pos(0.5D, 0.75D, 0.0D).tex((double)f1, (double)f2).normal(0.0F, 1.0F, 0.0F).endVertex(); vertexbuffer.pos(-0.5D, 0.75D, 0.0D).tex((double)f, (double)f2).normal(0.0F, 1.0F, 0.0F).endVertex(); tessellator.draw(); if (this.renderOutlines) { GlStateManager.disableOutlineMode(); GlStateManager.disableColorMaterial(); } GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); super.doRender(entity, x, y, z, entityYaw, partialTicks); } @Override protected ResourceLocation getEntityTexture(EntityOpalShot entity) { return location; } } yeah, as you see, I copied most of the code from EntityFireBall... this file is called in clientproxy, with all my other entities that havend Spawning problems public static void registerRenderers(){ //... RenderingRegistry.registerEntityRenderingHandler(EntityOpalShot.class, RenderOpalShot::new); } and this is called in the pre-Init method in the mainfile: @EventHandler public void PreInit(FMLPreInitializationEvent Event){ //... ClientProxy.registerRenderers(); } @EventHandler public void init(FMLInitializationEvent Event){ //... MobRegistry.init(); } and here I registered my mobs: public static void init(){ //... EntityRegistry.registerModEntity(EntityOpalShot.class, "OpalShot", 23, MainRegistry.instance, 80, 3, true); } thanks for helping me. Edited March 26, 2017 by Mark136 changed the thread title to let see it is solved now Quote my Mod: Extended RPG [W.I.P]
Draco18s Posted March 12, 2017 Posted March 12, 2017 12 minutes ago, Mark136 said: public void PreInit(FMLPreInitializationEvent Event){ //... ClientProxy.registerRenderers(); } You can't do this. This will 100% crash the dedicated server. Remember: the client proxy cannot load on the server, it references classes that don't exist. The only way to reference proxy methods is through an instance. Mainmod.instance.proxy.registerRenderers(); Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Mark136 Posted March 12, 2017 Author Posted March 12, 2017 (edited) @SideOnly(Side.CLIENT) public class ClientProxy extends CommonProxy { I havend done something with the proxies for over a year, but everything is working. No Crashes(proxy part) only added the line for the new Entity Projectile and that time the Old RegisterEntityRenderingHandler became Depricated in favor of the IRenderFactory thing Edited March 12, 2017 by Mark136 Quote my Mod: Extended RPG [W.I.P]
Jay Avery Posted March 12, 2017 Posted March 12, 2017 24 minutes ago, Mark136 said: @SideOnly(Side.CLIENT) public class ClientProxy extends CommonProxy { I havend done something with the proxies for over a year, but everything is working. No Crashes(proxy part) It won't crash when you run it as a client, but it will crash when you run it as a server. Quote
Draco18s Posted March 12, 2017 Posted March 12, 2017 1 hour ago, Mark136 said: @SideOnly(Side.CLIENT) public class ClientProxy extends CommonProxy { I havend done something with the proxies for over a year, but everything is working. No Crashes(proxy part) Yes but this: ClientProxy.registerRenderers(); Is in common code and that's a static reference to your client proxy. Next to the run button is a dropdown, click that and click "run server." Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Mark136 Posted March 25, 2017 Author Posted March 25, 2017 Ok, Thanks, I didn't knew I could run a server in Eclipse. now i had far more errors than this one, I didn't registered the the client things well, now I have separated the client things and the server things. and now the client and server both working. but it still didn't fix the problem. this is how my client proxy looks right now public class ClientProxy extends CommonProxy { @Override public void preInit(FMLPreInitializationEvent event) { super.preInit(event); this.registerRenderers(); } public void registerRenderers(){ RenderingRegistry.registerEntityRenderingHandler(EntityOpalShot.class, RenderOpalShot::new); } Quote my Mod: Extended RPG [W.I.P]
Mark136 Posted March 25, 2017 Author Posted March 25, 2017 ok, it is almost fully copied from EntityThrowable with some small changes public class EntityOpalShot extends Entity implements IProjectile { /** will be used Later for particle Trails */ //TODO private int BurstID; private int ignoreTimeM; private int xTile; private int yTile; private int zTile; private Block inTile; protected boolean inGround; public int throwableShake; /** The entity that threw this throwable item. */ private EntityLivingBase thrower; private String throwerName; private int ticksInGround; private int ticksInAir; public Entity ignoreEntity; public EntityOpalShot(World worldIn, int ID) { super(worldIn); this.xTile = -1; this.yTile = -1; this.zTile = -1; this.setSize(0.25F, 0.25F); this.BurstID = ID; } public EntityOpalShot(World worldIn, EntityLivingBase throwerIn, int ID) { this(worldIn, throwerIn.posX, throwerIn.posY + (double)throwerIn.getEyeHeight() - 0.10000000149011612D, throwerIn.posZ, ID); this.thrower = throwerIn; this.BurstID = ID; } public EntityOpalShot(World worldIn, double x, double y, double z, int ID) { this(worldIn, ID); this.setPosition(x, y, z); } protected void entityInit() { } /** * Checks if the entity is in range to render. */ @SideOnly(Side.CLIENT) public boolean isInRangeToRenderDist(double distance) { double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D; if (Double.isNaN(d0)) { d0 = 4.0D; } d0 = d0 * 64.0D; return distance < d0 * d0; } /** * Sets throwable heading based on an entity that's throwing it */ public void setHeadingFromThrower(Entity entityThrower, float rotationPitchIn, float rotationYawIn, float pitchOffset, float velocity, float inaccuracy) { float f = -MathHelper.sin(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F); float f1 = -MathHelper.sin((rotationPitchIn + pitchOffset) * 0.017453292F); float f2 = MathHelper.cos(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F); this.setThrowableHeading((double)f, (double)f1, (double)f2, velocity, inaccuracy); this.motionX += entityThrower.motionX; this.motionZ += entityThrower.motionZ; if (!entityThrower.onGround) { this.motionY += entityThrower.motionY; } } /** * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction. */ public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy) { float f = MathHelper.sqrt_double(x * x + y * y + z * z); x = x / (double)f; y = y / (double)f; z = z / (double)f; x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; x = x * (double)velocity; y = y * (double)velocity; z = z * (double)velocity; this.motionX = x; this.motionY = y; this.motionZ = z; float f1 = MathHelper.sqrt_double(x * x + z * z); this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI)); this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI)); this.prevRotationYaw = this.rotationYaw; this.prevRotationPitch = this.rotationPitch; this.ticksInGround = 0; } /** * Updates the velocity of the entity to a new value. * TODO: No Idea where this is called. Check if this is useful to keep in code. */ @SideOnly(Side.CLIENT) public void setVelocity(double x, double y, double z) { this.motionX = x; this.motionY = y; this.motionZ = z; if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(x * x + z * z); this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI)); this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI)); this.prevRotationYaw = this.rotationYaw; this.prevRotationPitch = this.rotationPitch; } } /** * updating movement, checks for inpact ect. TODO: check if I can lower the Velocity * and remove the Gravity. also check if there is some "if ticks in air = ? set dead ect." */ public void onUpdate() { this.lastTickPosX = this.posX; this.lastTickPosY = this.posY; this.lastTickPosZ = this.posZ; super.onUpdate(); if (this.throwableShake > 0) { --this.throwableShake; } if (this.inGround) { if (this.worldObj.getBlockState(new BlockPos(this.xTile, this.yTile, this.zTile)).getBlock() == this.inTile) { ++this.ticksInGround; if (this.ticksInGround == 1200) { this.setDead(); } return; } this.inGround = false; this.motionX *= (double)(this.rand.nextFloat() * 0.2F); this.motionY *= (double)(this.rand.nextFloat() * 0.2F); this.motionZ *= (double)(this.rand.nextFloat() * 0.2F); this.ticksInGround = 0; this.ticksInAir = 0; } else { ++this.ticksInAir; } Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ); Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); RayTraceResult raytraceresult = this.worldObj.rayTraceBlocks(vec3d, vec3d1); vec3d = new Vec3d(this.posX, this.posY, this.posZ); vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (raytraceresult != null) { vec3d1 = new Vec3d(raytraceresult.hitVec.xCoord, raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord); } Entity entity = null; List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expandXyz(1.0D)); double d0 = 0.0D; boolean flag = false; for (int i = 0; i < list.size(); ++i) { Entity entity1 = (Entity)list.get(i); if (entity1.canBeCollidedWith()) { if (entity1 == this.ignoreEntity) { flag = true; } else if (this.ticksExisted < 2 && this.ignoreEntity == null) { this.ignoreEntity = entity1; flag = true; } else { flag = false; AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expandXyz(0.30000001192092896D); RayTraceResult raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1); if (raytraceresult1 != null) { double d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec); if (d1 < d0 || d0 == 0.0D) { entity = entity1; d0 = d1; } } } } } if (this.ignoreEntity != null) { if (flag) { this.ignoreTimeM = 2; } else if (this.ignoreTimeM-- <= 0) { this.ignoreEntity = null; } } if (entity != null) { raytraceresult = new RayTraceResult(entity); } if (raytraceresult != null) { if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && this.worldObj.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.PORTAL) { this.setPortal(raytraceresult.getBlockPos()); } } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI)); for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { ; } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; float f1 = 0.99F; float f2 = this.getGravityVelocity(); if (this.isInWater()) { for (int j = 0; j < 4; ++j) { float f3 = 0.25F; this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ, new int[0]); } f1 = 0.8F; } this.motionX *= (double)f1; this.motionY *= (double)f1; this.motionZ *= (double)f1; if (!this.func_189652_ae()) { this.motionY -= (double)f2; } this.setPosition(this.posX, this.posY, this.posZ); } /** * Gets the amount of gravity to apply to the thrown entity with each tick. */ protected float getGravityVelocity() { return 0.03F; } /** * TODO: check why this is'nt called. * */ protected void onImpact(RayTraceResult result) { if (result.entityHit != null) { result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 2.0F); } if (!this.worldObj.isRemote) { this.setDead(); } } /** * TODO: wtf is this? Checkout! * */ public static void func_189661_a(DataFixer p_189661_0_, String p_189661_1_) { } /** * Protected helper method to write subclass entity data to NBT. */ public void writeEntityToNBT(NBTTagCompound compound) { compound.setInteger("xTile", this.xTile); compound.setInteger("yTile", this.yTile); compound.setInteger("zTile", this.zTile); ResourceLocation resourcelocation = (ResourceLocation)Block.REGISTRY.getNameForObject(this.inTile); compound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString()); compound.setByte("shake", (byte)this.throwableShake); compound.setByte("inGround", (byte)(this.inGround ? 1 : 0)); if ((this.throwerName == null || this.throwerName.isEmpty()) && this.thrower instanceof EntityPlayer) { this.throwerName = this.thrower.getName(); } compound.setString("ownerName", this.throwerName == null ? "" : this.throwerName); } /** * Protected helper method to read subclass entity data from NBT. */ public void readEntityFromNBT(NBTTagCompound compound) { this.xTile = compound.getInteger("xTile"); this.yTile = compound.getInteger("yTile"); this.zTile = compound.getInteger("zTile"); if (compound.hasKey("inTile", 8)) { this.inTile = Block.getBlockFromName(compound.getString("inTile")); } else { this.inTile = Block.getBlockById(compound.getByte("inTile") & 255); } this.throwableShake = compound.getByte("shake") & 255; this.inGround = compound.getByte("inGround") == 1; this.thrower = null; this.throwerName = compound.getString("ownerName"); if (this.throwerName != null && this.throwerName.isEmpty()) { this.throwerName = null; } this.thrower = this.getThrower(); } @Nullable public EntityLivingBase getThrower() { if (this.thrower == null && this.throwerName != null && !this.throwerName.isEmpty()) { this.thrower = this.worldObj.getPlayerEntityByName(this.throwerName); if (this.thrower == null && this.worldObj instanceof WorldServer) { try { Entity entity = ((WorldServer)this.worldObj).getEntityFromUuid(UUID.fromString(this.throwerName)); if (entity instanceof EntityLivingBase) { this.thrower = (EntityLivingBase)entity; } } catch (Throwable var2) { this.thrower = null; } } } return this.thrower; } } Quote my Mod: Extended RPG [W.I.P]
Mark136 Posted March 25, 2017 Author Posted March 25, 2017 12 minutes ago, diesieben07 said: An Entity must have a constructor with just a World argument, otherwise the client cannot spawn it and it cannot be reloaded from disk. ok, this are the constructors now: public EntityOpalShot(World worldIn) { super(worldIn); this.xTile = -1; this.yTile = -1; this.zTile = -1; this.setSize(0.25F, 0.25F); } public EntityOpalShot(World worldIn, EntityLivingBase throwerIn, int ID) { this(worldIn, throwerIn.posX, throwerIn.posY + (double)throwerIn.getEyeHeight() - 0.10000000149011612D, throwerIn.posZ, ID); this.shooter = throwerIn; } public EntityOpalShot(World worldIn, double x, double y, double z, int ID) { this(worldIn); this.setPosition(x, y, z); this.BurstID = ID; } unfortunately, nothing happened Quote my Mod: Extended RPG [W.I.P]
Kriptikz Posted March 25, 2017 Posted March 25, 2017 You can try offsetting it by a couple blocks and see what happens, it may be colliding with the thrower. Also if your using most of EntityThrowable code why not just extend from it and override/add stuff. Minecraft also has an EntityFireball class that you could check out. But yeah, working Git repo will make helping you out now and possibly in the future much easier. Quote
Mark136 Posted March 25, 2017 Author Posted March 25, 2017 (edited) hey, I already checked this with particle trails, and when the projectile lands in the water. the particles spawn, but the projectile doesn't I currently busy with separating the projectile from the rest of my code so its easier to read. I also gonna create a Git repo of it. I don't extend the entity Throwable because I want to change the character a bit. the gravity, the valocity ect. also, if i shoot an entityFireBall. the fireball goes through everything. here is ItemWand class. this is the Item how I shoot the projectile. Git repo is coming! public class MarkWand extends Item { /** * custom EnumMaterial to calculate some values that I need for * my combat system. * */ private EnumMaterial material; private float AttackDamage; private int Cooldown = 0; public MarkWand(EnumMaterial Material){ this.material = Material; this.maxStackSize = 1; this.setMaxDamage(Material.getMaxUses()); } /** TODO: Does Nothing, Why I have this, this is for holding a Tool right? */ @SideOnly(Side.CLIENT) public boolean isFull3D() { return true; } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack I, World W, EntityPlayer Player, EnumHand hand) { if(this.Cooldown < 1){ this.Cooldown = 30; Entity GemBall; if(this == MarkItems.Wand1){ GemBall = new EntityOpalShot(W, Player, 0); ((EntityOpalShot) GemBall).setHeadingFromThrower(Player, Player.rotationPitch, Player.rotationYaw, 0.0F, 1.5F, 1.0F); I.damageItem(1, Player); } else{ Vec3d aim = Player.getLookVec(); GemBall = new EntitySmallFireball(W, Player, 1, 1, 1); ((EntitySmallFireball)GemBall).setPosition( Player.posX + aim.xCoord * 1.5D, Player.posY + aim.yCoord * 1.5D, Player.posZ + aim.zCoord * 1.5D); ((EntitySmallFireball)GemBall).accelerationX = aim.xCoord * 0.1; ((EntitySmallFireball)GemBall).accelerationY = aim.yCoord * 0.1; ((EntitySmallFireball)GemBall).accelerationZ = aim.zCoord * 0.1; } W.spawnEntityInWorld(GemBall); } return new ActionResult(EnumActionResult.PASS, I); } /** I want a cooldown period between the shots, so this is why I have this */ @Override public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean B) { if (this.Cooldown > 0){ this.Cooldown--; } } } Edited March 25, 2017 by Mark136 Quote my Mod: Extended RPG [W.I.P]
Mark136 Posted March 26, 2017 Author Posted March 26, 2017 ... I was registering the Mobs in init instead of pre-init, so the rendering part was registered before the EntityRegistry. resulting in an invisible projectile. why the projectile was going through blocks is that I forgot the !world.isRemote() check in ItemWand. now the projectile is spawning well. thx for the help Quote my Mod: Extended RPG [W.I.P]
Recommended Posts
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.