Skip to content

Commit

Permalink
update to 1.1.3-alpha.1
Browse files Browse the repository at this point in the history
新增:

+ 增加了使用容器预览查看玩家背包和末影箱的功能(如果在服务器取决于服务器的实现,PCA 默认只有 op 才能查看其它玩家,或者可以查看 bot)

改变:

+ 优化了存储矿车同步的逻辑,矿车不再鬼畜
  • Loading branch information
plusls committed Jan 13, 2021
1 parent b5e59bf commit 304cc13
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 72 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
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;
import net.minecraft.client.MinecraftClient;
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 {
Expand Down Expand Up @@ -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));
}
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},

"license": "CC0-1.0",
"environment": "*",
"environment": "client",
"entrypoints": {
"client": [
"com.plusls.MasaGadget.MasaGadgetMod"
Expand All @@ -23,13 +23,16 @@
"mixins": [
"masa_gadget_mod.mixins.json"
],

"accessWidener": "masa_gadget_mod.accesswidener",
"depends": {
"fabricloader": ">=0.7.4",
"fabric": ">=0.28.0",
"minecraft": "1.16.x"
},
"suggests": {
"flamingo": "*"
},
"custom": {
"modmenu:clientsideOnly": true
}
}
2 changes: 2 additions & 0 deletions src/main/resources/masa_gadget_mod.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
accessWidener v1 named
accessible field net/minecraft/entity/vehicle/StorageMinecartEntity inventory Lnet/minecraft/util/collection/DefaultedList;
2 changes: 1 addition & 1 deletion src/main/resources/masa_gadget_mod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand All @@ -21,6 +20,7 @@
"malilib.feature.optimizeConfigWidgetSearch.MixinWidgetListConfigOptions",
"malilib.fix.configWidgetWidth.MixinWidgetListConfigOptions",
"tweakeroo.feature.inventoryPreviewSupportFreeCamera.MixinRenderUtils",
"tweakeroo.feature.inventoryPreviewSupportPlayer.MixinRenderUtils",
"util.MixinMinecraftClient"
]
}

0 comments on commit 304cc13

Please sign in to comment.