Jump to content

[1.7.10] Interact with block


TheiTay

Recommended Posts

Hello,

I'm working on Path-finding algorithm, also I have a class that makes the player go through the path that he found.

I want to programmally make the interaction between the player and a block,  when you try to harvest a block it takes time (depends on block and weapon) and while you try to break it you can see crack animation, this is what I'm looking for.

I want to call a function the does this interaction, I tried to use "harvestBlock" but it only harvests it without applying the animation and calculating how much time it supposed to take.

 

Any ideas how to it?

Thanks in advance.

Link to comment
Share on other sites

Hello, this is the code that I currently have - but the harvestBlock function is not what I'm looking for.

I need a function that would show the crack animation and break the block after the time it should take to mine it...

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
	//this condition is here in order to avoid this code running twice for each tick
	if (event.phase == TickEvent.Phase.END)
		return;

	EntityPlayer player = event.player;
	Minecraft mc = Minecraft.getMinecraft();
	World world = mc.getIntegratedServer().worldServerForDimension(player.dimension);

	Vec3 blockLocation = Vec3.createVectorHelper(403, 35, 250);
	Block block = world.getBlock((int)blockLocation.xCoord, (int)blockLocation.yCoord, (int)blockLocation.zCoord);

	if (!world.isRemote){
		block.harvestBlock(world, player, (int)blockLocation.xCoord, (int)blockLocation.yCoord, (int)blockLocation.zCoord, 0);
	}
}

 

 

Link to comment
Share on other sites

Can't help you directly (update to damn 1.8 please), but that is not way to go.

 

PlayerTickEvent is not only fired by both sides, but also for each player, you can't steer other players  on client.

 

*You need to use ClientTickEvent, registered by ClientProxy.

*You cannot reference ANY server methods/classes/logic.

*You will need to manipulate PlayerControllerMP (in 1.8, idk about 1.7).

*PlayerControllerMP handles client-sided player actions (note that is doesn NOT act on its own, but is a handler of actions) such as mining. It will send packets to server about those actions, including stuff like mining progress. It contains number of methods responsinble for handling mentioned actions. You will need to call those methods from ClientTickEvent whenever you want to create action without human-input (mouse/keyboard), and generate virtual actions - movement, mining, clicking).

 

Example:

Minecraft#rightClickMouse() has a line:

this.playerController.func_178890_a(this.thePlayer, this.theWorld, itemstack, blockpos, this.objectMouseOver.sideHit, this.objectMouseOver.hitVec)

 

Which informs client that "human" clicked mouse. PlayerController will be informed about it and send info to server. You need to replicate those actions.

Simply go over PlayerControllerMP.class and check its method callbacks. Then replicate them virually.

1.7.10 is no longer supported by forge, you are on your own.

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



×
×
  • Create New...

Important Information

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