Jump to content

Recommended Posts

Posted

So I am entirely new to modding, and for the most part I followed relevant tutorials on YouTube to get what I wanted into my mod. However, I haven't been able to get my block to function how I want it to.
To get to the point, I have what is essentially a custom lilypad that I want to place on water like a lilypad, and also have it be ticked randomly, and spread to a nearby block above water every time it is ticked. I also want it to break every time an entity comes in contact with it (I have that part more or less working).

If anybody could take a look at my code and tell me how to get it to spread correctly, I would appreciate it so much.
Thank you.

P.s. If any other part of code is required to help, I will be happy to provide it.

 

package jurassicfixx.jfmobs.blocks;

import java.util.Random;

import jurassicfixx.jfmobs.Main;
import jurassicfixx.jfmobs.init.BlockInit;
import jurassicfixx.jfmobs.init.ItemInit;
import jurassicfixx.jfmobs.util.IHasModel;
import net.minecraft.block.BlockLilyPad;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.BlockGrass;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockAlgae extends BlockLilyPad implements IHasModel //indicator jurassicfixx.jfmobs
{
	public static AxisAlignedBB ALGAE_AABB;
	
	public BlockAlgae(String name, Material material)
	{
		super();
		ALGAE_AABB = new AxisAlignedBB(1D, 0.0D, 1D, 0D, 0.09375D, 0D);
		
		this.getTickRandomly();
		
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.jfmobsblocks);
		
		BlockInit.BLOCKS.add(this);
		ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
	}
	@Override
	 public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
	    {
	        if (!worldIn.isRemote)
	        {
	            if (!worldIn.isAreaLoaded(pos, 3)) return;
	            {
	        {
	        		if ((worldIn.getBlockState(pos) == Blocks.WATER))
	        		{
	        			worldIn.setBlockState(pos.up(1), (IBlockState) BlockInit.ALGAE);
	        		}
        		}
	        }
        }
    }

    @Override
	public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        return ItemInit.SWAMP_ALGAE;
       }
  
  public int quantityDropped(IBlockState state, int fortune, Random random) {
        return random.nextInt(2);
       }

	@Override
	 public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
    {
        super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);

        if (entityIn instanceof Entity)
        {
            worldIn.destroyBlock(new BlockPos(pos), true);
        }
    }
	
	@Override
	public void registerModels() 
	{
		Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
	}
	
	@Override
	public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
	{
		return BlockFaceShape.UNDEFINED;
	}
}

 

Posted
2 hours ago, JurassicFixx said:

implements IHasModel

Don't. IHasModel is stupid cargo-cult programming. All items need models, no exceptions, and nothing about model registration requires you to access private/protected data. Register your models directly in the ModelRegistryEvent.

 

2 hours ago, JurassicFixx said:

BlockInit.BLOCKS.add(this);

This screams static initializers. Don't ever use static initializers since then you lose control over loading order and can introduce all sorts of bugs.

 

2 hours ago, JurassicFixx said:

ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));

Same here. Instantinate your stuff in the appropriate registry event.

 

2 hours ago, JurassicFixx said:

if (!worldIn.isAreaLoaded(pos, 3))

This will always be false. If the block at the given position receives a tick then the chunk is loaded.

 

2 hours ago, JurassicFixx said:

{ {

Why do you have these all over the place? They don't do anything in your code.

 

3 hours ago, JurassicFixx said:

if ((worldIn.getBlockState(pos) == Blocks.WATER))

This will always be false because

  1. IBlockState will never be equal to a Block.
  2. A block at the position passed will be your lily pad, it can't be water.
3 hours ago, JurassicFixx said:

if (entityIn instanceof Entity)

This will always be true since the argument passed is of an Entity type. You don't need this comparason at all.

 

3 hours ago, JurassicFixx said:

new BlockPos(pos)

...why?

 

3 hours ago, JurassicFixx said:

If anybody could take a look at my code and tell me how to get it to spread correctly

Well you are kinda close to the solution yourself, you just need to offset the position given to you in the method. And fix all those other issues.

Posted (edited)
Spoiler

---- Minecraft Crash Report ----
// I let you down. Sorry :(

Time: 2/3/19 10:05 PM
Description: Exception ticking world

java.lang.ClassCastException: jurassicfixx.jfmobs.blocks.BlockAlgae cannot be cast to net.minecraft.block.state.IBlockState
    at jurassicfixx.jfmobs.blocks.BlockAlgae.updateTick(BlockAlgae.java:51)
    at net.minecraft.block.Block.randomTick(Block.java:625)
    at net.minecraft.world.WorldServer.updateBlocks(WorldServer.java:497)
    at net.minecraft.world.WorldServer.tick(WorldServer.java:234)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:831)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
    at java.lang.Thread.run(Unknown Source)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
    at jurassicfixx.jfmobs.blocks.BlockAlgae.updateTick(BlockAlgae.java:51)
    at net.minecraft.block.Block.randomTick(Block.java:625)
    at net.minecraft.world.WorldServer.updateBlocks(WorldServer.java:497)
    at net.minecraft.world.WorldServer.tick(WorldServer.java:234)

-- Affected level --
Details:
    Level name: New World
    All players: 1 total; [EntityPlayerMP['Player227'/236, l='New World', x=86.06, y=6.49, z=205.83]]
    Chunk stats: ServerChunkCache: 625 Drop: 0
    Level seed: 1464878753198353783
    Level generator: ID 01 - flat, ver 0. Features enabled: true
    Level generator options: 
    Level spawn location: World: (75,4,246), Chunk: (at 11,0,6 in 4,15; contains blocks 64,0,240 to 79,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 86650 game time, 5000 day time
    Level dimension: 0
    Level storage version: 0x04ABD - Anvil
    Level weather: Rain time: 1 (now: false), thunder time: 1 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:831)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
    at java.lang.Thread.run(Unknown Source)

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_191, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 605959464 bytes (577 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
    FML: MCP 9.42 Powered by Forge 14.23.5.2768 5 mods loaded, 5 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

    | State          | ID        | Version      | Source                           | Signature |
    |:-------------- |:--------- |:------------ |:-------------------------------- |:--------- |
    | UCHIJAAAAAAAAA | minecraft | 1.12.2       | minecraft.jar                    | None      |
    | UCHIJAAAAAAAAA | mcp       | 9.42         | minecraft.jar                    | None      |
    | UCHIJAAAAAAAAA | FML       | 8.0.99.99    | forgeSrc-1.12.2-14.23.5.2768.jar | None      |
    | UCHIJAAAAAAAAA | forge     | 14.23.5.2768 | forgeSrc-1.12.2-14.23.5.2768.jar | None      |
    | UCHIJAAAAAAAAA | jfmobs    | 0.0.1        | bin                              | None      |

    Loaded coremods (and transformers): 
    GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
    Profiler Position: N/A (disabled)
    Player Count: 1 / 8; [EntityPlayerMP['Player227'/236, l='New World', x=86.06, y=6.49, z=205.83]]
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'fml,forge'

I was cleaning it up and I tested it out, the game crashed - if there is any chance you would like to have a look at the report and help me out some more, please let me know

Edited by JurassicFixx
Added Crash report as a spoiler
Posted
package jurassicfixx.jfmobs.blocks;

import java.util.Random;

import jurassicfixx.jfmobs.Main;
import jurassicfixx.jfmobs.init.BlockInit;
import jurassicfixx.jfmobs.init.ItemInit;
import jurassicfixx.jfmobs.util.IHasModel;
import net.minecraft.block.BlockLilyPad;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.BlockGrass;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockAlgae extends BlockLilyPad implements IHasModel //indicator jurassicfixx.jfmobs
{
	public static AxisAlignedBB ALGAE_AABB;
	
	public BlockAlgae(String name, Material material)
	{
		super();
		ALGAE_AABB = new AxisAlignedBB(1D, 0.0D, 1D, 0D, 0.09375D, 0D);
		
		this.getTickRandomly();
		
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.jfmobsblocks);
		
		BlockInit.BLOCKS.add(this);
		ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
	}
	@Override
	 public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
	    {
	        if (!worldIn.isRemote)
	        {
	        	{
	        	worldIn.setBlockState(pos, (IBlockState) BlockInit.ALGAE);
	        	}
	        }	
	    }

    @Override
	public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        return ItemInit.SWAMP_ALGAE;
       }
  
  public int quantityDropped(IBlockState state, int fortune, Random random) {
        return random.nextInt(2);
       }

	@Override
	 public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
    {
        super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
        {
            worldIn.destroyBlock(new BlockPos(pos), true);
        }
    }
	
	@Override
	public void registerModels() 
	{
		Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
	}
	
	@Override
	public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
	{
		return BlockFaceShape.UNDEFINED;
	}
}

 

Posted
15 hours ago, JurassicFixx said:

this.getTickRandomly();

Get tick randomly? Surely you mean Set tick randomly.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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