diff --git a/src/main/java/com/provismet/vmcmc/ClientVMC.java b/src/main/java/com/provismet/vmcmc/ClientVMC.java index 8ae1d40..13eaf95 100644 --- a/src/main/java/com/provismet/vmcmc/ClientVMC.java +++ b/src/main/java/com/provismet/vmcmc/ClientVMC.java @@ -9,24 +9,19 @@ import com.provismet.vmcmc.vmc.CaptureRegistry; import com.provismet.vmcmc.vmc.PacketSender; -import com.provismet.vmcmc.vmc.CaptureRegistry.CaptureType; public class ClientVMC implements ClientModInitializer { public static final String MODID = "vmc-mc"; public static final Logger LOGGER = LoggerFactory.getLogger(MODID); - private static Identifier identifier (String path) { + public static Identifier identifier (String path) { return Identifier.of(MODID, path); } @Override public void onInitializeClient () { PacketSender.initPort(39541); - - CaptureRegistry.register(identifier("light"), CaptureType.BLEND_SHAPE, client -> { - float light = client.getEntityRenderDispatcher().getLight(client.player, client.getTickDelta()); - return 15f / light; - }); + CaptureRegistry.registerStandardEvents(); ClientTickEvents.END_CLIENT_TICK.register(client -> { CaptureRegistry.iterate(client); diff --git a/src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java b/src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java index 90fb8fb..306cd3f 100644 --- a/src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java +++ b/src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java @@ -3,15 +3,48 @@ import java.util.HashMap; import java.util.function.Function; +import com.provismet.vmcmc.ClientVMC; + import net.minecraft.client.MinecraftClient; +import net.minecraft.registry.tag.FluidTags; import net.minecraft.util.Identifier; import net.minecraft.util.Pair; public class CaptureRegistry { private static final HashMap>> REGISTRY = new HashMap<>(); - public static void register (Identifier path, CaptureType type, Function callback) { - CaptureRegistry.REGISTRY.put(path, new Pair<>(type, callback)); + public static void register (Identifier identifier, CaptureType type, Function callback) { + CaptureRegistry.REGISTRY.put(identifier, new Pair<>(type, callback)); + } + + public static void register (String path, CaptureType type, Function callback) { + CaptureRegistry.register(ClientVMC.identifier(path), type, callback); + } + + public static void registerStandardEvents () { + CaptureRegistry.register("light", CaptureType.BLEND_SHAPE, client -> { + float light = client.getEntityRenderDispatcher().getLight(client.player, client.getTickDelta()); + return 15f / light; + }); + + CaptureRegistry.register("relative_health", CaptureType.BLEND_SHAPE, client -> { + return client.player.getMaxHealth() / client.player.getHealth(); + }); + + CaptureRegistry.register("hurt", CaptureType.BLEND_SHAPE, client -> { + final float DURATION = 5f; + float elapsed = client.player.getLastAttackedTime() - client.player.age; + if (elapsed > DURATION) return 0f; + else return elapsed / DURATION; + }); + + CaptureRegistry.register("in_water", CaptureType.BLEND_SHAPE, client -> { + return (float)client.player.getFluidHeight(FluidTags.WATER); + }); + + CaptureRegistry.register("in_lava", CaptureType.BLEND_SHAPE, client -> { + return (float)client.player.getFluidHeight(FluidTags.LAVA); + }); } public static void iterate (MinecraftClient client) {