Jump to content

InYourPotato

Members
  • Posts

    10
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

InYourPotato's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Sorry about the inconvenience but for some reason it randomly started working now, I reset eclipse and it works fine now, thanks though everyone!
  2. Everything seems correct, I get no errors in my console... I'm guessing the EventHandler class just isn't registering properly
  3. Yeah I saw that and changed it, it still doesn't work though, the class was originally called IYPDropHandler and I changed it to IYPEventHandler, even with IYPEventHandler registered in my CommonProxy class, I'm still having the original issue.
  4. The reason I have the math is because I'm going to change the chance and it was just one way I thought of doing chance out of 100. Here is my CommonProxy class public class CommonProxy { public void preInit(FMLPreInitializationEvent preEvent){ IYPBlocks.initBlocks(); IYPItems.initItems(); IYPRecipes.initRecipes(); IYPSmelting.initSmelting(); } public void init(FMLInitializationEvent event){ MinecraftForge.EVENT_BUS.register(new IYPDropHandler()); } public void postInit(FMLPostInitializationEvent postEvent){ } } Main Modding Class: @Mod(modid = IYPGlobal.MOD_ID, name = IYPGlobal.MOD_NAME, version = IYPGlobal.VERSION) public class Main { @Instance(IYPGlobal.MOD_ID) public static Main instance; @SidedProxy(clientSide = IYPGlobal.IYP_CLIENT_PROXY, serverSide = IYPGlobal.IYP_COMMON_PROXY) public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent preEvent){ this.proxy.preInit(preEvent); } @EventHandler public void init(FMLInitializationEvent event){ this.proxy.init(event); } @EventHandler public void postInit(FMLPostInitializationEvent postEvent){ this.proxy.postInit(postEvent); } }
  5. Can someone please explain to me what is wrong with this class? I have registered it in my CommonProxy class but it doesn't seem to register properly. None of the events inside the class seem to work. I used MinecraftForge.EVENT_BUS.register(new IYPEventHandler()); under init in my CommonProxy class, I also tried to put it under preInit which did nothing. EventHandler Class: public class IYPEventHandler { public static Random random; public static double rand; public Random r = new Random(); @SubscribeEvent public void onEntityDrop(LivingDropsEvent event){ if(event.entityLiving instanceof EntityWolf){ if(r.nextInt(100/100) == 0){ if(event.entity.isBurning()) event.entityLiving.dropItem(IYPItems.CookedWolf, r.nextInt(3) + 1); } else{ event.entityLiving.dropItem(IYPItems.RawWolf, r.nextInt(3) + 1); } } @SubscribeEvent public void onBlockBreak(BreakEvent event){ EntityPlayer player = event.getPlayer(); if (!player.capabilities.isCreativeMode && player.isPotionActive(IYPItems.SpicyPotion)); EntityItem item = new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), new ItemStack(event.state.getBlock())); event.world.spawnEntityInWorld(item); } Any help appreciated
  6. So should I just not extend anything or would I be able to change AGE to something else such as CROP_AGE
  7. I tried that, however it still crashes but it now says javalang.IllegalArgumentException: Cannot set property PropertyInteger{name=age, clazz=class java.lang.Integer, values=[0, 1, 2, 3, 4, 5, 6, 7]} as it does not exist in BlockState{block=null, properties=[age]} My BlockCrop class: package com.inyourpotato.mod.blocks.crops; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockCrops; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class IYPCrops extends BlockCrops { public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 15); protected IYPCrops() { this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0))); this.setTickRandomly(true); float f = 0.5F; this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f); this.setCreativeTab((CreativeTabs)null); this.setHardness(0.0F); this.setStepSound(soundTypeGrass); this.disableStats(); } @Override protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {AGE}); } @Override public BlockState getBlockState() { return this.blockState; } public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { int i = ((Integer)state.getValue(AGE)).intValue(); if (i < 15) { float f = getGrowthChance(this, worldIn, pos); if (rand.nextInt((int)(25.0F / f) + 1) == 0) { worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i + 1)), 2); } } } } @Override public void grow(World worldIn, BlockPos pos, IBlockState state) { int i = ((Integer)state.getValue(AGE)).intValue() + MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5); if (i > 15) { i = 15; } worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i)), 2); } protected static float getGrowthChance(Block blockIn, World worldIn, BlockPos pos) { float f = 1.0F; BlockPos blockpos = pos.down(); for (int i = -1; i <= 1; ++i) { for (int j = -1; j <= 1; ++j) { float f1 = 0.0F; IBlockState iblockstate = worldIn.getBlockState(blockpos.add(i, 0, j)); if (iblockstate.getBlock().canSustainPlant(worldIn, blockpos.add(i, 0, j), net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable)blockIn)) { f1 = 1.0F; if (iblockstate.getBlock().isFertile(worldIn, blockpos.add(i, 0, j))) { f1 = 3.0F; } } if (i != 0 || j != 0) { f1 /= 4.0F; } f += f1; } } BlockPos blockpos1 = pos.north(); BlockPos blockpos2 = pos.south(); BlockPos blockpos3 = pos.west(); BlockPos blockpos4 = pos.east(); boolean flag = blockIn == worldIn.getBlockState(blockpos3).getBlock() || blockIn == worldIn.getBlockState(blockpos4).getBlock(); boolean flag1 = blockIn == worldIn.getBlockState(blockpos1).getBlock() || blockIn == worldIn.getBlockState(blockpos2).getBlock(); if (flag && flag1) { f /= 2.0F; } else { boolean flag2 = blockIn == worldIn.getBlockState(blockpos3.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos3.south()).getBlock(); if (flag2) { f /= 2.0F; } } return f; } public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) { return (worldIn.getLight(pos) >= 8 || worldIn.canSeeSky(pos)) && worldIn.getBlockState(pos.down()).getBlock().canSustainPlant(worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this); } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return ((Integer)state.getValue(AGE)).intValue() == 15 ? this.getCrop() : this.getSeed(); } @Override public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient) { return ((Integer)state.getValue(AGE)).intValue() < 15; } public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state) { return true; } @Override public java.util.List<ItemStack> getDrops(net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { java.util.List<ItemStack> ret = super.getDrops(world, pos, state, fortune); int age = ((Integer)state.getValue(AGE)).intValue(); Random rand = world instanceof World ? ((World)world).rand : new Random(); if (age >= 15) { int k = 3 + fortune; for (int i = 0; i < 3 + fortune; ++i) { if (rand.nextInt(15) <= age) { ret.add(new ItemStack(this.getSeed(), 1, 0)); } } } return ret; } }
  8. So I'm trying to make a crop that has more stages (15). I created a custom BlockCrop class to state that it now has 15 ages instead of 7. However, my game crashes due to blockstate stuff and I'm not exactly sure what it is trying to tell me. Crash line: java.lang.IllegalArgumentException: Cannot set property PropertyInteger{name=age, clazz=class java.lang.Integer, values=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]} as it does not exist in BlockState{block=null, properties=[age]} Custom BlockCrop class: package com.inyourpotato.mod.blocks.crops; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockCrops; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class IYPCrops extends BlockCrops { public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 15); protected IYPCrops() { this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0))); this.setTickRandomly(true); float f = 0.5F; this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f); this.setCreativeTab((CreativeTabs)null); this.setHardness(0.0F); this.setStepSound(soundTypeGrass); this.disableStats(); } public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { int i = ((Integer)state.getValue(AGE)).intValue(); if (i < 15) { float f = getGrowthChance(this, worldIn, pos); if (rand.nextInt((int)(25.0F / f) + 1) == 0) { worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i + 1)), 2); } } } } public void grow(World worldIn, BlockPos pos, IBlockState state) { int i = ((Integer)state.getValue(AGE)).intValue() + MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5); if (i > 15) { i = 15; } worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i)), 2); } protected static float getGrowthChance(Block blockIn, World worldIn, BlockPos pos) { float f = 1.0F; BlockPos blockpos = pos.down(); for (int i = -1; i <= 1; ++i) { for (int j = -1; j <= 1; ++j) { float f1 = 0.0F; IBlockState iblockstate = worldIn.getBlockState(blockpos.add(i, 0, j)); if (iblockstate.getBlock().canSustainPlant(worldIn, blockpos.add(i, 0, j), net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable)blockIn)) { f1 = 1.0F; if (iblockstate.getBlock().isFertile(worldIn, blockpos.add(i, 0, j))) { f1 = 3.0F; } } if (i != 0 || j != 0) { f1 /= 4.0F; } f += f1; } } BlockPos blockpos1 = pos.north(); BlockPos blockpos2 = pos.south(); BlockPos blockpos3 = pos.west(); BlockPos blockpos4 = pos.east(); boolean flag = blockIn == worldIn.getBlockState(blockpos3).getBlock() || blockIn == worldIn.getBlockState(blockpos4).getBlock(); boolean flag1 = blockIn == worldIn.getBlockState(blockpos1).getBlock() || blockIn == worldIn.getBlockState(blockpos2).getBlock(); if (flag && flag1) { f /= 2.0F; } else { boolean flag2 = blockIn == worldIn.getBlockState(blockpos3.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos3.south()).getBlock(); if (flag2) { f /= 2.0F; } } return f; } public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) { return (worldIn.getLight(pos) >= 8 || worldIn.canSeeSky(pos)) && worldIn.getBlockState(pos.down()).getBlock().canSustainPlant(worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this); } public Item getItemDropped(IBlockState state, Random rand, int fortune) { return ((Integer)state.getValue(AGE)).intValue() == 15 ? this.getCrop() : this.getSeed(); } public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient) { return ((Integer)state.getValue(AGE)).intValue() < 15; } public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state) { return true; } @Override public java.util.List<ItemStack> getDrops(net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { java.util.List<ItemStack> ret = super.getDrops(world, pos, state, fortune); int age = ((Integer)state.getValue(AGE)).intValue(); Random rand = world instanceof World ? ((World)world).rand : new Random(); if (age >= 15) { int k = 3 + fortune; for (int i = 0; i < 3 + fortune; ++i) { if (rand.nextInt(15) <= age) { ret.add(new ItemStack(this.getSeed(), 1, 0)); } } } return ret; } } Why exactly is it crashing? And what must be done to stop it crashing? Thanks! Help much appreciated!
  9. Thank you so much!! It worked, really appreciate your help!
  10. I have made an OnBlockActivated method in my custom crop which causes the crop to drop 1-3 apples when right clicked. However, how would I make it so it also goes back a stage? Help much appreciated thank you. Crop class: public class IYPLettuceCrop extends BlockCrops{ public IYPLettuceCrop(String name){ this.setUnlocalizedName(name); } public Item getSeed(){ return IYPItems.LettuceSlice; } public Item getCrop(){ return IYPItems.Lettuce; } public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { int i = (((Integer) state.getValue(AGE)).intValue()); if (i > 6) Block.spawnAsEntity(worldIn, pos, new ItemStack(Items.apple, new Random().nextInt(3) + 1)); return false; } @Override public java.util.List<ItemStack> getDrops(net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { List<ItemStack> ret = new ArrayList<ItemStack>(); int i = (((Integer) state.getValue(AGE)).intValue()); if (i < 7) ret.add(new ItemStack ( this.getSeed(), 1, 0)); else if (i > 6) { ret.add(new ItemStack ( this.getCrop(), 1, 0)); } return ret; } } This is my first thread thus I'm not sure how to create text boxes to place your code, sorry about that!
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.