diff --git a/gradle.properties b/gradle.properties index 52ef46af..016d4b30 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ fabric_version=0.102.1+1.21.1 maven_group = eu.pb4 -mod_version = 0.9.12 +mod_version = 0.9.13 minecraft_version_supported = ">=1.21-" diff --git a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java index bbbcd7d3..21a9379e 100644 --- a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java +++ b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java @@ -3,25 +3,21 @@ import com.mojang.brigadier.arguments.BoolArgumentType; import eu.pb4.polymer.autohost.api.ResourcePackDataProvider; import eu.pb4.polymer.autohost.impl.providers.AbstractProvider; -import eu.pb4.polymer.autohost.impl.providers.NettyProvider; import eu.pb4.polymer.autohost.impl.providers.EmptyProvider; +import eu.pb4.polymer.autohost.impl.providers.NettyProvider; import eu.pb4.polymer.autohost.impl.providers.StandaloneWebServerProvider; import eu.pb4.polymer.common.impl.CommonImpl; import eu.pb4.polymer.common.impl.CommonImplUtils; import eu.pb4.polymer.common.impl.CommonNetworkHandlerExt; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; +import eu.pb4.polymer.resourcepack.impl.PolymerResourcePackMod; import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.packet.s2c.common.ResourcePackSendS2CPacket; -import net.minecraft.registry.DynamicRegistryManager; -import net.minecraft.registry.Registries; import net.minecraft.server.MinecraftServer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import net.minecraft.util.Util; import java.io.File; -import java.nio.file.Files; import java.nio.file.Path; import java.util.*; import java.util.function.Consumer; @@ -32,15 +28,12 @@ public class AutoHost implements ModInitializer { public static final Map> TYPES = new HashMap<>(); + public static final List GLOBAL_RESOURCE_PACKS = new ArrayList<>(); public static AutoHostConfig config = new AutoHostConfig(); public static Text message = Text.empty(); public static Text disconnectMessage = Text.empty(); - public static ResourcePackDataProvider provider = EmptyProvider.INSTANCE; - public static final List GLOBAL_RESOURCE_PACKS = new ArrayList<>(); - - public static void init(MinecraftServer server) { var config = CommonImpl.loadConfig("auto-host", AutoHostConfig.class); AutoHost.config = config; @@ -94,20 +87,9 @@ public static void end(MinecraftServer server) { provider.serverStopped(server); } + @Deprecated(forRemoval = true) public static void generateAndCall(MinecraftServer server, Consumer messageConsumer, Runnable runnable) { - Util.getIoWorkerExecutor().execute(() -> { - messageConsumer.accept(Text.literal("[Polymer] Starting resource pack generation...")); - boolean success = PolymerResourcePackUtils.buildMain(); - - server.execute(() -> { - if (success) { - messageConsumer.accept(Text.literal("[Polymer] Resource pack created successfully!")); - runnable.run(); - } else { - messageConsumer.accept(Text.literal("[Polymer] Found issues while creating resource pack! See logs above for more detail!")); - } - }); - }); + PolymerResourcePackMod.generateAndCall(server, true, messageConsumer, runnable); } public static File getFile(String path) { @@ -133,25 +115,33 @@ public void onInitialize() { ResourcePackDataProvider.register(Identifier.of("polymer", "standalone"), StandaloneWebServerProvider::new); ResourcePackDataProvider.register(Identifier.of("polymer", "empty"), EmptyProvider::new); + CommonImplUtils.registerCommands((c) -> c.then(literal("generate-pack") + .requires(CommonImplUtils.permission("command.generate", 3)) + .then(literal("reload").executes((ctx -> { + return PolymerResourcePackMod.generateResources(ctx, () -> { + if (!provider.isReady()) { + ctx.getSource().sendMessage(Text.literal("[Polymer] AutoHost module isn't configured/loaded correctly so resource pack won't be synced!")); + return; + } + for (var player : ctx.getSource().getServer().getPlayerManager().getPlayerList()) { + for (var x : provider.getProperties(((CommonNetworkHandlerExt) player.networkHandler).polymerCommon$getConnection())) { + player.networkHandler.sendPacket(new ResourcePackSendS2CPacket(x.id(), x.url(), x.hash(), AutoHost.config.require || PolymerResourcePackUtils.isRequired(), Optional.ofNullable(AutoHost.message))); + } + } + }); + }))) + ) + ); + CommonImplUtils.registerDevCommands((c) -> { c.then(literal("reload_resourcepack").executes(context -> { if (provider.isReady()) { - for (var x : provider.getProperties(((CommonNetworkHandlerExt) context.getSource().getPlayerOrThrow().networkHandler).polymerCommon$getConnection() - )) { + for (var x : provider.getProperties(((CommonNetworkHandlerExt) context.getSource().getPlayerOrThrow().networkHandler).polymerCommon$getConnection())) { context.getSource().getPlayerOrThrow().networkHandler.sendPacket(new ResourcePackSendS2CPacket(x.id(), x.url(), x.hash(), AutoHost.config.require || PolymerResourcePackUtils.isRequired(), Optional.ofNullable(AutoHost.message))); } } return 0; })); - c.then(literal("rebuild_reload_rp").executes(context -> { - generateAndCall(context.getSource().getServer(), context.getSource()::sendMessage, () -> { - for (var x : provider.getProperties(((CommonNetworkHandlerExt) context.getSource().getPlayer().networkHandler).polymerCommon$getConnection() - )) { - context.getSource().getPlayer().networkHandler.sendPacket(new ResourcePackSendS2CPacket(x.id(), x.url(), x.hash(), AutoHost.config.require || PolymerResourcePackUtils.isRequired(), Optional.ofNullable(AutoHost.message))); - } - }); - return 0; - })); c.then(literal("force_ready").then(argument("value", BoolArgumentType.bool()).executes((ctx) -> { if (provider instanceof AbstractProvider abs) { diff --git a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/providers/AbstractProvider.java b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/providers/AbstractProvider.java index f55803d4..aca1b90b 100644 --- a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/providers/AbstractProvider.java +++ b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/providers/AbstractProvider.java @@ -10,6 +10,7 @@ import eu.pb4.polymer.common.impl.CommonImpl; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import eu.pb4.polymer.resourcepack.api.ResourcePackBuilder; +import eu.pb4.polymer.resourcepack.impl.PolymerResourcePackMod; import net.minecraft.network.ClientConnection; import net.minecraft.server.MinecraftServer; import org.apache.http.HttpStatus; @@ -45,7 +46,7 @@ public void serverStarted(MinecraftServer minecraftServer) { isPackReady = true; }); - AutoHost.generateAndCall(minecraftServer, minecraftServer::sendMessage, () -> {}); + PolymerResourcePackMod.generateAndCall(minecraftServer, true, minecraftServer::sendMessage, () -> {}); } @Override diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/api/entity/PolymerEntity.java b/polymer-core/src/main/java/eu/pb4/polymer/core/api/entity/PolymerEntity.java index a2ce50d2..1cace482 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/api/entity/PolymerEntity.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/api/entity/PolymerEntity.java @@ -7,10 +7,13 @@ import net.minecraft.entity.data.DataTracker; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.s2c.play.EntityAttributesS2CPacket; import net.minecraft.server.network.PlayerAssociatedNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.math.Vec3d; +import xyz.nucleoid.packettweaker.PacketContext; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.function.Consumer; @@ -50,6 +53,11 @@ default void modifyRawTrackedData(List> data, Ser } + default void modifyRawEntityAttributeData(List data, PacketContext context, boolean initial) { + + } + + default void onEntityPacketSent(Consumer> consumer, Packet packet) { consumer.accept(packet); } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/api/utils/PolymerUtils.java b/polymer-core/src/main/java/eu/pb4/polymer/core/api/utils/PolymerUtils.java index 5994d1a5..919889bd 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/api/utils/PolymerUtils.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/api/utils/PolymerUtils.java @@ -148,7 +148,10 @@ public static void reloadWorld(ServerPlayerEntity player) { PolymerImplUtils.IS_RELOADING_WORLD.remove(); }); } - + /** + * @deprecated Use {@link PolymerComponent#registerDataComponent(ComponentType[])} instead + */ + @Deprecated public static void markAsPolymer(ComponentType... types) { PolymerItemUtils.markAsPolymer(types); } @@ -157,7 +160,7 @@ public static void markAsPolymer(ComponentType... types) { * Resends inventory to player */ public static void reloadInventory(ServerPlayerEntity player) { - player.networkHandler.sendPacket(new InventoryS2CPacket(0, 0, player.playerScreenHandler.getStacks(), player.playerScreenHandler.getCursorStack())); + player.currentScreenHandler.syncState(); } /** diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/Commands.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/Commands.java index 2f8d3b30..b4ce3080 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/Commands.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/Commands.java @@ -98,6 +98,10 @@ public static void register(LiteralArgumentBuilder command, .requires(CommonImplUtils.permission("command.target-block", 3)) .executes(Commands::targetBlock) ) + .then(literal("target-item") + .requires(CommonImplUtils.permission("command.target-item", 3)) + .executes(Commands::targetItem) + ) .then(literal("pick") .requires(CommonImplUtils.permission("command.pick", 0)) .executes((ctx) -> Commands.pickTarget(ctx, false)) @@ -248,6 +252,12 @@ private static int targetBlock(CommandContext context) { return 0; } + private static int targetItem(CommandContext context) throws CommandSyntaxException { + var itemStack = context.getSource().getPlayerOrThrow().getMainHandStack(); + context.getSource().sendFeedback(() -> Text.of(Registries.ITEM.getId(itemStack.getItem())), false); + return 0; + } + private static int dumpRegistries(CommandContext context) { var path = PolymerImplUtils.dumpRegistry(); if (path != null) { diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/VirtualClientItem.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/VirtualClientItem.java index fc834c42..0dfdb86a 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/VirtualClientItem.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/VirtualClientItem.java @@ -4,6 +4,7 @@ import eu.pb4.polymer.core.api.client.ClientPolymerItem; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.component.ComponentMap; import net.minecraft.item.tooltip.TooltipType; import net.minecraft.component.DataComponentTypes; import net.minecraft.item.Item; @@ -34,6 +35,11 @@ public RegistryEntry.Reference getRegistryEntry() { return this.polymerItem.visualStack().getItem().getRegistryEntry(); } + @Override + public ItemStack getDefaultStack() { + return this.polymerItem.visualStack().copy(); + } + @Override public Text getName() { return this.polymerItem.visualStack().getName(); @@ -48,6 +54,21 @@ public ClientPolymerItem getPolymerEntry() { return this.polymerItem; } + @Override + public ComponentMap getComponents() { + return this.polymerItem.visualStack().getComponents(); + } + + @Override + protected String getOrCreateTranslationKey() { + return ""; + } + + @Override + public int getMaxCount() { + return this.polymerItem.visualStack().getMaxCount(); + } + @Override public void appendTooltip(ItemStack stack, TooltipContext context, List tooltip, TooltipType type) { if (this.polymerItem.visualStack().contains(DataComponentTypes.LORE)) { diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/EntityTrackerUpdateS2CPacketExt.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/PossiblyInitialPacket.java similarity index 68% rename from polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/EntityTrackerUpdateS2CPacketExt.java rename to polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/PossiblyInitialPacket.java index fcdd8139..3388c792 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/EntityTrackerUpdateS2CPacketExt.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/PossiblyInitialPacket.java @@ -1,6 +1,6 @@ package eu.pb4.polymer.core.impl.interfaces; -public interface EntityTrackerUpdateS2CPacketExt { +public interface PossiblyInitialPacket { boolean polymer$getInitial(); void polymer$setInitial(); } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityAttributesS2CPacketMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityAttributesS2CPacketMixin.java index f83e68e3..78778945 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityAttributesS2CPacketMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityAttributesS2CPacketMixin.java @@ -6,6 +6,7 @@ import eu.pb4.polymer.core.api.utils.PolymerUtils; import eu.pb4.polymer.common.impl.entity.InternalEntityHelpers; import eu.pb4.polymer.core.impl.interfaces.EntityAttachedPacket; +import eu.pb4.polymer.core.impl.interfaces.PossiblyInitialPacket; import eu.pb4.polymer.core.impl.networking.TransformingPacketCodec; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -21,27 +22,45 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import xyz.nucleoid.packettweaker.PacketContext; import java.util.ArrayList; import java.util.Collection; import java.util.List; @Mixin(EntityAttributesS2CPacket.class) -public abstract class EntityAttributesS2CPacketMixin { +public abstract class EntityAttributesS2CPacketMixin implements PossiblyInitialPacket { + @Unique + private boolean isInitial = false; + + @Override + public boolean polymer$getInitial() { + return this.isInitial; + } + + @Override + public void polymer$setInitial() { + this.isInitial = true; + } + @SuppressWarnings("UnreachableCode") @ModifyExpressionValue(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/codec/PacketCodec;tuple(Lnet/minecraft/network/codec/PacketCodec;Ljava/util/function/Function;Lnet/minecraft/network/codec/PacketCodec;Ljava/util/function/Function;Ljava/util/function/BiFunction;)Lnet/minecraft/network/codec/PacketCodec;")) private static PacketCodec patchCodec(PacketCodec original) { return TransformingPacketCodec.encodeOnly(original, (buf, packet) -> { if (EntityAttachedPacket.get(packet, packet.getEntityId()) instanceof PolymerEntity entity) { - var type = entity.getPolymerEntityType(PolymerUtils.getPlayerContext()); + var context = PacketContext.get(); + var type = entity.getPolymerEntityType(context.getPlayer()); var p = new EntityAttributesS2CPacket(packet.getEntityId(), List.of()); var list = ((EntityAttributesS2CPacketAccessor) p).getEntries(); var vanillaContainer = DefaultAttributeRegistry.get((EntityType) type); - for (var entry : packet.getEntries()) { + var data = new ArrayList<>(packet.getEntries()); + entity.modifyRawEntityAttributeData(data, context, ((PossiblyInitialPacket) packet).polymer$getInitial()); + for (var entry : data) { if (vanillaContainer.has(entry.attribute()) && !PolymerEntityUtils.isPolymerEntityAttribute(entry.attribute())) { list.add(entry); } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityTrackerEntryMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityTrackerEntryMixin.java index a3baf80a..6037364a 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityTrackerEntryMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityTrackerEntryMixin.java @@ -4,7 +4,7 @@ import com.mojang.datafixers.util.Pair; import eu.pb4.polymer.core.api.entity.PolymerEntity; import eu.pb4.polymer.core.api.other.PlayerBoundConsumer; -import eu.pb4.polymer.core.impl.interfaces.EntityTrackerUpdateS2CPacketExt; +import eu.pb4.polymer.core.impl.interfaces.PossiblyInitialPacket; import eu.pb4.polymer.core.impl.networking.PolymerServerProtocol; import net.minecraft.entity.Entity; import net.minecraft.entity.EquipmentSlot; @@ -16,7 +16,6 @@ import net.minecraft.network.packet.s2c.play.EntityEquipmentUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket; import net.minecraft.server.network.EntityTrackerEntry; -import net.minecraft.server.network.PlayerAssociatedNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; @@ -48,7 +47,13 @@ public abstract class EntityTrackerEntryMixin { @ModifyArg(method = "sendPackets", at = @At(value = "INVOKE", target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V", ordinal = 1)) private Object polymer$markAsInitial(Object obj) { - ((EntityTrackerUpdateS2CPacketExt) obj).polymer$setInitial(); + ((PossiblyInitialPacket) obj).polymer$setInitial(); + return obj; + } + + @ModifyArg(method = "sendPackets", at = @At(value = "INVOKE", target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V", ordinal = 2)) + private Object polymer$markAsInitial2(Object obj) { + ((PossiblyInitialPacket) obj).polymer$setInitial(); return obj; } @@ -89,7 +94,7 @@ public abstract class EntityTrackerEntryMixin { if (this.entity instanceof PolymerEntity polymerEntity) { if (polymerEntity.sendEmptyTrackerUpdates(player) && this.changedEntries == null) { var x = new EntityTrackerUpdateS2CPacket(this.entity.getId(), List.of()); - ((EntityTrackerUpdateS2CPacketExt) (Object) x).polymer$setInitial(); + ((PossiblyInitialPacket) (Object) x).polymer$setInitial(); sender.accept(x); } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityTrackerUpdateS2CPacketMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityTrackerUpdateS2CPacketMixin.java index ab5fd2cd..418d8c1d 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityTrackerUpdateS2CPacketMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/entity/EntityTrackerUpdateS2CPacketMixin.java @@ -1,26 +1,16 @@ package eu.pb4.polymer.core.mixin.entity; -import eu.pb4.polymer.common.impl.client.ClientUtils; import eu.pb4.polymer.common.impl.entity.InternalEntityHelpers; import eu.pb4.polymer.core.api.block.PolymerBlockUtils; import eu.pb4.polymer.core.api.entity.PolymerEntity; import eu.pb4.polymer.core.api.entity.PolymerEntityUtils; -import eu.pb4.polymer.core.api.item.PolymerItem; -import eu.pb4.polymer.core.api.item.PolymerItemUtils; import eu.pb4.polymer.core.api.utils.PolymerUtils; import eu.pb4.polymer.core.impl.interfaces.EntityAttachedPacket; -import eu.pb4.polymer.core.impl.interfaces.EntityTrackerUpdateS2CPacketExt; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; +import eu.pb4.polymer.core.impl.interfaces.PossiblyInitialPacket; import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.data.DataTracker; -import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.entity.vehicle.AbstractMinecartEntity; -import net.minecraft.item.ItemStack; import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket; -import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.village.VillagerData; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; @@ -28,26 +18,19 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.ArrayList; import java.util.List; -import java.util.Optional; @SuppressWarnings({"rawtypes", "unchecked", "ConstantConditions"}) @Mixin(EntityTrackerUpdateS2CPacket.class) -public class EntityTrackerUpdateS2CPacketMixin implements EntityTrackerUpdateS2CPacketExt { +public class EntityTrackerUpdateS2CPacketMixin implements PossiblyInitialPacket { @Shadow @Final private int id; - - @Shadow - @Final - private List> trackedValues; @Unique - private boolean polymer$isInitial = false; + private boolean isInitial = false; @Unique @Nullable @@ -62,7 +45,7 @@ public class EntityTrackerUpdateS2CPacketMixin implements EntityTrackerUpdateS2C if (entity instanceof PolymerEntity polymerEntity && InternalEntityHelpers.canPatchTrackedData(player, entity)) { var mod = trackedValues != null ? new ArrayList<>(trackedValues) : new ArrayList>(); - polymerEntity.modifyRawTrackedData(mod, player, this.polymer$isInitial); + polymerEntity.modifyRawTrackedData(mod, player, this.isInitial); var legalTrackedData = InternalEntityHelpers.getExampleTrackedDataOfEntityType((polymerEntity.getPolymerEntityType(player))); @@ -109,11 +92,11 @@ public class EntityTrackerUpdateS2CPacketMixin implements EntityTrackerUpdateS2C @Override public boolean polymer$getInitial() { - return this.polymer$isInitial; + return this.isInitial; } @Override public void polymer$setInitial() { - this.polymer$isInitial = true; + this.isInitial = true; } } diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackMod.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackMod.java index 94a3984b..8ae0280b 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackMod.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackMod.java @@ -1,6 +1,7 @@ package eu.pb4.polymer.resourcepack.impl; import com.mojang.brigadier.context.CommandContext; +import eu.pb4.polymer.common.impl.CommonImpl; import eu.pb4.polymer.common.impl.CommonImplUtils; import eu.pb4.polymer.common.impl.CompatStatus; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; @@ -14,15 +15,18 @@ import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.metadata.CustomValue; import net.minecraft.item.ArmorMaterial; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.HoverEvent; import net.minecraft.text.Style; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.Util; import org.jetbrains.annotations.ApiStatus; import java.util.List; +import java.util.function.Consumer; import static net.minecraft.server.command.CommandManager.literal; @@ -68,31 +72,47 @@ public void onInitializeClient() { } public static int generateResources(CommandContext context) { - if (alreadyGeneration) { - context.getSource().sendFeedback(() -> Text.literal("Pack is already generating! Wait for it to finish..."), true); - } else { - alreadyGeneration = true; + generateAndCall(context.getSource().getServer(), false, x -> context.getSource().sendFeedback(() -> x, true), () -> {}); + return 1; + } - Util.getIoWorkerExecutor().execute(() -> { - context.getSource().sendFeedback(() -> Text.literal("Starting resource pack generation..."), true); + public static int generateResources(CommandContext context, Runnable runnable) { + generateAndCall(context.getSource().getServer(), false, x -> context.getSource().sendFeedback(() -> x, true), runnable); + return 1; + } + + public static void generateAndCall(MinecraftServer server, boolean ignoreLock, Consumer messageConsumer, Runnable runnable) { + if (alreadyGeneration && !ignoreLock) { + messageConsumer.accept(Text.literal("[Polymer] Pack is already generating! Wait for it to finish...")); + return; + } + alreadyGeneration = true; + + Util.getIoWorkerExecutor().execute(() -> { + try { + messageConsumer.accept(Text.literal("[Polymer] Starting resource pack generation...")); boolean success = PolymerResourcePackUtils.buildMain(); - context.getSource().getServer().execute(() -> { + server.execute(() -> { + alreadyGeneration = false; if (success) { - context.getSource().sendFeedback(() -> - Text.literal("Resource pack created successfully! You can find it in game folder as ") + messageConsumer.accept(Text.literal("[Polymer] Resource pack created successfully! You can find it in game folder as ") .append(Text.literal("polymer-resourcepack.zip") - .setStyle(Style.EMPTY.withUnderline(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(PolymerResourcePackUtils.getMainPath().toAbsolutePath().toString()))))), - true + .setStyle(Style.EMPTY.withUnderline(true) + .withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + Text.literal(PolymerResourcePackUtils.getMainPath().toAbsolutePath().toString()))))) ); + runnable.run(); } else { - context.getSource().sendError(Text.literal("Found issues while creating resource pack! See logs above for more detail!")); + messageConsumer.accept(Text.literal("[Polymer] Found issues while creating resource pack! See logs above for more detail!").formatted(Formatting.RED)); } }); - + } catch (Throwable e) { + messageConsumer.accept(Text.literal("[Polymer] Found critical issues while creating resource pack! See logs above for more detail!").formatted(Formatting.RED)); + CommonImpl.LOGGER.error("Failed to generate the resource pack!", e); alreadyGeneration = false; - }); - } - return 0; - } + } + }); + } } diff --git a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/block/PistonBlockEntityMixin.java b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/block/PistonBlockEntityMixin.java index 2f5a9a39..685c157c 100644 --- a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/block/PistonBlockEntityMixin.java +++ b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/block/PistonBlockEntityMixin.java @@ -46,23 +46,25 @@ private static void updatePos(World world, BlockPos pos, BlockState state, Pisto } } - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlockEntity(Lnet/minecraft/util/math/BlockPos;)V")) + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;postProcessState(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) private static void updatePos(World world, BlockPos pos, BlockState state, PistonBlockEntity blockEntity, CallbackInfo ci) { var att = ((PistonBlockEntityMixin) (Object) blockEntity).attachment; if (att != null) { att.update(1); BlockBoundAttachment.fromMoving(att.holder(), (ServerWorld) world, pos, blockEntity.getPushedBlock()); + ((PistonBlockEntityMixin) (Object) blockEntity).attachment = null; } } - @Inject(method = "finish", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlockEntity(Lnet/minecraft/util/math/BlockPos;)V")) + @Inject(method = "finish", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;postProcessState(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) private void updatePos(CallbackInfo ci) { var att = this.attachment; if (att != null) { att.update(1); BlockBoundAttachment.fromMoving(att.holder(), (ServerWorld) this.world, pos, this.getPushedBlock()); + this.attachment = null; } } } diff --git a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/block/PistonBlockMixin.java b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/block/PistonBlockMixin.java index e0414e1b..d080a9c4 100644 --- a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/block/PistonBlockMixin.java +++ b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/block/PistonBlockMixin.java @@ -48,6 +48,7 @@ private BlockEntity collectAttachmentHolder(BlockEntity blockEntity, @Share("att var val = attachment.get(); if (val != null && blockEntity != null) { ((PistonExt) blockEntity).polymer$setAttachement(val); + attachment.set(null); } return blockEntity; }