Skip to content

Commit

Permalink
Update to 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Dec 9, 2023
1 parent 31a71aa commit 251995f
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 362 deletions.
26 changes: 12 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.1.+'
id 'fabric-loom' version '1.4.+'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
}
Expand Down Expand Up @@ -84,32 +84,30 @@ dependencies {

modApi "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modApi include('xyz.nucleoid:server-translations-api:2.1.0+1.20.2-rc2')
modApi include('xyz.nucleoid:server-translations-api:2.2.0+1.20.3-rc1')
modApi include('xyz.nucleoid:packet-tweaker:0.5.0+1.20.2-rc1')
modApi include('xyz.nucleoid:fantasy:0.4.11+1.20-rc1')
modApi include('xyz.nucleoid:fantasy:0.5.0+1.20.4')
modApi include('xyz.nucleoid:more-codecs:0.3.3+1.20.2')
modApi include('xyz.nucleoid:stimuli:0.4.9+1.20.2')
modApi include('xyz.nucleoid:stimuli:0.4.10+1.20.4')
modApi include('xyz.nucleoid:map-templates:0.1.8+1.20')
modApi include('xyz.nucleoid:substrate:0.2.2+1.20.1')
modApi 'eu.pb4:polymer-core:0.6.0+1.20.2'
modApi 'eu.pb4:polymer-resource-pack:0.6.0+1.20.2'
modApi 'eu.pb4:polymer-blocks:0.6.0+1.20.2'
modApi 'eu.pb4:polymer-virtual-entity:0.6.0+1.20.2'
modApi 'eu.pb4:polymer-core:0.7.1+1.20.4'
modApi 'eu.pb4:polymer-resource-pack:0.7.1+1.20.4'
modApi 'eu.pb4:polymer-blocks:0.7.1+1.20.4'
modApi 'eu.pb4:polymer-virtual-entity:0.7.1+1.20.4'
modApi include('eu.pb4:hologram-api:0.2.5+1.20.2')
modApi include('eu.pb4:sgui:1.3.0+1.20.2')
modApi include('eu.pb4:sidebar-api:0.2.0+1.20.2')
modApi include("eu.pb4:placeholder-api:2.2.0+1.20.2")
modApi include('eu.pb4:sidebar-api:0.3.0+1.20.3')
modApi include("eu.pb4:placeholder-api:2.3.0+1.20.3")
modApi include("eu.pb4:map-canvas-api:0.2.2+1.19.4")
modApi include("eu.pb4:player-data-api:0.3.0+1.20.2")
modApi include("eu.pb4:player-data-api:0.4.0+1.20.3")
modApi include("eu.pb4:predicate-api:0.3.0+1.20.2")

modCompileOnly('xyz.nucleoid:disguiselib-fabric:1.3.2')
modCompileOnly('maven.modrinth:afkdisplay:1.1.0')
modCompileOnly('eu.pb4:polymer-autohost:0.6.0+1.20.2')
modCompileOnly('eu.pb4:polymer-autohost:0.7.1+1.20.4')
modCompileOnly("dev.emi:trinkets:3.7.1")

implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.mixin_extras_version}"))

testmodImplementation sourceSets.main.output
}

Expand Down
8 changes: 3 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
org.gradle.jvmargs=-Xmx2G

# Fabric Properties
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.1

#Fabric api
fabric_version=0.89.2+1.20.2
Expand All @@ -13,5 +13,3 @@ fabric_version=0.89.2+1.20.2
mod_version=0.5
maven_group=xyz.nucleoid
archives_base_name=plasmid

mixin_extras_version=0.2.0-rc.2
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
37 changes: 27 additions & 10 deletions src/main/java/xyz/nucleoid/plasmid/PlasmidWebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.MinecraftServer;
import org.apache.commons.io.IOUtils;
import net.minecraft.util.Util;
import org.apache.http.HttpStatus;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.plasmid.game.resource_packs.GameResourcePackManager;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;

public class PlasmidWebServer {
public static final String RESOURCE_PACKS_ENDPOINT = "resource-packs";

private static final Map<String, Path> RESOURCE_PACKS = new HashMap<>();

private static final String WEB_URL = Util.make(() -> {
var path = PlasmidConfig.get().userFacingPackAddress().orElse("");
return path.endsWith("/") ? path : path + "/";

});

@Nullable
public static HttpServer start(MinecraftServer minecraftServer, Config config) {
try {
Expand Down Expand Up @@ -46,35 +58,40 @@ private static InetSocketAddress createBindAddress(MinecraftServer server, Confi
}
}

public static String registerResourcePack(String s, Path path) {
RESOURCE_PACKS.put(s, path);
return WEB_URL + s;
}

private record ResourcePacksHandler(String endpoint) implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
try (exchange) {
var resourcePacks = GameResourcePackManager.get();
if (resourcePacks.isEmpty() || !this.tryHandle(exchange, resourcePacks.get())) {
if (!this.tryHandle(exchange)) {
exchange.sendResponseHeaders(HttpStatus.SC_NOT_FOUND, 0);
}
}
}

private boolean tryHandle(HttpExchange exchange, GameResourcePackManager resourcePacks) throws IOException {
private boolean tryHandle(HttpExchange exchange) throws IOException {
if ("GET".equals(exchange.getRequestMethod())) {
return this.tryHandleGet(exchange, resourcePacks);
return this.tryHandleGet(exchange);
}
return false;
}

private boolean tryHandleGet(HttpExchange exchange, GameResourcePackManager resourcePacks) throws IOException {
private boolean tryHandleGet(HttpExchange exchange) throws IOException {
var path = exchange.getRequestURI().getPath().substring(this.endpoint.length() + 2);
var pack = resourcePacks.load(path);
var pack = RESOURCE_PACKS.get(path);
if (pack != null) {
var size = Files.size(pack);
try (
var input = pack.openInputStream();
var input = Files.newInputStream(pack);
var output = exchange.getResponseBody()
) {
exchange.getResponseHeaders().add("Server", "plasmid");
exchange.getResponseHeaders().add("Content-Type", "application/zip");
exchange.sendResponseHeaders(HttpStatus.SC_OK, pack.getSize());
exchange.sendResponseHeaders(HttpStatus.SC_OK, size);

input.transferTo(output);
output.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private static int locatePlayer(CommandContext<ServerCommandSource> context) thr

var gameSpace = GameSpaceManager.get().byPlayer(player);
if (gameSpace == null) {
throw PLAYER_NOT_IN_GAME.create(player.getEntityName());
throw PLAYER_NOT_IN_GAME.create(player.getName());
}

context.getSource().sendFeedback(() -> GameTexts.Command.located(player, gameSpace), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static int connectEntity(CommandContext<ServerCommandSource> context) th
}

context.getSource().sendFeedback(() -> {
var message = Text.translatable("text.plasmid.game.portal.connect.entity", portal.getId(), entity.getEntityName());
var message = Text.translatable("text.plasmid.game.portal.connect.entity", portal.getId(), entity.getName());
return message.formatted(Formatting.GRAY);
}, false);

Expand Down Expand Up @@ -107,7 +107,7 @@ private static int disconnectEntity(CommandContext<ServerCommandSource> context)
portalInterface.invalidatePortal();

context.getSource().sendFeedback(() -> {
var message = Text.translatable("text.plasmid.game.portal.disconnect.entity", entity.getEntityName());
var message = Text.translatable("text.plasmid.game.portal.disconnect.entity", entity.getName());
return message.formatted(Formatting.GRAY);
}, false);

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/xyz/nucleoid/plasmid/game/GameSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.player.PlayerSet;
import xyz.nucleoid.plasmid.game.resource_packs.ResourcePackStates;
import xyz.nucleoid.plasmid.game.world.GameSpaceWorlds;

import java.util.function.Consumer;
Expand Down Expand Up @@ -111,9 +110,6 @@ public interface GameSpace {
*/
boolean isClosed();

ResourcePackStates getResourcePackStates();


@Nullable
<T> T getAttachment(String key);
void setAttachment(String key, @Nullable Object obj);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,67 @@
package xyz.nucleoid.plasmid.game.common;

import com.google.common.hash.Hashing;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import eu.pb4.polymer.resourcepack.api.ResourcePackCreator;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.network.packet.s2c.common.ResourcePackRemoveS2CPacket;
import net.minecraft.network.packet.s2c.common.ResourcePackSendS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.jetbrains.annotations.ApiStatus;
import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.Plasmid;
import xyz.nucleoid.plasmid.PlasmidConfig;
import xyz.nucleoid.plasmid.PlasmidWebServer;
import xyz.nucleoid.plasmid.game.GameActivity;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.resource_packs.GameResourcePackManager;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Optional;

// TODO: prevent resource-pack soft-lock
import java.util.UUID;

/**
* A very simple utility to apply a resource pack for all players within a {@link GameActivity}.
*
* @see GameResourcePack#addTo(GameActivity)
*/
public final class GameResourcePack {
private static final Path RESOURCE_PACKS_ROOT = FabricLoader.getInstance().getGameDir()
.resolve("plasmid-generated/resource-packs");
private final UUID uuid;

private final String url;
private final String hash;
private boolean required;
private Text prompt;

private boolean isLocal;

public GameResourcePack(String url, String hash) {
this.url = url;
this.uuid = UUID.nameUUIDFromBytes(hash.getBytes());
this.hash = hash;
this.isLocal = false;
}

public GameResourcePack(UUID uuid, String url, String hash) {
this.url = url;
this.uuid = uuid;
this.hash = hash;
this.isLocal = false;
}

private GameResourcePack(UUID uuid, String url, String hash, Void unused) {
this.url = url;
this.uuid = uuid;
this.hash = hash;
this.isLocal = true;
}

public boolean isLocal() {
return this.isLocal;
}

/**
Expand Down Expand Up @@ -57,26 +91,32 @@ public GameResourcePack setPrompt(Text prompt) {
* @param activity the activity to add to
*/
public void addTo(GameActivity activity) {
var gameSpace = activity.getGameSpace();
activity.listen(GamePlayerEvents.ADD, this::sendTo);
activity.listen(GamePlayerEvents.REMOVE, this::unload);
}

activity.listen(GamePlayerEvents.ADD, player -> {
gameSpace.getResourcePackStates().setFor(player, this);
});
private void sendTo(ServerPlayerEntity player) {
player.networkHandler.sendPacket(new ResourcePackSendS2CPacket(this.uuid, this.url, this.hash, this.required, this.prompt));
}

@ApiStatus.Internal
public void sendTo(ServerPlayerEntity player) {
player.networkHandler.sendPacket(new ResourcePackSendS2CPacket(this.url, this.hash, this.required, this.prompt));
private void unload(ServerPlayerEntity player) {
player.networkHandler.sendPacket(new ResourcePackRemoveS2CPacket(Optional.of(this.uuid)));
}

public static Optional<GameResourcePack> tryRegister(ResourcePackCreator creator) {
return GameResourcePackManager.get().flatMap(packs -> {
try {
return Optional.of(packs.register(creator));
} catch (Exception e) {
Plasmid.LOGGER.error("Failed to generate resource pack", e);
return Optional.empty();
}
});
public static Optional<GameResourcePack> from(Identifier identifier, ResourcePackCreator creator) {
try {
var relative = identifier.getNamespace() + "/" + identifier.getPath() + ".zip";
var path = RESOURCE_PACKS_ROOT.resolve(relative);
Files.createDirectories(path.getParent());
creator.build(path);

var hash = com.google.common.io.Files.asByteSource(path.toFile()).hash(Hashing.sha1()).toString();

var url = PlasmidWebServer.registerResourcePack(relative, path);
return Optional.of(new GameResourcePack(UUID.nameUUIDFromBytes(hash.getBytes(StandardCharsets.UTF_8)), url, hash, null));
} catch (Throwable e) {
Plasmid.LOGGER.error("Failed to create a resource pack '" + identifier + "'!", e);
return Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,15 @@ private void sendRemoveTeamsForPlayer(ServerPlayerEntity player) {

private void addOnlinePlayer(ServerPlayerEntity player, State state) {
state.onlinePlayers.add(player);
state.scoreboardTeam.getPlayerList().add(player.getEntityName());
state.scoreboardTeam.getPlayerList().add(player.getNameForScoreboard());

this.sendPacketToAll(this.changePlayerTeam(player, state, TeamS2CPacket.Operation.ADD));
this.sendPacketToAll(this.resetPlayerName(player));
}

private void removeOnlinePlayer(ServerPlayerEntity player, State state) {
state.onlinePlayers.remove(player);
state.scoreboardTeam.getPlayerList().remove(player.getEntityName());
state.scoreboardTeam.getPlayerList().remove(player.getNameForScoreboard());

this.sendPacketToAll(this.changePlayerTeam(player, state, TeamS2CPacket.Operation.REMOVE));
this.sendPacketToAll(this.resetPlayerName(player));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
import xyz.nucleoid.plasmid.game.player.PlayerOfferResult;
import xyz.nucleoid.plasmid.game.resource_packs.ResourcePackStates;

import java.util.Collection;
import java.util.HashMap;
Expand All @@ -36,7 +35,6 @@ public final class ManagedGameSpace implements GameSpace {
private final long openTime;

private final GameActivityState state = new GameActivityState(this);
private final ResourcePackStates resourcePackStateManager = new ResourcePackStates(this);
private boolean closed;

private final GameSpaceStatistics statistics = new GameSpaceStatistics();
Expand Down Expand Up @@ -171,12 +169,6 @@ public GameSpaceStatistics getStatistics() {
public boolean isClosed() {
return this.closed;
}

@Override
public ResourcePackStates getResourcePackStates() {
return this.resourcePackStateManager;
}

@Override
public <T> T getAttachment(String key) {
//noinspection unchecked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import xyz.nucleoid.plasmid.game.portal.GamePortalBackend;
import xyz.nucleoid.plasmid.game.portal.GamePortalDisplay;
import xyz.nucleoid.plasmid.util.Guis;
import xyz.nucleoid.plasmid.util.IdentityHashStrategy;

import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -58,7 +59,7 @@ public ItemStack getIcon() {
@Override
public int getPlayerCount() {
int count = 0;
var list = new ObjectOpenCustomHashSet<GameSpace>(Util.identityHashStrategy());
var list = new ObjectOpenCustomHashSet<GameSpace>(IdentityHashStrategy.INSTANCE);
provideGameSpaces(list::add);
for (var entry : list) {
count += Math.max(0, entry.getPlayers().size());
Expand Down
Loading

0 comments on commit 251995f

Please sign in to comment.