Jump to content

tlr38usd

Members
  • Posts

    93
  • Joined

  • Last visited

Everything posted by tlr38usd

  1. I have an entity that only renders on the client it was created on. I would like it to render on all the players clients but im not sure how. The entity is a projectile similar to an arrow.
  2. It seems every mod registers their entities with EntityRegistry.registerModEntity. Is there any way to access all the registered mobs? I would like to make it so that I could use a string, say "Cobra", and it gets me a mod entity named "Cobra"
  3. Ok, can someone please tell me how to use packets? I've been told they're very easy to do and almost every problem I've encountered in my modding adventures seems to be fixable by packets, but I have no idea how to use them and the post on the wiki is unhelpful. If someone could slowly walk my through them I would be very much appreciative.
  4. It's not an entity living either =P Just a plain entity. It's a projectile that renders as it's itemstack and when the player collides they pick up that itemstack.
  5. It's not a tile entity though =P Just plain entity. Is there anything like it for them?
  6. I have an entity that stores an itemstack in nbt and when it renders it uses that stack. However, when I unload and reload the world, the read/write to nbt is only called server side so according to the entity it's stack is null and it doesn't render. How would I fix this?
  7. isBookEnchantable doesn't activate at all unless the item ID is the enchanted book idea, looked at the source =/
  8. Thank you! I will definitely look at that =D I had seen the event before but had no idea how it was used. Now I do, sort of, we'll see =D
  9. but after x amount of ticks, not after world load / unload, I'll try removing it though. A lot of the code is take from EntityArrow.
  10. I had played around a bit with the whole bitflag system before and had a really crude setup created for potions. I'd like to find a better way though because as far as I know there are only so many combinations. I'll look at isBookEnchantable for the anvil.
  11. package TuxWeapons.TuxCraft.entity; import java.util.Iterator; import java.util.List; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IProjectile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; import TuxWeapons.TuxCraft.Assets; import TuxWeapons.TuxCraft.DamageModifier; import TuxWeapons.TuxCraft.DamageSourceWeapon; import TuxWeapons.TuxCraft.TuxWeaponsCore; import TuxWeapons.TuxCraft.item.ItemWeapon; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class EntitySpear extends Entity implements IProjectile { private int xTile = -1; private int yTile = -1; private int zTile = -1; private int inTile = 0; private int inData = 0; private boolean inGround = false; public int canBePickedUp = 0; public int arrowShake = 0; public Entity owner; private int ticksInGround; private int ticksInAir = 0; private ItemStack stack; public EntitySpear(World world) { super(world); this.setSize(0.5F, 0.5F); } public EntitySpear(World world, double x, double y, double z) { super(world); this.setSize(0.5F, 0.5F); this.setPosition(x, y, z); this.yOffset = 0.0F; } public EntitySpear(World world, EntityLivingBase thrower, EntityLivingBase target, float par4, float par5) { super(world); this.owner = thrower; if (owner instanceof EntityPlayer) { this.canBePickedUp = 1; } this.posY = owner.posY + owner.getEyeHeight() - 0.10000000149011612D; double var6 = target.posX - owner.posX; double var8 = target.posY + target.getEyeHeight() - 0.699999988079071D - this.posY; double var10 = target.posZ - owner.posZ; double var12 = MathHelper.sqrt_double(var6 * var6 + var10 * var10); if (var12 >= 1.0E-7D) { float var14 = (float) (Math.atan2(var10, var6) * 180.0D / Math.PI) - 90.0F; float var15 = (float) -(Math.atan2(var8, var12) * 180.0D / Math.PI); double var16 = var6 / var12; double var18 = var10 / var12; this.setLocationAndAngles(owner.posX + var16, this.posY, owner.posZ + var18, var14, var15); this.yOffset = 0.0F; float var20 = (float) var12 * 0.2F; this.setThrowableHeading(var6, var8 + var20, var10, par4, par5); } } public EntitySpear(World world, EntityLivingBase living, float charge, ItemStack item) { super(world); this.owner = living; if (owner instanceof EntityPlayer) { this.canBePickedUp = 1; } this.setSize(0.5F, 0.5F); this.setLocationAndAngles(owner.posX, owner.posY + owner.getEyeHeight(), owner.posZ, owner.rotationYaw, owner.rotationPitch); this.posX -= MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI) * 0.16F; this.posY -= 0.10000000149011612D; this.posZ -= MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI) * 0.16F; this.setPosition(this.posX, this.posY, this.posZ); this.yOffset = 0.0F; this.motionX = -MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float) Math.PI); this.motionZ = MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float) Math.PI); this.motionY = -MathHelper.sin(this.rotationPitch / 180.0F * (float) Math.PI); this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, charge * 1.5F, 1.0F); this.stack = item; } @Override protected void entityInit() { this.dataWatcher.addObject(16, Byte.valueOf((byte) 0)); } @Override public void setThrowableHeading(double motX, double motY, double motZ, float var7, float var8) { float var9 = MathHelper.sqrt_double(motX * motX + motY * motY + motZ * motZ); motX /= var9; motY /= var9; motZ /= var9; motX += this.rand.nextGaussian() * 0.007499999832361937D * var8; motY += this.rand.nextGaussian() * 0.007499999832361937D * var8; motZ += this.rand.nextGaussian() * 0.007499999832361937D * var8; motX *= var7; motY *= var7; motZ *= var7; this.motionX = motX; this.motionY = motY; this.motionZ = motZ; float var10 = MathHelper.sqrt_double(motX * motX + motZ * motZ); this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(motX, motZ) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(motY, var10) * 180.0D / Math.PI); this.ticksInGround = 0; } @Override @SideOnly(Side.CLIENT) public void setPositionAndRotation(double posX, double posY, double posZ, float pitch, float yaw) { this.setPosition(posX, posY, posZ); this.setRotation(pitch, yaw); } @Override @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 var7 = MathHelper.sqrt_double(x * x + z * z); this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(x, z) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(y, var7) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch; this.prevRotationYaw = this.rotationYaw; this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); this.ticksInGround = 0; } } @Override public void onUpdate() { super.onUpdate(); if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float var1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(this.motionY, var1) * 180.0D / Math.PI); } int id = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); if (id > 0) { Block.blocksList[id].setBlockBoundsBasedOnState(this.worldObj, this.xTile, this.yTile, this.zTile); AxisAlignedBB collisionBox = Block.blocksList[id].getCollisionBoundingBoxFromPool(this.worldObj, this.xTile, this.yTile, this.zTile); if (collisionBox != null && collisionBox.isVecInside(this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ))) { this.inGround = true; } } if (this.arrowShake > 0) { --this.arrowShake; } if (this.inGround) { int blockID = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); int meta = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile); if (blockID == this.inTile && meta == this.inData) { ++this.ticksInGround; if (this.ticksInGround == 1200) { this.setDead(); } } else { this.inGround = false; this.motionX *= this.rand.nextFloat() * 0.2F; this.motionY *= this.rand.nextFloat() * 0.2F; this.motionZ *= this.rand.nextFloat() * 0.2F; this.ticksInGround = 0; this.ticksInAir = 0; } } else { ++this.ticksInAir; Vec3 var17 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ); Vec3 var3 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition pos = this.worldObj.rayTraceBlocks_do_do(var17, var3, false, true); var17 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ); var3 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (pos != null) { var3 = this.worldObj.getWorldVec3Pool().getVecFromPool(pos.hitVec.xCoord, pos.hitVec.yCoord, pos.hitVec.zCoord); } Entity entity = null; List targets = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D)); double var7 = 0.0D; Iterator iter = targets.iterator(); float range; while (iter.hasNext()) { Entity target = (Entity) iter.next(); if (target.canBeCollidedWith() && (target != this.owner || this.ticksInAir >= 5)) { range = 0.3F; AxisAlignedBB var12 = target.boundingBox.expand(range, range, range); MovingObjectPosition pos2 = var12.calculateIntercept(var17, var3); if (pos2 != null) { double distance = var17.distanceTo(pos2.hitVec); if (distance < var7 || var7 == 0.0D) { entity = target; var7 = distance; } } } } if (entity != null) { pos = new MovingObjectPosition(entity); } float var20; if (pos != null) { if (pos.entityHit != null) { var20 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); DamageSource source = null; if (this.owner == null) { source = new DamageSourceWeapon(TuxWeaponsCore.modid + ":" + "spear" + ".spearThrow", pos.entityHit, null); } else { source = new DamageSourceWeapon(TuxWeaponsCore.modid + ":" + "spear" + ".spearThrow", pos.entityHit, owner); } if (pos.entityHit instanceof EntityLivingBase) { if (this.isBurning()) { pos.entityHit.setFire(5); } this.worldObj.playSoundAtEntity(this, "random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F - 0.0F)); this.motionX *= -0.10000000149011612D; this.motionY *= -0.10000000149011612D; this.motionZ *= -0.10000000149011612D; this.rotationYaw += 180.0F; this.prevRotationYaw += 180.0F; float damageDealt = 0; if(stack != null) { damageDealt = (float) (DamageModifier.getModifiedDamage((4 + (ItemWeapon.getWeaponMat(stack).getDamage())), stack, entity, this)); } if(damageDealt != 0) pos.entityHit.attackEntityFrom(source, damageDealt); } else { this.motionX *= -0.10000000149011612D; this.motionY *= -0.10000000149011612D; this.motionZ *= -0.10000000149011612D; this.rotationYaw += 180.0F; this.prevRotationYaw += 180.0F; this.ticksInAir = 0; } } else { this.xTile = pos.blockX; this.yTile = pos.blockY; this.zTile = pos.blockZ; this.inTile = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); this.inData = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile); this.motionX = (float) (pos.hitVec.xCoord - this.posX); this.motionY = (float) (pos.hitVec.yCoord - this.posY); this.motionZ = (float) (pos.hitVec.zCoord - this.posZ); var20 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); this.posX -= this.motionX / var20 * 0.05000000074505806D; this.posY -= this.motionY / var20 * 0.05000000074505806D; this.posZ -= this.motionZ / var20 * 0.05000000074505806D; this.worldObj.playSoundAtEntity(this, "random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F - 0.0F)); this.inGround = true; this.arrowShake = 7; this.setIsCritical(false); } } if (this.getIsCritical()) { for (int var21 = 0; var21 < 4; ++var21) { this.worldObj.spawnParticle("crit", this.posX + this.motionX * var21 / 4.0D, this.posY + this.motionY * var21 / 4.0D, this.posZ + this.motionZ * var21 / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ); } } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; var20 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); for (this.rotationPitch = (float) (Math.atan2(this.motionY, var20) * 180.0D / 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 var23 = 0.99F; range = 0.05F; if (this.isInWater()) { for (int var26 = 0; var26 < 4; ++var26) { float var27 = 0.25F; this.worldObj.spawnParticle("bubble", this.posX - this.motionX * var27, this.posY - this.motionY * var27, this.posZ - this.motionZ * var27, this.motionX, this.motionY, this.motionZ); } var23 = 0.8F; } this.motionX *= var23; this.motionY *= var23; this.motionZ *= var23; this.motionY -= range; this.setPosition(this.posX, this.posY, this.posZ); this.doBlockCollisions(); } } @Override public void writeEntityToNBT(NBTTagCompound nbtTag) { nbtTag.setShort("xTile", (short) this.xTile); nbtTag.setShort("yTile", (short) this.yTile); nbtTag.setShort("zTile", (short) this.zTile); nbtTag.setByte("inTile", (byte) this.inTile); nbtTag.setByte("inData", (byte) this.inData); nbtTag.setByte("shake", (byte) this.arrowShake); nbtTag.setByte("inGround", (byte) (this.inGround ? 1 : 0)); nbtTag.setByte("pickup", (byte) this.canBePickedUp); nbtTag.setCompoundTag("stack", stack.writeToNBT(new NBTTagCompound())); } @Override public void readEntityFromNBT(NBTTagCompound nbtTag) { this.xTile = nbtTag.getShort("xTile"); this.yTile = nbtTag.getShort("yTile"); this.zTile = nbtTag.getShort("zTile"); this.inTile = nbtTag.getByte("inTile") & 255; this.inData = nbtTag.getByte("inData") & 255; this.arrowShake = nbtTag.getByte("shake") & 255; this.inGround = nbtTag.getByte("inGround") == 1; this.stack.readFromNBT(nbtTag.getCompoundTag("stack")); } public ItemStack getStack() { return stack; } @Override public void onCollideWithPlayer(EntityPlayer player) { if (this.inGround && this.arrowShake <= 0) { if (!this.worldObj.isRemote) { if (player.capabilities.isCreativeMode != true) { player.inventory.addItemStackToInventory(stack); this.setDead(); this.kill(); this.isDead = true; } else { this.setDead(); this.kill(); this.isDead = true; } } if (this.worldObj.isRemote) { this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); player.onItemPickup(this, 1); this.setDead(); this.kill(); this.isDead = true; } } } @Override protected boolean canTriggerWalking() { return false; } @Override @SideOnly(Side.CLIENT) public float getShadowSize() { return 0.0F; } @Override public boolean canAttackWithItem() { return true; } public void setIsCritical(boolean b) { byte var2 = this.dataWatcher.getWatchableObjectByte(16); if (b) { this.dataWatcher.updateObject(16, Byte.valueOf((byte) (var2 | 1))); } else { this.dataWatcher.updateObject(16, Byte.valueOf((byte) (var2 & -2))); } } public boolean getIsCritical() { byte var1 = this.dataWatcher.getWatchableObjectByte(16); return (var1 & 1) != 0; } } I put this register in the core mod file EntityRegistry.registerModEntity(EntitySpear.class, "spear", 1, this, 128, 1, true); And this in the client proxy RenderingRegistry.registerEntityRenderingHandler(EntitySpear.class, new RenderSpear());
  12. Is there a way to add anvil/potion recipes? For instance if I wanted to add an anvil recipe where a weapon plus an emerald gives it an emerald upgrade. Or for the brewing stand, a water bottle plus a melon yields a melon drink etc.
  13. Yes it ceases to exist. So when I reload the chunk it's not there.
  14. Is there anyway to save the entity then? I know when you spawn a zombie for instance and give it a name it won't despawn. Or even after you unload the game the zombie will still try to kill you when you reload. It seems like there should be a simple fix, but I'm not sure about it.
  15. Any entity I make that does not extend EntityLiving from seems to despawn from the game whenever I unload the world / chunk. I have a lot of important technical entities so this is a big problem that I'm not sure how to solve.
  16. Here's the setup, I'm making weapons of all different tiers, gold, iron, diamond etc. and I wanted to have mod support so other people could add there own weapon types, copper, bronze, tin etc. These weapons are textured weird, they use overlays & colors. I was getting complaints from resource packers that the textures limited their options when texturing my mod. As a resource pack user myself I didn't want to upset them. So what I did is each weapon material has it's own instance WeaponMaterial.stone, WeaponMaterial.iron etc. In each one of those instances I stored a list of possible icons and in the render file I had it check whether these icons existed in the current resource pack. If it returned true it would get the correct icon from the list and display it. To you this may seem like an obvious solution, but to me, a relatively new modder, this was a ground breaking discovery. If you want to see the code and laugh at me for it, here's the github link =P https://github.com/TuxCraft/TuxWeapons
  17. nvm , it was necessary for it to be in the item class. =D My idea worked, would you like to hear it?
  18. Is there a way to access the register icons class that's not in an item or a block? Theoretically my idea could work in an item/block but it's not the optimal solution.
  19. Well they'd be registered dynamically at startup. I'd check what mods were in the mods folder then add (maybe delete wasn't the best word) all the icons it needs. I'd rather not make a new icon for all the mods I plan to support. I actually have an idea, it's a little tough to explain though =P
  20. I would like to add mod support though so the icon amounts will be dynamic. Is there a way to dynamically create / delete icons at any given time? Also could I'm using a custom renderer, would there be a way to make it work with that?
  21. I have an itemstack that needs to have different textures depending on nbt data, for example, an item with an nbt value of "wood" would have a "item_wood" texture while an itemstack with nbt value of "fire" would have a "item_fire" texture. I would also like this to be modular so I don't want to make a bunch of icons in the iconRegister method. What would be the best way to do this?
  22. I figured that would be the problem. The thing is I don't know how to use packets. Everyone I've talked to says there easy, but no one has ever told me how to do it myself and the tutorial on the forums doesn't make sense
  23. I have an entity that uses a Random to decide where it should move. It appears as if they are desynced from server to client. How would I go about syncing the client with the server?
  24. yes, it is a flying entity, it's more of a technical entity then anything else. I overrid it and deleted everything inside, but it still really likes to stop moving when colliding with a block.
  25. How do I make an entity that can move through blocks, like a ghost
×
×
  • Create New...

Important Information

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