help with code

Started by KBEHAN on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
help with code
Mon, 01/02/2017 - 22:05 (edited)

Hi I need help.  This code is for 1.8 but can I use it for 1.7.10 for my entity throwable?

https://s24.postimg.org/uk3y88dhh/Code.png

Edited by KBEHAN on Mon, 01/02/2017 - 22:05
Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
this is my code:
Mon, 01/02/2017 - 21:14

this is my code:

/**
 * Called when this EntityThrowable hits a block or entity.
 */
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
{
    if (movingobjectPos.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)    
    {    
       Block block = this.worldObj.getBlockState(movingobjectPos.func_178782_a()).getBlock();
        
      if(block == Blocks.tallgrass || block == Blocks.vine || block == Blocks.red_flower || block == Blocks.yellow_flower || block == Blocks.brown_mushroom_block ||   
         block == Blocks.red_mushroom || block == Blocks.reeds || block == Blocks.double_plant || block == Blocks.deadbush || block == Blocks.brown_mushroom ||
         block == Blocks.wheat || block == Blocks.waterlily || block == Blocks.carrots || block == Blocks.potatoes || block == Blocks.snow_layer)
    {    
          BlockPos blockpos = movingobjectPos.func_178782_a();
          IBlockState blockstate = this.worldobj.getBlockState(blockpos);
          Tileentity te + this.worldObj.getTileEntity(blockpos);
          if(this.getThrower() instanceof EntityPlayer) // if the thrower is a player
                {
                    EntityPlayer player = (EntityPlayer)this.getThrower();
                    this.worldObj.destroyBlock(blockpos, false);
                    block.harvestBlock(this.worldObj, player, blockpos, blockstate, te);   
                }
    }
    else    
      
        this.setDead();  
    }
        
        if (par1MovingObjectPosition.entityHit != null)
        {
            byte b0 = 54;          
 
            par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)b0);
        }
 
        if (!this.worldObj.isRemote)
        {
            this.setDead();
        }
    }
}
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_stevensShield.block, 1) && currentItem.getItemDamage() == 0){
     event.target.setDead();
     currentItem.setItemDamage(entityID);
     }
}
}
}}

 

Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I get this error>Executing
Mon, 01/02/2017 - 21:15

I get this error>Executing gradle command: build
>****************************
> Powered By MCP:            
> http://modcoderpack.com/   
> Searge, ProfMobius, Fesh0r,
> R4wk, ZeuX, IngisKahn, bspkrs
> MCP Data version : unknown
>****************************
>:compileApiJava UP-TO-DATE
>:processApiResources UP-TO-DATE
>:apiClasses UP-TO-DATE
>:sourceMainJava
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:162: error: ';' expected
>          Tileentity te + this.worldObj.getTileEntity(blockpos);
>                       ^
>1 error
>:compileJava FAILED

Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok, so I figured out why it
Mon, 01/02/2017 - 22:08

Ok, so I figured out why it was wrong, so I fixed the + to =.  But now I get these errors:/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:152: error: cannot find symbol
>    if (movingobjectPos.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)   
>        ^
>  symbol:   variable movingobjectPos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:154: error: cannot find symbol
>       Block block = this.worldObj.getBlockState(movingobjectPos.func_178782_a()).getBlock();
>                                                 ^
>  symbol:   variable movingobjectPos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:160: error: cannot find symbol
>          BlockPos blockpos = movingobjectPos.func_178782_a();
>          ^
>  symbol:   class BlockPos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:160: error: cannot find symbol
>          BlockPos blockpos = movingobjectPos.func_178782_a();
>                              ^
>  symbol:   variable movingobjectPos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:161: error: cannot find symbol
>          IBlockState blockstate = this.worldobj.getBlockState(blockpos);
>          ^
>  symbol:   class IBlockState
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:161: error: cannot find symbol
>          IBlockState blockstate = this.worldobj.getBlockState(blockpos);
>                                       ^
>  symbol: variable worldobj
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:162: error: cannot find symbol
>          Tileentity te = this.worldObj.getTileEntity(blockpos);
>          ^
>  symbol:   class Tileentity
>  location: class Entityshield
>Note: /Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_sugilitesFlail.java uses unchecked or unsafe operations.
>7 errors
>:compileJava FAILED
>FAILURE: Build failed with an exception.
>* What went wrong:
>Execution failed for task ':compileJava'.
>> Compilation failed; see the compiler error output for details.
>* Try:
>Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
>BUILD FAILED
>Total time: 11.461 secs
>Task completed with return code 1 in 12023 milliseconds

 

Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
anyone?? plz??
Tue, 01/03/2017 - 23:10

anyone?? plz??

Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I recommend more base it on 1
Wed, 01/04/2017 - 22:49

I recommend more base it on 1.7.10 code from start , not using 1.8+ code and editing it because 1.8+ versions are too way different because of the new BlockState system , however if you want keep this code , first it is TileEntity not Tileentity , you alwo want to remove 
BlockPos blockpos = movingobjectPos.func_178782_a();
          IBlockState blockstate = this.worldobj.getBlockState(blockpos);

and change 
getBlockState(movingobjectPos.func_178782_a()).getBlock();
to 
getBlock(movingobjectPos.blockX,movingobjectPos.blockY,movingobjectPos.blockZ);

Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:I recommend more base it on 1
Sun, 01/08/2017 - 23:35

@#5 I have one error:

>Executing gradle command: build
>****************************
> Powered By MCP:            
> http://modcoderpack.com/   
> Searge, ProfMobius, Fesh0r,
> R4wk, ZeuX, IngisKahn, bspkrs
> MCP Data version : unknown
>****************************
>:compileApiJava UP-TO-DATE
>:processApiResources UP-TO-DATE
>:apiClasses UP-TO-DATE
>:sourceMainJava
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:161: error: ';' expected
>          TileEntity te + this.worldObj.getTileEntity(blockpos);
>                       ^
>1 error
>:compileJava FAILED
>FAILURE: Build failed with an exception.
>* What went wrong:
>Execution failed for task ':compileJava'.
>> Compilation failed; see the compiler error output for details.
>* Try:
>Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
>BUILD FAILED
>Total time: 6.877 secs
>Task completed with return code 1 in 7433 milliseconds
 

 

 

 

 

 

this is my code:

/**
 * Called when this EntityThrowable hits a block or entity.
 */
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
{
    if (movingobjectPos.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)    
    {    
       Block block = this.worldObj.getBlock(movingobjectPos.blockX,movingobjectPos.blockY,movingobjectPos.blockZ);
        
      if(block == Blocks.tallgrass || block == Blocks.vine || block == Blocks.red_flower || block == Blocks.yellow_flower || block == Blocks.brown_mushroom_block ||   
         block == Blocks.red_mushroom || block == Blocks.reeds || block == Blocks.double_plant || block == Blocks.deadbush || block == Blocks.brown_mushroom ||
         block == Blocks.wheat || block == Blocks.waterlily || block == Blocks.carrots || block == Blocks.potatoes || block == Blocks.snow_layer)
    {    
          
          TileEntity te + this.worldObj.getTileEntity(blockpos);
          if(this.getThrower() instanceof EntityPlayer) // if the thrower is a player
                {
                    EntityPlayer player = (EntityPlayer)this.getThrower();
                    this.worldObj.destroyBlock(blockpos, false);
                    block.harvestBlock(this.worldObj, player, blockpos, blockstate, te);   
                }
    }
    else    
      
        this.setDead();  
    }
        
        if (par1MovingObjectPosition.entityHit != null)
        {
            byte b0 = 54;          
 
            par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)b0);
        }
 
        if (!this.worldObj.isRemote)
        {
            this.setDead();
        }
    }
}

Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
First of all, you are trying
Mon, 01/09/2017 - 06:15

First of all, you are trying substract the value instead of asign

Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:First of all, you are trying
Mon, 01/09/2017 - 11:31

@#6

Executing gradle command: build
>****************************
> Powered By MCP:            
> http://modcoderpack.com/   
> Searge, ProfMobius, Fesh0r,
> R4wk, ZeuX, IngisKahn, bspkrs
> MCP Data version : unknown
>****************************
>:compileApiJava UP-TO-DATE
>:processApiResources UP-TO-DATE
>:apiClasses UP-TO-DATE
>:sourceMainJava
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:161: error: ';' expected
>          TileEntity te - this.worldObj.getTileEntity(blockpos);
>                       ^
>1 error
>:compileJava FAILED
>BUILD FAILED
>FAILURE: Build failed with an exception.
>* What went wrong:
>Execution failed for task ':compileJava'.
>> Compilation failed; see the compiler error output for details.
>* Try:
>Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
>Total time: 8.678 secs
>Task completed with return code 1 in 9227 milliseconds

Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
In the universe that we all
Mon, 01/09/2017 - 14:08

In the universe that we all live in , is not "+" or "-" used for asigning values. There is one symbol ( = ) for it. :D

Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:In the universe that we all
Mon, 01/09/2017 - 19:06

@#8 Executing gradle command: build
>****************************
> Powered By MCP:            
> http://modcoderpack.com/   
> Searge, ProfMobius, Fesh0r,
> R4wk, ZeuX, IngisKahn, bspkrs
> MCP Data version : unknown
>****************************
>:compileApiJava UP-TO-DATE
>:processApiResources UP-TO-DATE
>:apiClasses UP-TO-DATE
>:sourceMainJava
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:116: error: cannot find symbol
>        RenderingRegistry.registerEntityRenderingHandler(mcreator_shield.Entityshield.class, new RenderSnowball(mcreator_StevensShield.block));
>                                                                                                                ^
>  symbol:   variable mcreator_StevensShield
>  location: class mcreator_shield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:125: error: cannot find symbol
>        EntityRegistry.registerModEntity(mcreator_shield.Entitythrowspear.class, "shield", entityID, instance, 64, 1, true);
>                                                        ^
>  symbol:   class Entitythrowspear
>  location: class mcreator_shield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:152: error: cannot find symbol
>    if (movingobjectPos.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)   
>        ^
>  symbol:   variable movingobjectPos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:154: error: cannot find symbol
>       Block block = this.worldObj.getBlock(movingobjectPos.blockX,movingobjectPos.blockY,movingobjectPos.blockZ);
>                                            ^
>  symbol:   variable movingobjectPos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:154: error: cannot find symbol
>       Block block = this.worldObj.getBlock(movingobjectPos.blockX,movingobjectPos.blockY,movingobjectPos.blockZ);
>                                                                   ^
>  symbol:   variable movingobjectPos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:154: error: cannot find symbol
>       Block block = this.worldObj.getBlock(movingobjectPos.blockX,movingobjectPos.blockY,movingobjectPos.blockZ);
>                                                                                          ^
>  symbol:   variable movingobjectPos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:161: error: cannot find symbol
>          TileEntity te = this.worldObj.getTileEntity(blockpos);
>                                                      ^
>  symbol:   variable blockpos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:165: error: cannot find symbol
>                    this.worldObj.destroyBlock(blockpos, false);
>                                               ^
>  symbol:   variable blockpos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:166: error: cannot find symbol
>                    block.harvestBlock(this.worldObj, player, blockpos, blockstate, te);  
>                                                              ^
>  symbol:   variable blockpos
>  location: class Entityshield
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:166: error: cannot find symbol
>                    block.harvestBlock(this.worldObj, player, blockpos, blockstate, te);  
>                                                                        ^
>  symbol:   variable blockstate
>  location: class Entityshield
>:compileJava FAILED
>Note: /Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_sugilitesFlail.java uses unchecked or unsafe operations.
>10 errors
>FAILURE: Build failed with an exception.
>* What went wrong:
>Execution failed for task ':compileJava'.
>> Compilation failed; see the compiler error output for details.
>* Try:
>Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
>BUILD FAILED
>Total time: 1 mins 26.665 secs
>Task completed with return code 1 in 87222 milliseconds
 

Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:In the universe that we all
Mon, 01/09/2017 - 19:32

@#8 also, if I add in this code will it make it so when it hits an entity/block it will come back to player?

 

 

 

onUpdate(){

            double d0 = (target.posX - this.posX);
            double d1 = target.posY + 1 - this.posY;
            double d2 = (target.posZ - this.posZ);

            SetThrowableHeading(d0, d1, d2, 0.4F, 1.0F);

            this.motionX = MovePart(this.motionX, this.PerfectMotionX, 0.02);
            this.motionY = MovePart(this.motionY, this.PerfectMotionY, 0.005);
            this.motionZ = MovePart(this.motionZ, this.PerfectMotionZ, 0.02);

 

}

    /**
     * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
     */
    public void SetThrowableHeading(double par1, double par3, double par5, float par7, float par8)
    {
        float f2 = MathHelper.sqrt_double(par1  par1 + par3  par3 + par5 * par5);
        par1 /= (double)f2;
        par3 /= (double)f2;
        par5 /= (double)f2;
        par1 += this.rand.nextGaussian()  0.007499999832361937D  (double)par8;
        par3 += this.rand.nextGaussian()  0.007499999832361937D  (double)par8;
        par5 += this.rand.nextGaussian()  0.007499999832361937D  (double)par8;
        par1 *= (double)par7;
        par3 *= (double)par7;
        par5 *= (double)par7;
        this.PerfectMotionX = par1;
        this.PerfectMotionY = par3;
        this.PerfectMotionZ = par5;

    }

 

    public double MovePart(double part, double destination, double speed){
        if(part < destination) {
            part += speed;
        } else if (part > destination + speed) {
            part -= speed;
        } else {
            part = destination;
        }
        return part;
    }

 

Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
MCreator always converts
Mon, 01/09/2017 - 19:43

MCreator always converts first letter to lowercase (So mcreator_StevensShield is impossible) , and then you have there problem (that seems like connecting multiple codes together) that you constntly chnge nme of vrible (from movingobjectPos to par1MovingObjectPosition) , then you also need change all methods that use blockpos to x;y;z coords.also is better what are you trying to do , because it seems that are trying to remove all plants (Maybe is better just check for BlockBush or Material.plants) that the entity flies through (and in that case there I do not see reason for checking for TileEntity)

Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:MCreator always converts
Mon, 01/09/2017 - 20:53

@#9

what about this code?

private void destroyVines() { int i = MathHelper.floor_double(posX); int j = MathHelper.floor_double(posY); int k = MathHelper.floor_double(posZ); if (worldObj.getBlock(i, j, k).getMaterial() == Material.plants) { // func_147480_a is destroyBlock worldObj.func_147480_a(i, j, k, true); } }  
Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:MCreator always converts
Mon, 01/09/2017 - 20:54

@#9

also is there way for onImpact to have it so when it hits an entity or block the project tile goes back to player? I was thinking of maybe have the entity track the player. Or does it have to be in handler?