diff --git a/build.gradle b/build.gradle index 8f3d0a10..cbcd7325 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,10 @@ repositories { } } +loom { + accessWidener "src/main/resources/masa_gadget_mod.accesswidener" +} + dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" diff --git a/gradle.properties b/gradle.properties index b2df07c1..ceb49afc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.10.8 # Mod Properties - mod_version = 1.1.2-alpha.1 + mod_version = 1.1.3-alpha.1 maven_group = io.github.plusls archives_base_name = MasaGadget @@ -19,7 +19,7 @@ org.gradle.jvmargs=-Xmx1G # tweakeroo version tweakeroo_version = 0.10.0-dev.20201213.222846 # litematica version - litematica_version = 0.0.0-dev.20201225.203013 + litematica_version = 0.0.0-dev.20210104.135541 # multiconnect version multiconnect_version = 1.3.34 diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/inventoryPreviewSupportPlayer/MixinRenderUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/inventoryPreviewSupportPlayer/MixinRenderUtils.java new file mode 100644 index 00000000..56088324 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/inventoryPreviewSupportPlayer/MixinRenderUtils.java @@ -0,0 +1,64 @@ +package com.plusls.MasaGadget.mixin.tweakeroo.feature.inventoryPreviewSupportPlayer; + +import fi.dy.masa.malilib.render.InventoryOverlay; +import fi.dy.masa.malilib.util.GuiUtils; +import fi.dy.masa.tweakeroo.renderer.RenderUtils; +import net.minecraft.block.ShulkerBoxBlock; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.Inventory; +import net.minecraft.util.DyeColor; +import net.minecraft.util.hit.HitResult; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(value = RenderUtils.class, remap = false) +public abstract class MixinRenderUtils { + + static private Entity traceEntity = null; + + @Inject(method = "renderInventoryOverlay", + at = @At(value = "INVOKE_ASSIGN", + target = "Lnet/minecraft/util/hit/EntityHitResult;getEntity()Lnet/minecraft/entity/Entity;", + ordinal = 0, remap = true), locals = LocalCapture.CAPTURE_FAILHARD) + private static void getTraceEntity(MinecraftClient mc, MatrixStack matrixStack, CallbackInfo ci, + World world, PlayerEntity player, HitResult trace, Inventory inv, ShulkerBoxBlock block, + LivingEntity entityLivingBase, Entity entity) { + traceEntity = entity; + } + + @ModifyVariable(method = "renderInventoryOverlay", + at = @At(value = "INVOKE", + target = "Lfi/dy/masa/malilib/util/GuiUtils;getScaledWindowWidth()I", + ordinal = 0, remap = false), ordinal = 0) + private static Inventory modifyInv(Inventory inv) { + Inventory ret = inv; + if (ret == null && traceEntity instanceof PlayerEntity) { + PlayerEntity playerEntity = (PlayerEntity) traceEntity; + ret = playerEntity.inventory; + + int x = GuiUtils.getScaledWindowWidth() / 2 - 88; + int y = GuiUtils.getScaledWindowHeight() / 2 + 10; + int slotOffsetX = 8; + int slotOffsetY = 8; + InventoryOverlay.InventoryRenderType type = InventoryOverlay.InventoryRenderType.GENERIC; + DyeColor dye = DyeColor.GRAY; + float[] colors = dye.getColorComponents(); + + fi.dy.masa.malilib.render.RenderUtils.color(colors[0], colors[1], colors[2], 1.0F); + InventoryOverlay.renderInventoryBackground(type, x, y, 9, 27, MinecraftClient.getInstance()); + InventoryOverlay.renderInventoryStacks(type, playerEntity.getEnderChestInventory(), x + slotOffsetX, y + slotOffsetY, 9, 9, 27, MinecraftClient.getInstance()); + fi.dy.masa.malilib.render.RenderUtils.color(1.0F, 1.0F, 1.0F, 1.0F); + } + traceEntity = null; + return ret; + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/pcaSyncProtocol/MixinMerchantEntity.java b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/pcaSyncProtocol/MixinMerchantEntity.java deleted file mode 100644 index 1af1544e..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/pcaSyncProtocol/MixinMerchantEntity.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.feature.pcaSyncProtocol; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.Npc; -import net.minecraft.entity.passive.MerchantEntity; -import net.minecraft.entity.passive.PassiveEntity; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.village.Merchant; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MerchantEntity.class) -public abstract class MixinMerchantEntity extends PassiveEntity implements Npc, Merchant { - @Final - //@Dynamic - @Shadow - private SimpleInventory inventory; - - protected MixinMerchantEntity(EntityType entityType, World world) { - super(entityType, world); - } - - - // mojang 的 SimpleInventory 实现的有问题,readTags 时不会清空原有数据需要手动清空 - @Inject(method = "readCustomDataFromTag(Lnet/minecraft/nbt/CompoundTag;)V", at = @At(value = "HEAD")) - private void preReadTags(CompoundTag tag, CallbackInfo info) { - if (!MinecraftClient.getInstance().isIntegratedServerRunning()) { - this.inventory.clear(); - } - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/pcaSyncProtocol/MixinRenderUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/pcaSyncProtocol/MixinRenderUtils.java index 0e9d814b..d884a1b1 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/pcaSyncProtocol/MixinRenderUtils.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/feature/pcaSyncProtocol/MixinRenderUtils.java @@ -50,7 +50,8 @@ private static Inventory redirectGetBlockInventory(World world, BlockPos pos) { private static Entity redirectGetEntity(EntityHitResult entityHitResult) { Entity entity = entityHitResult.getEntity(); if (PcaSyncProtocol.enable) { - if (entity instanceof Inventory || entity instanceof VillagerEntity || entity instanceof HorseBaseEntity) { + if (entity instanceof Inventory || entity instanceof VillagerEntity || entity instanceof HorseBaseEntity + || entity instanceof PlayerEntity) { PcaSyncProtocol.syncEntity(entity.getEntityId()); } } diff --git a/src/main/java/com/plusls/MasaGadget/tweakeroo/feature/pcaSyncProtocol/network/PcaSyncProtocol.java b/src/main/java/com/plusls/MasaGadget/tweakeroo/feature/pcaSyncProtocol/network/PcaSyncProtocol.java index ed45643b..7e532fff 100644 --- a/src/main/java/com/plusls/MasaGadget/tweakeroo/feature/pcaSyncProtocol/network/PcaSyncProtocol.java +++ b/src/main/java/com/plusls/MasaGadget/tweakeroo/feature/pcaSyncProtocol/network/PcaSyncProtocol.java @@ -6,7 +6,6 @@ import net.earthcomputer.multiconnect.api.ICustomPayloadEvent; import net.earthcomputer.multiconnect.api.ICustomPayloadListener; import net.earthcomputer.multiconnect.api.MultiConnectAPI; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.block.entity.BlockEntity; @@ -14,11 +13,16 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.Entity; +import net.minecraft.entity.passive.HorseBaseEntity; +import net.minecraft.entity.passive.MerchantEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.vehicle.StorageMinecartEntity; +import net.minecraft.inventory.Inventories; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; import net.minecraft.network.PacketByteBuf; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; public class PcaSyncProtocol { @@ -130,31 +134,23 @@ private static void updateEntityHandler(MinecraftClient client, ClientPlayNetwor if (entity != null) { MasaGadgetMod.LOGGER.debug("update entity!"); - Vec3d localPos = entity.getPos(); - double prevX = entity.prevX; - double prevY = entity.prevY; - double prevZ = entity.prevZ; - float pitch = entity.pitch; - float horizontalSpeed = entity.horizontalSpeed; - float yaw = entity.yaw; - float prevPitch = entity.prevPitch; - float prevHorizontalSpeed = entity.prevHorizontalSpeed; - float prevYaw = entity.prevYaw; - Vec3d velocity = entity.getVelocity(); - - entity.fromTag(tag); - - entity.prevX = prevX; - entity.prevY = prevY; - entity.prevZ = prevZ; - entity.setPos(localPos.x, localPos.y, localPos.z); - entity.prevPitch = prevPitch; - entity.prevHorizontalSpeed = prevHorizontalSpeed; - entity.prevYaw = prevYaw; - entity.pitch = pitch; - entity.horizontalSpeed = horizontalSpeed; - entity.yaw = yaw; - entity.setVelocity(velocity); + assert tag != null; + if (entity instanceof StorageMinecartEntity) { + ((StorageMinecartEntity) entity).inventory.clear(); + Inventories.fromTag(tag, ((StorageMinecartEntity) entity).inventory); + } else if (entity instanceof MerchantEntity) { + ((MerchantEntity) entity).getInventory().clear(); + ((MerchantEntity) entity).getInventory().readTags(tag.getList("Inventory", 10)); + } else if (entity instanceof HorseBaseEntity) { + // TODO 写的更优雅一些 + entity.fromTag(tag); + } else if (entity instanceof PlayerEntity) { + PlayerEntity playerEntity = (PlayerEntity) entity; + playerEntity.inventory.deserialize(tag.getList("Inventory", 10)); + if (tag.contains("EnderItems", 9)) { + playerEntity.getEnderChestInventory().readTags(tag.getList("EnderItems", 10)); + } + } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 76074025..81386861 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -14,7 +14,7 @@ }, "license": "CC0-1.0", - "environment": "*", + "environment": "client", "entrypoints": { "client": [ "com.plusls.MasaGadget.MasaGadgetMod" @@ -23,7 +23,7 @@ "mixins": [ "masa_gadget_mod.mixins.json" ], - + "accessWidener": "masa_gadget_mod.accesswidener", "depends": { "fabricloader": ">=0.7.4", "fabric": ">=0.28.0", @@ -31,5 +31,8 @@ }, "suggests": { "flamingo": "*" + }, + "custom": { + "modmenu:clientsideOnly": true } } diff --git a/src/main/resources/masa_gadget_mod.accesswidener b/src/main/resources/masa_gadget_mod.accesswidener new file mode 100644 index 00000000..79249cdb --- /dev/null +++ b/src/main/resources/masa_gadget_mod.accesswidener @@ -0,0 +1,2 @@ +accessWidener v1 named +accessible field net/minecraft/entity/vehicle/StorageMinecartEntity inventory Lnet/minecraft/util/collection/DefaultedList; \ No newline at end of file diff --git a/src/main/resources/masa_gadget_mod.mixins.json b/src/main/resources/masa_gadget_mod.mixins.json index 9cb13506..eb9ab2cc 100644 --- a/src/main/resources/masa_gadget_mod.mixins.json +++ b/src/main/resources/masa_gadget_mod.mixins.json @@ -8,7 +8,6 @@ "minihud.feature.compactBborProtocol.MixinCustomPayloadS2CPacket", "minihud.feature.compactBborProtocol.MixinDataStorage", "minihud.feature.compactBborProtocol.MixinPlayerRespawnS2CPacket", - "tweakeroo.feature.pcaSyncProtocol.MixinMerchantEntity", "tweakeroo.feature.pcaSyncProtocol.MixinRenderHandler", "tweakeroo.feature.pcaSyncProtocol.MixinRenderUtils" ], @@ -21,6 +20,7 @@ "malilib.feature.optimizeConfigWidgetSearch.MixinWidgetListConfigOptions", "malilib.fix.configWidgetWidth.MixinWidgetListConfigOptions", "tweakeroo.feature.inventoryPreviewSupportFreeCamera.MixinRenderUtils", + "tweakeroo.feature.inventoryPreviewSupportPlayer.MixinRenderUtils", "util.MixinMinecraftClient" ] }