Started by
_Fa11out_
on
Topic category: Troubleshooting, bugs, and solutions
Recently I was trying to make custom tnt, however I don't know how to write the code so I decided to copy one from original minecraft(source in mcreator).
So, everytime when I try to compile it, gradle gives me an error "connot find symbol ()"
public void (...)
BUT parentheses "()" are already there and the code is correct.
I have no idea why it's not working as expected. Please help to solve this issue somehow.
The compiler is never wrong. If you get errors with Java syntax, the code is not ok. Paste the code.
Okay, here the code of my "dummy", however before pasting original minecraft tnt block code compulation runs good
package mod.mcreator;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.Item;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
public class mcreator_dummy extends tnt_mod.ModElement {
public static Block block;
static {
block = new BlockCustom().setHardness(0F).setResistance(10F).setLightLevel(0F).setUnlocalizedName("dummy").setLightOpacity(255)
.setCreativeTab(mcreator_customTntTab.tab);
}
public void preInit(FMLPreInitializationEvent event) {
block.setHarvestLevel("pickaxe", 1);
block.setRegistryName("dummy");
ForgeRegistries.BLOCKS.register(block);
ForgeRegistries.ITEMS.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
}
public void load(FMLInitializationEvent event) {
if (event.getSide() == Side.CLIENT) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.register(Item.getItemFromBlock(block), 0, new ModelResourceLocation("tnt_mod:dummy", "inventory"));
}
}
public static class BlockCustom extends Block {
public BlockCustom() {
super(Material.ROCK);
setSoundType(SoundType.GROUND);
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer() {
return BlockRenderLayer.SOLID;
}
}
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack itemstack = playerIn.getHeldItem(hand);
if (!itemstack.isEmpty() && (itemstack.getItem() == Items.FLINT_AND_STEEL || itemstack.getItem() == Items.FIRE_CHARGE))
{
this.explode(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)), playerIn);
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
if (itemstack.getItem() == Items.FLINT_AND_STEEL)
{
itemstack.damageItem(1, playerIn);
}
else if (!playerIn.capabilities.isCreativeMode)
{
itemstack.shrink(1);
}
return true;
}
else
{
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
}
public boolean canDropFromExplosion(Explosion explosionIn)
{
return false;
}
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(EXPLODE, Boolean.valueOf((meta & 1) > 0));
}
public int getMetaFromState(IBlockState state)
{
return ((Boolean)state.getValue(EXPLODE)).booleanValue() ? 1 : 0;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {EXPLODE});
}
}
UPD: yes you will notiсe a lot useless imports and some of them are doubled. However compilator reacts 'ok' about them
Please paste the compiler error too.
Okay, here the full gradle log
D:\Minecraft\MCreator\forge\build\sources\main\java\mod\mcreator\mcreator_dummy.java:95: error: cannot find symbol
this.explode(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)), playerIn);
^
symbol: variable EXPLODE
location: class mcreator_dummy
D:\Minecraft\MCreator\forge\build\sources\main\java\mod\mcreator\mcreator_dummy.java:111: error: cannot find symbol
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
^
symbol: method onBlockActivated(World,BlockPos,IBlockState,EntityPlayer,EnumHand,EnumFacing,float,float,float)
D:\Minecraft\MCreator\forge\build\sources\main\java\mod\mcreator\mcreator_dummy.java:122: error: cannot find symbol
return this.getDefaultState().withProperty(EXPLODE, Boolean.valueOf((meta & 1) > 0));
^
symbol: variable EXPLODE
location: class mcreator_dummy
D:\Minecraft\MCreator\forge\build\sources\main\java\mod\mcreator\mcreator_dummy.java:122: error: cannot find symbol
return this.getDefaultState().withProperty(EXPLODE, Boolean.valueOf((meta & 1) > 0));
^
symbol: method getDefaultState()
D:\Minecraft\MCreator\forge\build\sources\main\java\mod\mcreator\mcreator_dummy.java:127: error: cannot find symbol
return ((Boolean)state.getValue(EXPLODE)).booleanValue() ? 1 : 0;
^
symbol: variable EXPLODE
location: class mcreator_dummy
D:\Minecraft\MCreator\forge\build\sources\main\java\mod\mcreator\mcreator_dummy.java:132: error: cannot find symbol
return new BlockStateContainer(this, new IProperty[] {EXPLODE});
^
symbol: variable EXPLODE
location: class mcreator_dummy
D:\Minecraft\MCreator\forge\build\sources\main\java\mod\mcreator\mcreator_dummy.java:132: error: incompatible types: mcreator_dummy cannot be converted to Block
return new BlockStateContainer(this, new IProperty[] {EXPLODE});
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
7 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. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 12s
You need to define block state variable EXPLODE. You have some missing parts of the code to make this work.