help with code

Started by KBEHAN on Mon, 01/02/2017 - 18:12

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:
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
Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
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);
     }
}
}
}}

 

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

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
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

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

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
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

 

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

Statistics:

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

anyone?? plz??

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

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
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);

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

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
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();
        }
    }
}

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

Statistics:

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

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

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

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
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

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

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
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

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

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
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