Jump to content

Recommended Posts

Posted
  On 3/11/2020 at 8:59 PM, Dr.Nickenstein said:

So I want this item to check the block that it hits on right click, and if it is a certain block, it returns a certain item

 

Expand  

Don't do it on the item, do it on the block. If it is your block override onBlockActivated and check if the player is holding your item. If it is a vanilla block use events to achieve the same thing.

Posted (edited)
  On 3/12/2020 at 9:45 AM, Dr.Nickenstein said:

Yes, it is. It's called "RubberStreamingRubberWoodLog", that's the class that I created.

 

Expand  

Then go to your block class, override onBlockActivated and check there if the player is holding your item. If it is, do stuff. onBlockActivated provides you with the player that right clicked the block and the hand he used, so you have pretty much all you need.

 

Alternatively, you can subscribe to PlayerInteractEvent.RightClickBlock and check there if the player is holding your item.

Edited by Cerandior
Posted (edited)
  On 3/12/2020 at 10:40 AM, Cerandior said:

Then go to your block class, override onBlockActivated and check there if the player is holding your item. If it is, do stuff. onBlockActivated provides you with the player that right clicked the block and the hand he used, so you have pretty much all you need.

 

Alternatively, you can subscribe to PlayerInteractEvent.RightClickBlock and check there if the player is holding your item.

Expand  

so this? player.getHeldItem(handIn); and then how do i check which item it is?

Edited by Dr.Nickenstein
Posted
  On 3/12/2020 at 10:44 AM, Dr.Nickenstein said:

so this? player.getHeldItem(handIn); and then how do i check which item it is?

Expand  

That will return an itemstack I believe. 
itemstack.getItem() will give you the item and then you use instanceof to check whether that item is the same with what you want or not.

Posted
  On 3/12/2020 at 10:46 AM, Cerandior said:

That will return an itemstack I believe. 
itemstack.getItem() will give you the item and then you use instanceof to check whether that item is the same with what you want or not.

Expand  

Yeah i want this block to drop a certain item when it is right clicked (activated) with another item.

Posted (edited)
  On 3/12/2020 at 10:46 AM, Cerandior said:

That will return an itemstack I believe. 
itemstack.getItem() will give you the item and then you use instanceof to check whether that item is the same with what you want or not.

Expand  

@Override
    public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player,
            Hand handIn, BlockRayTraceResult hit)
    {    
        ItemStack itemstack = player.getHeldItem(handIn);
        itemstack.getItem();
        if
        {
            itemstack = ItemInit.RUBBER_EXTRACTOR.get();
        }
        
    }
   

I've done this, but on itemstack = ItemInit.RUBBER_EXTRACTOR.get(); it gives me an error it says it can't convert from ItemStack to Item. How do I fix it?

The problem is item and itemstack are different things apparently, and the methods work with itemstack. Help

Edited by Dr.Nickenstein
Posted
  On 3/12/2020 at 10:54 AM, Dr.Nickenstein said:

@Override
    public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player,
            Hand handIn, BlockRayTraceResult hit)
    {    
        ItemStack itemstack = player.getHeldItem(handIn);
        itemstack.getItem();
        if
        {
            itemstack = ItemInit.RUBBER_EXTRACTOR.get();
        }
        
    }
   

I've done this, but on itemstack = ItemInit.RUBBER_EXTRACTOR.get(); it gives me an error it says it can't convert from ItemStack to Item. How do I fix it?

The problem is item and itemstack are different things apparently, and the methods work with itemstack. Help

Expand  

 

I have no clue what the hell are you doing there. Don't mean to insult you, but based on that I am assuming you don't have much experience with programming in general.

I'll help you this time and write it for you, but you will not get far if you don't know much programming.
 

Item item = player.getHeldItem(handIn).getItem();

if(item instanceof ItemInit.RUBBER_EXTRACTOR){
	//Do stuff
}

 

What you did wrong before:
1) itemstack.getItem() returns an item and does nothing else. Simply calling it and not assigning the returned value anywhere means that line of code is pretty much useless.

2) That is not how you use if statements. The syntax is:

if(condition){
statement
}

 

Posted (edited)
  On 3/12/2020 at 11:04 AM, Cerandior said:

 

I have no clue what the hell are you doing there. Don't mean to insult you, but based on that I am assuming you don't have much experience with programming in general.

I'll help you this time and write it for you, but you will not get far if you don't know much programming.
 

Item item = player.getHeldItem(handIn).getItem();

if(item instanceof ItemInit.RUBBER_EXTRACTOR){
	//Do stuff
}

 

What you did wrong before:
1) itemstack.getItem() returns an item and does nothing else. Simply calling it and not assigning the returned value anywhere means that line of code is pretty much useless.

2) That is not how you use if statements. The syntax is:

if(condition){
statement
}

 

Expand  

For the second error, i corrected it later but didn't correct the post with it, for the first one thanks. BTW wehn you do (item instanceof ItemInit.RUBBER_EXTRACTOR)

{

stuff

}

it says rubber extractor isn't a type, and I can't reference any kind of other items

Edited by Dr.Nickenstein
Posted
  On 3/12/2020 at 11:07 AM, Dr.Nickenstein said:

item instanceof ItemInit.RUBBER_EXTRACTOR

Expand  

Sigh.

Let me break this down.

X instanceof Y requires X to be an object and Y to be a Class.

X == Y requires X to be an object (or primative) and Y to be an object (or primative).

Your code, item instanceof ItemInit.RUBBER_EXTRACTOR, has X is an object, Y is an object.

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.

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

    • That is incorrect. Use the run.bat or run.sh to run the server.
    • Hello, I have been trying for days to create my server with forge-1.20.1-47.4.1-installer, which installs the server, but the forge-1.20.1-47.4.1.jar file, which is necessary to create the server, does not appear. I no longer know what to do. Help. hola buenas, llevo dias intentando poder hacer mi servidor con forge-1.20.1-47.4.1-installer el cual instalo el server, pero no aparece el archivo forge-1.20.1-47.4.1.jar , el cual es necesario para poder crear el server, ya no se que hacer ayuda.
    • Does this happen if you use the regular vanilla minecraft launcher? Also, unsure if TLauncher ever has a legit usage, as I have always seen it associated with software piracy, but if it has a legit mode, make sure it is using online mode so that it can authenticate your MS account to login. Aside from that, more information is likely needed. Post logs, as well as the paths you are placing files in (screenshots of your file explorer can be helpful as well).
    • I am using a third-party launcher that has pre-installed forge versions of Minecraft.  When I insert mods from CurseForge, I extract the files and as expected put them in the .mods folder. I am guessing that there is an error with the file transfer but I don't know for sure and sometimes I use Forge to test mods that I created before releasing previously on a different pc, so I don't know if it is the if it an extraction error but if are any tips or knowledge reply and I will read it. This is also will be kept on the forum for others that have the issues.
    • I make wires and i need connection 2 wires block. I have BooleanPropertys registered, but in mod loading it show Unknown the property in assets/wuntare/blockState. public static final BooleanProperty CONNECTED_NORTH = BooleanProperty.create("connected_north"); public static final BooleanProperty CONNECTED_SOUTH = BooleanProperty.create("connected_south"); public static final BooleanProperty CONNECTED_WEST = BooleanProperty.create("connected_west"); public static final BooleanProperty CONNECTED_EAST = BooleanProperty.create("connected_east"); public static final BooleanProperty CONNECTED_UP = BooleanProperty.create("connected_up"); public static final BooleanProperty CONNECTED_DOWN = BooleanProperty.create("connected_down"); public CopperWireWithoutInsulation0(Properties properties) { super(properties); this.registerDefaultState(this.stateDefinition.any() .setValue(CONNECTED_NORTH, false) .setValue(CONNECTED_SOUTH, false) .setValue(CONNECTED_WEST, false) .setValue(CONNECTED_EAST, false) .setValue(CONNECTED_UP, false) .setValue(CONNECTED_DOWN, false)); } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(CONNECTED_NORTH, CONNECTED_SOUTH, CONNECTED_WEST, CONNECTED_EAST, CONNECTED_UP, CONNECTED_DOWN); } In this part blockState have problem "multipart": [ { "apply": { "model": "wuntare:block/copper_wire_without_insulation0" } }, { "when": { "connected_north": true }, "apply": { "model": "wuntare:block/copper_wire_without_insulation0_north" } },  
  • Topics

×
×
  • Create New...

Important Information

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