Jump to content

[1.15.2][Solved] Weird issue with adding blocks to creative tab


GhostGaming

Recommended Posts

I created a mod a few days ago but moved everything to a new project to tidy it up because I really wasn't happy with how unorganized everything was (although most things were working fine). For the most part, the code didn't change which is why I'm utterly confused on why the blocks are not being added to the creative inventory anymore. I tried it with a custom creative tab and also with the vanilla ones but it's not working in both cases. I checked whether the BlockItems are not being registered but they are. I can place the blocks down using /setblock, I can give them to myself using /give and place them down afterwards but they are not only not being rendered in the creative inv, they simply don't exist. Anyone has a clue why this could happen?

Edited by GhostGaming
Link to comment
Share on other sites

Just now, GhostGaming said:

Anyone has a clue why this could happen?

When you created your BlockItem instances did you set the ItemGroup via Item.Properties?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

3 minutes ago, GhostGaming said:

Yes, I did. I used the code that Cadiboo used in his example mod

I don't need to look at someone else's code when I am helping you with your own. I have no guarantee you did everything Cadiboo did unless you directly copy-pasted his code.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Just now, Animefan8888 said:

I don't need to look at someone else's code when I am helping you with your own. I have no guarantee you did everything Cadiboo did unless you directly copy-pasted his code.

Basically, I loop through all my blocks in the item registry event and create and register a new ItemBlock with the ItemGroup. The weird thing is, that even when using one of my blocks as the tab icon it doesn't show up

Link to comment
Share on other sites

Just now, GhostGaming said:

Basically, I loop through all my blocks in the item registry event and create and register a new ItemBlock with the ItemGroup. The weird thing is, that even when using one of my blocks as the tab icon it doesn't show up

If you don't show us your code no one on here can actually help you all we can do is make shortsighted guesses on what could be causing your problem. If you don't feel comfortable sharing your code then don't and know we can't really help you.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 minute ago, Animefan8888 said:

If you don't show us your code no one on here can actually help you all we can do is make shortsighted guesses on what could be causing your problem. If you don't feel comfortable sharing your code then don't and know we can't really help you.

Sorry, I was on my phone ?

 

My Mod class constructor:

public GhostsExplosives() {
	final ModLoadingContext modLoadingContext = ModLoadingContext.get();
	final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

	ModBlocks.BLOCKS.register(modEventBus);
	ModItems.ITEMS.register(modEventBus);
	ModEntityTypes.ENTITY_TYPES.register(modEventBus);

	modLoadingContext.registerConfig(ModConfig.Type.CLIENT, ConfigHolder.CLIENT_SPEC, "ghostsexplosives2-client.toml");
	modLoadingContext.registerConfig(ModConfig.Type.SERVER, ConfigHolder.SERVER_SPEC, "ghostsexplosives2-server.toml");
}

 

My ModBlocks class:

public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, GhostsExplosives.MODID);

public static final RegistryObject<BlockTNTGhostsExplosives> TNT_X1_2 = registerBlockTNT(TNTProperties.TNT_X1_2);

 

My ModEventBusSubscriber class:

@Mod.EventBusSubscriber(modid = GhostsExplosives.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEventBusSubscriber {
	@SubscribeEvent
	public static void onItemRegistry(RegistryEvent.Register<Item> event) {
		final IForgeRegistry<Item> registry = event.getRegistry();

		ModBlocks.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(block -> {
     			final Item.Properties properties = new Item.Properties().group(ItemGroup.SEARCH);
       			final BlockItem blockItem = new BlockItem(block, properties);
       			blockItem.setRegistryName(block.getRegistryName());
       			registry.register(blockItem);
       		});
	}

 

I think this should be everything important

Link to comment
Share on other sites

5 minutes ago, GhostGaming said:

I think this should be everything important

When, where, and how is ItemGroup.SEARCH initialized?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

2020-04-13_15_00_59.thumb.png.661f16c806a7e9e3f88cf9cffac0c8db.png

Here is an image where I tried to add the block in the hotbar to my custom creative tab and set it as the tab icon

 

My custom ItemGroup class:

public class ModItemGroups {
	public static final ItemGroup ITEMGROUP_TNT_BLOCKS = new ModItemGroup("tnt_blocks", () -> new ItemStack(ModBlocks.TNT_X5.get()));
	public static final ItemGroup ITEMGROUP_TNT_MINECARTS = new ModItemGroup("tnt_minecarts", () -> new ItemStack(Items.TNT_MINECART));

	public static final class ModItemGroup extends ItemGroup {
		@Nonnull
		private final Supplier<ItemStack> iconSupplier;

		public ModItemGroup(@Nonnull final String name, @Nonnull final Supplier<ItemStack> iconSupplier) {
			super(GhostsExplosives.MODID + "." + name);
			this.iconSupplier = iconSupplier;
		}

		@Override
		@Nonnull
		public ItemStack createIcon() {
			return iconSupplier.get();
		}
	}
}

 

Edited by GhostGaming
Link to comment
Share on other sites

Just now, GhostGaming said:

Here is an image where I tried to add the block in the hotbar to the inventory and set it as the tab icon

Post your code as a working github repo I would like to test this locally to find an answer. I might be blind or missing information.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

56 minutes ago, Animefan8888 said:

Post your code as a working github repo I would like to test this locally to find an answer. I might be blind or missing information.

I tried using GitHub Desktop to publish my repository but it looks like it completely wrecked my project because all my source files are gone, so I'm gonna cry now for a few days and maybe I'll come back here after I've implemented everything back ?

Link to comment
Share on other sites

10 minutes ago, GhostGaming said:

Well... I got my project back running and the issue still exists. Here is the github repository

Wait are you registering your Blocks twice? Here and here. I'm not sure how I didn't notice this. And commenting out the registry event fixes the issue. Register your Blocks once and only once.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

3 minutes ago, Animefan8888 said:

Wait are you registering your Blocks twice? Here and here. I'm not sure how I didn't notice this. And commenting out the registry event fixes the issue. Register your Blocks once and only once.

So my blocks are being registered again just by subscribing to the registry event? Interesting, I though that event was just called after all blocks have been registered. But anyways, thanks for your help ?

Link to comment
Share on other sites

Just now, GhostGaming said:

So my blocks are being registered again just by subscribing to the registry event? Interesting, I though that event was just called after all blocks have been registered.

Actually I'm crazy sleep deprived, they aren't being registered twice. But commenting out the registry event does fix the problem. And honestly I don't have the brain capacity to see what exactly is happening but I'm gonna say the problem is your Items are getting a different version of the Block than what is actually registered. As such the Block to Item mapping is returning an air Block.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

10 minutes ago, GhostGaming said:

So my blocks are being registered again just by subscribing to the registry event? Interesting, I though that event was just called after all blocks have been registered. But anyways, thanks for your help ?

Well.

Yes.

Because that's what that event is for. You use either a deferred register or the appropriate event.

 

Also:

// SET THE BLOCKS IN THE TNT PROPERTIES

...do that when you construct the block...seriously. You have a perfectly good place to do this already:

https://github.com/alessio1309/GhostsExplosives/blob/cd50068d6c3d5a213df7e7c8791b2b3d69470ffc/scr/main/java/mod/ghostgaming/ghostsexplosives2/init/ModBlocks.java#L73

Edited by Draco18s

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.

Link to comment
Share on other sites

48 minutes ago, Draco18s said:

Well.

Yes.

Because that's what that event is for. You use either a deferred register or the appropriate event.

 

Also:


// SET THE BLOCKS IN THE TNT PROPERTIES

...do that when you construct the block...seriously. You have a perfectly good place to do this already:

https://github.com/alessio1309/GhostsExplosives/blob/cd50068d6c3d5a213df7e7c8791b2b3d69470ffc/scr/main/java/mod/ghostgaming/ghostsexplosives2/init/ModBlocks.java#L73

Yes, I realized that as well, thank you anyways :)

Link to comment
Share on other sites

1 hour ago, Animefan8888 said:

Actually I'm crazy sleep deprived, they aren't being registered twice. But commenting out the registry event does fix the problem. And honestly I don't have the brain capacity to see what exactly is happening but I'm gonna say the problem is your Items are getting a different version of the Block than what is actually registered. As such the Block to Item mapping is returning an air Block.

I've examined what exactly caused the problem and it had nothing to do with the registry event but instead with registering the dispense behavior. I don't understand why this is happening but as soon as I register any sort of dispense behavior, even the default one, it won't show up in the creative inventory anymore. Really weird

Link to comment
Share on other sites

Just now, GhostGaming said:

I've examined what exactly caused the problem and it had nothing to do with the registry event but instead with registering the dispense behavior. I don't understand why this is happening but as soon as I register any sort of dispense behavior, even the default one, it won't show up in the creative inventory anymore. Really weird

Where are you doing it and how are you doing it?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 minute ago, Animefan8888 said:

Where are you doing it and how are you doing it?

In the constructor of the block and by using DispenserBlock.registerDispenseBehavior()

DispenserBlock.registerDispenseBehavior(this, new DefaultDispenseItemBehavior() {
			protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
				World world = source.getWorld();
				BlockPos blockpos = source.getBlockPos().offset(source.getBlockState().get(DispenserBlock.FACING));

				BlockTNTGhostsExplosives block = (BlockTNTGhostsExplosives) ((BlockItem) stack.getItem()).getBlock();

				if (block.getProperties().isIgnitableByDispensers()) {
					EntityTNTGhostsExplosives tntentity = new EntityTNTGhostsExplosives(world, (double) blockpos.getX() + 0.5D, (double) blockpos.getY(), (double) blockpos.getZ() + 0.5D, (LivingEntity) null, block.getProperties());
					world.addEntity(tntentity);
					world.playSound(null, tntentity.getPosX(), tntentity.getPosY(), tntentity.getPosZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
					stack.shrink(1);
				} else {
					Direction direction = source.getBlockState().get(DispenserBlock.FACING);
					IPosition iposition = DispenserBlock.getDispensePosition(source);
					ItemStack itemstack = stack.split(1);
					doDispense(source.getWorld(), itemstack, 6, direction, iposition);
				}
				return stack;
			}
		});

 

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.

Announcements



×
×
  • Create New...

Important Information

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