Right clicking mob won't open GUI

Started by lobsterted on

Topic category: Help with MCreator software

Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Right clicking mob won't open GUI

So I created a GUI for my custom mob, and set it to open on right click with the open screen for event/target entity function, but it doesn't work.  I also set it to play a sound, and that works fine, but my GUI just won't open for some reason.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Code, images nothing...
Thu, 06/04/2020 - 23:13

Code, images nothing...

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This happened to be too,…
Fri, 06/05/2020 - 00:24

This happened to be too, just set it to source entity instead of target entity.

Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
 Fair enough, here you go…
Fri, 06/05/2020 - 16:29

what I tried Fair enough, here you go. Thank you!

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can't see the image
Fri, 06/05/2020 - 16:30

Can't see the image

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How is the procedure ran?  
Fri, 06/05/2020 - 16:31

How is the procedure ran?

 

Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it's when right clicked on…
Fri, 06/05/2020 - 16:32

it's when right clicked on entity

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well. Post code if that…
Fri, 06/05/2020 - 16:38

Well. Post code if that procedure doesn't work.]

Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
package net.mcreator…
Fri, 06/05/2020 - 16:46
package net.mcreator.obamamod.procedures;

import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.fml.network.NetworkHooks;

import net.minecraft.world.World;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.network.PacketBuffer;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.inventory.container.Container;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.Entity;

import net.mcreator.obamamod.gui.ObamacareGui;
import net.mcreator.obamamod.ObamaModModElements;

import io.netty.buffer.Unpooled;

@ObamaModModElements.ModElement.Tag
public class ObamaRightClickedOnEntityProcedure extends ObamaModModElements.ModElement {
	public ObamaRightClickedOnEntityProcedure(ObamaModModElements instance) {
		super(instance, 6);
	}

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure ObamaRightClickedOnEntity!");
			return;
		}
		if (dependencies.get("x") == null) {
			System.err.println("Failed to load dependency x for procedure ObamaRightClickedOnEntity!");
			return;
		}
		if (dependencies.get("y") == null) {
			System.err.println("Failed to load dependency y for procedure ObamaRightClickedOnEntity!");
			return;
		}
		if (dependencies.get("z") == null) {
			System.err.println("Failed to load dependency z for procedure ObamaRightClickedOnEntity!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure ObamaRightClickedOnEntity!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		int x = (int) dependencies.get("x");
		int y = (int) dependencies.get("y");
		int z = (int) dependencies.get("z");
		World world = (World) dependencies.get("world");
		{
			Entity _ent = entity;
			if (_ent instanceof ServerPlayerEntity) {
				BlockPos _bpos = new BlockPos((int) x, (int) y, (int) z);
				NetworkHooks.openGui((ServerPlayerEntity) _ent, new INamedContainerProvider() {
					@Override
					public ITextComponent getDisplayName() {
						return new StringTextComponent("Obamacare");
					}

					@Override
					public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) {
						return new ObamacareGui.GuiContainerMod(id, inventory, new PacketBuffer(Unpooled.buffer()).writeBlockPos(_bpos));
					}
				}, _bpos);
			}
		}
		world.playSound((PlayerEntity) null, x, y, z,
				(net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("obama_mod:healthcare")),
				SoundCategory.NEUTRAL, (float) 1, (float) 1);
	}
}

I pretty new to this so I'm not sure if this is what you're looking for, but here you go.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is exactly what I was…
Fri, 06/05/2020 - 17:01

This is exactly what I was looking for. Set it to source entity. I believe that target entity is not referring to the player.

Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It works now! Thanks for…
Fri, 06/05/2020 - 17:06

It works now! Thanks for your help.

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
But I just said that. Why…
Fri, 06/05/2020 - 17:10

But I just said that. Why did you only do it when some else said it...

Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
sorry about that, I thought…
Fri, 06/05/2020 - 17:40

sorry about that, I thought I had already tried that but I guess I just needed to try it again.