Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello my saviour,

 

I'm creating an item/tool that is supposed to change a log into a stripped_log just like the new 1.13 mechanic.

I'm using onItemUse (by a saw) to setBlockState.

But my problem is that whenever I use the item in game, it doesn't do anything it also doesn't activate the print.

 

Please consider that I'm not too advanced in modding. And I mainly use the Minecraft files and forge docs as reference.

 

This is a GitHub I setup:

I think the problem is within Java/objects/item/saw

https://github.com/AlmightyElement/thirteen/tree/AlmightyElement-thirteen

 

Thanks in advance,

AlmightyElement

  • Author

Hey diesieben,

 

You're totally right, even dumber is that I've made this mistake before.

 

Do you know how I can resolve this, so I can check the equality?

 

Also I tried to use the debugger, but I have to look further into how to use it; :)

  • Author

I tried this but it still doesn't seem to do anything.

 

package com.almightyelement.thirteen.objects.item;

import com.almightyelement.thirteen.Main;
import com.almightyelement.thirteen.init.ModBlocks;
import com.almightyelement.thirteen.init.ModItems;
import com.almightyelement.thirteen.items.BlockBase;
import com.almightyelement.thirteen.items.ItemBase;
import com.almightyelement.thirteen.util.interfaces.IHasModel;
import com.mojang.realmsclient.dto.PlayerInfo;

import net.minecraft.block.Block;
import net.minecraft.block.BlockLog;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class Saw extends ItemBase implements IHasModel{
	
	public Saw(String name){
		super(name);
	}
	
	
	@Override
	public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitx, float hity, float hitz)
	{
		
		ItemStack item = playerIn.getHeldItem(hand);
		IBlockState block = Blocks.LOG.getDefaultState();
		Block clickedBlock = worldIn.getBlockState(pos).getBlock();
		
			if (clickedBlock == block.getBlock())
			{
				
				worldIn.setBlockState(pos, ModBlocks.STRIPPED_LOG.getDefaultState());
                System.out.println("The system succeeded.");
                return EnumActionResult.PASS;
                
			}	
		
			else
			{
				
			System.out.println("The system failed.");
			return EnumActionResult.FAIL;
			
			}
			
		}
	
	@Override
	public void registerModels() 
	{
		Main.proxy.registerItemRenderer(this, 0, "inventory");
	}
	
}


 

Edited by AlmightyElement

  • Author

Hey,

So I did what you said and my method isn't being called.

 

I even took away the if-statement that checks for the block (as a test)

Is this because onItemUse isn't the right event?

I want a block to change into another block whenever you right click it with this 'saw' item.

49 minutes ago, AlmightyElement said:

IHasModel

Code Style Issue #3

16 minutes ago, AlmightyElement said:

Is this because onItemUse isn't the right event?

You have an @Override annotation. If it was wrong, your IDE would be giving you an error.

 

You're still doing this:

47 minutes ago, diesieben07 said:

Why are you first getting the default state from Blocks.LOG only to then immediately call getBlock on it? This roundtrip makes no sense.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.