Skip to content

Commit 390472e

Browse files
Add use item clip
1 parent 971d081 commit 390472e

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/client/java/com/skycatdev/autocut/AutocutClient.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package com.skycatdev.autocut;
22

3-
import com.skycatdev.autocut.clips.Clip;
43
import com.skycatdev.autocut.clips.ClipBuilder;
54
import com.skycatdev.autocut.clips.ClipTypes;
65
import io.obswebsocket.community.client.OBSRemoteController;
76
import net.fabricmc.api.ClientModInitializer;
87
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
98
import net.fabricmc.fabric.api.event.client.player.ClientPlayerBlockBreakEvents;
109
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
10+
import net.fabricmc.fabric.api.event.player.UseItemCallback;
11+
import net.minecraft.item.ItemStack;
1112
import net.minecraft.registry.Registries;
1213
import net.minecraft.util.ActionResult;
14+
import net.minecraft.util.TypedActionResult;
1315
import net.minecraft.util.math.Vec3d;
1416
import org.jetbrains.annotations.Nullable;
1517

@@ -33,13 +35,12 @@ public void onInitializeClient() {
3335
.setSource(player.getNameForScoreboard())
3436
.setSourceLocation(player.getPos())
3537
.build()); // TODO: Localize
36-
} catch (SQLException e) { // TODO
37-
e.printStackTrace();
38+
} catch (SQLException ignored) { // TODO
3839
}
3940
}
4041
}));
4142
AttackEntityCallback.EVENT.register(((player, world, hand, entity, hitResult) -> {
42-
if (currentRecordingHandler != null && entity != null) { // WARN: DEBUG Ignores when not attacking entity
43+
if (currentRecordingHandler != null && entity != null) {
4344
long time = System.currentTimeMillis();
4445
try {
4546
ClipBuilder builder = new ClipBuilder(time - 250, time, time + 250, ClipTypes.ATTACK_ENTITY)
@@ -54,5 +55,21 @@ public void onInitializeClient() {
5455
}
5556
return ActionResult.PASS;
5657
}));
58+
UseItemCallback.EVENT.register((player, world, hand) -> {
59+
if (currentRecordingHandler != null) {
60+
long time = System.currentTimeMillis();
61+
try {
62+
ItemStack itemStack = player.getStackInHand(hand);
63+
ClipBuilder builder = new ClipBuilder(time - 250, time, time + 250, ClipTypes.USE_ITEM)
64+
.setDescription("Used " + itemStack.getName().getString())
65+
.setSource(player.getNameForScoreboard())
66+
.setSourceLocation(player.getPos())
67+
.setObject(Registries.ITEM.getId(itemStack.getItem()).toString());
68+
currentRecordingHandler.addClip(builder.build());
69+
} catch (SQLException ignored) { // TODO
70+
}
71+
}
72+
return TypedActionResult.pass(ItemStack.EMPTY);
73+
});
5774
}
5875
}

src/client/java/com/skycatdev/autocut/clips/ClipTypes.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,39 @@
77
import java.util.Collection;
88

99
/**
10-
* Stores {@link Identifier}s that show the reason for a recording element (clip or event).
10+
* Stores {@link Identifier}s that show the reason for a clip.
1111
*/
12-
public class ClipTypes {
12+
public class ClipTypes { // TODO: Probably should make just a bunch of `extends Clip`s
1313
/**
14-
* An element made using debug methods. Ideally not used by the end user.
14+
* A clip made using debug methods. Ideally not used by the end user.
1515
*/
1616
public static final Identifier DEBUG = Identifier.of(Autocut.MOD_ID, "debug");
1717
/**
18-
* An element made for internal use. Should not end up being serialized.
18+
* A clip made for internal use. Should not end up being serialized.
1919
* @see RecordingHandler#mergeClips(Collection)
2020
*/
2121
public static final Identifier INTERNAL = Identifier.of(Autocut.MOD_ID, "internal");
2222
/**
23-
* An element based on a block breaking.
23+
* A clip based on a block breaking.
2424
*/
2525
public static final Identifier BREAK_BLOCK = Identifier.of(Autocut.MOD_ID, "break_block");
2626
/**
27-
* An element triggered by a manual input, but which was not manually constructed.
28-
* An element made via a keybind for clipping probably should have this id, but an element made by choosing start and end points through a GUI should not.
27+
* A clip triggered by a manual input, but which was not manually constructed.
28+
* A clip made via a keybind for clipping probably should have this id, but a clip made by choosing start and end points through a GUI should not.
2929
* @see ClipTypes#MANUAL_MADE
3030
*/
3131
public static final Identifier MANUAL_TRIGGERED = Identifier.of(Autocut.MOD_ID, "manual");
3232
/**
33-
* An element created manually - times selected by hand.
33+
* An clip created manually - times selected by hand.
3434
* @see ClipTypes#MANUAL_TRIGGERED
3535
*/
3636
public static final Identifier MANUAL_MADE = Identifier.of(Autocut.MOD_ID, "manual_made");
3737
/**
38-
* An element created by attacking an entity.
38+
* A clip created by attempting to attack an entity.
3939
*/
4040
public static final Identifier ATTACK_ENTITY = Identifier.of(Autocut.MOD_ID, "attack_entity");
41+
/**
42+
* A clip created by attempting to use an item.
43+
*/
44+
public static final Identifier USE_ITEM = Identifier.of(Autocut.MOD_ID, "use_item");
4145
}

0 commit comments

Comments
 (0)