Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Solved] [1.12] Rotate block with item


PegBeard
 Share

Recommended Posts

I have created a wrench item. When right-clicking a rotatable block, such as a piston, with said wrench, it rotates the block. This works fine but;
If I rotate the block during 'onItemUse' and the block has an inventory, the inventory is shown - is there a way I can stop that but still rotate the block?
If I rotate the block during 'onItemUseFirst' no gui is opened but the block resets after a block update - is there a way to make the rotation stick, or is this just the wrong place to do the rotation.

I have my own rotate code, but for testing purposes I am just using the default method and still getting the results stated above:

    @Override
    public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
    	if (hand == EnumHand.OFF_HAND)
    	{
    		return EnumActionResult.FAIL;
    	}

    	Block block = world.getBlockState(pos).getBlock();
    	if (!player.canPlayerEdit(pos, facing, player.getHeldItem(hand)))
    	{
    		return EnumActionResult.PASS;
    	}
    	
    	if (block.getValidRotations(world, pos) != null)
    	{
            if (!player.capabilities.isCreativeMode)
            {
                player.getHeldItem(hand).damageItem(1, player);
            }
            block.rotateBlock(world, pos, facing);
    		SoundType soundtype = block.getSoundType(world.getBlockState(pos), world, pos, player);
            world.playSound(player, pos, soundtype.getHitSound(), SoundCategory.BLOCKS, soundtype.getVolume() * 0.5F, soundtype.getPitch() * 0.75F);
        	player.swingArm(hand);
        	return EnumActionResult.SUCCESS;
    	}
    	return EnumActionResult.PASS;
    }

 

Edited by PegBeard
Link to comment
Share on other sites

If you want the item to always rotate the block, even if it has a GUI and even if the player is not sneaking (this is counter-intuitive!) you need to use onItemUseFirst.

But you should stick to onItemUse, which will prefer the block, unless the player is sneaking, in which case it will cal your item.

Link to comment
Share on other sites

Not meaning to sound rude, but I had figured that much out and it doesn't really answer my question.
Are you saying that there is no good way to get the rotation to stick when using  onItemUseFirst and no good way to give my item preference with  onItemUse except when sneaking?

 

I don't mind sticking with  onItemUse and sneaking, I am just curious if there is a way to do what I am asking, for versatility reasons.

Link to comment
Share on other sites

30 minutes ago, diesieben07 said:

If you want the item to always rotate the block, even if it has a GUI and even if the player is not sneaking (this is counter-intuitive!)

To a degree. 

I can see the rational both ways, but I'd have to play with it for a while before I could decide if the counter-intuitive method would cause me more frustrating than the must-crouch method. 

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.

Link to comment
Share on other sites

It was identical to the code shown above, but in the  onItemUseFirst method. So I didn't want to over complicate the original post.

 

    @Override
    public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, EnumHand hand)
    {
    	if (hand == EnumHand.OFF_HAND)
    	{
    		return EnumActionResult.FAIL;
    	}

    	Block block = world.getBlockState(pos).getBlock();
    	if (!player.canPlayerEdit(pos, facing, player.getHeldItem(hand)))
    	{
    		return EnumActionResult.PASS;
    	}
    	
    	if (block.getValidRotations(world, pos) != null)
    	{
            if (!player.capabilities.isCreativeMode)
            {
                player.getHeldItem(hand).damageItem(1, player);
            }
            block.rotateBlock(world, pos, facing);
    		SoundType soundtype = block.getSoundType(world.getBlockState(pos), world, pos, player);
            world.playSound(player, pos, soundtype.getHitSound(), SoundCategory.BLOCKS, soundtype.getVolume() * 0.5F, soundtype.getPitch() * 0.75F);
        	player.swingArm(hand);
        	return EnumActionResult.SUCCESS;
    	}
    	return EnumActionResult.PASS;
    }

When doing the rotation this way, it appears to rotate, but when the block is updated, it reverts the rotation.

Edited by PegBeard
Link to comment
Share on other sites

Make sure to only do the rotation on the server.

Note that onItemUseFirst is a bit tricky, as when you handle it on the client to cancel further processing, you will need to send CPacketPlayerTryUseItemOnBlock to the server manually, to fire the right click there as well. 

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.

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Every time when i close my inventory in search mode the game crashes. i have many mods installed, but it has nothing to do with the mods.   here is the crash report: pastebin
    • I have a problem and that when I open forge it stays loading in the model manager and there it stays until I close the game then the game appears to have ended incorrectly Exit code 1
    • forge-1.16.4-35.1.4-installer.jar will not install. My 11 y/o son has been working on a world for months and all the mods need this specific version. Is there a way to get the missing files and install them manually? Please review this log file and reply with links if possible:   JVM info: Oracle Corporation - 12.0.2 - 12.0.2+10 java.net.preferIPv4Stack=true Found java version 12.0.2 Extracting json Considering minecraft client jar Downloading libraries Considering library net.minecraftforge:forge:1.16.4-35.1.4   File exists: Checksum validated. Considering library org.ow2.asm:asm:7.2   File exists: Checksum validated. Considering library org.ow2.asm:asm-commons:7.2   File exists: Checksum validated. Considering library org.ow2.asm:asm-tree:7.2   File exists: Checksum validated. Considering library org.ow2.asm:asm-util:7.2   File exists: Checksum validated. Considering library org.ow2.asm:asm-analysis:7.2   File exists: Checksum validated. Considering library cpw.mods:modlauncher:8.0.6   File exists: Checksum validated. Considering library cpw.mods:grossjava9hacks:1.3.0   File exists: Checksum validated. Considering library net.minecraftforge:accesstransformers:2.2.0-shadowed   Downloading library from https://maven.creeperhost.net/net/minecraftforge/accesstransformers/2.2.0-shadowed/accesstransformers-2.2.0-shadowed.jar java.io.FileNotFoundException: https://maven.creeperhost.net/net/minecraftforge/accesstransformers/2.2.0-shadowed/accesstransformers-2.2.0-shadowed.jar     at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)     at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)     at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)     at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1969)     at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1964)     at java.base/java.security.AccessController.doPrivileged(AccessController.java:552)     at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1963)     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1531)     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)     at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:251)     at net.minecraftforge.installer.DownloadUtils.download(DownloadUtils.java:146)     at net.minecraftforge.installer.DownloadUtils.download(DownloadUtils.java:134)     at net.minecraftforge.installer.DownloadUtils.downloadLibrary(DownloadUtils.java:123)     at net.minecraftforge.installer.actions.Action.downloadLibraries(Action.java:79)     at net.minecraftforge.installer.actions.ClientInstall.run(ClientInstall.java:108)     at net.minecraftforge.installer.InstallerPanel.run(InstallerPanel.java:428)     at net.minecraftforge.installer.SimpleInstaller.launchGui(SimpleInstaller.java:170)     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:143) Caused by: java.io.FileNotFoundException: https://maven.creeperhost.net/net/minecraftforge/accesstransformers/2.2.0-shadowed/accesstransformers-2.2.0-shadowed.jar     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1915)     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)     at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)     at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:335)     at net.minecraftforge.installer.DownloadUtils.getConnection(DownloadUtils.java:203)     at net.minecraftforge.installer.DownloadUtils.download(DownloadUtils.java:144)     ... 7 more Considering library net.minecraftforge:eventbus:3.0.5-service   Downloading library from https://maven.creeperhost.net/net/minecraftforge/eventbus/3.0.5-service/eventbus-3.0.5-service.jar java.io.FileNotFoundException: https://maven.creeperhost.net/net/minecraftforge/eventbus/3.0.5-service/eventbus-3.0.5-service.jar     at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)     at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)     at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)     at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1969)     at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1964)     at java.base/java.security.AccessController.doPrivileged(AccessController.java:552)     at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1963)     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1531)     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)     at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:251)     at net.minecraftforge.installer.DownloadUtils.download(DownloadUtils.java:146)     at net.minecraftforge.installer.DownloadUtils.download(DownloadUtils.java:134)     at net.minecraftforge.installer.DownloadUtils.downloadLibrary(DownloadUtils.java:123)     at net.minecraftforge.installer.actions.Action.downloadLibraries(Action.java:79)     at net.minecraftforge.installer.actions.ClientInstall.run(ClientInstall.java:108)     at net.minecraftforge.installer.InstallerPanel.run(InstallerPanel.java:428)     at net.minecraftforge.installer.SimpleInstaller.launchGui(SimpleInstaller.java:170)     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:143) Caused by: java.io.FileNotFoundException: https://maven.creeperhost.net/net/minecraftforge/eventbus/3.0.5-service/eventbus-3.0.5-service.jar     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1915)     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)     at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)     at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:335)     at net.minecraftforge.installer.DownloadUtils.getConnection(DownloadUtils.java:203)     at net.minecraftforge.installer.DownloadUtils.download(DownloadUtils.java:144)     ... 7 more Considering library net.minecraftforge:forgespi:3.2.0   File exists: Checksum validated. Considering library net.minecraftforge:coremods:3.0.0   File exists: Checksum validated. Considering library net.minecraftforge:unsafe:0.2.0   File exists: Checksum validated. Considering library com.electronwill.night-config:core:3.6.2   File exists: Checksum validated. Considering library com.electronwill.night-config:toml:3.6.2   File exists: Checksum validated. Considering library org.jline:jline:3.12.1   File exists: Checksum validated. Considering library org.apache.maven:maven-artifact:3.6.0   File exists: Checksum validated. Considering library net.jodah:typetools:0.8.1   File exists: Checksum validated. Considering library org.apache.logging.log4j:log4j-api:2.11.2   File exists: Checksum validated. Considering library org.apache.logging.log4j:log4j-core:2.11.2   File exists: Checksum validated. Considering library net.minecrell:terminalconsoleappender:1.2.0   File exists: Checksum validated. Considering library net.sf.jopt-simple:jopt-simple:5.0.4   File exists: Checksum validated. Considering library org.spongepowered:mixin:0.8.2   File exists: Checksum validated. Considering library com.github.jponge:lzma-java:1.3   File exists: Checksum validated. Considering library com.google.code.findbugs:jsr305:3.0.2   File exists: Checksum validated. Considering library com.google.code.gson:gson:2.8.0   File exists: Checksum validated. Considering library com.google.errorprone:error_prone_annotations:2.1.3   File exists: Checksum validated. Considering library com.google.guava:guava:20.0   File exists: Checksum validated. Considering library com.google.guava:guava:25.1-jre   File exists: Checksum validated. Considering library com.google.j2objc:j2objc-annotations:1.1   File exists: Checksum validated. Considering library com.nothome:javaxdelta:2.0.1   File exists: Checksum validated. Considering library commons-io:commons-io:2.4   File exists: Checksum validated. Considering library de.oceanlabs.mcp:mcp_config:1.16.4-20201102.104115@zip   File exists: Checksum validated. Considering library de.siegmar:fastcsv:1.0.2   File exists: Checksum validated. Considering library net.md-5:SpecialSource:1.8.5   File exists: Checksum validated. Considering library net.minecraftforge:binarypatcher:1.0.12   File exists: Checksum validated. Considering library net.minecraftforge:forge:1.16.4-35.1.4:universal   File exists: Checksum validated. Considering library net.minecraftforge:installertools:1.1.11   File exists: Checksum validated. Considering library net.minecraftforge:jarsplitter:1.1.2   File exists: Checksum validated. Considering library net.sf.jopt-simple:jopt-simple:4.9   File exists: Checksum validated. Considering library net.sf.jopt-simple:jopt-simple:5.0.4   File exists: Checksum validated. Considering library net.sf.opencsv:opencsv:2.3   File exists: Checksum validated. Considering library org.checkerframework:checker-qual:2.0.0   File exists: Checksum validated. Considering library org.codehaus.mojo:animal-sniffer-annotations:1.14   File exists: Checksum validated. Considering library org.ow2.asm:asm-analysis:6.1.1   File exists: Checksum validated. Considering library org.ow2.asm:asm-commons:6.1.1   File exists: Checksum validated. Considering library org.ow2.asm:asm-tree:6.1.1   File exists: Checksum validated. Considering library org.ow2.asm:asm:6.1.1   File exists: Checksum validated. Considering library trove:trove:1.0.2   File exists: Checksum validated. These libraries failed to download. Try again. net.minecraftforge:accesstransformers:2.2.0-shadowed net.minecraftforge:eventbus:3.0.5-service
    • Sad, so there isnt any working 1.8 ones not 1.8.9
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.