Skip to content

Commit

Permalink
Bump version to 0.5.0, fix compatibility with Immersive Portals for V…
Browse files Browse the repository at this point in the history
…irtual Entity API
  • Loading branch information
Patbox committed Jun 11, 2023
1 parent 99929fc commit d5a6594
Show file tree
Hide file tree
Showing 22 changed files with 268 additions and 55 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ fabric_version=0.82.1+1.20

maven_group = eu.pb4

mod_version = 0.5.0-rc.3
mod_version = 0.5.0

minecraft_version_supported = ">=1.20-"

packet_tweaker_version = 0.4.0+1.19.4

is_stable = false
is_stable = true
8 changes: 3 additions & 5 deletions polymer-autohost/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ loom {
dependencies {
modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"
//modCompileOnly "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"

modImplementation "xyz.nucleoid:packet-tweaker:0.3.0+1.18.2"
//modCompileOnly "me.lucko:fabric-permissions-api:0.1-SNAPSHOT"

implementation (project(path: ':polymer-common', configuration: 'namedElements'))
implementation (project(path: ':polymer-resource-pack', configuration: 'namedElements'))
implementation (project(path: ':polymer-networking', configuration: 'namedElements'))
api (project(path: ':polymer-common', configuration: 'namedElements'))
api (project(path: ':polymer-resource-pack', configuration: 'namedElements'))
api (project(path: ':polymer-networking', configuration: 'namedElements'))


testmodImplementation sourceSets.main.output
Expand Down
1 change: 0 additions & 1 deletion polymer-blocks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ dependencies {
implementation(project(path: ':polymer-core', configuration: 'namedElements'))
implementation(project(path: ':polymer-common', configuration: 'namedElements'))
implementation(project(path: ':polymer-resource-pack', configuration: 'namedElements'))
modImplementation "xyz.nucleoid:packet-tweaker:0.3.0+1.18.2"
modCompileOnly "me.lucko:fabric-permissions-api:0.1-SNAPSHOT"

//modLocalRuntime "fr.catcore:server-translations-api:1.4.9+1.18.2-rc1"
Expand Down
4 changes: 3 additions & 1 deletion polymer-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ loom {

dependencies {
modCompileOnly ("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")
modApi include("xyz.nucleoid:packet-tweaker:${packet_tweaker_version}")
modApi include("xyz.nucleoid:packet-tweaker:${packet_tweaker_version}") {
transitive(false)
}
modCompileOnly "xyz.nucleoid:disguiselib-fabric:1.2.2"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private PolymerCommonUtils(){}

public static final SimpleEvent<ResourcePackChangeCallback> ON_RESOURCE_PACK_STATUS_CHANGE = new SimpleEvent<>();

private final static String SAFE_CLIENT_SHA1 = "958928a560c9167687bea0cefeb7375da1e552a8";
private final static String SAFE_CLIENT_SHA1 = "e575a48efda46cf88111ba05b624ef90c520eef1";
private final static String SAFE_CLIENT_URL = "https://piston-data.mojang.com/v1/objects/" + SAFE_CLIENT_SHA1 + "/client.jar";
@Nullable
public static Path getClientJar() {
Expand Down
7 changes: 5 additions & 2 deletions polymer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ dependencies {
modCompileOnly("xyz.nucleoid:server-translations-api:2.0.0-beta.2+1.19.4-pre2")
modLocalRuntime("xyz.nucleoid:server-translations-api:2.0.0-beta.2+1.19.4-pre2")

modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v2.5.1-mc1.19.3'
modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:v2.5.1-mc1.19.3'
modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v3.0.2-mc1.20'
//modLocalRuntime 'com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v3.0.2-mc1.20'
modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:v3.0.2-mc1.20'
//modLocalRuntime 'com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:v3.0.2-mc1.20'

//modLocalRuntime 'maven.modrinth:immersiveportals:v3.0.2-mc1.20'
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package eu.pb4.polymer.core.impl.compat;

import eu.pb4.polymer.common.api.PolymerCommonUtils;
import eu.pb4.polymer.core.impl.networking.BlockPacketUtil;
import net.minecraft.network.packet.Packet;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand All @@ -10,11 +9,11 @@
public class ImmersivePortalsUtils {
public static void sendBlockPackets(ServerPlayNetworkHandler handler, Packet<?> packet) {
if (packet instanceof IECustomPayloadPacket attachedPacket && attachedPacket.ip_getRedirectedPacket() != null && attachedPacket.ip_getRedirectedDimension() != null) {
PolymerCommonUtils.executeWithPlayerContext(handler.player, () -> {
PacketRedirection.withForceRedirect(handler.player.getServer().getWorld(attachedPacket.ip_getRedirectedDimension()), () -> {
BlockPacketUtil.sendFromPacket(attachedPacket.ip_getRedirectedPacket(), handler);
});
PacketRedirection.withForceRedirect(handler.player.getServer().getWorld(attachedPacket.ip_getRedirectedDimension()), () -> {
BlockPacketUtil.sendFromPacket(attachedPacket.ip_getRedirectedPacket(), handler);
});
} else {
BlockPacketUtil.sendFromPacket(packet, handler);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public static Packet<ClientPlayPacketListener> replace(ServerPlayNetworkHandler
public static void sendExtra(ServerPlayNetworkHandler handler, Packet<ClientPlayPacketListener> packet) {
if (CompatStatus.IMMERSIVE_PORTALS) {
ImmersivePortalsUtils.sendBlockPackets(handler, packet);
} else {
BlockPacketUtil.sendFromPacket(packet, handler);
}

BlockPacketUtil.sendFromPacket(packet, handler);
}

public static boolean prevent(ServerPlayNetworkHandler handler, Packet<ClientPlayPacketListener> packet) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package eu.pb4.polymer.resourcepack.api;

import net.minecraft.util.Identifier;

public final class AssetPaths {
public static String PACK_METADATA = "pack.mcmeta";
public static String PACK_ICON = "pack.png";

private AssetPaths() {}

public static String texture(String namespace, String path) {
return "assets/" + namespace + "/textures/" + path;
}

public static String model(String namespace, String path) {
return "assets/" + namespace + "/models/" + path;
}

public static String model(Identifier id) {
return model(id.getNamespace(), id.getPath());
}

public static String texture(Identifier id) {
return texture(id.getNamespace(), id.getPath());
}

public static String blockModel(Identifier id) {
return model(id.getNamespace(), "block/" + id.getPath() + ".json");
}

public static String blockTexture(Identifier id) {
return texture(id.getNamespace(), "block/" + id.getPath() + ".png");
}

public static String blockTextureMetadata(Identifier id) {
return texture(id.getNamespace(), "block/" + id.getPath() + ".png.mcmeta");
}

public static String itemModel(Identifier id) {
return model(id.getNamespace(), "item/" + id.getPath() + ".json");
}

public static String itemTexture(Identifier id) {
return texture(id.getNamespace(), "item/" + id.getPath() + ".png");
}

public static String itemTextureMetadata(Identifier id) {
return texture(id.getNamespace(), "item/" + id.getPath() + ".png.mcmeta");
}

public static String armorTexture(Identifier id, int layer) {
return texture(id.getNamespace(), "models/armor/" + id.getPath() + "_layer_" + layer + ".png");
}

public static String armorOverlayTexture(Identifier id, int layer) {
return texture(id.getNamespace(), "models/armor/" + id.getPath() + "_layer_" + layer + "_overlay.png");
}

public static String armorTexturePolymerMetadata(Identifier id, int layer) {
return texture(id.getNamespace(), "models/armor/" + id.getPath() + "_layer_" + layer + ".polymer.json");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private PolymerResourcePackUtils() {
private static final ResourcePackCreator INSTANCE = new ResourcePackCreator(PolymerResourcePackImpl.USE_OFFSET ? PolymerResourcePackImpl.OFFSET_VALUES : 1);

public static final SimpleEvent<Consumer<ResourcePackBuilder>> RESOURCE_PACK_CREATION_EVENT = INSTANCE.creationEvent;
public static final SimpleEvent<Consumer<ResourcePackBuilder>> RESOURCE_PACK_AFTER_INITIAL_CREATION_EVENT = INSTANCE.afterInitialCreationEvent;
public static final SimpleEvent<Runnable> RESOURCE_PACK_FINISHED_EVENT = INSTANCE.finishedEvent;
private static boolean REQUIRED = PolymerResourcePackImpl.FORCE_REQUIRE;
private static boolean DEFAULT_CHECK = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ default boolean copyFromPath(Path path) {
boolean addArmorModel(PolymerArmorModel model);
@Nullable
byte[] getData(String path);
@Nullable
byte[] getDataOrVanilla(String path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import eu.pb4.polymer.common.api.events.SimpleEvent;
import eu.pb4.polymer.common.impl.CommonImpl;
import eu.pb4.polymer.common.impl.CommonImplUtils;
import eu.pb4.polymer.resourcepack.api.AssetPaths;
import eu.pb4.polymer.resourcepack.api.PolymerArmorModel;
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
import eu.pb4.polymer.resourcepack.impl.ArmorTextureMetadata;
Expand Down Expand Up @@ -34,6 +35,9 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import static eu.pb4.polymer.resourcepack.api.AssetPaths.armorOverlayTexture;
import static eu.pb4.polymer.resourcepack.api.AssetPaths.armorTexture;

@SuppressWarnings("ResultOfMethodCallIgnored")
@ApiStatus.Internal
public class DefaultRPBuilder implements InternalRPBuilder {
Expand Down Expand Up @@ -200,7 +204,7 @@ public boolean addCustomModelData(PolymerModelData cmdInfo) {
jsonArray.add(jsonObject);
}
JsonObject modelObject = null;
var modelPath = "assets/" + cmdInfo.modelPath().getNamespace() + "/models/" + cmdInfo.modelPath().getPath() + ".json";
var modelPath = AssetPaths.model(cmdInfo.modelPath().getNamespace(), cmdInfo.modelPath().getPath() + ".json");

if (this.fileMap.containsKey(modelPath)) {
modelObject = JsonParser.parseString(new String(this.fileMap.get(modelPath), StandardCharsets.UTF_8)).getAsJsonObject();
Expand Down Expand Up @@ -249,6 +253,7 @@ public byte[] getData(String path) {
return this.fileMap.get(path);
}

@Override
@Nullable
public byte[] getDataOrVanilla(String path) {
if (this.fileMap.containsKey(path)) {
Expand All @@ -266,7 +271,7 @@ private byte[] getVanillaData(String path) {
return stream.readAllBytes();
}
} catch (Throwable e) {
CommonImpl.LOGGER.warn("Error occurred while getting data from vanilla jar! {}", e);
CommonImpl.LOGGER.warn("Error occurred while getting data from vanilla jar!", e);
}
return null;
}
Expand All @@ -275,16 +280,17 @@ private byte[] getVanillaData(String path) {
private InputStream getVanillaStream(String path) {
try {
if (this.clientJar == null) {
//noinspection ConstantConditions
this.clientJar = FileSystems.newFileSystem(PolymerCommonUtils.getClientJar());
}

var entry = this.clientJar.getPath(path);

if (entry != null && Files.exists(entry)) {
if (Files.exists(entry)) {
return Files.newInputStream(entry);
}
} catch (Exception e) {
CommonImpl.LOGGER.warn("Error occurred while getting data from vanilla jar! {}", e);
CommonImpl.LOGGER.warn("Error occurred while getting data from vanilla jar!", e);
}

return null;
Expand Down Expand Up @@ -418,7 +424,7 @@ public CompletableFuture<Boolean> buildResourcePack() {
images[i] = bi;
}
{
var path = "assets/" + entry.modelPath().getNamespace() + "/textures/models/armor/" + entry.modelPath().getPath() + "_layer_" + (i + 1) + ".polymer.json";
var path = AssetPaths.armorTexturePolymerMetadata(entry.modelPath(), i + 1);
var data = this.fileMap.get(path);

if (data != null) {
Expand Down Expand Up @@ -448,11 +454,10 @@ public CompletableFuture<Boolean> buildResourcePack() {
list.sort(Comparator.comparing(e -> -e.color()));

this.fileMap.put("assets/polymer/armors.json", GSON.toJson(armorDataMap).getBytes(StandardCharsets.UTF_8));
this.fileMap.put("assets/minecraft/textures/models/armor/vanilla_leather_layer_1.png", this.getVanillaData("assets/minecraft/textures/models/armor/leather_layer_1.png"));
this.fileMap.put("assets/minecraft/textures/models/armor/vanilla_leather_layer_1_overlay.png", this.getVanillaData("assets/minecraft/textures/models/armor/leather_layer_1_overlay.png"));
this.fileMap.put("assets/minecraft/textures/models/armor/vanilla_leather_layer_2.png", this.getVanillaData("assets/minecraft/textures/models/armor/leather_layer_2.png"));
this.fileMap.put("assets/minecraft/textures/models/armor/vanilla_leather_layer_2_overlay.png", this.getVanillaData("assets/minecraft/textures/models/armor/leather_layer_2_overlay.png"));

this.fileMap.put(armorTexture(vId("vanilla_leather"), 1), this.getVanillaData(armorTexture(new Identifier("leather"), 1)));
this.fileMap.put(armorOverlayTexture(vId("vanilla_leather"), 1), this.getVanillaData(armorOverlayTexture(vId("leather"), 1)));
this.fileMap.put(armorTexture(vId("vanilla_leather"), 2), this.getVanillaData(armorTexture(new Identifier("leather"), 2)));
this.fileMap.put(armorOverlayTexture(vId("vanilla_leather"), 2), this.getVanillaData(armorOverlayTexture(vId("leather"), 2)));
int[] width = new int[]{64 * globalScale, 64 * globalScale};
int[] height = new int[]{32 * globalScale, 32 * globalScale};

Expand Down Expand Up @@ -489,11 +494,13 @@ public CompletableFuture<Boolean> buildResourcePack() {
try {
for (int i = 0; i <= 1; i++) {
{
var tex = ImageIO.read(this.getVanillaStream("assets/minecraft/textures/models/armor/leather_layer_" + (i + 1) + ".png"));
//noinspection ConstantConditions
var tex = ImageIO.read(this.getVanillaStream(armorTexture(vId("leather"), i + 1)));
graphics[i].drawImage(tex, 0, 0, tex.getWidth() * globalScale, tex.getHeight() * globalScale, null);
}
{
var tex = ImageIO.read(this.getVanillaStream("assets/minecraft/textures/models/armor/leather_layer_" + (i + 1) + "_overlay.png"));
//noinspection ConstantConditions
var tex = ImageIO.read(this.getVanillaStream(armorOverlayTexture(vId("leather"), i + 1)));
graphics[i].drawImage(tex, 0, 0, tex.getWidth() * globalScale, tex.getHeight() * globalScale, null);
}
graphics[i].setColor(Color.WHITE);
Expand Down Expand Up @@ -535,12 +542,12 @@ public CompletableFuture<Boolean> buildResourcePack() {
{
var out = new ByteArrayOutputStream();
ImageIO.write(image[i], "png", out);
this.fileMap.put("assets/minecraft/textures/models/armor/leather_layer_" + (i + 1) + ".png", out.toByteArray());
this.fileMap.put(armorTexture(vId("leather"), i + 1), out.toByteArray());
}
{
var out = new ByteArrayOutputStream();
ImageIO.write(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB), "png", out);
this.fileMap.put("assets/minecraft/textures/models/armor/leather_layer_" + (i + 1) + "_overlay.png", out.toByteArray());
this.fileMap.put(armorOverlayTexture(vId("leather"), i + 1), out.toByteArray());
}
}
} catch (Throwable e) {
Expand All @@ -559,8 +566,8 @@ public CompletableFuture<Boolean> buildResourcePack() {

}

if (!this.fileMap.containsKey("pack.mcmeta")) {
this.fileMap.put("pack.mcmeta", ("" +
if (!this.fileMap.containsKey(AssetPaths.PACK_METADATA)) {
this.fileMap.put(AssetPaths.PACK_METADATA, ("" +
"{\n" +
" \"pack\":{\n" +
" \"pack_format\":" + SharedConstants.RESOURCE_PACK_VERSION + ",\n" +
Expand All @@ -570,13 +577,13 @@ public CompletableFuture<Boolean> buildResourcePack() {
}


if (!this.fileMap.containsKey("pack.png")) {
if (!this.fileMap.containsKey(AssetPaths.PACK_ICON)) {
var filePath = FabricLoader.getInstance().getGameDir().resolve("server-icon.png");

if (filePath.toFile().exists()) {
this.fileMap.put("pack.png", Files.readAllBytes(filePath));
this.fileMap.put(AssetPaths.PACK_ICON, Files.readAllBytes(filePath));
} else {
this.fileMap.put("pack.png", Files.readAllBytes(getSelfPath("assets/icon.png")));
this.fileMap.put(AssetPaths.PACK_ICON, Files.readAllBytes(getSelfPath("assets/icon.png")));
}
}

Expand Down Expand Up @@ -630,6 +637,10 @@ public CompletableFuture<Boolean> buildResourcePack() {
});
}

private Identifier vId(String path) {
return new Identifier(path);
}


private record ArmorData(Identifier identifier, int color, BufferedImage[] images,
ArmorTextureMetadata[] metadata) {
Expand Down
3 changes: 3 additions & 0 deletions polymer-virtual-entity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ loom {
dependencies {
//modCompileOnly ('nl.theepicblock:PolyMc:5.1.0+1.19')
api include(project(path: ':polymer-common', configuration: 'namedElements'))

modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v3.0.2-mc1.20'
modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:v3.0.2-mc1.20'
}

afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.minecraft.network.packet.s2c.play.EntitiesDestroyS2CPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;

Expand All @@ -25,6 +27,8 @@ public class ElementHolder {
private final List<VirtualElement> elements = new ObjectArrayList<>();
private final List<ServerPlayNetworkHandler> players = new ArrayList<>();
protected Vec3d currentPos = Vec3d.ZERO;
private ChunkPos currentChunkPos = null;

private final IntList entityIds = new IntArrayList();

public boolean isPartOf(int entityId) {
Expand Down Expand Up @@ -161,7 +165,19 @@ protected void updatePosition() {
var delta = newPos.subtract(newPos);
this.notifyElementsOfPositionUpdate(newPos, delta);
this.currentPos = newPos;
this.currentChunkPos = null;
}
}

protected void invalidateCaches() {
this.currentChunkPos = null;
}

public ChunkPos getChunkPos() {
if (this.currentChunkPos == null) {
this.currentChunkPos = new ChunkPos(BlockPos.ofFloored(this.currentPos));
}
return this.currentChunkPos;
}

protected void notifyElementsOfPositionUpdate(Vec3d newPos, Vec3d delta) {
Expand Down
Loading

0 comments on commit d5a6594

Please sign in to comment.