Jump to content

Recommended Posts

Posted

I'm new to Minecraft modding but have experience in Java.  

I used some tutorials in order to add an item, so now I want to give this item a purpose.  

There are 2 main things I'm trying to solve:  

  1. If the player right clicks on the ground while holding my item, I need to save the coordinates, in order to spawn blocks at that location
  2. I somehow need to write commands in the in game chat to spawn the blocks, I was thinking something like "/setblock <COORDINATES_FROM_RIGHT_CLICK> <BLOCK_TYPE>. (maybe there is a better way?)

 I probably need some kind of EventHandler for both, but I have no idea where to start.  

Maybe someone can give me some tips and help me go in the right direction, I would be very thankful.  

In the following I will post the code I have so far.  

 

Main mod class:

  Reveal hidden contents

 

Reference class:  

  Reveal hidden contents

 

ModItems class:  

  Reveal hidden contents

 

Item class:  

  Reveal hidden contents

 If there are more information I can give, please let me know.

Posted (edited)
  On 4/26/2019 at 12:41 PM, diesieben07 said:
  • It is not "not ideal", it is fundamentally broken and causes problems. Your way of doing it will additionally completely crash a dedicated server.
  • Your code does not even contain any kind of attempt at the problems you are describing. What have you tried?

Expand  

I don't plan on releasing the mod, it's just a project I'm doing and I wanted to try to implement it in Minecraft.  

 

I tried some methods that I found on other posts with similar questions, but none worked:  

For example:

@Subscribe
	public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
	{
		String command = "Hello, Test!";
		Minecraft.getMinecraft().getConnection().sendPacket((new CPacketChatMessage("/help")));
		return par1ItemStack;
	}

I couldn't figure out how to use the "@Subscribe" annotation properly

Edited by Kekz
Posted (edited)
  On 4/26/2019 at 12:49 PM, diesieben07 said:

I am not even sure what that code is supposed to achieve.

  • Item#onItemUse will be called when your item is used (right-clicked) on a block.
  • "Spawning" blocks can be done via World#setBlockState on the server. There is no need to send packets or chat messages.
Expand  

Thanks, I will look into those methods.  

For clarification: I wrote some code that takes an image and transforms each pixel into a String, like "yellow".  

I thought I could make a mod out of this, where you can instantly spawn an image. (May already exist)

Edited by Kekz
Posted (edited)
  On 4/26/2019 at 12:53 PM, Kekz said:

For clarification: I wrote some code that takes an image and transforms each pixel into a String, like "yellow".  

I thought I could make a mod out of this, where you can instantly spawn an image. (May already exist)

Expand  

Sorry, but your clarification is slightly ambiguous.

What do you mean by "spawn an image"?

Edited by DavidM

Some tips:

  Reveal hidden contents

 

Posted
  On 4/26/2019 at 1:01 PM, DavidM said:

Sorry, but your clarification is slightly ambiguous.

What do you mean by "spawn an image"?

Expand  

Each pixel of the image will be mapped to a String, in this case a Minecraftblock. Then these blocks will be spawned in order to create the image.

Posted
  On 4/26/2019 at 1:04 PM, Kekz said:

Each pixel of the image will be mapped to a String, in this case a Minecraftblock. Then these blocks will be spawned in order to create the image.

Expand  

In this case you should just map each color to a block; there is no need for strings.

Something like Map<Color, Block> should suffice.

Some tips:

  Reveal hidden contents

 

Posted
  On 4/26/2019 at 1:17 PM, DavidM said:

In this case you should just map each color to a block; there is no need for strings.

Something like Map<Color, Block> should suffice.

Expand  

Thanks, but that's not the part of the mod I'm having issues with ^^

Posted
  On 4/26/2019 at 12:49 PM, diesieben07 said:

Item#onItemUse will be called when your item is used (right-clicked) on a block.

Expand  

Is there an event for that? I tried the example from the Forge Doc with the EntityItemPickUpEvent, and that works.  

Couldn't find any Events that are called on Item use.

At least now I have somewhere to start.

Posted

The player interact event has a few subclasses that do what you want.

 

Also: http://wiki.c2.com/?StringlyTyped

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 4/26/2019 at 1:20 PM, Kekz said:

Thanks, but that's not the part of the mod I'm having issues with ^^

Expand  

I thought your main problem was fixed...

If you want to implement the behavior on a custom item, just override Item#onItemUse.

  • Thanks 1

Some tips:

  Reveal hidden contents

 

Posted
  On 4/26/2019 at 2:07 PM, DavidM said:

If you want to implement the behavior on a custom item, just override Item#onItemUse.

Expand  

That seems the best solution, it already works for small 10 x 10 matrices.

Posted

Is there a way to spawn colored wool with 

worldIn.setBlockState(pos, state);

I use 

Blocks.CLAY.getDefaultState();

to spawn a clay block, but I can only find  

Blocks.WOOL;

with no option for colored wool.

Posted

I don't know exactly what you need to do but I think it needs to be something along the lines of

Blocks.WOOL.getDefaultState().withProperty();

Thing is I have not messed with wool so I don't know what properties it has or what you need to put inside the withProperty() part

  • Thanks 1
Posted
  On 4/26/2019 at 5:21 PM, Blue_Atlas said:

I don't know exactly what you need to do but I think it needs to be something along the lines of

Blocks.WOOL.getDefaultState().withProperty();

Thing is I have not messed with wool so I don't know what properties it has or what you need to put inside the withProperty() part

Expand  

Figured it out btw:  

Create a PropertyEnum constant for the EnumDyeColor "COLOR":

public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);

Select a color for wool (should also work for clay):  

Blocks.WOOL.getDefaultState().withProperty(COLOR, EnumDyeColor.WHITE);

 

Posted
  On 4/27/2019 at 5:56 PM, Kekz said:

Create a PropertyEnum constant for the EnumDyeColor "COLOR":

public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);

Select a color for wool (should also work for clay):  

Blocks.WOOL.getDefaultState().withProperty(COLOR, EnumDyeColor.WHITE);

 

Expand  

No. Use BlockWool.COLOR or whatever it’s called

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.