Skip to content

Commit

Permalink
Fix mods triggering resource reload too early, add check for path, fi…
Browse files Browse the repository at this point in the history
…x rei compat
  • Loading branch information
Patbox committed Jan 16, 2023
1 parent 3d83cd3 commit 95e3635
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 36 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ yarn_mappings=1.19.3+build.1
loader_version=0.14.12

#Fabric api
fabric_version=0.68.1+1.19.3
fabric_version=0.72.0+1.19.3

maven_group = eu.pb4

mod_version = 0.3.6
mod_version = 0.3.7

minecraft_version_supported = ">=1.19.3-beta.3"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Environment(EnvType.CLIENT)
public class ClientUtils {
public static final String PACK_ID = "$polymer-resources";
public static volatile ServerPlayerEntity backupPlayer;

public static boolean isResourcePackLoaded() {
return MinecraftClient.getInstance().getResourcePackManager().getEnabledNames().contains(PACK_ID);
Expand All @@ -22,7 +23,7 @@ public static boolean isSingleplayer() {
public static ServerPlayerEntity getPlayer() {
return MinecraftClient.getInstance().getServer() != null && MinecraftClient.getInstance().player != null
? MinecraftClient.getInstance().getServer().getPlayerManager().getPlayer(MinecraftClient.getInstance().player.getUuid())
: null;
: backupPlayer;
}

public static boolean isClientThread() {
Expand Down
4 changes: 2 additions & 2 deletions polymer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ dependencies {
modCompileOnly "mcp.mobius.waila:wthit:fabric-5.1.3"

//modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:9.1.530"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-fabric:9.1.565"
modCompileOnly modLocalRuntime("dev.emi:emi:0.5.3+1.19.3")
modCompileOnly "me.shedaniel:RoughlyEnoughItems-fabric:10.0.581"
modCompileOnly /*modLocalRuntime*/("dev.emi:emi:0.5.3+1.19.3")

//modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-common:11.0.0.206")
//modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-fabric:11.0.0.206")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
Expand All @@ -30,7 +31,11 @@ private PolymerItemGroupUtils() {}
public static final SimpleEvent<ItemGroupEventListener> LIST_EVENT = new SimpleEvent<>();

public static Contents getContentsFor(ServerPlayerEntity player, ItemGroup group) {
return ((ItemGroupExtra) group).polymer$getContentsWith(player.world.getEnabledFeatures(), CommonImplUtils.permissionCheck(player, "op_items", 2));
return getContentsFor(group, player.world.getEnabledFeatures(), CommonImplUtils.permissionCheck(player, "op_items", 2));
}

public static Contents getContentsFor(ItemGroup group, FeatureSet featureSet, boolean operator) {
return ((ItemGroupExtra) group).polymer$getContentsWith(featureSet, operator);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@
@ApiStatus.Internal
public class CompatUtils {
public static void iterateItems(Consumer<ItemStack> consumer) {
var stacks = ItemStackSet.create();

for (var group : ItemGroups.getGroups()) {
if (group.getType() != ItemGroup.Type.CATEGORY) {
continue;
}

var stacks = ItemStackSet.create();

stacks.addAll(((ClientItemGroupExtension) group).polymer$getStacksGroup());
stacks.addAll(((ClientItemGroupExtension) group).polymer$getStacksSearch());
}

if (stacks != null) {
for (var stack : stacks) {
consumer.accept(stack);
}
}
for (var stack : stacks) {
consumer.accept(stack);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
import eu.pb4.polymer.core.impl.PolymerImpl;
import eu.pb4.polymer.core.impl.PolymerImplUtils;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.RoughlyEnoughItemsCoreClient;
import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.comparison.EntryComparator;
import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry;
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.impl.init.RoughlyEnoughItemsInitializer;
import net.minecraft.item.ItemStack;

import java.util.function.Predicate;
Expand All @@ -26,10 +31,6 @@ public class ReiCompatibility implements REIClientPlugin {
return 0;
};

static {
CompatUtils.registerReload(() -> update(EntryRegistry.getInstance()));
}

private static void update(EntryRegistry registry) {
try {
registry.removeEntryIf(SHOULD_REMOVE);
Expand All @@ -40,7 +41,17 @@ private static void update(EntryRegistry registry) {
}
}

public static void registerEvents() {}
public static void registerEvents() {
CompatUtils.registerReload(() -> {
try {
RoughlyEnoughItemsCoreClient.reloadPlugins(null, null);
}catch (Throwable e) {
e.printStackTrace();
}

//update(EntryRegistry.getInstance());
});
}

@Override
public void registerItemComparators(ItemComparatorRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
public class ReloadableResourceManagerImplMixin {
@Inject(method = "reload", at = @At("RETURN"))
private void polymer$onReload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture<Unit> initialStage, List<ResourcePack> packs, CallbackInfoReturnable<ResourceReload> cir) {
var server = MinecraftClient.getInstance().getServer();
if (server != null) {
server.execute(() -> PolymerUtils.reloadWorld(ClientUtils.getPlayer()));
var player = ClientUtils.getPlayer();
if (player != null) {
player.server.execute(() -> PolymerUtils.reloadWorld(player));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public abstract class ServerPlayNetworkHandlerMixin {


@Inject(method = "onPlayerInteractBlock", at = @At("TAIL"))
private void polymer_updateMoreBlocks(PlayerInteractBlockC2SPacket packet, CallbackInfo ci) {

private void polymer$updateMoreBlocks(PlayerInteractBlockC2SPacket packet, CallbackInfo ci) {
if (PolymerImpl.RESEND_BLOCKS_AROUND_CLICK) {
var base = packet.getBlockHitResult().getBlockPos();
for (Direction direction : Direction.values()) {
Expand All @@ -90,14 +89,14 @@ private void polymer_updateMoreBlocks(PlayerInteractBlockC2SPacket packet, Callb
}
}

var stack = this.player.getStackInHand(packet.getHand());
/*var stack = this.player.getStackInHand(packet.getHand());
if (stack.getItem() instanceof PolymerItem virtualItem) {
var data = PolymerItemUtils.getItemSafely(virtualItem, stack, this.player);
if (data.item() instanceof BlockItem || data.item() instanceof BucketItem) {
this.onPlayerInteractItem(new PlayerInteractItemC2SPacket(packet.getHand(), 0));
}
}
}*/
}

@Inject(method = "onClickSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V", shift = At.Shift.AFTER))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package eu.pb4.polymer.networking.mixin;

import eu.pb4.polymer.common.impl.client.ClientUtils;
import eu.pb4.polymer.networking.api.PolymerServerNetworking;
import eu.pb4.polymer.networking.impl.TempPlayerLoginAttachments;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;
import net.minecraft.server.PlayerManager;
Expand All @@ -21,6 +25,7 @@ public class PlayerManagerMixin {

if (handshake != null) {
handshake.apply(player.networkHandler);

PolymerServerNetworking.AFTER_HANDSHAKE_APPLY.invoke(x -> x.accept(player.networkHandler, handshake));
}

Expand All @@ -41,4 +46,20 @@ public class PlayerManagerMixin {
connection.send(new PlayerRespawnS2CPacket(world.getDimensionKey(), world.getRegistryKey(), BiomeAccess.hashSeed(((ServerWorld) world).getSeed()),player.interactionManager.getGameMode(), player.interactionManager.getPreviousGameMode(), world.isDebugWorld(), ((ServerWorld) world).isFlat(), (byte) 0xFF, player.getLastDeathPos()));
}
}

@Environment(EnvType.CLIENT)
@Inject(method = "onPlayerConnect", at = @At("HEAD"))
private void polymerNet$storePlayer(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {
if (player.server.isHost(player.getGameProfile())) {
ClientUtils.backupPlayer = player;
}
}

@Environment(EnvType.CLIENT)
@Inject(method = "onPlayerConnect", at = @At("TAIL"))
private void polymerNet$removePlayer(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {
if (player.server.isHost(player.getGameProfile())) {
ClientUtils.backupPlayer = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,19 @@ public boolean copyAssets(String modId) {
try {
for (var rootPaths : container.getRootPaths()) {
Path assets = rootPaths.resolve("assets");
Files.walk(assets).forEach((file) -> {
var relative = assets.relativize(file);
var path = relative.toString().replace("\\", "/");
if (Files.isRegularFile(file)) {
try {
this.addData("assets/" + path, Files.readAllBytes(file));
} catch (IOException e) {
e.printStackTrace();
if (Files.exists(assets)) {
Files.walk(assets).forEach((file) -> {
var relative = assets.relativize(file);
var path = relative.toString().replace("\\", "/");
if (Files.isRegularFile(file)) {
try {
this.addData("assets/" + path, Files.readAllBytes(file));
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
});
}
}

return true;
Expand Down

0 comments on commit 95e3635

Please sign in to comment.