player swinging events.
This commit is contained in:
1 parent
c6529c3d3c
commit
f54ab746fe
8 files changed
+61
-4
No files matched your search
@@ -1,9 +1,9 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.c2s.play.ButtonClickC2SPacket;
|
||||
import net.minecraft.network.packet.c2s.play.CraftRequestC2SPacket;
|
||||
import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket;
|
||||
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@@ -40,6 +40,7 @@ import static carpet.script.CarpetEventServer.Event.PLAYER_STARTS_SPRINTING;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_STOPS_SNEAKING;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_STOPS_SPRINTING;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_SWAPS_HANDS;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_SWINGS_HAND;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_SWITCHES_SLOT;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_USES_ITEM;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_WAKES_UP;
|
||||
@@ -266,4 +267,17 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
PLAYER_SWITCHES_SLOT.onSlotSwitch(player, player.inventory.selectedSlot, packet.getSelectedSlot());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onHandSwing", at = @At(
|
||||
value = "INVOKE", target =
|
||||
"Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V",
|
||||
shift = At.Shift.BEFORE)
|
||||
)
|
||||
private void onSwing(HandSwingC2SPacket packet, CallbackInfo ci)
|
||||
{
|
||||
if (PLAYER_SWINGS_HAND.isNeeded() && !player.handSwinging)
|
||||
{
|
||||
PLAYER_SWINGS_HAND.onHandAction(player, packet.getHand());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -693,6 +693,18 @@ public class CarpetEventServer
|
||||
handler.call( () -> Collections.singletonList(new EntityValue(player)), player::getCommandSource);
|
||||
}
|
||||
};
|
||||
public static final Event PLAYER_SWINGS_HAND = new Event("player_swings_hand", 2, false)
|
||||
{
|
||||
@Override
|
||||
public void onHandAction(ServerPlayerEntity player, Hand hand)
|
||||
{
|
||||
handler.call( () -> Arrays.asList(
|
||||
new EntityValue(player),
|
||||
StringValue.of(hand == Hand.MAIN_HAND ? "mainhand" : "offhand")
|
||||
)
|
||||
, player::getCommandSource);
|
||||
}
|
||||
};
|
||||
public static final Event PLAYER_TAKES_DAMAGE = new Event("player_takes_damage", 4, false)
|
||||
{
|
||||
@Override
|
||||
@@ -938,6 +950,7 @@ public class CarpetEventServer
|
||||
public void onBlockBroken(ServerPlayerEntity player, BlockPos pos, BlockState previousBS) { }
|
||||
public void onBlockPlaced(ServerPlayerEntity player, BlockPos pos, Hand enumhand, ItemStack itemstack) { }
|
||||
public void onEntityHandAction(ServerPlayerEntity player, Entity entity, Hand enumhand) { }
|
||||
public void onHandAction(ServerPlayerEntity player, Hand enumhand) { }
|
||||
public void onEntityAction(Entity entity) { }
|
||||
public void onDimensionChange(ServerPlayerEntity player, Vec3d from, Vec3d to, RegistryKey<World> fromDim, RegistryKey<World> dimTo) {}
|
||||
public void onDamage(Entity target, float amount, DamageSource source) { }
|
||||
|
||||
@@ -512,6 +512,11 @@ public class EntityValue extends Value
|
||||
put("sneaking", (e, a) -> e.isSneaking()?Value.TRUE:Value.FALSE);
|
||||
put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE);
|
||||
put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE);
|
||||
put("swinging", (e, a) -> {
|
||||
if (e instanceof LivingEntity) return new NumericValue(((LivingEntity) e).handSwinging);
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
put("air", (e, a) -> new NumericValue(e.getAir()));
|
||||
put("persistence", (e, a) -> {
|
||||
if (e instanceof MobEntity) return new NumericValue(((MobEntity) e).isPersistent());
|
||||
|
||||
Reference in new issue
Block a user