Jump to content

Exception in Server Tick Loop


FlordiaDucky

Recommended Posts

I keep crashing each time a load a new world

when a i run the client!!! Do you know how to fix it?

 

Code:

//src.main.java
//com.flordiaducky.DuckyUtilMod
  //Main.java
    package com.flordiaducky.duckyutilmod;

import com.flordiaducky.duckyutilmod.proxy.CommonProxy;
import com.flordiaducky.duckyutilmod.tabs.DuckyUtilModTab;
import com.flordiaducky.duckyutilmod.util.Reference;
import com.flordiaducky.duckyutilmod.world.ModWorldGen;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)
public class Main 
{

	//Tab
	public static final CreativeTabs duckyutilmodtab = new DuckyUtilModTab("duckyutilmodtab");
	
	//Instance
	@Instance
	public static Main instance;
	
	//Proxy
	@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.COMMON_PROXY_CLASS)
	public static CommonProxy proxy;
	
	//Event Handlers
	@EventHandler
	public static void PreInit(FMLPreInitializationEvent event)
	{
		GameRegistry.registerWorldGenerator(new ModWorldGen(), 3);
	}
	
	@EventHandler
	public static void init(FMLInitializationEvent event)
	{
		
	}
	
	@EventHandler
	public static void Postinit(FMLPostInitializationEvent event)
	{
		
	}
}
   //Util Package
     //Reference.java
      package com.flordiaducky.duckyutilmod.util;

public class Reference 
{

	public static final String MOD_ID = "dum";
	public static final String NAME = "Ducky's Util Mod";
	public static final String VERSION = "1.0";
	public static final String ACCEPTED_VERSIONS = "[1.12.2]";
	public static final String CLIENT_PROXY_CLASS = "com.flordiaducky.duckyutilmod.proxy.ClientProxy";
	public static final String COMMON_PROXY_CLASS = "com.flordiaducky.duckyutilmod.proxy.CommonProxy";
	
}
   //IHasModel 
     package com.flordiaducky.duckyutilmod.util;

public interface IHasModel 
{
	public void registerModels();
}
  //Handlers Package
   //RegistryHandler
    package com.flordiaducky.duckyutilmod.util.handlers;

import com.flordiaducky.duckyutilmod.init.ModBlocks;
import com.flordiaducky.duckyutilmod.init.ModItems;
import com.flordiaducky.duckyutilmod.util.IHasModel;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Mod.EventBusSubscriber
public class RegistryHandler 
{

	@SubscribeEvent
	public static void onItemRegister(RegistryEvent.Register<Item> event)
	{
		event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0]));
	}
	
	@SubscribeEvent
	public static void onBlockRegister(RegistryEvent.Register<Block> event)
	{
		event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0]));
	}
	
	@SubscribeEvent
	public static void onModelRegister(ModelRegistryEvent event)
	{
		for(Item item : ModItems.ITEMS)
		{
			if(item instanceof IHasModel)
			{
				((IHasModel)item).registerModels();
			}
		}
		
		for(Block block : ModBlocks.BLOCKS)
		{
			if(block instanceof IHasModel)
			{
				((IHasModel)block).registerModels();
			}
		}
		
	}
	

}
//world package
   //ModWorldGen.java
      package com.flordiaducky.duckyutilmod.world;

import java.util.Random;

import com.flordiaducky.duckyutilmod.init.ModBlocks;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraftforge.fml.common.IWorldGenerator;

public class ModWorldGen implements IWorldGenerator
{

	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
	{
		if (world.provider.getDimension() == 0)
		{
			generateOverworld(random, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
		}
	}
	
	private void generateOverworld(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
	{
		generateOre(ModBlocks.PLATINUM_ORE.getDefaultState(), world, random, chunkX * 16, chunkZ * 16, 16, 64, random.nextInt(7) + 4, 5);
	}
	  private void generateOre(IBlockState ore, World world, Random random, int x, int z, int minY, int maxY, int size, int chances)
	{
	   int deltaY = minY - maxY;
		
		for (int i = 0; i < chances; i++)
		{
			BlockPos pos = new BlockPos(x + random.nextInt(16), minY + random.nextInt(deltaY), z + random.nextInt(16));
			
	        WorldGenMinable generator = new WorldGenMinable(ore, size);
	        generator.generate(world, random, pos);
		}
	}
}
 //Init
   //ModBlocks.java
     package com.flordiaducky.duckyutilmod.init;

import java.util.ArrayList;
import java.util.List;

import com.flordiaducky.duckyutilmod.blocks.BlockBase;
import com.flordiaducky.duckyutilmod.blocks.PlatinumOre;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;

public class ModBlocks 
{

	public static final List<Block> BLOCKS = new ArrayList<Block>();
	
	//Blocks
	public static final Block PLATINUM_BLOCK = new BlockBase("platinum_block", Material.IRON);
	public static final Block PLATINUM_ORE = new PlatinumOre("platinum_ore", Material.ROCK);
	
}
    //ModItems.java
      package com.flordiaducky.duckyutilmod.init;

import java.util.ArrayList;
import java.util.List;

import com.flordiaducky.duckyutilmod.items.ItemBase;

import net.minecraft.item.Item;

public class ModItems 
{

	public static final List<Item> ITEMS = new ArrayList<Item>();
	
	//Items
	public static final Item RUBBER_DUCKY = new ItemBase("rubber_ducky");
    public static final Item PLATINUM_INGOT = new ItemBase("platinum_ingot");

}
 //Proxy
   //ClientProxy.java
     package com.flordiaducky.duckyutilmod.proxy;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;

public class ClientProxy extends CommonProxy
{

	public void registerItemRenderer(Item item, int meta, String id)
	{
		ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), id));
	}
	
}
   //CommonProxy.java
     package com.flordiaducky.duckyutilmod.proxy;

import net.minecraft.item.Item;

public class CommonProxy 
{

	public void registerItemRenderer(Item item, int meta, String id){}
	
}
//items
  //ItemBase.java
    package com.flordiaducky.duckyutilmod.items;

import com.flordiaducky.duckyutilmod.Main;
import com.flordiaducky.duckyutilmod.init.ModItems;
import com.flordiaducky.duckyutilmod.util.IHasModel;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class ItemBase extends Item implements IHasModel
{

	public ItemBase(String name)
	{
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.duckyutilmodtab);
		
		ModItems.ITEMS.add(this);
	}
	
	@Override
	public void registerModels() 
	{
		Main.proxy.registerItemRenderer(this, 0, "inventory");
	}

}
//blocks
  //BlockBase.java
    ackage com.flordiaducky.duckyutilmod.blocks;

import com.flordiaducky.duckyutilmod.Main;
import com.flordiaducky.duckyutilmod.init.ModBlocks;
import com.flordiaducky.duckyutilmod.init.ModItems;
import com.flordiaducky.duckyutilmod.util.IHasModel;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;

public class BlockBase extends Block implements IHasModel
{

	public BlockBase(String name, Material material)
	{
		super(material);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.duckyutilmodtab);
		
		ModBlocks.BLOCKS.add(this);
		ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
	}

	@Override
	public void registerModels() 
	{
		Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
	}
	
}
   //PlatinumOre.java
     package com.flordiaducky.duckyutilmod.blocks;

import java.util.Random;

import com.flordiaducky.duckyutilmod.init.ModBlocks;

import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;

public class PlatinumOre extends BlockBase
{

	public PlatinumOre(String name, Material material)
	{
		super(name, material);
		
		setSoundType(SoundType.METAL);
		setHardness(5.0F);
		setResistance(30.0F);
		setHarvestLevel("pickaxe", 2);
	}
	
     @Override
     public int quantityDropped(Random rand)
     {
    	 int max = 3;
         int min = 1;
         return rand.nextInt(max) + min;
     }
}
//src.main.resources
  //assets
     //dum 
       //blockstates   
         //platinum_ore.json
            {
    "variants": {
        "normal": { "model": "dum:platinum_ore" }
    }
}
         //platinum_block.json
         {
    "variants": {
        "normal": { "model": "dum:platinum_block" }
    }
}
      //lang
        //en_us.lang
//Items
item.rubber_ducky.name=Rubber Ducky
item.platinum_ingot.name=Platinum Ingot
//Blocks
tile.platinum_block.name=Platinum Block
tile.platinum_ore.name=Platinum Ore
//Tabs
itemGroup.duckyutilmodtab=Ducky's Util Mod
    //models
      //item
       //platinum_ore.json
         {
   "parent": "dum:block/platinum_ore"
         }
       //platinum_block.json
         {
   "parent": "dum:block/platinum_block"
         }
       //rubber_ducky.json
         {
   "parent": "item/generated",
   "textures": {
       "layer0": "dum:items/rubber_ducky"
               }
          }
       //platinum_ingot.json
         {
   "parent": "item/generated",
   "textures": {
       "layer0": "dum:items/platinum_ingot"
               }
         }
     //block
       //platinum_ore.json
         {
   "parent": "block/cube_all",
   "textures": {
       "all": "dum:blocks/platinum_ore"
               }
         }
      //platinum_block.json
        {
   "parent": "block/cube_all",
   "textures": {
       "all": "dum:blocks/platinum_ore"
               }
         }

  

Crash Report:

Time: 11/8/18 2:39 PM
Description: Exception in server tick loop

java.lang.IllegalArgumentException: bound must be positive
	at java.util.Random.nextInt(Unknown Source)
	at com.flordiaducky.duckyutilmod.world.ModWorldGen.generateOre(ModWorldGen.java:38)
	at com.flordiaducky.duckyutilmod.world.ModWorldGen.generateOverworld(ModWorldGen.java:30)
	at com.flordiaducky.duckyutilmod.world.ModWorldGen.generate(ModWorldGen.java:24)
	at net.minecraftforge.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:167)
	at net.minecraft.world.chunk.Chunk.populate(Chunk.java:1095)
	at net.minecraft.world.chunk.Chunk.populate(Chunk.java:1074)
	at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:169)
	at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:383)
	at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:143)
	at net.minecraft.server.integrated.IntegratedServer.init(IntegratedServer.java:160)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:552)
	at java.lang.Thread.run(Unknown Source)


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

-- System Details --
Details:
	Minecraft Version: 1.12.2
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_171, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 862620056 bytes (822 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
	JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
	IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
	FML: MCP 9.42 Powered by Forge 14.23.5.2772 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 |
	|:------- |:--------- |:------------ |:-------------------------------- |:--------- |
	| UCHIJAA | minecraft | 1.12.2       | minecraft.jar                    | None      |
	| UCHIJAA | mcp       | 9.42         | minecraft.jar                    | None      |
	| UCHIJAA | FML       | 8.0.99.99    | forgeSrc-1.12.2-14.23.5.2772.jar | None      |
	| UCHIJAA | forge     | 14.23.5.2772 | forgeSrc-1.12.2-14.23.5.2772.jar | None      |
	| UCHIJAA | dum       | 1.0          | 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: 0 / 8; []
	Type: Integrated Server (map_client.txt)
	Is Modded: Definitely; Client brand changed to 'fml,forge'

 

platinum_block.png

platinum_ore.png

platinum_ingot.png

rubber_ducky.png

Link to comment
Share on other sites

36 minutes ago, FlordiaDucky said:

public static CommonProxy proxy;

CommonProxy makes no sense. Proxies exist to separate sided-only code. If your code is common it goes anywhere else but your proxy. Hmm... didn't I tell you that already?

Why yes, I did.

 

38 minutes ago, FlordiaDucky said:

serverSide = Reference.COMMON_PROXY_CLASS

This makes even less sense. A server proxy either supplies noop implementations for client-only methods or invokes server-side only code that would crash the client. Your common proxy can't be your server proxy because if it were it would crash the client.

 

39 minutes ago, FlordiaDucky said:

public interface IHasModel

IHasModel is stupid. All items need models, no exceptions and nothing about model registration requires access to private/protected information of the item. Just register your models in the model regitry event directly. I told you this one earlier too.

 

40 minutes ago, FlordiaDucky said:

public static final Block PLATINUM_BLOCK = new BlockBase("platinum_block", Material.IRON);

Don't ever use static initializers, instantinate your stuff directly in the appropriate registry event. And yet again, you were told to do this aswell. Same for the items.

 

41 minutes ago, FlordiaDucky said:

public class ItemBase

ItemBase is an antipattern. There is already an ItemBase - it's called Item. Same goes for BlockBase

 

42 minutes ago, FlordiaDucky said:

return rand.nextInt(max) + min;

This is not how you specify max/min bounds logically. It only works in this case because min is 1(drops 1 - 3). If min was 2 it would drop 2-4.

 

As for the issue - look at your random logic here:

43 minutes ago, FlordiaDucky said:

minY + random.nextInt(deltaY)

So, generate at minY + [0-deltaY]. Okay, what's deltaY?

44 minutes ago, FlordiaDucky said:

int deltaY = minY - maxY;

Unless min > max which makes no sense deltaY will always be negative. You can't pass a value less than 1 to a random method. In your case

45 minutes ago, FlordiaDucky said:

16, 64

deltaY is -48.

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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