Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit cf02fa1

Browse files
authored
Added LeftClickEmpty. (#197)
* Added LeftClickEmpty. * Added license header * Added license header * Added @Environment to the event * Alphabetical order * Import order shenanigans * Import order shenanigans... again * Added LeftClickEmpty to ForgeHooks. * Removed unused imports. Also added a @deprecated flag to PlayerPickupXpEvent because yes
1 parent 09451ec commit cf02fa1

File tree

6 files changed

+65
-11
lines changed

6 files changed

+65
-11
lines changed

patchwork-events-entity/src/main/java/net/minecraftforge/event/entity/player/PlayerInteractEvent.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ public Direction getFace() {
9292
}
9393

9494
/**
95-
* @return Convenience method to get the world of this interaction.
95+
* @return The effective, i.e. logical, side of this interaction. This will be {@link LogicalSide#CLIENT} on the client thread, and {@link LogicalSide#SERVER} on the server thread.
9696
*/
97-
public World getWorld() {
98-
return getPlayer().getEntityWorld();
97+
public LogicalSide getSide() {
98+
return getWorld().isClient ? LogicalSide.CLIENT : LogicalSide.SERVER;
9999
}
100100

101101
/**
102-
* @return The effective, i.e. logical, side of this interaction. This will be {@link LogicalSide#CLIENT} on the client thread, and {@link LogicalSide#SERVER} on the server thread.
102+
* @return Convenience method to get the world of this interaction.
103103
*/
104-
public LogicalSide getSide() {
105-
return getWorld().isClient ? LogicalSide.CLIENT : LogicalSide.SERVER;
104+
public World getWorld() {
105+
return getPlayer().getEntityWorld();
106106
}
107107

108108
/**
@@ -295,10 +295,8 @@ public RightClickEmpty(PlayerEntity player, Hand hand) {
295295
* This event is fired when a player left clicks while targeting a block.
296296
*
297297
* <p>This event controls which of {@link net.minecraft.block.Block#onBlockBreakStart(BlockState, World, BlockPos, PlayerEntity)} and/or the item harvesting methods will be called.</p>
298-
299298
* <p>This event is cancellable.
300299
* Cancelling the event will cause none of the above noted methods to be called.</p>
301-
302300
* There are various results to this event, see the getters below.
303301
*
304302
* <p>Note that if the event is canceled and the player holds down left mouse, the event will continue to fire.
@@ -359,9 +357,9 @@ public void setCanceled(boolean canceled) {
359357
*
360358
* <p>This event is not cancellable.</p>
361359
*/
362-
/* TODO public static class LeftClickEmpty extends PlayerInteractEvent {
360+
public static class LeftClickEmpty extends PlayerInteractEvent {
363361
public LeftClickEmpty(PlayerEntity player) {
364362
super(player, Hand.MAIN_HAND, new BlockPos(player), null);
365363
}
366-
}*/
364+
}
367365
}

patchwork-events-entity/src/main/java/net/minecraftforge/event/entity/player/PlayerPickupXpEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import net.minecraft.entity.player.PlayerEntity;
2424

2525
/**
26-
* Legacy version of PlayerXpEvent.PickupXp. Mods should move to PickupXp, and
26+
* Legacy version of PlayerXpEvent.PickupXp.<br/>
2727
* this class is removed in 1.15.
28+
*
29+
* @deprecated Mods should move to {@link net.minecraftforge.event.entity.player.PlayerXpEvent.PickupXp}
2830
*/
2931
@Deprecated
3032
public class PlayerPickupXpEvent extends PlayerXpEvent.PickupXp {

patchwork-events-entity/src/main/java/net/patchworkmc/impl/event/entity/PlayerEvents.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.minecraftforge.common.MinecraftForge;
2323
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
2424
import net.minecraftforge.event.entity.player.PlayerEvent;
25+
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
2526
import net.minecraftforge.eventbus.api.Event;
2627

2728
import net.minecraft.entity.ItemEntity;
@@ -59,6 +60,10 @@ public static void firePlayerSmeltedEvent(PlayerEntity player, ItemStack smelted
5960
MinecraftForge.EVENT_BUS.post(new PlayerEvent.ItemSmeltedEvent(player, smelted));
6061
}
6162

63+
public static void fireLeftClickEmptyEvent(PlayerEntity player) {
64+
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player));
65+
}
66+
6267
/**
6368
*
6469
* @return -1 if the event was canceled, 0 if the event was denied or had no result set, and 1 if the event was allowed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.mixin.event.entity;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.Shadow;
24+
import org.spongepowered.asm.mixin.injection.At;
25+
import org.spongepowered.asm.mixin.injection.Inject;
26+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
27+
28+
import net.minecraft.client.MinecraftClient;
29+
import net.minecraft.client.network.ClientPlayerEntity;
30+
31+
import net.patchworkmc.impl.event.entity.PlayerEvents;
32+
33+
@Mixin(MinecraftClient.class)
34+
public abstract class MixinMinecraftClient {
35+
@Shadow
36+
public ClientPlayerEntity player;
37+
38+
@Inject(method = "doAttack()V",
39+
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;resetLastAttackedTicks()V", shift = At.Shift.AFTER))
40+
private void fireLeftClickEmpty(CallbackInfo ci) {
41+
PlayerEvents.fireLeftClickEmptyEvent(player);
42+
}
43+
}

patchwork-events-entity/src/main/resources/patchwork-events-entity.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"MixinClientPlayerEntity",
3333
"MixinClientWorld",
3434
"MixinItemStack",
35+
"MixinMinecraftClient",
3536
"MixinOtherClientPlayerEntity",
3637
"MixinPlayerEntityRenderer"
3738
],

patchwork-god-classes/src/main/java/net/minecraftforge/common/ForgeHooks.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import net.minecraft.world.World;
5050

5151
import net.patchworkmc.impl.event.entity.EntityEvents;
52+
import net.patchworkmc.impl.event.entity.PlayerEvents;
5253
import net.patchworkmc.impl.extensions.block.BlockHarvestManager;
5354
import net.patchworkmc.impl.loot.LootHooks;
5455

@@ -64,6 +65,10 @@ public static int canEntitySpawn(MobEntity entity, IWorld world, double x, doubl
6465

6566
// TODO: onInteractEntityAt
6667

68+
public static void onEmptyLeftClick(PlayerEntity player) {
69+
PlayerEvents.fireLeftClickEmptyEvent(player);
70+
}
71+
6772
public static ActionResult onInteractEntity(PlayerEntity player, Entity entity, Hand hand) {
6873
return EntityEvents.onInteractEntity(player, entity, hand);
6974
}

0 commit comments

Comments
 (0)