gurujive Posted November 23, 2016 Posted November 23, 2016 I have an entity that has a main class similar to entity throwable, I have adjust the eye height that it gets (which I shouldn't have to when not specifying onImpact of PlayerEntity) + 0.2000000149011612D instead of - 0.10000000149011612D which entitythrowable has. I have also changed the getGravityVelocity to 0.0 Main Class: package exampled.modinfo.entity; import java.util.List; import java.util.UUID; import javax.annotation.Nullable; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IProjectile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.ResourceLocation; import net.minecraft.util.datafix.DataFixer; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public abstract class EntityOrb2 extends Entity implements IProjectile { 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; private int ignoreTime; public EntityOrb2(World worldIn) { super(worldIn); this.xTile = -1; this.yTile = -1; this.zTile = -1; this.setSize(0.25F, 0.25F); } public EntityOrb2(World worldIn, double x, double y, double z) { this(worldIn); this.setPosition(x, y, z); } public EntityOrb2(World worldIn, EntityLivingBase throwerIn) { this(worldIn, throwerIn.posX, throwerIn.posY + (double)throwerIn.getEyeHeight() + 0.2000000149011612D, throwerIn.posZ); this.thrower = throwerIn; } public boolean canRenderOnFire() { return false; } protected void entityInit() { } @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; } 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; } } 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.0D * (double)inaccuracy; y = y + this.rand.nextGaussian() * 0.0D * (double)inaccuracy; z = z + this.rand.nextGaussian() * 0.0D * (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; } @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; } } 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.thrower != null && 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.ignoreTime = 2; } else if (this.ignoreTime-- <= 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()); } else { this.onImpact(raytraceresult); } } 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.hasNoGravity()) { this.motionY -= (double)f2; } this.setPosition(this.posX, this.posY, this.posZ); } protected float getGravityVelocity() { return 0.0F; } protected abstract void onImpact(RayTraceResult result); public static void registerFixesThrowable(DataFixer fixer, String name) { } 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); } public void readEntityFromNBT(NBTTagCompound compound) { this.xTile = compound.getInteger("xTile"); this.yTile = compound.getInteger("yTile"); this.zTile = compound.getInteger("zTile"); if (compound.hasKey("inTile", ) { 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; } } Entity that extends main class: package exampled.modinfo.entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.MobEffects; import net.minecraft.init.SoundEvents; import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class EntityAetherOrb extends EntityOrb2 { public EntityAetherOrb(World worldIn) { super(worldIn); } public EntityAetherOrb(World worldIn, EntityLivingBase throwerIn) { super(worldIn, throwerIn); } public void onUpdate() { super.onUpdate(); ++ticksExisted; if (this.ticksExisted >= 114) { this.worldObj.spawnParticle(EnumParticleTypes.REDSTONE, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / 2 - worldObj.rand.nextFloat()) / 2, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 4, -1, -1, 1); this.setDead(); } this.worldObj.spawnParticle(EnumParticleTypes.SPELL_MOB_AMBIENT, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / -2 - worldObj.rand.nextFloat()) / -1, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / -1.0, -1d, -1d, 1d); } public float getGravityVelocity() { return 0.0F; } public EntityAetherOrb(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } protected void onImpact(RayTraceResult result) { if (result.entityHit != null) { int i = 0; if (result.entityHit instanceof EntityLivingBase) { i = 0; ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i); worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 0.7F, 1.3F / (worldObj.rand.nextFloat() * 0.4F + 0.8F)); } for (int j = 0; j < 8; ++j) { this.worldObj.spawnParticle(EnumParticleTypes.SPELL_MOB, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / -2 - worldObj.rand.nextFloat()) / -1, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / -1.0, -1d, -1d, 1d); } if (!this.worldObj.isRemote) { this.doBlockCollisions(); } } public float getBrightness(float partialTicks) { return 0.001F; } @SideOnly(Side.CLIENT) public int getBrightnessForRender(float partialTicks) { return 15728880; } } previously this worked without having to adjust eye height level. specifying the player such as: { if (result.entityHit != null) { int i = 0; if (result.entityHit instanceof EntityLivingBase) { i = 0; ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } if (result.entityHit instanceof EntityPlayer) { i = 0; ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i); worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 0.7F, 1.3F / (worldObj.rand.nextFloat() * 0.4F + 0.8F)); } Not too certain if this is a bug or not, so I figured I'd post it here. When I right click, potion effects are applied to my player even though it is spawned in above his head and onImpact EntityPlayer is not specified. When I hold shift and right click the entity is spawned in and no potion effects are applied. It just sits there in the air then goes to setdead. edit: ....this has got to be either a bug or something being worked on or something.... as this does not work: if (result.entityHit instanceof !EntityPlayer) { i = 0; ((!EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((!EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((!EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((!EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((!EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } Quote
Draco18s Posted November 23, 2016 Posted November 23, 2016 ((!EntityPlayer)result.entityHit) The hell? What are you trying to do here? An anti-cast? Also, that's not how you check for "not an instance of." http://stackoverflow.com/questions/9068150/best-way-to-negate-an-instanceof 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.
gurujive Posted November 23, 2016 Author Posted November 23, 2016 I don't believe it would work there anyways, haha. -your link seems to be broken btw. edit: Its so you can heal players and mobs, without applying it to yourself. To apply it to yourself then you'd shift right click. and that would summon the other entity in, that part I haven't gotten too. that way you can heal everyone, and everything, including yourself in a nice manner while slaying everything undead. Quote
gurujive Posted November 23, 2016 Author Posted November 23, 2016 Not sure if this is working or not, will soon find out after making entity2 but by the looks of it this appears to be working: { if (result.entityHit != null) { int i = 0; if (result.entityHit instanceof EntityPlayer == false) { i = 0; ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } if (result.entityHit instanceof EntityLivingBase == false) { i = 0; ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i); worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 0.7F, 1.3F / (worldObj.rand.nextFloat() * 0.4F + 0.8F)); } Quote
gurujive Posted November 23, 2016 Author Posted November 23, 2016 nope.... that doesn't work on players.... it effects entities though. Quote
Lambda Posted November 23, 2016 Posted November 23, 2016 if(!(result.entityHit instanceof EntityPlayer)) Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Matryoshika Posted November 23, 2016 Posted November 23, 2016 [b]if (result.entityHit instanceof EntityLivingBase == false)[/b] { i = 0; ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } If the entity is not EntityLivingBase, then magically it is an EntityPlayer? That's not type-safe casting. Not to mention, guess what class EntityPlayer extends... Well look at that, EntityLivingBase, which means Entityplayer IS an instance of EntityLivingBase, because it extends it. Quote Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
gurujive Posted November 23, 2016 Author Posted November 23, 2016 [b]if (result.entityHit instanceof EntityLivingBase == false)[/b] { i = 0; ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } If the entity is not EntityLivingBase, then magically it is an EntityPlayer? That's not type-safe casting. Not to mention, guess what class EntityPlayer extends... Well look at that, EntityLivingBase, which means Entityplayer IS an instance of EntityLivingBase, because it extends it. That's why it needs to look similar to this so you can also heal other players, heal entities, and heal yourself when holding shift and right click. Using the above false true etc and matching stuff up back and forth Is not working the same. I can cast it on entities and myself but when going to cast it on other players it won't work. if (result.entityHit != null) { int i = 0; if (result.entityHit instanceof EntityLivingBase) { i = 0; ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } if (result.entityHit instanceof EntityPlayer) { i = 0; ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2)); } Quote
gurujive Posted November 23, 2016 Author Posted November 23, 2016 I finally fixed it, If it double impacts then it returns a false blank instant health so there is no permanent buff, and I am now able to walk realllly close to mobs and hit them. The false blank can be cleared by just applying the buff again with shift right click. The issue was with the amount of time before the onImpact was recognized. Now it works if (ticksExisted >= 2.1001 && result.entityHit instanceof EntityLivingBase) protected void onImpact(RayTraceResult result) { if (result.entityHit != null) { int i = 0; if (ticksExisted >= 2.1001 && result.entityHit instanceof EntityLivingBase) { i = 0; ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 197, 1)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 195, 5)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 198, 2)); } if (ticksExisted >= 2.1001 && result.entityHit instanceof EntityPlayer) { i = 0; ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 197, 1)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 195, 5)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 198, 2)); } result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i); worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 0.5F, 1.0F / (worldObj.rand.nextFloat() * 0.4F + 0.8F)); } Quote
Leviathan143 Posted November 23, 2016 Posted November 23, 2016 I finally fixed it, If it double impacts then it returns a false blank instant health so there is no permanent buff, and I am now able to walk realllly close to mobs and hit them. The false blank can be cleared by just applying the buff again with shift right click. The issue was with the amount of time before the onImpact was recognized. Now it works if (ticksExisted >= 2.1001 && result.entityHit instanceof EntityLivingBase) protected void onImpact(RayTraceResult result) { if (result.entityHit != null) { int i = 0; if (ticksExisted >= 2.1001 && result.entityHit instanceof EntityLivingBase) { i = 0; ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 197, 1)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 195, 5)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 198, 2)); } if (ticksExisted >= 2.1001 && result.entityHit instanceof EntityPlayer) { i = 0; ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 197, 1)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 195, 5)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7)); ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 198, 2)); } result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i); worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 0.5F, 1.0F / (worldObj.rand.nextFloat() * 0.4F + 0.8F)); } You still haven't fixed any of the issues we mentioned(e.g the issues Matryoshika mentioned). Quote
gurujive Posted November 23, 2016 Author Posted November 23, 2016 You still haven't fixed any of the issues we mentioned(e.g the issues Matryoshika mentioned). EntityLivingBase Is EntityLivingBase and EntityPlayer is EntityPlayer. But the effect will not effect the player when thrown, it will effect entities though. It will effect other players when thrown. The issue was when you threw it because entityplayer extends entitylivingbase it was applying the effect to the player when this was not what was needed. this was fixed by adding a timed delay. Quote
Animefan8888 Posted November 23, 2016 Posted November 23, 2016 You still haven't fixed any of the issues we mentioned(e.g the issues Matryoshika mentioned). EntityLivingBase Is EntityLivingBase and EntityPlayer is EntityPlayer. But the effect will not effect the player when thrown, it will effect entities though. It will effect other players when thrown. The issue was when you threw it because entityplayer extends entitylivingbase it was applying the effect to the player when this was not what was needed. this was fixed by adding a timed delay. instanceof check is if that is the class or if it is an extension of the class ie EntityPlayer is an EntityLivingBase, but EntityLivingBase is not always an EntityPlayer. So by doing a check for EntityLivingBase you are also checking if it is a EntityPlayer. Then you go on to specifically check for EntityPlayer for no reason because it is included in the instanceof EntityLivingBase. Edit: and yes I understand what the original problem was your entity was spawning in the thrower and applying the effects to that player so adding a time delay defiantly worked. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
gurujive Posted November 23, 2016 Author Posted November 23, 2016 So by doing a check for EntityLivingBase you are also checking if it is a EntityPlayer. Then you go on to specifically check for EntityPlayer for no reason because it is included in the instanceof EntityLivingBase. I don't know if its only me, but doing it that way seems to effect the timer and its success to not stick and result in a blank buff icon popping up in the top right of the screen. That's why I do it that way. Quote
Animefan8888 Posted November 23, 2016 Posted November 23, 2016 So by doing a check for EntityLivingBase you are also checking if it is a EntityPlayer. Then you go on to specifically check for EntityPlayer for no reason because it is included in the instanceof EntityLivingBase. I don't know if its only me, but doing it that way seems to effect the timer and its success to not stick and result in a blank buff icon popping up in the top right of the screen. That's why I do it that way. I have not seen that "bug" myself, could you post a screenshot and the code you get from what I said? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
Leviathan143 Posted November 23, 2016 Posted November 23, 2016 instanceof check is if that is the class or if it is an extension of the class ie EntityPlayer is an EntityLivingBase, but EntityLivingBase is not an EntityPlayer. So by doing a check for EntityLivingBase you are also checking if it is a EntityPlayer. Then you go on to specifically check for EntityPlayer for no reason because it is included in the instanceof EntityLivingBase. That's not quite correct, or at least not clear enough. Since EntityPlayer extends EntityLivingBase, any instance of EntityPlayer is an instance of EntityLivingBase. The reverse is not true, not all instances of EntityLivingBase are an instance of EntityPlayer. This is why you cannot cast an EntityLivingBase to EntityPlayer, unless you first check that the EntityLivingBase is an instance of EntityPlayer. Quote
Animefan8888 Posted November 23, 2016 Posted November 23, 2016 instanceof check is if that is the class or if it is an extension of the class ie EntityPlayer is an EntityLivingBase, but EntityLivingBase is not an EntityPlayer. So by doing a check for EntityLivingBase you are also checking if it is a EntityPlayer. Then you go on to specifically check for EntityPlayer for no reason because it is included in the instanceof EntityLivingBase. That's not quite correct, or at least not clear enough. Since EntityPlayer extends EntityLivingBase, any instance of EntityPlayer is an instance of EntityLivingBase. The reverse is not true, not all instances of EntityLivingBase are an instance of EntityPlayer. This is why you cannot cast an EntityLivingBase to EntityPlayer, unless you first check that the EntityLivingBase is an instance of EntityPlayer. Yes, my wording on that was not quite right I will amend that right now. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
gurujive Posted November 24, 2016 Author Posted November 24, 2016 So by doing a check for EntityLivingBase you are also checking if it is a EntityPlayer. Then you go on to specifically check for EntityPlayer for no reason because it is included in the instanceof EntityLivingBase. I don't know if its only me, but doing it that way seems to effect the timer and its success to not stick and result in a blank buff icon popping up in the top right of the screen. That's why I do it that way. I have not seen that "bug" myself, could you post a screenshot and the code you get from what I said? I wouldn't be so harsh as to call it a bug, because on recommended 1.10.2 this worked alright. The way it looks on my screen having the potion effects like that makes it look like the icons in the top right are spinning around in a circle and flashing. Now that I recall the same happened on unrecommended 1.10.2 where my icon for instant health stuck. I know that having the internet in the background running or multiple things going at once can cause it to stick too, so its w/e. I aint trippin' bout it. Quote
gurujive Posted November 27, 2016 Author Posted November 27, 2016 Just to update this, after cleaning up all my code and making it look spotless the potion effects are applying right and I have no problem at all. instant health doesn't stick. Quote
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.