Jump to content

Recommended Posts

Posted

Im making a security camera, that has to be an entity since I'm going to implement a feature to spectate it. I'm extending entityHanging since paintings are similar, but I am getting a crash when I try placing it down.

ModSecurityCamera:

package com.leomelonseeds.moarstuff.items;

import javax.annotation.Nullable;

import com.leomelonseeds.moarstuff.entity.EntityCamera;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityHanging;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.item.EntityPainting;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class ModSecurityCamera extends Item
{
    private final Class <? extends EntityHanging > hangingEntityClass;

    public ModSecurityCamera(Class <? extends EntityHanging > entityClass)
    {
        this.hangingEntityClass = entityClass;
        this.setCreativeTab(Moditems.moarStuff);
        this.setUnlocalizedName("security_camera");
    }

    /**
     * Called when a Block is right-clicked with this Item
     */
    public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        BlockPos blockpos = pos.offset(facing);

        if (facing != EnumFacing.DOWN && facing != EnumFacing.UP && playerIn.canPlayerEdit(blockpos, facing, stack))
        {
            EntityHanging entityhanging = this.createEntity(worldIn, blockpos, facing);

            if (entityhanging != null && entityhanging.onValidSurface())
            {
                if (!worldIn.isRemote)
                {
                    entityhanging.playPlaceSound();
                    worldIn.spawnEntityInWorld(entityhanging);
                }

                --stack.stackSize;
            }

            return EnumActionResult.SUCCESS;
        }
        else
        {
            return EnumActionResult.FAIL;
        }
    }

    @Nullable
    private EntityHanging createEntity(World worldIn, BlockPos pos, EnumFacing clickedSide)
    {
        return (EntityHanging)(this.hangingEntityClass == EntityCamera.class ? new EntityCamera(worldIn, pos, clickedSide): null);  
        }
}

Error:

[20:11:16] [Server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_25]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_25]
	at net.minecraft.util.Util.runTask(Util.java:26) [Util.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:742) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687) [MinecraftServer.class:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [IntegratedServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536) [MinecraftServer.class:?]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
Caused by: java.lang.NullPointerException
	at net.minecraft.entity.EntityHanging.onValidSurface(EntityHanging.java:147) ~[EntityHanging.class:?]
	at com.leomelonseeds.moarstuff.items.ModSecurityCamera.onItemUse(ModSecurityCamera.java:42) ~[ModSecurityCamera.class:?]
	at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:780) ~[ForgeHooks.class:?]
	at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:158) ~[ItemStack.class:?]
	at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:509) ~[PlayerInteractionManager.class:?]
	at net.minecraft.network.NetHandlerPlayServer.processRightClickBlock(NetHandlerPlayServer.java:706) ~[NetHandlerPlayServer.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_25]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_25]
	at net.minecraft.util.Util.runTask(Util.java:25) ~[Util.class:?]
	... 5 more

 

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

You called EntityHanging#onValidSurface without setting EntityHanging#hangingPosition to a non-null value. which probably means that you're calling the EntityHanging(World) constructor instead of the EntityHanging(World, BlockPos) constructor.

 

If this isn't the case, post the ModSecurityCamera class.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Well I already have the ModSecurityCamera up there.

If you want the entity class, here:

package com.leomelonseeds.moarstuff.entity;

import javax.annotation.Nullable;

import com.leomelonseeds.moarstuff.items.Moditems;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityHanging;
import net.minecraft.entity.item.EntityPainting;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityCamera extends EntityHanging {

	public EntityCamera(World worldIn) {
		super(worldIn);
		
	}
	
	 public EntityCamera(World worldIn, BlockPos pos, EnumFacing facing)
	    {
	        super(worldIn, pos);
	    }
	 
	 @SideOnly(Side.CLIENT)
	    public EntityCamera(World worldIn, BlockPos pos, EnumFacing facing, String title)
	    {
	        this(worldIn, pos, facing);

	      
	        this.updateFacingWithBoundingBox(facing);
	    }

	@Override
	public int getWidthPixels() {
		
		return 12;
	}

	@Override
	public int getHeightPixels() {
		
		return 12;
	}

	@Override
	public void onBroken(@Nullable Entity brokenEntity) {
		
		if (this.worldObj.getGameRules().getBoolean("doEntityDrops"))
        {
            this.playSound(SoundEvents.BLOCK_STONE_BREAK, 1.0F, 1.0F);

            if (brokenEntity instanceof EntityPlayer)
            {
                EntityPlayer entityplayer = (EntityPlayer)brokenEntity;

                if (entityplayer.capabilities.isCreativeMode)
                {
                    return;
                }
            }

            this.entityDropItem(new ItemStack(Moditems.camera), 0.0F);
        }
	
		
		
		
	}

	@Override
	public void playPlaceSound() {
		
		this.playSound(SoundEvents.BLOCK_STONE_HIT, 1.0F, 1.0F);
		
	}
	
	 public void setLocationAndAngles(double x, double y, double z, float yaw, float pitch)
	    {
	        this.setPosition(x, y, z);
	    }

	    /**
	     * Set the position and rotation values directly without any clamping.
	     */
	    @SideOnly(Side.CLIENT)
	    public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
	    {
	        BlockPos blockpos = this.hangingPosition.add(x - this.posX, y - this.posY, z - this.posZ);
	        this.setPosition((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
	    }

}

 

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

I meant EntityCamera, yes.

 

It's actually the EntityHanging#facingDirection field that's null rather than EntityHanging#hangingPosition as I initially suspected; this is because the EntityCamera(World, BlockPos, EnumFacing) constructor doesn't call EntityHanging#updateFacingWithBoundingBox.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

OK it works now. A few problems: I know my entity is invisible right now, but when I tried to destroy it, it also destroys the block behind it, and after a few seconds drops the block. How would I set a break time, and what is wrong with it?

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
37 minutes ago, TheSunCat said:

Paintings don't have a break time. They have 1HP, drop a painting item (which is actually a spawn egg ^_^). Same with item frames.

Actually they don't.  Entities that aren't living don't even have an HP field. When they take any damage at all, even if that damage is 0, they die.

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.

Posted
43 minutes ago, TheSunCat said:

Also, is it possible to add a custom painting without replacing the actual painting file?

Hell if I know. Probably not.

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.

Posted
14 minutes ago, TheSunCat said:

Ok. What is the h*** for?

Because I'm an abrasive jerk and I don't actually know everything, despite appearances on this forum.

I've never touched paintings and don't feel like doing the research for you.

  • Like 1

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.

Posted

I've added custom paintings, creating new item and entity classes for them. I added a bunch of texture files and left the existing one alone. Because my custom painting class is not identical to EntityPainting, the client-side message handler would not cooperate. The message was ok, but I needed to jump through some hoops on the client side to spawn my entity.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

@TheSunCatPlease turn signatures on and read Draco18s'. Its nice. 

So how about my problems?

19 hours ago, Leomelonseeds said:

t when I tried to destroy it, it also destroys the block behind it, and after a few seconds drops the block

 

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

Why isint it working?

On 2/20/2017 at 11:27 AM, jeffryfisher said:

The message was ok, but I needed to jump through some hoops on the client side to spawn my entity.

Well how would I do that?

 

Code:

package com.leomelonseeds.moarstuff.entity;

import javax.annotation.Nullable;

import com.leomelonseeds.moarstuff.items.Moditems;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityHanging;
import net.minecraft.entity.item.EntityPainting;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityCamera extends EntityHanging {

	public EntityCamera(World worldIn) {
		super(worldIn);
		
	}
	
	 public EntityCamera(World worldIn, BlockPos pos, EnumFacing facing)
	    {
	        super(worldIn, pos);
	        
	        this.updateFacingWithBoundingBox(facing);
	    }
	 
	 @SideOnly(Side.CLIENT)
	    public EntityCamera(World worldIn, BlockPos pos, EnumFacing facing, String title)
	    {
	        this(worldIn, pos, facing);

	      
	        this.updateFacingWithBoundingBox(facing);
	    }

	@Override
	public int getWidthPixels() {
		
		return 12;
	}

	@Override
	public int getHeightPixels() {
		
		return 12;
	}

	@Override
	public void onBroken(@Nullable Entity brokenEntity) {
		
		if (this.worldObj.getGameRules().getBoolean("doEntityDrops"))
        {
            this.playSound(SoundEvents.BLOCK_STONE_BREAK, 1.0F, 1.0F);

            if (brokenEntity instanceof EntityPlayer)
            {
                EntityPlayer entityplayer = (EntityPlayer)brokenEntity;

                if (entityplayer.capabilities.isCreativeMode)
                {
                    return;
                }
            }

            this.entityDropItem(new ItemStack(Moditems.camera), 0.0F);
        }
	
		
		
		
	}

	@Override
	public void playPlaceSound() {
		
		this.playSound(SoundEvents.BLOCK_STONE_HIT, 1.0F, 1.0F);
		
	}
	
	 public void setLocationAndAngles(double x, double y, double z, float yaw, float pitch)
	    {
	        this.setPosition(x, y, z);
	    }

	    /**
	     * Set the position and rotation values directly without any clamping.
	     */
	    @SideOnly(Side.CLIENT)
	    public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
	    {
	        BlockPos blockpos = this.hangingPosition.add(x - this.posX, y - this.posY, z - this.posZ);
	        this.setPosition((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
	    }

}

 

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

In 1.10.2, to stop MC from trying to spawn a vanilla painting, I needed to provide a callback class to a custom spawning registration that was called from client proxy init.

 

Client Proxy line in init:

    registration.setCustomSpawning (new SomeSpawnCallback (), false);

 

Excerpt from Callback Class:

import com.google.common.base.Function;

@SideOnly(Side.CLIENT)
public class SomeSpawnCallback implements Function<EntitySpawnMessage, Entity> {
  
  ...
  
  @Override
  public Entity apply(EntitySpawnMessage m) {
    // read message and call your hanging entity's client-side constructor
  }
}

 

Forge reflection will call your "apply" method.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted (edited)
35 minutes ago, jeffryfisher said:

// read message

So... What is that?

And also which package shouold I put that class in?

Edited by Leomelonseeds

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

Ok so the ClientRegistry line is saying that it can not make a static reference to the non static method of setCustomSpawning. When I try to store an instance of the EntityRegistration class in my clientproxy, what things should I put in the constructor? Nothing seems to be working right now.

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

Ok now what values should I put in the constructor EntityCamera(client-side) when creating an instance of my Entity in SomeSpawnCallback to use in the apply method? null does not work apparently, and this either:

package com.leomelonseeds.moarstuff.entity;

import com.google.common.base.Function;

import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.internal.FMLMessage.EntitySpawnMessage;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.leomelonseeds.moarstuff.entity.EntityCamera;


	
	@SideOnly(Side.CLIENT)
	public class SomeSpawnCallBack implements Function<EntitySpawnMessage, Entity> {
	  
	private World worldIn;
	private BlockPos pos;
	private EnumFacing facing;
	private String title;
	EntityCamera entityC = new EntityCamera(worldIn, pos, facing, title);
	  
	  @Override
	  public Entity apply(EntitySpawnMessage m) {
		
	
	    return entityC;
		  
	  }
	  
	}

 

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

The apply method gets parameter m (message). See what that gives you.

 

When I make a mod, I put everything in one package.

 

You might want to replace "Some" with a word pertaining to what you're working on (e.g. "Camera").

 

Sorry 'bout the local "registration" variable. Here's what I used in 1.8 - 1.10.2:

 

    container = Loader.instance ().getIndexedModList ().get (modId);
    EntityRegistration registration = EntityRegistry.instance ().lookupModSpawn (container, 0);

 

I think you want to instantiate each new camera inside the callback. Then return a new entity every time. The parameters for the constructor are whatever your camera needs plus what HangingEntity needs. If you're lucky, you'll find what you need inside the message m.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
8 hours ago, jeffryfisher said:

When I make a mod, I put everything in one package.

Gosh, that's so... unorganized!

 

 

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

I make simple mods that don't need lots of compartmentalization.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
12 hours ago, jeffryfisher said:

The parameters for the constructor are whatever your camera needs plus what HangingEntity needs. If you're lucky, you'll find what you need inside the message m.

Well, some examples please? Like, what do I put for worldIn?

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

Ok I changed my code to this:

package com.leomelonseeds.moarstuff.entity;

import com.google.common.base.Function;

import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.internal.FMLMessage.EntitySpawnMessage;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.leomelonseeds.moarstuff.entity.EntityCamera;


	
	@SideOnly(Side.CLIENT)
	public class SomeSpawnCallBack implements Function<EntitySpawnMessage, Entity> {
	  
	public World worldIn;
	public BlockPos pos;
	public EnumFacing facing;
	public String title;
	
	  
	  @Override
	  public Entity apply(EntitySpawnMessage m) {
		System.out.println(m);
		EntityCamera entityC = new EntityCamera(worldIn, pos, facing, title);
	    return entityC;
		  
	  }
	  
	}

But now its giving me a null pointer exeption for this line:

registration.setCustomSpawning( new SomeSpawnCallBack (), false);

 

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

Wait I put this:

public ModContainer container = Loader.instance ().getIndexedModList ().get (Main.MODID);
    EntityRegistration registration = EntityRegistry.instance ().lookupModSpawn (container, 0);

Does that work? Cause it errors when I copyPaste yours in there.

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

I don't know if it's the best way, but I hunted around and found a world client instance in FML:

    WorldClient wc = FMLClientHandler.instance ().getWorldClient ();

 

Everything else I needed for my constructor came out of EntitySpawnMessage m.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Its still giving me this:

[12:28:34] [Client thread/ERROR] [FML]: Caught exception from Moar Stuff (moarstuff)
java.lang.NullPointerException
	at com.leomelonseeds.moarstuff.ClientProxy.init(ClientProxy.java:65) ~[bin/:?]
	at com.leomelonseeds.moarstuff.Main.init(Main.java:33) ~[bin/:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]
	at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]
	at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:602) ~[forgeSrc-1.10.2-12.18.3.2185.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]
	at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]
	at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
	at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
	at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
	at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
	at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:243) ~[forgeSrc-1.10.2-12.18.3.2185.jar:?]
	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:221) ~[forgeSrc-1.10.2-12.18.3.2185.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]
	at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]
	at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
	at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
	at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
	at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
	at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:145) [LoadController.class:?]
	at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:795) [Loader.class:?]
	at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:324) [FMLClientHandler.class:?]
	at net.minecraft.client.Minecraft.startGame(Minecraft.java:561) [Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:386) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]
	at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]
	at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:26) [start/:?]

When i try to open game.

ClientProxy:

package com.leomelonseeds.moarstuff;

import com.leomelonseeds.moarstuff.blocks.BlockMegaTNT;
import com.leomelonseeds.moarstuff.blocks.BlockNuke;
import com.leomelonseeds.moarstuff.blocks.Modblocks;
import com.leomelonseeds.moarstuff.client.render.blocks.BlockRenderRegister;
import com.leomelonseeds.moarstuff.client.render.blocks.TileGrillRenderer;
import com.leomelonseeds.moarstuff.client.render.entity.RenderMegaTNTPrimed;
import com.leomelonseeds.moarstuff.client.render.entity.RenderNukePrimed;
import com.leomelonseeds.moarstuff.client.render.items.ItemRenderRegister;
import com.leomelonseeds.moarstuff.entity.EntityCamera;
import com.leomelonseeds.moarstuff.entity.MegaTNTPrimed;
import com.leomelonseeds.moarstuff.entity.ModLivingDropsEvent;
import com.leomelonseeds.moarstuff.entity.NukePrimed;
import com.leomelonseeds.moarstuff.entity.SomeSpawnCallBack;
import com.leomelonseeds.moarstuff.tileentity.Grill;

import net.minecraft.block.properties.IProperty;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.item.Item;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
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.EntityRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration;



public class ClientProxy extends CommonProxy {
	
	
	
	ModContainer container = Loader.instance ().getIndexedModList ().get (Main.MODID);
    EntityRegistration registration = EntityRegistry.instance ().lookupModSpawn (container, 0);

	@Override
	public void preInit(FMLPreInitializationEvent e){ 
		super.preInit(e);
		
		ModelLoader.setCustomStateMapper(Modblocks.megatnt, (new StateMap.Builder()).ignore(new IProperty[] {BlockMegaTNT.EXPLODE}).build());
		ModelLoader.setCustomStateMapper(Modblocks.nuke, (new StateMap.Builder()).ignore(new IProperty[] {BlockNuke.EXPLODE}).build());
	   RenderingRegistry.registerEntityRenderingHandler(NukePrimed.class, RenderNukePrimed::new);
	    RenderingRegistry.registerEntityRenderingHandler(MegaTNTPrimed.class, RenderMegaTNTPrimed::new);
	    MinecraftForge.EVENT_BUS.register(new ModLivingDropsEvent());
        
	  
	}
	@Override
	public void init(FMLInitializationEvent e) {
		super.init(e);
		 BlockRenderRegister.registerBlockRenderer();
		 ItemRenderRegister.registerItemRenderer();
		 EntityRegistry.registerModEntity(MegaTNTPrimed.class, "megatnt", 1, Main.instance, 160, 10, true);
		 EntityRegistry.registerModEntity(NukePrimed.class, "nuke", 2, Main.instance, 160, 10, true);
		 EntityRegistry.registerModEntity(EntityCamera.class, "camera", 3, Main.instance, 100000, 30, false);
		 ClientRegistry.bindTileEntitySpecialRenderer(Grill.class, new TileGrillRenderer());
		 ForgeHooksClient.registerTESRItemStack(Item.getItemFromBlock(Modblocks.grill), 0, Grill.class);
		 registration.setCustomSpawning(new SomeSpawnCallBack(), false);
		
		 
	}

	@Override
	public void postInit(FMLPostInitializationEvent e) {
		super.postInit(e);
	}

}

 

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted

Try moving assignments such as  "EntityRegistration registration = ..."  into methods whose timing assures that they'll get values other than null at the time of assignment.

 

You might be far enough along in this that you need more general help to understand the differences between preinit, init etc, so you might want to start a new thread.

  • Like 1

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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

    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I&#39;m not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
  • Topics

×
×
  • Create New...

Important Information

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