Jump to content

[Solvedviaworkaround]addVelocity works in onBlockActivated but not in updateTick


Recommended Posts

Posted

Here's the code:

 

Edit: And here's the code on paste.minecraftforge.net for the syntax highlighting:

http://paste.minecraftforge.net/view/4eed23b9

 

public void updateTick(World currentWorld, int x, int y, int z, Random random)
{
	currentWorld.scheduleBlockUpdate(x, y, z, this.blockID, this.tickRate());

	AxisAlignedBB interactionBox = AxisAlignedBB.getBoundingBox(x, y, z, x+1, y+8, z+1);
	List entitiesToPush = currentWorld.getEntitiesWithinAABBExcludingEntity((Entity)null, interactionBox);
	Iterator entityToCheck = entitiesToPush.iterator();

	while (entityToCheck.hasNext())
	{
		Object tempObject = entityToCheck.next();
		Entity currentEntity = (Entity) tempObject;
		System.out.println(currentEntity.toString());
		currentEntity.addVelocity(0, 1, 0);
	}
}

 

public boolean onBlockActivated(World currentWorld, int x, int y, int z, EntityPlayer activatingPlayer, int par6, float par7, float par8, float par9)
{
System.out.println(activatingPlayer.toString());
activatingPlayer.addVelocity(0, 1, 0);
return true;
}

 

The output from updateTick when I stand within the bounding box is:

EntityPlayerMP['Player926'/533, l='New World', x=4.85, y=64.00, z=229.69]

The physical result of standing in the bounding box is absolutely nothing. Though other entities (mobs, items, etc) do get pushed properly, though there is some visual jittering if the block tries to keep them at a steady height.

 

The output from onBlockActivated is:

EntityClientPlayerMP['Player926'/533, l='MpServer', x=3.44, y=65.62, z=229.95]
EntityPlayerMP['Player926'/533, l='New World', x=3.44, y=64.00, z=229.95]

The physical result of right-clicking the block is that I get flung up into the air, as expected.

 

The forge modloader version is 4.7.4.520, and the forge version is v6.6.0.497. Minecraft coder pack is version 7.26. The Minecraft version is, of course, 1.4.7.

 

Does anyone know what I'm doing wrong? Or if this is a bug of some sort?

 

Edit2: Note, I have changed the types in the updateTick code from "Entity" to "EntityPlayer", and even "EntityPlayerMP", but none of those changed the output or actually moved the player.

Posted

Sorry to bump the thread, but it's been three days since I posted, which seems like a safe amount of time to wait.

 

I've been poking around a bit, but still haven't figured out what the problem is. My guess is that it's related to the fact that onBlockActivated gets called twice, once with an EntityClientPlayerMP and once with an EntityPlayerMP, but I have no idea why that is, or how to get an EntityClientPlayerMP for updateTick to act upon. Especially since casting from EntityPlayerMP to EntityClientPlayerMP is not possible.

Posted

Making a new post to ensure that anyone who has subscribed to the thread gets a notification.

 

After much more poking around, I finally figured out a work around. I made the block extend BlockContainer instead of just Block, and added a tileEntity that moves entities in its UpdateEntity method.

 

Lolth knows why player movement is handled client-side instead of server-side, or why the updateTick method of a standard block doesn't bother to get used for prediction by the client.

 

If anyone knows how to properly notify the client that stuff is being pushed around without resorting to using a tile entity, please let me know. Until then, I'll just have to make do with this method. :/

 

Edit: Sorry about the squished together "[solved]" title edit. Apparently I was just barely under the title length limit with the original title, so there wasn't much leeway for me to use.

Posted

I don't have a tick handler class (I was using the updateTick method in my block's class), and the proxies are just the ones from the wiki tutorial which preload the textures.

 

Taking a cue from you comment, however, I've just moved the method that pushes entities into the proxy classes, and called it from the block's updateTick method. Unfortunately, even after making the code run in the client proxy, the World.getEntitiesWithinAABB method still only seems to return EntityPlayerMP when the player is within the bounding box, instead of returning an EntityClientPlayerMP.

 

After a bit more testing, it turns out that this is because the block only receives the server's world object when it ticks, so when it passes that to the client proxy, the client proxy doesn't have the client world, and only the client's world will have the EntityClientPlayerMP in it to detect and move the player.

 

So now the question is, how do I get the client's world, so that I can detect the EntityClientPlayerMP in it?

With the TileEntity (and also the block's onBlockActivated), it will be triggered by both the client and server, and thus gets the proper client world to push the player in. Whereas blocks seem to only receive the server world when they get ticked, and never the client world.

Posted

on re-reading your post i realised that my tick handler method probably isn't the most optimal here, have you instead considered overriding

public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {
//code
}

in your block class?

 

you could also look at the following other methods in the block class:

 public void onEntityWalking(World par1World, int par2, int par3, int par4, Entity par5Entity) {
//code
}

public void onFallenUpon(World par1World, int par2, int par3, int par4, Entity par5Entity, float par6) {
//code
}

 

[EDIT]

all these methods are in the block class

Posted

onEntityCollidedWithBlock only seemed to trigger with arrows (which seem to slightly enter the block), while players, mobs, and items, just seem to bump into the block without triggering it.

 

onEntityWalking seems to work properly, both pushing the player, and being called with an EntityClientPlayerMP.

I probably should have mentioned, however, that I want to be able to move all types entities, and move them from a distance. (The goal for this block is to function similarly to the Arcane Levitator from Thaumcraft 3, except to also be able to push (or pull) in all six directions, instead of only pushing up.)

 

As for onFallenUpon, things just get strange. That method does get called on both the client and server, once with an EntityClientPlayerMP and once with an EntityPlayerMP, but then the player doesn't actually move when using addVelocity, or even when their velocity is manually set (even though the velocity does indeed get set, as a check of the entity's velocity afterward shows). Even stranger, checking the entity's velocity afterwards shows that it slows as if reaching the top of a jump, but the entity is still firmly on the ground. If I repeatedly jump up and down on the block, it will keep increasing my "motionY" to greater and greater levels, but I never actually rocket into the sky as the high motionY would suggest I should. If I put a block above myself, the motionY does not keep increasing the more I jump on the block.

It does the same thing for mobs too, detects them, sets their velocity, and then they simply stay firmly on the ground.

It also doesn't seem to detect items that fall on it.

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

    • Well, when I log in to the server, sometimes within an hour, sometimes within a minute, the server closes and informs me that there was a Ticking entity error. Below is the crash report
    • Try switching to Windowed or Borderless Window mode in Minecraft. These modes make it easier for the recorder to capture gameplay, as it still has access to the display without the game taking up all of the graphics resources.
    • This forum is for Forge, not NeoForge. Please go to them for support.
    • Forge version: 55.0.0 Minecraft version: 1.21.5 Downloads: As this is the start of a new version, it is recommended that you check the downloads page and use the latest version to receive any bug fixes. Downloads page Intro: Good evening! Today, we have released our initial build of Forge 55.0 for Minecraft 1.21.5. 1.21.5 is the newest member of the 1.21 family of versions, which was released yesterday on March 25, 2025. As a reminder, the first minor (X.0) of a Forge version is a beta. Forge betas are marked as such on the bottom left of the title screen and are candidates for any breaking changes. Additionally, there are a couple of important things to note about this update, which I've made sure to mention in this post as well. Feel free to chat with us about bugs or these implementation changes on GitHub and in our Discord server. As always, we will continue to keep all versions of 1.21 and 1.20 in active support as covered by our tiered support policy. Cheers, happy modding, and good luck porting! Rendering Refactor For those who tuned in to Minecraft Live on March 22, 2025, you may already know that Mojang have announced their intention to bring their new Vibrant Visuals overhaul to Java in the future. They've taken the first steps toward this by refactoring how rendering pipelines and render types are handled internally. This has, in turn, made many of Forge's rendering APIs that have existed for years obsolete, as they (for the most part) can be done directly in vanilla. If there was a rendering API that was provided by Forge which you believe should be re-implemented, we're happy to discuss on GitHub through an issue or a pull request. Deprecation of weapon-like ToolActions In 1.21.5, Minecraft added new data components for defining the characteristics of weapons in data. This includes attack speed, block tags which define efficient blocks, and more. As such, we will begin marking our ToolActions solution for this as deprecated. ToolActions were originally added to address the problem of creating modded tools that needed to perform the same actions as vanilla tools. There are still a few tool actions that will continue to be used, such as the shears tool action for example. There are some existing Forge tool actions that are currently obsolete and have no effect given the way the new data components are implemented. We will continue to work on these deprecations and invite you to chat with us on GitHub or Discord if you have any questions.
    • In summary, a full mod to adjust mining progress in such a specific way does not yet exist in its exact form, but it is possible to find mods that change certain aspects of progression (e.g. "Harder Ores").
  • Topics

×
×
  • Create New...

Important Information

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