z3r0_null Posted September 30, 2013 Share Posted September 30, 2013 I'm writing a mod in which the player can pick up blocks (turning them into EntityFallingSand) and fling them about. I've run into the problem that for some reason I can't seem to override the fact that EntityFallingSand always falls downward, regardless of what I write into my custom class to counteract it. Here is the item that I'm using to pick up blocks: package arcanepower.items; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntitySmallFireball; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; import arcanepower.ArcanePower; import arcanepower.entities.EarthBolt; import arcanepower.lib.ModInfo; import arcanepower.lib.Names; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class EarthWand extends WoodWand { private int targetBlock = -1; private MovingObjectPosition hitEnt; private int ix; private int iy; private int iz; private EarthBolt bolt; public EarthWand(int id) { super(id); setCreativeTab(ArcanePower.tabArcanePower); setUnlocalizedName(Names.earthWand_unlocalizedName); } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister icon) { itemIcon = icon.registerIcon(ModInfo.ID.toLowerCase() + ":" + Names.earthWand_unlocalizedName); } public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10) { if (!world.isRemote) { if (targetBlock == -1) { if (world.getBlockMaterial(x, y, z) == Material.ground || world.getBlockMaterial(x, y, z) == Material.sand || world.getBlockMaterial(x, y, z) == Material.rock || world.getBlockMaterial(x, y, z) == Material.grass) { if (world.getBlockMaterial(x, y, z) == Material.grass) { targetBlock = Block.dirt.blockID; } ix = x; iy = y; iz = z; world.destroyBlock(x, y, z, false); bolt = new EarthBolt(world); bolt.blockID = targetBlock; bolt.metadata = world.getBlockMetadata(x, y, z); bolt.setTar(x + 0.5, y + 4, z + 0.5); bolt.setPosition(x + 0.5, y + 1, z + 0.5); world.spawnEntityInWorld(bolt); } else { System.out.println("Bad block type!"); } } else { float f = 1.0F; float f1 = entityplayer.prevRotationPitch + (entityplayer.rotationPitch - entityplayer.prevRotationPitch) * f; float f2 = entityplayer.prevRotationYaw + (entityplayer.rotationYaw - entityplayer.prevRotationYaw) * f; double d0 = entityplayer.prevPosX + (entityplayer.posX - entityplayer.prevPosX) * (double) f; double d1 = entityplayer.prevPosY + (entityplayer.posY - entityplayer.prevPosY) * (double) f + 1.62D - (double) entityplayer.yOffset; double d2 = entityplayer.prevPosZ + (entityplayer.posZ - entityplayer.prevPosZ) * (double) f; Vec3 vec3 = world.getWorldVec3Pool().getVecFromPool(d0, d1, d2); float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI); float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI); float f5 = -MathHelper.cos(-f1 * 0.017453292F); float f6 = MathHelper.sin(-f1 * 0.017453292F); float f7 = f4 * f5; float f8 = f3 * f5; double d3 = 60.0D; Vec3 vec31 = vec3.addVector((double) f7 * d3, (double) f6 * d3, (double) f8 * d3); hitEnt = world.rayTraceBlocks_do_do(vec3, vec31, false, true); } } return true; } public void onUpdate(ItemStack itemstack, World world, Entity entityplayer, int par4, boolean par5) { if (targetBlock != -1) { if (entityplayer.getDistance(ix, iy, iz) > 10) { System.out.println("Moved out of range, deselecting block."); bolt.setTar(ix, iy, iz); targetBlock = -1; } } } public void throwBolt(EarthBolt bolt, EntityPlayer entityplayer) { float f = 0.4F; bolt.motionX = (double) (-MathHelper.sin(entityplayer.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(entityplayer.rotationPitch / 180.0F * (float) Math.PI) * f); bolt.motionZ = (double) (MathHelper.cos(entityplayer.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(entityplayer.rotationPitch / 180.0F * (float) Math.PI) * f); bolt.motionY = (double) (-MathHelper.sin((entityplayer.rotationPitch) / 180.0F * (float) Math.PI) * f); } } Here is my custom Entity: package arcanepower.entities; import java.util.Random; import net.minecraft.entity.item.EntityFallingSand; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; public class EarthBolt extends EntityFallingSand { private EntityPlayer thrower; private float deltaPitch; private float deltaYaw; private double tarX; private double tarY; private double tarZ; private double deltaX; private double deltaY; private double deltaZ; public float speedMul = 10.0F; public EarthBolt(World world) { super(world); Random rand = new Random(); deltaPitch = -1 + rand.nextFloat() * 2; deltaYaw = -1 + rand.nextFloat() * 2; this.shouldDropItem = true; } @Override public void onUpdate() { Random rand = new Random(); worldObj.spawnParticle("smoke", this.posX - 0.5 + rand.nextDouble(), this.posY - 0.5 + rand.nextDouble(), this.posZ - 0.5 + rand.nextDouble(), 0, 0, 0); this.rotationPitch += deltaPitch; this.rotationYaw += deltaYaw; deltaX = (this.posX - tarX) * speedMul; deltaY = (this.posY - tarY) * speedMul; deltaZ = (this.posZ - tarZ) * speedMul; this.posX += deltaX; this.posY += deltaY; this.posZ += deltaZ; } public void setTar(double x, double y, double z) { tarX = x; tarY = y; tarZ = z; } } Many thanks in advance, I'm totally stumped at this. Quote Link to comment Share on other sites More sharing options...
thebest108 Posted September 30, 2013 Share Posted September 30, 2013 You probably shouldn't extend falling sand class. I would just make a basic entity that isn't affected by gravity, but instead is brought down on command. Rendering a block entity is very simple as it has a pre-made rendering method so you don't have to fiddle around with vectors. Edit: there is a boolean that determines if an entity should passively fall, you can disable it in the earthbolt method. Something like this.shouldFall = false or like this.isNoclip = true Hope this helps Quote "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ Link to comment Share on other sites More sharing options...
z3r0_null Posted September 30, 2013 Author Share Posted September 30, 2013 You probably shouldn't extend falling sand class. I would just make a basic entity that isn't affected by gravity, but instead is brought down on command. Rendering a block entity is very simple as it has a pre-made rendering method so you don't have to fiddle around with vectors. Edit: there is a boolean that determines if an entity should passively fall, you can disable it in the earthbolt method. Something like this.shouldFall = false or like this.isNoclip = true Hope this helps Ah ok, that makes things a bit simpler! Could you provide a little snippet of example code for the rendering? Quote Link to comment Share on other sites More sharing options...
thebest108 Posted September 30, 2013 Share Posted September 30, 2013 Ill see if I can find some Quote "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ Link to comment Share on other sites More sharing options...
z3r0_null Posted September 30, 2013 Author Share Posted September 30, 2013 Ill see if I can find some Thanks now to take a well-earned sleep, I've been hammering away at this mod for about 7 hours solid... Quote Link to comment Share on other sites More sharing options...
thebest108 Posted October 1, 2013 Share Posted October 1, 2013 I found some much more specific code, here package MultiMannedVehichles.Client.Render; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.Render; import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.profiler.Profiler; import net.minecraft.util.AxisAlignedBB; import org.lwjgl.opengl.GL11; import MultiMannedVehichles.Common.Entities.BasicShipEntity; public class RenderBlockEntity extends Render{ @Override public void doRender(Entity var1, double var2, double var4, double var6, float var8, float var9) { Profiler derp = new Profiler(); derp.startSection("MultiMannedVehichles"); RenderBlocks render = new RenderBlocks(var1.worldObj); BasicShipEntity entity = (BasicShipEntity)var1; float brightness =entity.getBrightness(0); Block block = Block.bedrock; //You can set block to be anything by putting some data in the entity GL11.glPushMatrix(); if(entity.Blockid>0){ block = Block.blocksList[entity.Blockid]; } this.loadTexture("/terrain.png"); //this.renderManager.renderEntity(var1, 1); //Block block = entity.block; GL11.glTranslatef((float)var2, (float)var4, (float)var6 ); GL11.glRotatef( entity.rotationYaw, 0.0F, 1.0F, 0.0F) render.renderBlockAsItem(block, entity.BlockMeta, brightness); GL11.glPopMatrix(); derp.endSection(); } } Also far the collision code you could try @Override protected boolean pushOutOfBlocks(double par1, double par3, double par5){ //place a block where the entity is and kill the entity return false; } And to keep it from jittering randomly I recommend to do this.yOffset = this.height / 2.0F; in the constructor method. Quote "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ Link to comment Share on other sites More sharing options...
z3r0_null Posted October 1, 2013 Author Share Posted October 1, 2013 So do I instantiate the above class, or is it instantiated somewhere else in the game code? Quote Link to comment Share on other sites More sharing options...
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.