Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.19.3

# Mod Properties
mod_version=2.0.0
mod_version=2.0.1
maven_group=nl.devpieter
archives_base_name=utilize
27 changes: 27 additions & 0 deletions src/client/java/nl/devpieter/utilize/client/utils/ClientUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.sounds.SoundManager;

public final class ClientUtils {

Expand All @@ -24,4 +27,28 @@ public static boolean hasPlayer() {
public static LocalPlayer getPlayer() {
return getClient().player;
}

public static boolean hasLevel() {
return getClient().level != null;
}

public static ClientLevel getLevel() {
return getClient().level;
}

public static boolean hasConnection() {
return getClient().getConnection() != null;
}

public static ClientPacketListener getConnection() {
return getClient().getConnection();
}

public static boolean hasSoundManager() {
return getClient().getSoundManager() != null;
}

public static SoundManager getSoundManager() {
return getClient().getSoundManager();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package nl.devpieter.utilize.client.utils;

import net.minecraft.network.protocol.Packet;
import org.jetbrains.annotations.NotNull;

public final class NetworkUtils {

private NetworkUtils() {
}

public static void sendPacket(@NotNull Packet<?> packet) {
if (!ClientUtils.hasConnection()) return;
ClientUtils.getConnection().send(packet);
}

public static void sendChatMessage(@NotNull String message) {
if (!ClientUtils.hasConnection()) return;

if (message.startsWith("/")) sendChatCommand(message);
else ClientUtils.getConnection().sendChat(message);
}

public static void sendChatCommand(@NotNull String command) {
if (!ClientUtils.hasConnection()) return;
if (command.startsWith("/")) command = command.substring(1);

ClientUtils.getConnection().sendCommand(command);
}
}
29 changes: 29 additions & 0 deletions src/client/java/nl/devpieter/utilize/client/utils/SoundUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package nl.devpieter.utilize.client.utils;

import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.sounds.SoundEvent;
import org.jetbrains.annotations.NotNull;

public final class SoundUtils {

private SoundUtils() {
}

public static void playUi(@NotNull SoundEvent soundEvent) {
playUi(soundEvent, 1.0F, 1.0F);
}

public static void playUi(@NotNull SoundEvent soundEvent, float pitch) {
playUi(soundEvent, pitch, 1.0F);
}

public static void playUi(@NotNull SoundEvent soundEvent, float pitch, float volume) {
play(SimpleSoundInstance.forUI(soundEvent, pitch, volume));
}

public static void play(@NotNull SoundInstance soundInstance) {
if (!ClientUtils.hasSoundManager()) return;
ClientUtils.getSoundManager().play(soundInstance);
}
}
32 changes: 32 additions & 0 deletions src/client/java/nl/devpieter/utilize/client/utils/TextUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package nl.devpieter.utilize.client.utils;

import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import org.jetbrains.annotations.NotNull;

public final class TextUtils {

private TextUtils() {
}

public static MutableComponent currentOrDefaultStyle(@NotNull Component text, @NotNull Style defaultStyle) {
return Component.literal("").copy().setStyle(defaultStyle).append(text);
}

public static MutableComponent withStyle(@NotNull String text, @NotNull Style style) {
return withStyle(Component.literal(text), style);
}

public static MutableComponent withStyle(@NotNull Component text, @NotNull Style style) {
return text.copy().setStyle(style);
}

public static MutableComponent clearStyle(@NotNull String text) {
return clearStyle(Component.literal(text));
}

public static MutableComponent clearStyle(@NotNull Component text) {
return text.copy().setStyle(Style.EMPTY);
}
}
31 changes: 31 additions & 0 deletions src/client/java/nl/devpieter/utilize/client/utils/WorldUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package nl.devpieter.utilize.client.utils;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class WorldUtils {

private WorldUtils() {
}

public static @Nullable BlockState getStateAt(@NotNull BlockPos pos) {
if (!ClientUtils.hasLevel()) return null;
return ClientUtils.getLevel().getBlockState(pos);
}

public static @Nullable Block getBlockAt(@NotNull BlockPos pos) {
BlockState state = getStateAt(pos);
if (state == null) return null;

return state.getBlock();
}

public static @Nullable Entity getEntity(int id) {
if (!ClientUtils.hasLevel()) return null;
return ClientUtils.getLevel().getEntity(id);
}
}
Loading