Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Commit

Permalink
Update to v1.21-0.3.0 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmitch215 authored Sep 8, 2024
2 parents b28cbda + f541b49 commit c7b22a9
Show file tree
Hide file tree
Showing 88 changed files with 3,290 additions and 119 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Change Permissions
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean assemble publishToMavenLocal
run: ./gradlew assemble publishToMavenLocal

upload:
runs-on: ubuntu-latest
Expand All @@ -83,7 +83,7 @@ jobs:
- name: Change Permissions
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean assemble
run: ./gradlew assemble
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
Expand All @@ -110,7 +110,7 @@ jobs:
- name: Change Permissions
run: chmod +x ./gradlew
- name: Build JavaDocs
run: ./gradlew clean allJavadoc
run: ./gradlew allJavadoc
- name: Deploy JavaDoc
run: bash javadoc.sh ${GITHUB_SHA::7}

Expand All @@ -133,4 +133,4 @@ jobs:
run: chmod +x ./gradlew
- name: Build with Gradle
run: |
./gradlew clean publish -Psuffix=${GITHUB_SHA::7} -Purl=https://maven.pkg.github.com/gmitch215/SocketMC -Pusername=${{ secrets.GITHUB_ACTOR }} -Ppassword=${{ secrets.GITHUB_TOKEN }}
./gradlew publish -Psuffix=${GITHUB_SHA::7} -Purl=https://maven.pkg.github.com/gmitch215/SocketMC -Pusername=${{ secrets.GITHUB_ACTOR }} -Ppassword=${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ build/
.kotlin/
logs/
.DS_Store
run/
run/
runs/
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ plugins {
// Mod
id("fabric-loom") version "1.7.3" apply false
id("net.minecraftforge.gradle") version "6.0.27" apply false
id("net.neoforged.gradle.userdev") version "7.0.162" apply false
id("net.neoforged.gradle.mixin") version "7.0.162" apply false
id("org.parchmentmc.librarian.forgegradle") version "1.+" apply false
id("org.spongepowered.mixin") version "0.7.+" apply false
id("com.modrinth.minotaur") version "2.+" apply false
Expand Down Expand Up @@ -52,7 +54,7 @@ tasks {

allprojects {
val mc = "1.21"
val pr = "0.2.2"
val pr = "0.3.0"

project.ext["minecraft_version"] = mc
project.ext["project_version"] = pr
Expand Down Expand Up @@ -94,6 +96,7 @@ allprojects {
maven("https://maven.parchmentmc.org")
maven("https://maven.terraformersmc.com/")
maven("https://libraries.minecraft.net/")
maven("https://maven.neoforged.net/releases/")
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public enum ModPermission {
*/
READ_GAME_PROPERTIES(true),

/**
* Permission to change various soft game preferences, such as social interactions.
*/
CHANGE_GAME_PREFERENCES(false),

;

private final boolean changeable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
import java.lang.reflect.Modifier;
import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
import java.util.*;
import java.util.List;
import java.util.Objects;

/**
* Represents a SocketMC Instruction to be sent to the client.
Expand Down Expand Up @@ -181,6 +180,24 @@ public final class Instruction implements Serializable, Paramaterized {
@InstructionPermission(ModPermission.USE_GUI)
public static final String DRAW_ITEMSTACK = "draw_itemstack";

/**
* Instruction to change the native window icon of the client.
*/
@InstructionPermission(ModPermission.USE_GUI)
public static final String SET_WINDOW_ICON = "set_window_icon";

/**
* Instruction to show players on the social interactions menu.
*/
@InstructionPermission(ModPermission.CHANGE_GAME_PREFERENCES)
public static final String SHOW_PLAYERS = "show_players";

/**
* Instruction to hide players from the social interactions menu.
*/
@InstructionPermission(ModPermission.CHANGE_GAME_PREFERENCES)
public static final String HIDE_PLAYERS = "hide_players";

@Serial
private static final long serialVersionUID = -4177824277470078500L;

Expand Down Expand Up @@ -1719,6 +1736,69 @@ public static Instruction drawItemStack(@NotNull NBTTag item, int x, int y, int
return new Instruction(DRAW_ITEMSTACK, List.of(item, x, y, guiOffset, randomSeed, millis));
}

/**
* <p>Creates a {@link #SET_WINDOW_ICON} instruction.</p>
* <ul>
* <li>On Windows/Linux, a {@code .png} file must be loaded. The recommended size is {@code 16x16}.</li>
* <li>On macOS, a {@code .icns} file must be loaded.</li>
* </ul>
* <p>The library will <strong>not</strong> make an effort to validate the byte array.</p>
* @param icon Icon to Set
* @return Set Window Icon Instruction
*/
@NotNull
public static Instruction setWindowIcon(byte[] icon) {
return new Instruction(SET_WINDOW_ICON, List.of(icon));
}

/**
* Creates a {@link #SHOW_PLAYERS} instruction.
* @param players Players to Show
* @return Show Players Instruction
*/
@NotNull
public static Instruction showPlayers(@NotNull Iterable<UUID> players) {
if (players == null) throw new IllegalArgumentException("Players cannot be null");

return new Instruction(SHOW_PLAYERS, List.of(players));
}

/**
* Creates a {@link #SHOW_PLAYERS} instruction.
* @param players Players to Show
* @return Show Players Instruction
*/
@NotNull
public static Instruction showPlayers(@NotNull UUID... players) {
if (players == null) throw new IllegalArgumentException("Players cannot be null");

return new Instruction(SHOW_PLAYERS, List.of(players));
}

/**
* Creates a {@link #HIDE_PLAYERS} instruction.
* @param players Players to Hide
* @return Hide Players Instruction
*/
@NotNull
public static Instruction hidePlayers(@NotNull Iterable<UUID> players) {
if (players == null) throw new IllegalArgumentException("Players cannot be null");

return new Instruction(HIDE_PLAYERS, List.of(players));
}

/**
* Creates a {@link #HIDE_PLAYERS} instruction.
* @param players Players to Hide
* @return Hide Players Instruction
*/
@NotNull
public static Instruction hidePlayers(@NotNull UUID... players) {
if (players == null) throw new IllegalArgumentException("Players cannot be null");

return new Instruction(HIDE_PLAYERS, List.of(players));
}

// <editor-fold defaultstate="collapsed" desc="Instruction Serialization">
// Serialization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.jetbrains.annotations.NotNull;
import org.joml.Matrix4f;
import xyz.gmitch215.socketmc.util.DataHolder;
import xyz.gmitch215.socketmc.util.NBTTag;

import java.io.Serial;
import java.io.Serializable;
import java.security.SecureRandom;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -74,6 +76,15 @@ public static RenderInstruction.GameRenderer game() {
return new GameRenderer();
}

/**
* Creates a new instruction for the DebugRenderer.
* @return Debug Renderer Instruction
*/
@NotNull
public static RenderInstruction.DebugRenderer debug() {
return new DebugRenderer();
}

/**
* Represents instructions for the Game Renderer.
*/
Expand Down Expand Up @@ -120,7 +131,7 @@ public void transformItemInHand(@NotNull Matrix4f matrix, long millis) throws Il
}

/**
* Renders the confusion effect, used when the player has the nausea effect.
* Renders the confusion effect. Used when the player has the nausea effect.
* @param strength The strength of the effect, between 0 and 1
* @throws IllegalArgumentException if the strength is not between 0 and 1
*/
Expand All @@ -135,6 +146,61 @@ public void renderConfusionEffect(float strength) throws IllegalArgumentExceptio
isFilled = true;
}

/**
* Renders the item activation effect. Used when the player activates a Totem of Undying.
* @param item The item that is being activated
* @throws IllegalArgumentException if the item is null
*/
public void renderItemActivation(@NotNull NBTTag item) throws IllegalArgumentException {
SecureRandom random = new SecureRandom();
renderItemActivation(item, random.nextFloat() * 2.0f - 1.0f, random.nextFloat() * 2.0f - 1.0f);
}

/**
* Renders the item activation effect. Used when the player activates a Totem of Undying.
* @param item The item that is being activated
* @param offsetX The final offsetX the item should glide to
* @param offsetY The final offsetY the item should glide to
* @throws IllegalArgumentException if the item is null
*/
public void renderItemActivation(@NotNull NBTTag item, float offsetX, float offsetY) throws IllegalArgumentException {
checkFilled();

data.put("item", item);
data.put("offsetX", offsetX);
data.put("offsetY", offsetY);

subOrdinal = 2;
isFilled = true;
}

}

public static final class DebugRenderer extends RenderInstruction {

/**
* The ordinal for a {@link RenderInstruction.DebugRenderer}.
*/
public static final int ORDINAL = 1;

@Serial
private static final long serialVersionUID = -2873349323016509570L;

private DebugRenderer() { super(ORDINAL); }

/**
* Renders the chunk border seen when using the F3+G debug keybind.
* @param enabled Whether the chunk border should be rendered
*/
public void renderChunkborder(boolean enabled) {
checkFilled();

data.put("enabled", enabled);

subOrdinal = 0;
isFilled = true;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public final class RetrieverType<T> implements Serializable {
@RetrieverPermission(ModPermission.READ_GAME_PROPERTIES)
public static final RetrieverType<String[]> COMMAND_HISTORY = new RetrieverType<>("command_history", String[].class);

/**
* A retriever for the client's hidden players on their social interaction screen.
*/
@RetrieverPermission(ModPermission.READ_GAME_PROPERTIES)
public static final RetrieverType<UUID[]> HIDDEN_PLAYERS = new RetrieverType<>("hidden_players", UUID[].class);

//<editor-fold desc="Implementation" defaultstate="collapsed">

private final String id;
Expand Down
51 changes: 48 additions & 3 deletions core/src/main/java/xyz/gmitch215/socketmc/retriever/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,44 @@ public final class Window implements Serializable {
String platform;
int refreshRate;

Window() {}
/**
* Creates a new, empty window.
*/
public Window() {}

/**
* Creates a new window with the specified parameters.
* @param id Window ID
* @param fullscreen Fullscreen Mode
* @param x X Position
* @param y Y Position
* @param width Width
* @param height Height
* @param screenWidth Screen Width
* @param screenHeight Screen Height
* @param guiScaledWidth GUI Scaled Width
* @param guiScaledHeight GUI Scaled Height
* @param guiScale GUI Scale
* @param framerateLimit Framerate Limit
* @param platform Window Platform
* @param refreshRate Refresh Rate
*/
public Window(long id, boolean fullscreen, int x, int y, int width, int height, int screenWidth, int screenHeight, int guiScaledWidth, int guiScaledHeight, double guiScale, int framerateLimit, String platform, int refreshRate) {
this.id = id;
this.fullscreen = fullscreen;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.screenWidth = screenWidth;
this.screenHeight = screenHeight;
this.guiScaledWidth = guiScaledWidth;
this.guiScaledHeight = guiScaledHeight;
this.guiScale = guiScale;
this.framerateLimit = framerateLimit;
this.platform = platform;
this.refreshRate = refreshRate;
}

/**
* Gets the window ID.
Expand Down Expand Up @@ -125,8 +162,16 @@ public int getFramerateLimit() {
}

/**
* <p>Gets the platform this window is currently on.</p>
* <p>Common values are {@code "win32"}, {@code "cocoa"}, {@code "wayland"}, and {@code "x11"}. {@code "null"} will be returned if not accessible, and {@code "<error>"} will be returned if something happened.</p>
* <p>Gets the platform this window is currently using.</p>
* <p>Some potential values are:</p>
* <ul>
* <li>{@code win32} if on Windows</li>
* <li>{@code cocoa} if on macOS</li>
* <li>{@code x11} or {@code wayland} if on Unix</li>
* <li>{@code null} if inaccessible</li>
* <li>{@code <error>} if can't fetch the value</li>
* <li>{@code unknown} if not using a generally known windows API</li>
* </ul>
* @return Window Platform
*/
public String getPlatform() {
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/xyz/gmitch215/socketmc/util/Paramaterized.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ public interface Paramaterized {
@Unmodifiable
List<Object> getParameters();

/**
* Gets the parameters of the specified type.
* @param type The type of the parameters to get
* @return The parameters of the specified type
* @param <T> The type of the parameters
*/
default <T> List<T> getParameters(@NotNull Class<T> type) {
return getParameters()
.stream()
.filter(type::isInstance)
.map(type::cast)
.toList();
}

/**
* Gets the parameter at the specified index.
* @param index The index of the parameter to get
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Loading

0 comments on commit c7b22a9

Please sign in to comment.