Jump to content

Codding Dices


Joe L Chasseu

Recommended Posts

Hi,

I started to code one week ago, so I'm a beginner and i want to create an item Dice for my server. We have a plugin wich can make dice rolls, so i want to link my item to a command (/dndroll 2d6)...  I tried to use the "onItemRightClick" in my ItemDice class but I'm a bit lost when i have to create the line to send the command into the chat of Minecraft.

 

I hope someone can help me, thanks.

Link to comment
Share on other sites

package init;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;

public class Des extends Item
{
	
	public static ItemStack itemdes;
	
    public ItemStack useItemRightClick(World world, EntityPlayer player)
    {
    	
    	IChatComponent jet = new ChatComponentText("/dndroll 2d6");
    	player.addChatComponentMessage(jet);
    	
    	return player;
    }
}

Des = Dice in french ;)

itemdes = new Des().setUnlocalizedName("des").setCreativeTab(Heimnor.HeimnorCreativeTabs).setTextureName(Heimnor.MODID + ":des");

 

Actually i did this. Please tell me if i did something wrong, i have no error but when i do a right click with my item it did nothing.

Edited by Joe L Chasseu
Link to comment
Share on other sites

There's no method in Item called useItemRightClick, so your method doesn't override anything and is never called. You shouldn't be storing an ItemStack in your Item class, the ItemStack will be provided to most Item methods you override.

 

Always annotate override methods with @Override so you get a compilation error if they don't actually override a super methods. You should use your IDE to auto-generate override methods with the correct signature and annotation.

 

In this case, you'll want to override Item#onItemRightClick and use ICommandManager#executeCommand to execute the command. Use MinecraftServer#getCommandManager to get the server's ICommandManager instance and use World#getMinecraftServer to get the MinecraftServer instance. You should only do all of this on the logical server (when World#isRemote is false).

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.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have been currently having this issue where if I join my server, I get one of these 2 errors. I have tried fixing this issue by looking at the output log in both Server and Client side, from what I have seen I was not able to find anything I can understand that would have helped me. These two errors pop up randomly with no pattern when attempting to join the server when it says Encrypting... I have tried removing all mods from the Client and Server side, which did nothing and still showed the same errors (I don't remember which error showed or even if it showed both), so from what I tried to do, I do not think this is a mod Issue but rather a Forge Issue. How do I fix this? Here are the errors and all the information: Internal Exception: java.lang.NoClassDefFoundError: com/google/common/util/concurrent/TrustedListenableFutureTask Debug.log: https://www.mediafire.com/file/hbtycb1tamqt1qr/debug2.log/file (PS: Debug.log file cannot be uploaded to Pastebin due to it crashing because of the Large Amount of Spam OpenGL logs) Internal Exception: Internal Exception: java.lang.NoClassDefFoundError: com/google/common/collect/LinkedHashMultiMap$ValueSet Debug.log: https://www.mediafire.com/file/o1d48z0bjfyff1e/debug.log/file (PS: Debug.log file cannot be uploaded to Pastebin due to it crashing because of the Large Amount of Spam OpenGL logs) Client Mods: Server Mods:
    • the removing of the Material class has mess up bad mi code now have to many broken things after updating mi code to 1.20.4 this are mi pipes they conect each others but to have it right i have to made a custome BlockItem  the thing its that i need to check the block im looking at  if its some something like grass or wheat i need to ignore and replace whit mi pipe block but if its something like leaves then it must respect it and set the pipe above or at the side  in x < 1.9just check the material the target block is made of     in 1.20 cannot be done like this soo i was trying to make a list of solid blocks but is much work and also it don't have in account blocks from other mods              
    • tysm, ur a life saver,, its weird immersive portals became the issue because I play-tested the mod pack once and everything ran, it only started crashing when I tried playing it a second time.
    • could it be by making a custome block whit no hitbox  or by a falling block entity  // ########## ########## ########## public FallingBlockEntity create_FallingBlock(BlockPos cursor){ this.fallingblock = FallingBlockEntity.fall(warudo, cursor, this.getBlockState() ); this.fallingblock.setNoGravity(true); warudo.addFreshEntity(this.fallingblock); return this.fallingblock; }
    • in 1.19 i notice that an have to fix by hand  in 1.20.4 this is not a problem anymore but 1.20 has its own set of new problems   // ########## ########## ########## ########## // lista de entidades atravezadas por la linea entre vi y vh|vo public ArrayList<LivingEntity> findHitEntitys() { return findHitEntitys(0.0D); } public ArrayList<LivingEntity> findHitEntitys(double grow) { double hgrow = (grow/2) * -1; Vec3 vi = this.subject.getEyePosition(); Vec3 vo = (this.vh != null) ? this.vh : this.vo; /* Double xn = Math.min(vi.x, vo.x); Double xm = Math.max(vi.x, vo.x); Double yn = Math.min(vi.y, vo.y); Double ym = Math.max(vi.y, vo.y); Double zn = Math.min(vi.z, vo.z); Double zm = Math.max(vi.z, vo.z); Vec3 vdi = new Vec3(xn,yn,zn); Vec3 vdo = new Vec3(xm,ym,zm); */ // particle(warudo, vo); AABB bb = new AABB(vi, vo).inflate(2.0D); //System.out.println( (bb.maxX - bb.minX) + ", " + (bb.maxY - bb.minY) + ", " + (bb.maxZ - bb.minZ) ); ArrayList<LivingEntity> list = new ArrayList<LivingEntity>(); Predicate<? super Entity> cosa = target -> (target instanceof LivingEntity);// for (Entity target_entity : this.warudo.getEntities(this.subject, bb, cosa)) { //System.out.println(entity1.getBoundingBox()); // is the entity in the line //if (entity1 instanceof LivingEntity) { AABB aabb = target_entity.getBoundingBox().inflate(grow); //System.out.println( "x " + (aabb.maxX - entity1.getX()) + ", " + ( entity1.getX() - aabb.minX ) ); //System.out.println( "y " + (aabb.maxY - entity1.getY()) + ", " + ( entity1.getY() - aabb.minY ) ); //System.out.println( "z " + (aabb.maxZ - entity1.getZ()) + ", " + ( entity1.getZ() - aabb.minZ ) ); Optional<Vec3> optional = aabb.clip(vi, vo); //System.out.println(aabb); if (optional.isPresent()) { list.add((LivingEntity) target_entity); } } } list.sort((o1, o2) -> (Double.compare(o1.position().distanceTo(vi), o2.position().distanceTo(vi)))); return list; }   1.20.4 has not this problem anymore
  • Topics

×
×
  • Create New...

Important Information

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