Jump to content

Recommended Posts

Posted

So I have an item that needs to check if the player is actually looking at some block, so I use RayTraceResult for this, that can be called only on Client Side.

 

My Problem is that then, if that returns true, I need to do something on the Server side, but as I'm setting a boolean to true on the Client side, that boolean is true only on the Client, and not on the Server.

 

How would I go around this so the server knows that the boolean is returning true on the Client and it needs to do stuff?

 

This is the code:

 

	@Override
    public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)
    {

	//CHECK IF IS SELECTED
	if(isSelected){

		if(updateTick>=4)
    	{
    		updateTick = 0;
    		
    		//CLIENT SIDE
    		if(world.isRemote){
    			
    			//IS LOCKED?
    			if(this.getNBTTagBoolean(stack, TAG_WATERING_DONGLE_LOCKED)){
    				
    				//GET BLOCK PLAYER IS LOOKING AT
        			RayTraceResult rtr = Minecraft.getMinecraft().objectMouseOver;
        	    	
        			if(rtr!=null){
        	
        				RayTraceResult.Type rtrHit = rtr.typeOfHit;
        	
        				//IS PLAYER LOOKING AT A BLOCK?
        				if(rtrHit == RayTraceResult.Type.BLOCK) {
        					
        					posBlockWatering = rtr.getBlockPos();
        					playerWatering = (EntityPlayer) entity;
        					doWatering = true;
        				}//END LOOKING AT BLOCK
        				
        				//NO LOOKING AT BLOCK
        				else{
        					posBlockWatering = null;
        					playerWatering = null;
        					doWatering = false;
        				}//END NO LOOKING AT BLOCK
        			}
        			
    				
    			}//END IS LOCKED
    			
    			//NO LOCKED
    			else{
    				doWatering = false;
    			}//END NO LOCKED
    			
    		}//END CLIENT SIDE
    		
    		if(doWatering){
    			doWater(stack, world, playerWatering, posBlockWatering);
    		}
    		
    	}

		//UPDATE TICK NOT 4 OR HIGHER - INCREASE IT
		else{
			updateTick++;
		}

	}

	//NO SELECTED
	else{

		this.updateNBTData(stack, TAG_WATERING_DONGLE_LOCKED, false);
		doWatering = false;
	}
    	
	    	    		
    }//END ON UPDATE

 

Complete code here: http://pastebin.com/6gXh7inP

 

Thanks for the help.

Posted

You can ray trace on the server just fine.

So... Maybe the error was another?

 

This was the crash report.

 

[12:11:40] [server thread/WARN] [net.minecraft.network.NetworkSystem]: Failed to handle packet for /127.0.0.1:51001
net.minecraft.util.ReportedException: Ticking player
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:418) ~[EntityPlayerMP.class:?]
at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:174) ~[NetHandlerPlayServer.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:215) ~[NetworkDispatcher$1.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:308) ~[NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:195) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:806) [MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:408) [DedicatedServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/Minecraft
at com.mramericanmike.mikedongles.items.WateringDongle.onUpdate(WateringDongle.java:214) ~[WateringDongle.class:?]
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:526) ~[itemStack.class:?]
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:389) ~[inventoryPlayer.class:?]
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:559) ~[EntityPlayer.class:?]
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2218) ~[EntityLivingBase.class:?]
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:259) ~[EntityPlayer.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:341) ~[EntityPlayerMP.class:?]
... 9 more
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.Minecraft
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191) ~[launchwrapper-1.12.jar:?]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
at com.mramericanmike.mikedongles.items.WateringDongle.onUpdate(WateringDongle.java:214) ~[WateringDongle.class:?]
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:526) ~[itemStack.class:?]
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:389) ~[inventoryPlayer.class:?]
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:559) ~[EntityPlayer.class:?]
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2218) ~[EntityLivingBase.class:?]
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:259) ~[EntityPlayer.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:341) ~[EntityPlayerMP.class:?]
... 9 more
Caused by: net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerException: Exception in class transformer net.minecraftforge.fml.common.asm.transformers.SideTransformer@770b3be0 from coremod FMLCorePlugin
at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:253) ~[forgeSrc-1.10.2-12.18.1.2018.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) ~[launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) ~[launchwrapper-1.12.jar:?]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
at com.mramericanmike.mikedongles.items.WateringDongle.onUpdate(WateringDongle.java:214) ~[WateringDongle.class:?]
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:526) ~[itemStack.class:?]
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:389) ~[inventoryPlayer.class:?]
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:559) ~[EntityPlayer.class:?]
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2218) ~[EntityLivingBase.class:?]
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:259) ~[EntityPlayer.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:341) ~[EntityPlayerMP.class:?]
... 9 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/Minecraft for invalid side SERVER
at net.minecraftforge.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:56) ~[forgeSrc-1.10.2-12.18.1.2018.jar:?]
at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:249) ~[forgeSrc-1.10.2-12.18.1.2018.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) ~[launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) ~[launchwrapper-1.12.jar:?]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
at com.mramericanmike.mikedongles.items.WateringDongle.onUpdate(WateringDongle.java:214) ~[WateringDongle.class:?]
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:526) ~[itemStack.class:?]
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:389) ~[inventoryPlayer.class:?]
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:559) ~[EntityPlayer.class:?]
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2218) ~[EntityLivingBase.class:?]
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:259) ~[EntityPlayer.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:341) ~[EntityPlayerMP.class:?]
... 9 more

 

Maybe I misread it and the problem was a different one?

 

Line 214 I believe it was were this was on the original code before I redid it.

 

RayTraceResult rtr = Minecraft.getMinecraft().objectMouseOver;

 

Posted

:o

I think I noticed now where I went wrong, using:

 

RayTraceResult rtr = Minecraft.getMinecraft().objectMouseOver;

 

When apparently I should be using:

 

RayTraceResult rtr = entity.rayTrace(6, 1);

 

Gonna do some tests with that now and see how it goes. Hopefully this is the fix.

Posted

Entity#rayTrace

is a client-only method, you can't use it on the server.

 

Use

Item#rayTrace

to raytrace along a player's look vector for their reach distance.

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.

Posted

Thanks, I'm using something like this now. Problems solved apparently ;)

 

EntityPlayer player = (EntityPlayer) entity;
RayTraceResult rtr = this.rayTrace(world, player, false);

 

And I'm also running the code only when:

 

if(entity instanceof EntityPlayer){

 

I think I have to make that check right? Because otherway the code will also run if some mob is holding the item?

Posted

Thanks, I'm using something like this now. Problems solved apparently ;)

 

EntityPlayer player = (EntityPlayer) entity;
RayTraceResult rtr = this.rayTrace(world, player, false);

 

And I'm also running the code only when:

 

if(entity instanceof EntityPlayer){

 

I think I have to make that check right? Because otherway the code will also run if some mob is holding the item?

 

Yes. You can only cast a value to a type if you know that it's a value of that type.

 

I just noticed that you appear to be using a field of your

Item

class as a timer, this won't work.

Item

s are singletons, only one instance exists per item type. This means that you can't store per-stack data in fields, you need to store it in the

ItemStack

(using metadata, NBT or capabilities).

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.

Posted

Thanks, I'm using something like this now. Problems solved apparently ;)

 

EntityPlayer player = (EntityPlayer) entity;
RayTraceResult rtr = this.rayTrace(world, player, false);

 

And I'm also running the code only when:

 

if(entity instanceof EntityPlayer){

 

I think I have to make that check right? Because otherway the code will also run if some mob is holding the item?

 

Yes. You can only cast a value to a type if you know that it's a value of that type.

 

I just noticed that you appear to be using a field of your

Item

class as a timer, this won't work.

Item

s are singletons, only one instance exists per item type. This means that you can't store per-stack data in fields, you need to store it in the

ItemStack

(using metadata, NBT or capabilities).

 

You mean the "updateTick"?

 

It's only running if the item is selected and the item is only max stack at 1, so it shouldn't be a problem, right?

Posted

What he said was that your timer variable is the same for every item in the game, so if one Player is holding this item and another player is holding it or not holding it the variable will be equal among the items.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

So guys, I went onr of the way you suggested and I'm using the NBT to store the timer, but the problem I see now is that whenever I'm holding the item, it never comes to position. Like you know when you hold a tool and it shows from down and it comes up, its happening the same, but it stays always down.

 

The item works and everything, but I'm not sure what's causing this. I believe it is the reason that I'm constantly updating the NBT (I mean, it has to be that right?) but not sure what I can do to prevent this.

 

Here is the code:

 

http://pastebin.com/46S1v18u

 

Thanks once again for the patience, as always :D

Posted

Basically:

if the equipped slot changes

if the item (ItemStack#getItem) in the slot changes

or if the item metadata changes (most likely you still want this)

 

The base implementation checks all of those and if any NBT changes were made (you're wanting to ignore this).

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.

Posted

Basically:

if the equipped slot changes

if the item (ItemStack#getItem) in the slot changes

or if the item metadata changes (most likely you still want this)

 

The base implementation checks all of those and if any NBT changes were made (you're wanting to ignore this).

 

Yes, I went with checking if the LOCKED on the NBT changed from the oldStack to the newStack and performed the animation just in that case, that way the item get "re-equipped" and the render effect of been enchanted get recognized. Any other just returns false.

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

    • Hello! I have been having a problem with Forgematica, Embeddium, Oculus, and create. I wanted to download litematica so I could see which blocks are in my creative mode build, so that I could collect them all in survival. However, litematica is a fabric mod. I found a port called forgematica, which I added (along with it's dependency) to my mods folder. I loaded into a new world, and built a structure. Then, I added a part from the create mod, and the game crashed instantly, with exit code -1. Thanks for any help! Crash Report and mods list: https://pastebin.com/rtzh6LAi
    • To say that losing 40,000 BTC was a devastating blow would be an understatement. It was an emotional and financial crisis that left me feeling hopeless and utterly lost. For weeks, I was trapped in a whirlwind of regret, second-guessing every decision that led me to that point. The fear that I would never be able to recover such a significant sum of cryptocurrency consumed me, and with each passing day, my despair deepened. I had all but given up on ever regaining my wealth. Then I happened to stumble onto Tech Cyber Force Recovery. In the beginning, I was hesitant. It looked too good to be true: could someone get back so much of their lost Bitcoin? After trying several different approaches and programs without success, I was hesitant to put my trust in another recovery agency. However, I changed my mind after reading Tech Cyber Force Recovery's stellar reviews and reputation. Reaching out to their team was a risk I made. They were courteous and professional from the first time I got in touch with them. I felt like I wasn't just another case to be solved by the staff at Tech Cyber Force Recovery; they truly cared about getting me my lost Bitcoin back. They listened carefully to my circumstances and guided me through each stage, giving me succinct and understandable explanations as I went. Their passion gave me new hope, and their openness instantly made me feel better. As the recovery process began, I still had my doubts, but I knew I had placed my trust in the right hands. The Tech Cyber Force Recovery team kept me informed and updated on their progress, ensuring I never felt in the dark. Despite the complexity of my case, they worked tirelessly, and their expertise became evident at every turn. The level of professionalism and attention to detail they demonstrated throughout the process was beyond impressive. And then, after what felt like an eternity of anticipation, the moment I had been waiting for arrived. I received the news that my 40,000 BTC had been successfully recovered. It was hard to believe at first—it felt like a dream. The weight that had been dragging me down for so long was suddenly lifted, and I could breathe again. The financial loss I had feared would define my future was no longer a reality. I can’t fully express the emotions I felt during that moment. It was a mix of relief, joy, and an overwhelming sense of gratitude. I had gone from a place of utter despair to a complete resurgence of wealth, both emotionally and financially. The Tech Cyber Force Recovery team didn’t just restore my Bitcoin—they restored my faith in the possibility of recovery and gave me back something far more valuable: peace of mind. I will urge anyone in this same predicament to.  
    • Have you found a modder for this vehicle project? Because it will be really hard and I want to know that hero who can create all this
    • and what?????????
  • Topics

×
×
  • Create New...

Important Information

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