Grappling hook

Started by KBEHAN on Wed, 12/28/2016 - 21:52

Topic category: Help with MCreator modding

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Grappling hook
Wed, 12/28/2016 - 21:52

Hi, I want to create a grappling hook, this is my code so far:

package mod.mcreator;//based on master condiguration
 
import cpw.mods.fml.client.*;
import cpw.mods.fml.client.registry.*;
import cpw.mods.fml.common.*;
import cpw.mods.fml.common.asm.*;
import cpw.mods.fml.common.asm.transformers.*;
import cpw.mods.fml.common.discovery.*;
import cpw.mods.fml.common.discovery.asm.*;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.functions.*;
import cpw.mods.fml.common.network.*;
import cpw.mods.fml.common.registry.*;
import cpw.mods.fml.common.toposort.*;
import cpw.mods.fml.common.versioning.*;
import cpw.mods.fml.relauncher.*;
import cpw.mods.fml.server.*;
import net.minecraft.block.*;
import net.minecraft.block.material.*;
import net.minecraft.client.*;
import net.minecraft.client.audio.*;
import net.minecraft.client.entity.*;
import net.minecraft.client.gui.*;
import net.minecraft.client.gui.achievement.*;
import net.minecraft.client.gui.inventory.*;
import net.minecraft.client.model.*;
import net.minecraft.client.multiplayer.*;
import net.minecraft.client.particle.*;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.culling.*;
import net.minecraft.client.renderer.entity.*;
import net.minecraft.client.renderer.tileentity.*;
import net.minecraft.client.settings.*;
import net.minecraft.command.*;
import net.minecraft.crash.*;
import net.minecraft.creativetab.*;
import net.minecraft.dispenser.*;
import net.minecraft.enchantment.*;
import net.minecraft.entity.*;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.boss.*;
import net.minecraft.entity.effect.*;
import net.minecraft.entity.item.*;
import net.minecraft.entity.monster.*;
import net.minecraft.entity.passive.*;
import net.minecraft.entity.player.*;
import net.minecraft.entity.projectile.*;
import net.minecraft.inventory.*;
import net.minecraft.item.*;
import net.minecraft.item.crafting.*;
import net.minecraft.nbt.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.*;
import net.minecraft.network.rcon.*;
import net.minecraft.pathfinding.*;
import net.minecraft.potion.*;
import net.minecraft.profiler.*;
import net.minecraft.server.*;
import net.minecraft.server.dedicated.*;
import net.minecraft.server.gui.*;
import net.minecraft.server.integrated.*;
import net.minecraft.server.management.*;
import net.minecraft.src.*;
import net.minecraft.stats.*;
import net.minecraft.tileentity.*;
import net.minecraft.util.*;
import net.minecraft.village.*;
import net.minecraft.world.*;
import net.minecraft.world.biome.*;
import net.minecraft.world.chunk.*;
import net.minecraft.world.chunk.storage.*;
import net.minecraft.world.demo.*;
import net.minecraft.world.gen.*;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.layer.*;
import net.minecraft.world.gen.structure.*;
import net.minecraft.world.storage.*;
import net.minecraftforge.classloading.*;
import net.minecraftforge.client.*;
import net.minecraftforge.client.event.*;
import net.minecraftforge.client.event.sound.*;
import net.minecraftforge.common.*;
import net.minecraftforge.event.*;
import net.minecraftforge.event.entity.*;
import net.minecraftforge.event.entity.item.*;
import net.minecraftforge.event.entity.living.*;
import net.minecraftforge.event.entity.minecart.*;
import net.minecraftforge.event.entity.player.*;
import net.minecraftforge.event.terraingen.*;
import net.minecraftforge.event.world.*;
import net.minecraftforge.oredict.*;
import net.minecraftforge.transformers.*;
import net.minecraft.init.*;
import java.util.*;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
 import org.lwjgl.opengl.GL11;
 import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.EntityFishHook;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Vec3;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import io.netty.buffer.ByteBuf;
 
@SuppressWarnings("unchecked")
public class mcreator_yoYo {

    public static int mobid = 0;
    public Object instance;
 
    public void load(){}
 
    public void generateNether(World world, Random random, int chunkX, int chunkZ){}
    public void generateSurface(World world, Random random, int chunkX, int chunkZ){}
    public int addFuel(ItemStack fuel){
        return 0;
    }
    @SideOnly(Side.CLIENT)
    public void registerRenderers(){
       
        RenderingRegistry.registerEntityRenderingHandler(mcreator_yoYo.EntityyoYo.class, new RenderFish());
    }
 
 
    public void serverLoad(FMLServerStartingEvent event){}
    public void preInit(FMLPreInitializationEvent event){
        int entityID = EntityRegistry.findGlobalUniqueEntityId();
        mobid = entityID;
        EntityRegistry.registerGlobalEntityID(mcreator_yoYo.EntityyoYo.class, "yoYo", entityID);
        EntityRegistry.registerModEntity(mcreator_yoYo.EntityyoYo.class, "yoYo", entityID, instance, 64, 1, true);
       
 
       
    }
 

 
 public static class EntityyoYo extends EntityThrowable implements IEntityAdditionalSpawnData{
 public EntityPlayer field_146042_b;
public EntityyoYo(World par1World, double par2, double par4, double par6)
{
super(par1World, par2, par4, par6);
}
public EntityyoYo(World par1World, EntityLivingBase par2EntityLivingBase)
{
super(par1World, par2EntityLivingBase);
}
public EntityyoYo(World par1World)
{
super(par1World);
}
public EntityyoYo(World par1World, EntityLivingBase par2EntityLivingBase, EntityPlayer player)
{
super(par1World, par2EntityLivingBase);
this.field_146042_b = player;
}
/**
 * Called when this EntityThrowable hits a block or entity.
 */
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
    {
        if (par1MovingObjectPosition.entityHit != null)
        {
            byte b0 = 18;          
 
            par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)b0);
        }
 
        if (!this.worldObj.isRemote)
        {
            this.setDead();
        }
    }
    public void writeSpawnData(ByteBuf data)
    {
     data.writeInt(this.field_146042_b != null ? this.field_146042_b.getEntityId() : 0);
    }

    public void readSpawnData(ByteBuf data)
    {
     this.field_146042_b = (EntityPlayer)this.worldObj.getEntityByID(data.readInt());
    }
 
public void interactEvent(EntityInteractEvent event){
if(event.target instanceof EntityCreature){
int entityID = EntityList.getEntityID(event.target);
ItemStack currentItem = event.entityPlayer.inventory.getCurrentItem();
if(currentItem != null){
     if(currentItem == new ItemStack( mcreator_amethystsWhip.block, 1) && currentItem.getItemDamage() == 0){
     event.target.setDead();
     currentItem.setItemDamage(entityID);
     }
}
}
}
 
 
}
 
 
@SideOnly(Side.CLIENT)
public static class RenderFish extends Render
{
    private static final ResourceLocation field_110792_a = new ResourceLocation("textures/particle/particles.png");
    private static final String __OBFID = "CL_00000996";

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
     */
    public void doRender(Entitywhip p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)
    {
        GL11.glPushMatrix();
        GL11.glTranslatef((float)p_76986_2_, (float)p_76986_4_, (float)p_76986_6_);
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glScalef(0.5F, 0.5F, 0.5F);
        this.bindEntityTexture(p_76986_1_);
        Tessellator tessellator = Tessellator.instance;
        byte b0 = 1;
        byte b1 = 2;
        float f2 = (float)(b0 * 8 + 0) / 128.0F;
        float f3 = (float)(b0 * 8 + 8) / 128.0F;
        float f4 = (float)(b1 * 8 + 0) / 128.0F;
        float f5 = (float)(b1 * 8 + 8) / 128.0F;
        float f6 = 1.0F;
        float f7 = 0.5F;
        float f8 = 0.5F;
        GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 1.0F, 0.0F);
        tessellator.addVertexWithUV((double)(0.0F - f7), (double)(0.0F - f8), 0.0D, (double)f2, (double)f5);
        tessellator.addVertexWithUV((double)(f6 - f7), (double)(0.0F - f8), 0.0D, (double)f3, (double)f5);
        tessellator.addVertexWithUV((double)(f6 - f7), (double)(1.0F - f8), 0.0D, (double)f3, (double)f4);
        tessellator.addVertexWithUV((double)(0.0F - f7), (double)(1.0F - f8), 0.0D, (double)f2, (double)f4);
        tessellator.draw();
        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
        GL11.glPopMatrix();

        if (p_76986_1_.field_146042_b != null)
        {
            float f9 = p_76986_1_.field_146042_b.getSwingProgress(p_76986_9_);
            float f10 = MathHelper.sin(MathHelper.sqrt_float(f9) * (float)Math.PI);
            Vec3 vec3 = Vec3.createVectorHelper(-0.5D, 0.03D, 0.8D);
            vec3.rotateAroundX(-(p_76986_1_.field_146042_b.prevRotationPitch + (p_76986_1_.field_146042_b.rotationPitch - p_76986_1_.field_146042_b.prevRotationPitch) * p_76986_9_) * (float)Math.PI / 180.0F);
            vec3.rotateAroundY(-(p_76986_1_.field_146042_b.prevRotationYaw + (p_76986_1_.field_146042_b.rotationYaw - p_76986_1_.field_146042_b.prevRotationYaw) * p_76986_9_) * (float)Math.PI / 180.0F);
            vec3.rotateAroundY(f10 * 0.5F);
            vec3.rotateAroundX(-f10 * 0.7F);
            double d3 = p_76986_1_.field_146042_b.prevPosX + (p_76986_1_.field_146042_b.posX - p_76986_1_.field_146042_b.prevPosX) * (double)p_76986_9_ + vec3.xCoord;
            double d4 = p_76986_1_.field_146042_b.prevPosY + (p_76986_1_.field_146042_b.posY - p_76986_1_.field_146042_b.prevPosY) * (double)p_76986_9_ + vec3.yCoord;
            double d5 = p_76986_1_.field_146042_b.prevPosZ + (p_76986_1_.field_146042_b.posZ - p_76986_1_.field_146042_b.prevPosZ) * (double)p_76986_9_ + vec3.zCoord;
            double d6 = p_76986_1_.field_146042_b == Minecraft.getMinecraft().thePlayer ? 0.0D : (double)p_76986_1_.field_146042_b.getEyeHeight();

            if (this.renderManager.options.thirdPersonView > 0 || p_76986_1_.field_146042_b != Minecraft.getMinecraft().thePlayer)
            {
                float f11 = (p_76986_1_.field_146042_b.prevRenderYawOffset + (p_76986_1_.field_146042_b.renderYawOffset - p_76986_1_.field_146042_b.prevRenderYawOffset) * p_76986_9_) * (float)Math.PI / 180.0F;
                double d7 = (double)MathHelper.sin(f11);
                double d9 = (double)MathHelper.cos(f11);
                d3 = p_76986_1_.field_146042_b.prevPosX + (p_76986_1_.field_146042_b.posX - p_76986_1_.field_146042_b.prevPosX) * (double)p_76986_9_ - d9 * 0.35D - d7 * 0.85D;
                d4 = p_76986_1_.field_146042_b.prevPosY + d6 + (p_76986_1_.field_146042_b.posY - p_76986_1_.field_146042_b.prevPosY) * (double)p_76986_9_ - 0.45D;
                d5 = p_76986_1_.field_146042_b.prevPosZ + (p_76986_1_.field_146042_b.posZ - p_76986_1_.field_146042_b.prevPosZ) * (double)p_76986_9_ - d7 * 0.35D + d9 * 0.85D;
            }

            double d14 = p_76986_1_.prevPosX + (p_76986_1_.posX - p_76986_1_.prevPosX) * (double)p_76986_9_;
            double d8 = p_76986_1_.prevPosY + (p_76986_1_.posY - p_76986_1_.prevPosY) * (double)p_76986_9_ + 0.25D;
            double d10 = p_76986_1_.prevPosZ + (p_76986_1_.posZ - p_76986_1_.prevPosZ) * (double)p_76986_9_;
            double d11 = (double)((float)(d3 - d14));
            double d12 = (double)((float)(d4 - d8));
            double d13 = (double)((float)(d5 - d10));
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glDisable(GL11.GL_LIGHTING);
            tessellator.startDrawing(3);
            tessellator.setColorOpaque_I(0);
            byte b2 = 16;

            for (int i = 0; i <= b2; ++i)
            {
                float f12 = (float)i / (float)b2;
                tessellator.addVertex(p_76986_2_ + d11 * (double)f12, p_76986_4_ + d12 * (double)(f12 * f12 + f12) * 0.5D + 0.25D, p_76986_6_ + d13 * (double)f12);
            }

            tessellator.draw();
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glEnable(GL11.GL_TEXTURE_2D);
        }
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(Entitywhip p_110775_1_)
    {
        return field_110792_a;
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(Entity p_110775_1_)
    {
        return this.getEntityTexture((Entitywhip)p_110775_1_);
    }

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
     */
    public void doRender(Entity p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)
    {
        this.doRender((Entitywhip)p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_);
    }
}
 
public static class ModelWhip extends ModelBase
{
  //fields
    ModelRenderer whip;
 
  public ModelWhip()
  {
    textureWidth = 64;
    textureHeight = 32;
   
      whip = new ModelRenderer(this, 2, 1);
      whip.addBox(0F, 0F, 0F, 1, 0, 16);
      whip.setRotationPoint(-5F, 16F, -23F);
      whip.setTextureSize(64, 32);
      whip.mirror = true;
      setRotation(whip, 0F, 0F, 0F);
  }
 
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
   
    whip.render(f5);
  }
 
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
 
 
 
 
}
}

 

 

 

 

 

So, in the impact part I want it to be so where entity hits block player is telaported there.

Can anyone help?

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
I'm pretty sure I need
Sun, 01/01/2017 - 00:30

I'm pretty sure I need EntityLivingBase#setPositionAndUpdate in the code.  Not sure how to have it and have code that does damage to entity.

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Hmm, I'm trying to look
Sat, 01/14/2017 - 14:53

Hmm, I'm trying to look everwhere and I can't find anything.  I just need simple mechanic of when the entity hits a block it teleports player.  This should all be coded in OnImpact? or it should need entity update? I am not sure.

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
I'm not really sure what code
Mon, 01/16/2017 - 17:49

I'm not really sure what code to put in.

will this work?

@Override
    protected void onImpact(MovingObjectPosition mop) {
        if (mop.typeOfHit == MovingObjectType.BLOCK && getTarget() == null) {
            Block block = worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ);
            if (!block.getMaterial().blocksMovement()) {
                return;
            }
            if (block.getMaterial() != Material.air) {
                block.onEntityCollidedWithBlock(worldObj, mop.blockX, mop.blockY, mop.blockZ, this);
            }
            if (!isInGround() && ticksExisted < getMaxDistance()) {
                motionX = motionY = motionZ = 0.0D;
                if (canGrabBlock(block, mop.blockX, mop.blockY, mop.blockZ, mop.sideHit)) {
                    setInGround(true);
                    // adjusting posX/Y/Z here seems to make no difference to the rendering, even when client side makes same changes
                    posX = (double) mop.blockX + 0.5D;
                    posY = (double) mop.blockY + 0.5D;
                    posZ = (double) mop.blockZ + 0.5D;
                    // side hit documentation is wrong!!! based on printing out mop.sideHit:
                    // 2 = NORTH (face of block), 3 = SOUTH, 4 = WEST, 5 = EAST, 0 = BOTTOM, 1 = TOP
                    switch(mop.sideHit) {
                    case 5: posX += 0.5D; break; // EAST
                    case 4: posX -= 0.515D; break; // WEST (a little extra to compensate for block border, otherwise renders black)
                    case 3: posZ += 0.5D; break; // SOUTH
                    case 2: posZ -= 0.515D; break; // NORTH (a little extra to compensate for block border, otherwise renders black)
                    case SideHit.TOP: posY = mop.blockY + 1.0D; break;
                    case SideHit.BOTTOM: posY = mop.blockY; break;
                    }
                    // however, setting position as watched values and using these on the client works... weird
                    dataWatcher.updateObject(HIT_POS_X, (float) posX);
                    dataWatcher.updateObject(HIT_POS_Y, (float) posY);
                    dataWatcher.updateObject(HIT_POS_Z, (float) posZ);
                } else if (!worldObj.isRemote) {
                    if (canDestroyBlock(block, mop.blockX, mop.blockY, mop.blockZ, mop.sideHit)) {
                        worldObj.func_147480_a(mop.blockX, mop.blockY, mop.blockZ, false);
                    }
                    setDead();
                    }
                }
}

@Override
    public void onUpdate() {
        // Added DataWatcher to track inGround separately from EntityThrowable, and
        // avoid the super.onUpdate if the hookshot is in the ground; not sure what
        // changed from 1.6.4, but EntityThrowable's onUpdate is no longer working
        // acceptably for the Hookshot
        if (isInGround()) {
            super.onEntityUpdate();
        } else {
            super.onUpdate();
        }
        if (canUpdate()) {
            if ((ticksExisted > getMaxDistance() && !isInGround() && getTarget() == null) || ticksExisted > (getMaxDistance() * 8)) {
                if (worldObj.isRemote && getThrower() instanceof EntityPlayer && Config.enableHookshotSound) {
                    ((EntityPlayer) getThrower()).playSound(Sounds.WOOD_CLICK, 1.0F, 1.0F);
                }
                setDead();
            } else if (getTarget() != null) {
                pullTarget();
            } else {
                pullThrower();
            }
        } else {
            setDead();
        }
    }

 

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
Because this exact code comes
Mon, 01/16/2017 - 18:22

Because this exact code comes from someone else's mod , yes , this code is able to work.

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:Because this exact code comes
Mon, 01/16/2017 - 18:26

@#4

 

I got these errors, I am also not sure if the code I added to my code is enough or I need more parts

 

 

>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_yoyo.java:246: error: ';' expected
>    public void onUpdate() {
>                        ^
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_yoyo.java:273: error: illegal start of expression
>public void interactEvent(EntityInteractEvent event){
>^
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_yoyo.java:273: error: illegal start of expression
>public void interactEvent(EntityInteractEvent event){
>       ^
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_yoyo.java:273: error: ';' expected
>public void interactEvent(EntityInteractEvent event){
>                         ^
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_yoyo.java:273: error: ';' expected
>public void interactEvent(EntityInteractEvent event){
>                                                   ^
>5 errors

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
You defintelly did not copied
Mon, 01/16/2017 - 18:44

You defintelly did not copied enough. As I stated many times , it is not good to just mindless copy code from GitHub. Yes , these sites , in case that it is allowed in theit license (this specific mod it has allowed) , are good for educational purposes , but not for copying.
And also in case you copy some code , at least check if you have correct brackets.

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:You defintelly did not copied
Mon, 01/16/2017 - 18:56

@#5

I can start from scratch.  Using only the code that you gave me for the fish hook/line entity.  But I wouldn't kno what code to put n

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:You defintelly did not copied
Mon, 01/16/2017 - 19:32

@#5

Other idea I had was for ender teleport event.  I am not sure if It would work

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
Start is somehow write "the
Mon, 01/16/2017 - 20:03

Start is somehow write "the code in words"
So let's say you want something like
"If the entity is collided with any blocks , stops any motion.
Then , if the player right clicks , it moves him towards the entity and also kills the entity"

Now if you have something like this , is good have some imagination where roughtly you will handle this. Because there is possibility that some player/mob can destroy meanwhile the block that it is attached to it , it is better handle the motion in toUpdate();
The item right click is suprisingly handled in item right click :D

It is fine to look in someone else's code and look for some part that you really need for it
(For example storing the thrower , for this you actually need use NBTtags),but it is not recommended copy whole methods(in case that it is not something generic)

So pseudocode can be something like:
ITEM:

public static class ItemHook extends Item{

 

public ItemHook(){

}

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
 if (!par2World.isRemote)
            {

 if (ipar1ItemStack.getTagCompound() == null)
        {
            par1ItemStack.setTagCompound(new NBTTagCompound());
            
        }

EntityHook hook = par2World.getEntityByID(par1ItemStack.getTagCompound().getInteger("hook));
if(hook == null){
hook = new EntityHook(par2World,par3EntityPlayer);

par1ItemStack.getTagCompound().setInteger("hook,hook.getEntityId());

par2World.spawnEntityInWorld(hook);
}else{
if(hookis.Collided){
      double X = par3EntityPlayer.posX - hook.posX;
                double Y = hook.posY+1.5D - par3EntityPlayer.posY;
                double Z = par3EntityPlayer.posZ - hook.posZ;
                double D = Math.atan2(Z, X);
                double S = 1F / hook.getDistanceToEntity(par3EntityPlayer) * 0.5;
                
                 hook.motionX = Math.cos(D) * S;
                if (Y<0)
                {
                    hook.motionY += S;
                }
                hook.motionZ = Math.sin(D) * S;
}
}
}

}
return par1ItemStack;

}

ENTITY:

public static class EntityHook extends EntityThrowable{

public EntityHook(World world , Entity entity){
}
//SOME MORE STUFF

 

  public void onUpdate()
    {
       
            super.onUpdate();

if(this.isCollided){
this.motionX = 0d;

this.motionY = 0d;

this.motionZ = 0d;
}
}
}

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:Start is somehow write "the
Mon, 01/16/2017 - 20:56

@#6

par2World.getEntityByID(par1ItemStack.getTagCompound().getInteger("hook));
if(hook == null){
hook = new EntityHook(par2World,par3EntityPlayer);

par1ItemStack.getTagCompound().setInteger("hook,hook.getEntityId());

par2World.spawnEntityInWorld(hook);
}else{
if(hookis.Collided){
      double X = par3EntityPlayer.posX - hook.posX;
                double Y = hook.posY+1.5D - par3EntityPlayer.posY;
                double Z = par3EntityPlayer.posZ - hook.posZ;
                double D = Math.atan2(Z, X);
                double S = 1F / hook.getDistanceToEntity(par3EntityPlayer) * 0.5;
                
                 hook.motionX = Math.cos(D) * S;
                if (Y<0)
                {
                    hook.motionY += S;
                }
                hook.motionZ = Math.sin(D) * S;
}
}
}

}
return par1ItemStack;

}

 

can go in onImpact?