Jump to content

[HELP] Rendering Problems with gun code


MinecraftWero

Recommended Posts

hello guys so im having some problems with the rendering of my gun code, for example it shoots and it deals damage to the mobs but you cant actually see the bullet its invisiible so i was wondering if you guys know why is that happening and also i have a bug that when the clip runs out of ammo it looks like the image its in there but its actually not so i hope you guys can help me

Link to comment
Share on other sites

Not sure how to debug your own code, but either way, the issue with not seeing the bullet is probably that you're not tracking the bullet entity properly so the client isnt being informed that that bullet exists.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

uhmm do you want to check out EntityBullet.java?

 

 

 

package minecraftwero.common; //CHANGE THIS
import java.util.List;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.Block;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityDamageSource;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.MathHelper;
import net.minecraft.src.MovingObjectPosition;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.Vec3;
import net.minecraft.src.Vec3Pool;
import net.minecraft.src.World;
public class EntityBullet extends Entity
{
                private int xTile;
                private int yTile;
                private int zTile;
                private int inTile;
                private boolean inGround;
                public int arrowShake;
                public EntityLiving shootingEntity;
                private int timeTillDeath;
                private int flyTime;
                private EntityPlayer owner;
                private int damage;
                private final float size = 1F;
           
                public EntityBullet(World world)
                {
                                super(world);
                                xTile = -1;
                                yTile = -1;
                                zTile = -1;
                                inTile = 0;
                                inGround = false;
                                arrowShake = 0;
                                flyTime = 0;
                                setSize(size, size);
                }
                public EntityBullet(World world, double d, double d1, double d2,
                                                double d3, double d4, double d5, EntityPlayer entityplayer)
                {
                                super(world);
                                xTile = -1;
                                yTile = -1;
                                zTile = -1;
                                inTile = 0;
                                inGround = false;
                                arrowShake = 0;
                                flyTime = 0;
                                setSize(size, size);
                                setPosition(d, d1, d2);
                                yOffset = 0.0F;
                                setVelocity(d3, d4, d5);
                                owner = entityplayer;
                }
                public EntityBullet(World world, double d, double d1, double d2)
                {
                                super(world);
                                xTile = -1;
                                yTile = -1;
                                zTile = -1;
                                inTile = 0;
                                inGround = false;
                                arrowShake = 0;
                                flyTime = 0;
                                setSize(size, size);
                                setPosition(d, d1, d2);
                                yOffset = 0.0F;
                }
                public EntityBullet(World world, EntityLiving entityliving, int damage, int accuracy)
                {
                                super(world);
                                this.damage = damage;
                                xTile = -1;
                                yTile = -1;
                                zTile = -1;
                                inTile = 0;
                                inGround = false;
                                arrowShake = 0;
                                flyTime = 0;
                                shootingEntity = entityliving;
                                setSize(size, size);
                                setLocationAndAngles(entityliving.posX, entityliving.posY + (double)entityliving.getEyeHeight(), entityliving.posZ, entityliving.rotationYaw, entityliving.rotationPitch);
                                posX -= MathHelper.cos((rotationYaw / 180F) * 3.141593F) * 0.16F;
                                posY -= 0.10000000149011612D;
                                posZ -= MathHelper.sin((rotationYaw / 180F) * 3.141593F) * 0.16F;
                                setPosition(posX, posY, posZ);
                                yOffset = 0.0F;
                                motionX = 1000F * -MathHelper.sin((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
                                motionZ = 1000F * MathHelper.cos((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
                                motionY = 1000F * -MathHelper.sin((rotationPitch / 180F) * 3.141593F);
                                setArrowHeading(motionX, motionY, motionZ, 200.0F, 1.5F, accuracy);
                }
                protected void entityInit()
                {
                }
                public void setArrowHeading(double d, double d1, double d2, float f,
                                                float f1, int i)
                {
                                float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
                                d /= f2;
                                d1 /= f2;
                                d2 /= f2;
                                d += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
                                d1 += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
                                d2 += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
                                d *= f;
                                d1 *= f;
                                d2 *= f;
                                motionX = d;
                                motionY = d1;
                                motionZ = d2;
                                float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
                                prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
                                prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f3) * 180D) / 3.1415927410125732D);
                                timeTillDeath = 0;
                }
                public void setVelocity(double d, double d1, double d2)
                {
                                motionX = d;
                                motionY = d1;
                                motionZ = d2;
                                if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
                                {
                                                float f = MathHelper.sqrt_double(d * d + d2 * d2);
                                                prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
                                                prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f) * 180D) / 3.1415927410125732D);
                                }
                }
                public void onUpdate()
                {
                                super.onUpdate();
                                if (flyTime > 1000)
                                {
                                                setDead();
                                }
                                if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
                                {
                                                float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
                                                prevRotationYaw = rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
                                                prevRotationPitch = rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D);
                                }
                                if (arrowShake > 0)
                                {
                                                arrowShake--;
                                }
                                if (inGround)
                                {
                                                int i = worldObj.getBlockId(xTile, yTile, zTile);
                                                if (i != inTile)
                                                {
                                                                inGround = false;
                                                                motionX *= rand.nextFloat() * 0.2F;
                                                                motionY *= rand.nextFloat() * 0.2F;
                                                                motionZ *= rand.nextFloat() * 0.2F;
                                                                timeTillDeath = 0;
                                                                flyTime = 0;
                                                }
                                                else
                                                {
                                                                timeTillDeath++;
                                                                if (timeTillDeath == 1200)
                                                                {
                                                                                setDead();
                                                                }
                                                                return;
                                                }
                                }
                                else
                                {
                                                flyTime++;
                                }
                                Vec3 vec3d = Vec3.getVec3Pool().getVecFromPool(posX, posY, posZ);
                                Vec3 vec3d1 = Vec3.getVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ);
                                MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
                                vec3d = Vec3.getVec3Pool().getVecFromPool(posX, posY, posZ);
                                vec3d1 = Vec3.getVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ);
                                if (movingobjectposition != null)
                                {
                                                vec3d1 = Vec3.getVec3Pool().getVecFromPool(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
                                }
                                Entity entity = null;
                                List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
                                double d = 0.0D;
                                for (int j = 0; j < list.size(); j++)
                                {
                                                Entity entity1 = (Entity)list.get(j);
                                                if (!entity1.canBeCollidedWith() || entity1 == shootingEntity && flyTime < 5)
                                                {
                                                                continue;
                                                }
                                                float f4 = 0.3F;
                                                AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f4, f4, f4);
                                                MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
                                                if (movingobjectposition1 == null)
                                                {
                                                                continue;
                                                }
                                                double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
                                                if (d1 < d || d == 0.0D)
                                                {
                                                                entity = entity1;
                                                                d = d1;
                                                }
                                }
                                if (entity != null)
                                {
                                                movingobjectposition = new MovingObjectPosition(entity);
                                }
                                if (movingobjectposition != null)
                                {
                                                if (movingobjectposition.entityHit != null)
                                                {
                                                                if (movingobjectposition.entityHit.attackEntityFrom(new EntityDamageSource("player", owner), damage))
                                                                {
                                                                                worldObj.playSoundAtEntity(this, "BulletHit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
                                                                                setDead();
                                                                }
                                                                else
                                                                {
                                                                                motionX *= 0.10000000149011612D;
                                                                                motionY *= 0.10000000149011612D;
                                                                                motionZ *= 0.10000000149011612D;
                                                                                flyTime = 0;
                                                                                setDead();
                                                                }
                                                }
                                                else
                                                {
                                                                xTile = movingobjectposition.blockX;
                                                                yTile = movingobjectposition.blockY;
                                                                zTile = movingobjectposition.blockZ;
                                                                inTile = worldObj.getBlockId(xTile, yTile, zTile);
                                                                if (inTile == Block.glass.blockID || inTile == Block.glowStone.blockID || inTile == Block.leaves.blockID)
                                                                {
                                                                                Block block = Block.blocksList[inTile];
                                                                                //ModLoader.getMinecraftInstance().sndManager.playSound(block.stepSound.stepSoundDir(), (float)xTile + 0.5F, (float)yTile + 0.5F, (float)zTile + 0.5F, (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
                                                                                worldObj.setBlockWithNotify(xTile, yTile, zTile, 0);
                                                                }
                                                                else
                                                                {
                                                                                motionX = (float)(movingobjectposition.hitVec.xCoord - posX);
                                                                                motionY = (float)(movingobjectposition.hitVec.yCoord - posY);
                                                                                motionZ = (float)(movingobjectposition.hitVec.zCoord - posZ);
                                                                                float f1 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);
                                                                                posX -= (motionX / (double)f1) * 0.05000000074505806D;
                                                                                posY -= (motionY / (double)f1) * 0.05000000074505806D;
                                                                                posZ -= (motionZ / (double)f1) * 0.05000000074505806D;
                                                                                worldObj.playSoundAtEntity(this, "Bullet2Hit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
                                                                                setDead();
                                                                }
                                                }
                                }
                                posX += motionX * 3D;
                                posY += motionY * 3D;
                                posZ += motionZ * 3D;
                                float f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
                                rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
                                for (rotationPitch = (float)((Math.atan2(motionY, f2) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { }
                                for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { }
                                for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { }
                                for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { }
                                rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
                                rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
                                float f3 = 0.99F;
                                float f5 = 0.03F;
                                if (handleWaterMovement())
                                {
                                                for (int k = 0; k < 4; k++)
                                                {
                                                                float f6 = 0.25F;
                                                                worldObj.spawnParticle("bubble", posX - motionX * (double)f6, posY - motionY * (double)f6, posZ - motionZ * (double)f6, motionX, motionY, motionZ);
                                                }
                                                f3 = 0.8F;
                                }
                                motionX *= f3;
                                motionY *= f3;
                                motionZ *= f3;
                                setPosition(posX, posY, posZ);
                }
                public void writeEntityToNBT(NBTTagCompound nbttagcompound)
                {
                                nbttagcompound.setShort("xTile", (short)xTile);
                                nbttagcompound.setShort("yTile", (short)yTile);
                                nbttagcompound.setShort("zTile", (short)zTile);
                                nbttagcompound.setByte("inTile", (byte)inTile);
                                nbttagcompound.setByte("shake", (byte)arrowShake);
                                nbttagcompound.setByte("inGround", (byte)(inGround ? 1 : 0));
                }
                public void readEntityFromNBT(NBTTagCompound nbttagcompound)
                {
                                xTile = nbttagcompound.getShort("xTile");
                                yTile = nbttagcompound.getShort("yTile");
                                zTile = nbttagcompound.getShort("zTile");
                                inTile = nbttagcompound.getByte("inTile") & 0xff;
                                arrowShake = nbttagcompound.getByte("shake") & 0xff;
                                inGround = nbttagcompound.getByte("inGround") == 1;
                }
                public void onCollideWithPlayer(EntityPlayer entityplayer)
                {
                                if (worldObj.isRemote)
                                {
                                                return;
                                }
                                if (inGround && shootingEntity == entityplayer && arrowShake <= 0 && entityplayer.inventory.addItemStackToInventory(new ItemStack(Item.arrow, 1)))
                                {
                                                worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
                                                entityplayer.onItemPickup(this, 1);
                                                setDead();
                                }
                }
                
                
                public float getShadowSize()
                {
                                return 0.0F;
                }
}

 

 

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 have done this now but have got the error:   'food(net.minecraft.world.food.FoodProperties)' in 'net.minecraft.world.item.Item.Properties' cannot be applied to                '(net.minecraftforge.registries.RegistryObject<net.minecraft.world.item.Item>)' public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register( "lemon_juice", () -> new Item( new HoneyBottleItem.Properties().stacksTo(1).food( (new FoodProperties.Builder()) .nutrition(3) .saturationMod(0.25F) .effect(() -> new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 1500), 0.01f ) .build() ) )); The code above is from the ModFoods class, the one below from the ModItems class. public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register("lemon_juice", () -> new Item(new Item.Properties().food(ModFoods.LEMON_JUICE)));   I shall keep going between them to try and figure out the cause. I am sorry if this is too much for you to help with, though I thank you greatly for your patience and all the effort you have put in to help me.
    • I have been following these exact tutorials for quite a while, I must agree that they are amazing and easy to follow. I have registered the item in the ModFoods class, I tried to do it in ModItems (Where all the items should be registered) but got errors, I think I may need to revert this and figure it out from there. Once again, thank you for your help! 👍 Just looking back, I have noticed in your code you added ITEMS.register, which I am guessing means that they are being registered in ModFoods, I shall go through the process of trial and error to figure this out.
    • ♈+2349027025197ஜ Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join a brotherhood for protection and wealth here’s is your opportunity, but you should know there’s no ritual without repercussions but with the right guidance and support from this great temple your destiny is certain to be changed for the better and equally protected depending if you’re destined for greatness Call now for enquiry +2349027025197☎+2349027025197₩™ I want to join ILLUMINATI occult without human sacrificeGREATORLDRADO BROTHERHOOD OCCULT , Is The Club of the Riches and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In Greatorldrado BROTHERHOOD we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money Rewards once they join in order to upgrade their lifestyle.; interested viewers should contact us; on. +2349027025197 ۝ஐℰ+2349027025197 ₩Greatorldrado BROTHERHOOD OCCULT IS A SACRED FRATERNITY WITH A GRAND LODGE TEMPLE SITUATED IN G.R.A PHASE 1 PORT HARCOURT NIGERIA, OUR NUMBER ONE OBLIGATION IS TO MAKE EVERY INITIATE MEMBER HERE RICH AND FAMOUS IN OTHER RISE THE POWERS OF GUARDIANS OF AGE+. +2349027025197   SEARCHING ON HOW TO JOIN THE Greatorldrado BROTHERHOOD MONEY RITUAL OCCULT IS NOT THE PROBLEM BUT MAKE SURE YOU'VE THOUGHT ABOUT IT VERY WELL BEFORE REACHING US HERE BECAUSE NOT EVERYONE HAS THE HEART TO DO WHAT IT TAKES TO BECOME ONE OF US HERE, BUT IF YOU THINK YOU'RE SERIOUS MINDED AND READY TO RUN THE SPIRITUAL RACE OF LIFE IN OTHER TO ACQUIRE ALL YOU NEED HERE ON EARTH CONTACT SPIRITUAL GRANDMASTER NOW FOR INQUIRY +2349027025197   +2349027025197 Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join
    • Hi, I'm trying to use datagen to create json files in my own mod. This is my ModRecipeProvider class. public class ModRecipeProvider extends RecipeProvider implements IConditionBuilder { public ModRecipeProvider(PackOutput pOutput) { super(pOutput); } @Override protected void buildRecipes(Consumer<FinishedRecipe> pWriter) { ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', ModItems.COMPRESSED_DIAMOND.get()) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get(),9) .requires(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .unlockedBy(getHasName(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()), has(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get())) .save(pWriter); ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', Blocks.DIAMOND_BLOCK) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); } } When I try to run the runData client, it shows an error:  Caused by: java.lang.IllegalStateException: Duplicate recipe compressed:compressed_diamond I know that it's caused by the fact that there are two recipes for the ModItems.COMPRESSED_DIAMOND. But I need both of these recipes, because I need a way to craft ModItems.COMPRESSED_DIAMOND_BLOCK and restore 9 diamond blocks from ModItems.COMPRESSED_DIAMOND. Is there a way to solve this?
  • Topics

×
×
  • Create New...

Important Information

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