Skip to content

Commit

Permalink
update to 1.0.5-alpha.3
Browse files Browse the repository at this point in the history
1. 修复陷阱箱的同步问题
2. 灵魂出窍支持容器预览
3. 多人游戏空潜影盒堆叠修复
4. 多人游戏蜜蜂数量预览
  • Loading branch information
plusls committed Oct 17, 2020
1 parent f9a2105 commit 35b0d44
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 40 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ minihud 的查看结构和史莱姆区块渲染需要服务端安装了 carpet

tweakeroo 的容器预览功能在多人游戏中是不可用的,在安装此 mod 后可以让该功能在多人游戏中使用(需要服务端也安装 MasaGadget)

### 灵魂出窍支持容器预览

tweakeroo 的灵魂出窍默认情况下是不支持容器预览的,在安装此 mod 后可以在灵魂出窍的情况下预览容器的内容

### 多人游戏空潜影盒堆叠修复

carpet 的空潜影盒堆叠只能让空潜影盒在地面上堆叠,无法在容器内和背包内操作堆叠,服务端安装 mod 后会修复这个行为

注:由于作者忙于学业,功能全部都没有做开关,即全部默认开启,这意味着服务器中容器内的空潜影盒也是会堆叠的,会影响漏斗投掷器的行为

### 多人游戏蜜蜂数量预览

MiniHUD 支持查看蜂箱内的蜜蜂数量,但是在多人游戏会失效。服务端安装 mod 后需在客户端开启容器预览,按下容器预览的快捷键即可同步蜜蜂数量

有时候数量显示会有 bug,这是 MiniHUD 的问题,按 2 下 H 即可解决

数量显示不是即时同步的,按一下同步一次

## 安装

该 mod 依赖 malilib, minihud, fabric-api
Expand All @@ -33,7 +51,8 @@ tweakeroo 的容器预览功能在多人游戏中是不可用的,在安装此
```
# 1.16.x
malilib_version = 0.10.0-dev.21+arne.1
minihud_version = 0.19.0-dev.20200720.162605
minihud_version = 0.19.0-dev.20200928.220110
tweakeroo_version = 0.10.0-dev.20201001.000406
# 1.15.x
malilib_version = 0.10.0-dev.21+arne.1
Expand Down
15 changes: 7 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.1
yarn_mappings=1.16.1+build.21
loader_version=0.9.0+build.204
minecraft_version=1.16.3
yarn_mappings=1.16.3+build.47
loader_version=0.10.1+build.209

# Mod Properties
mod_version = 1.0.4-alpha.1
mod_version = 1.0.5-alpha.3
maven_group = io.github.plusls
archives_base_name = MasaGadget

# malilib version
malilib_version = 0.10.0-dev.21+arne.1
# minihud version
minihud_version = 0.19.0-dev.20200720.162605
minihud_version = 0.19.0-dev.20200928.220110
# tweakeroo version
tweakeroo_version = 0.10.0-dev.20200720.162627

tweakeroo_version = 0.10.0-dev.20201001.000406

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.16.2+build.385-1.16.1
fabric_version=0.24.0+build.411-1.16
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.plusls.MasaGadget.mixin.client;

import io.github.plusls.MasaGadget.MasaGadgetMod;
import net.minecraft.block.entity.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
Expand Down Expand Up @@ -29,8 +30,10 @@ private void postOnBlockEntityUpdate(BlockEntityUpdateS2CPacket packet, Callback
blockEntity instanceof DispenserBlockEntity || // 包括了投掷器
blockEntity instanceof BarrelBlockEntity ||
blockEntity instanceof BrewingStandBlockEntity ||
blockEntity instanceof ChestBlockEntity // 包括了陷井箱
blockEntity instanceof ChestBlockEntity || // 包括了陷井箱
blockEntity instanceof BeehiveBlockEntity
)) {
MasaGadgetMod.LOGGER.debug("recv BlockEntity at {}", packet.getPos());
blockEntity.fromTag(this.client.world.getBlockState(blockEntity.getPos()), packet.getCompoundTag());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.plusls.MasaGadget.mixin.client;

import net.minecraft.entity.Npc;
import net.minecraft.entity.passive.AbstractTraderEntity;
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.Trader;
import net.minecraft.village.Merchant;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -15,14 +15,14 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(AbstractTraderEntity.class)
public abstract class MixinAbstractTraderEntity extends PassiveEntity implements Npc, Trader {
@Mixin(MerchantEntity.class)
public abstract class MixinMerchantEntity extends PassiveEntity implements Npc, Merchant {
@Final
@Dynamic
@Shadow
private SimpleInventory inventory;

public MixinAbstractTraderEntity(World world) {
public MixinMerchantEntity(World world) {
super(null, null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.github.plusls.MasaGadget.mixin.client.tweakeroo;

import fi.dy.masa.malilib.util.InventoryUtils;
import fi.dy.masa.tweakeroo.config.FeatureToggle;
import fi.dy.masa.tweakeroo.renderer.RenderUtils;
import io.github.plusls.MasaGadget.network.DataAccessor;
import net.minecraft.block.entity.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.util.math.BlockPos;
Expand All @@ -13,6 +16,8 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.UUID;

@Mixin(value = RenderUtils.class, remap = false)
public abstract class MixinRenderUtils {
@Redirect(method = "renderInventoryOverlay",
Expand All @@ -27,7 +32,8 @@ private static Inventory redirectGetBlockInventory(World world, BlockPos pos) {
blockEntity instanceof ShulkerBoxBlockEntity ||
blockEntity instanceof BarrelBlockEntity ||
blockEntity instanceof BrewingStandBlockEntity ||
blockEntity instanceof ChestBlockEntity
blockEntity instanceof ChestBlockEntity ||
blockEntity instanceof BeehiveBlockEntity
) {
DataAccessor.requestBlockEntity(pos);
}
Expand All @@ -42,4 +48,17 @@ private static SimpleInventory redirectGetVillagerInventory(VillagerEntity entit
DataAccessor.requestEntity(entity.getEntityId());
return entity.getInventory();
}

@Redirect(method = "renderInventoryOverlay",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/World;getPlayerByUuid(Ljava/util/UUID;)Lnet/minecraft/entity/player/PlayerEntity;",
ordinal = 0, remap = true))
private static PlayerEntity redirectGetPlayerByUuid(World world, UUID uuid) {
// support free camera
if (FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue()) {
return (PlayerEntity) MinecraftClient.getInstance().getCameraEntity();
} else {
return world.getPlayerByUuid(uuid);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.plusls.MasaGadget.mixin.server.block;

import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.util.Tickable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(BeehiveBlockEntity.class)
public abstract class MixinBeehiveBlockEntity extends BlockEntity implements Tickable {

@Shadow
public abstract CompoundTag toTag(CompoundTag tag);

public MixinBeehiveBlockEntity() {
super(null);
}

@Override
public BlockEntityUpdateS2CPacket toUpdatePacket() {
return new BlockEntityUpdateS2CPacket(this.pos, 0, this.toTag(new CompoundTag()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.github.plusls.MasaGadget.MasaGadgetMod;
import io.github.plusls.MasaGadget.network.ServerNetworkHandler;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.LootableContainerBlockEntity;
Expand Down Expand Up @@ -38,8 +37,9 @@ public void markDirty() {
if (ServerNetworkHandler.lastBlockPosMap.containsValue(this.pos)) {
((ServerWorld) this.world).getChunkManager().markForUpdate(this.getPos());
MasaGadgetMod.LOGGER.debug("update ChestBlockEntity: {}", this.pos);
} else if (blockState.isOf(Blocks.CHEST) && blockState.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE) {
} else if (blockState.getBlock() instanceof ChestBlock && blockState.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE) {
// 如果是一个大箱子需要特殊处理
// 上面不用 isOf 是为了考虑到陷阱箱的情况,陷阱箱继承自箱子
BlockPos posAdj = pos.offset(ChestBlock.getFacing(blockState));
if (ServerNetworkHandler.lastBlockPosMap.containsValue(posAdj)) {
((ServerWorld) this.world).getChunkManager().markForUpdate(this.getPos());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.Npc;
import net.minecraft.entity.passive.AbstractTraderEntity;
import net.minecraft.entity.passive.MerchantEntity;
import net.minecraft.entity.passive.PassiveEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
Expand All @@ -16,8 +16,9 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.village.Trader;
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;
Expand All @@ -28,18 +29,19 @@
import java.util.Map;
import java.util.UUID;

@Mixin(AbstractTraderEntity.class)
public abstract class MixinAbstractTraderEntity extends PassiveEntity implements Npc, Trader, InventoryChangedListener {
@Mixin(MerchantEntity.class)
public abstract class MixinMerchantEntity extends PassiveEntity implements Npc, Merchant, InventoryChangedListener {
@Final
@Dynamic
@Shadow
private SimpleInventory inventory;

public MixinAbstractTraderEntity(World world) {
public MixinMerchantEntity(World world) {
super(null, null);
}

@Inject(method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At(value = "RETURN"))
private void postInit(EntityType<? extends AbstractTraderEntity> entityType, World world, CallbackInfo info) {
private void postInit(EntityType<? extends MerchantEntity> entityType, World world, CallbackInfo info) {
if (this.world.isClient()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.github.plusls.MasaGadget.mixin.server.item;

import io.github.plusls.MasaGadget.MasaGadgetMod;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
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.CallbackInfoReturnable;

@Mixin(ItemStack.class)
public abstract class MixinItemStack {
@Shadow
public abstract Item getItem();

@Inject(method = "getMaxCount", at = @At("HEAD"), cancellable = true)
public void getMaxStackSizeStackSensitive(CallbackInfoReturnable<Integer> ci) {
// support shulkerbox stack
Item item = this.getItem();
// MasaGadgetMod.LOGGER.info("ItemStack: {}", this);
if (this.getItem() instanceof BlockItem &&
((BlockItem) item).getBlock() instanceof ShulkerBoxBlock &&
!shulkerBoxHasItems((ItemStack) (Object) this)) {
//MasaGadgetMod.LOGGER.info("Modify ret!");
ci.setReturnValue(64);
ci.cancel();
}
}

private static boolean shulkerBoxHasItems(ItemStack stackShulkerBox) {
// MasaGadgetMod.LOGGER.info("Try to calc shulkerBoxHasItems: {}", stackShulkerBox);
CompoundTag nbt = stackShulkerBox.getTag();
if (nbt != null && nbt.contains("BlockEntityTag", 10)) {
CompoundTag tag = nbt.getCompound("BlockEntityTag");
if (tag.contains("Items", 9)) {
ListTag tagList = tag.getList("Items", 10);
return tagList.size() > 0;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.fabricmc.fabric.api.network.PacketContext;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.enums.ChestType;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -46,7 +45,7 @@ private static void requestBlockEntityHandler(PacketContext packetContext, Packe
// 大不了 op 直接拉黑
world.getChunkManager().markForUpdate(pos);
// 不是单个箱子则需要更新隔壁箱子
if (blockState.isOf(Blocks.CHEST) && blockState.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE) {
if (blockState.getBlock() instanceof ChestBlock && blockState.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE) {
BlockPos posAdj = pos.offset(ChestBlock.getFacing(blockState));
world.getChunkManager().markForUpdate(posAdj);
}
Expand Down
30 changes: 16 additions & 14 deletions src/main/resources/masa_gadget_mod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@
"minVersion": "0.8",
"package": "io.github.plusls.MasaGadget.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"server": [
"server.MixinPlayerManager",
"server.MixinServerPlayNetworkHandler",
"server.entity.MixinAbstractTraderEntity",
"server.block.MixinShulkerBoxBlockEntity",
"server.block.MixinHopperBlockEntity",
"server.block.MixinAbstractFurnaceBlockEntity",
"server.block.MixinDispenserBlockEntity",
"server.block.MixinChestBlockEntity",
"server.block.MixinBarrelBlockEntity",
"server.block.MixinBrewingStandBlockEntity"
"server.block.MixinBrewingStandBlockEntity",
"server.block.MixinChestBlockEntity",
"server.block.MixinDispenserBlockEntity",
"server.block.MixinHopperBlockEntity",
"server.block.MixinShulkerBoxBlockEntity",
"server.entity.MixinMerchantEntity",
"server.item.MixinItemStack",
"server.block.MixinBeehiveBlockEntity"
],
"client": [
"client.malilib.MixinWidgetListConfigOptions",
"client.malilib.MixinDataStorage",
"client.tweakeroo.MixinRenderHandler",
"client.tweakeroo.MixinRenderUtils",
"client.IMixinClientPlayNetworkHandler",
"client.MixinClientPlayNetworkHandler",
"client.MixinCustomPayloadS2CPacket",
"client.MixinPlayerRespawnS2CPacket",
"client.MixinMerchantEntity",
"client.MixinMinecraftClient",
"client.MixinClientPlayNetworkHandler",
"client.MixinAbstractTraderEntity"
"client.MixinPlayerRespawnS2CPacket",
"client.malilib.MixinDataStorage",
"client.malilib.MixinWidgetListConfigOptions",
"client.tweakeroo.MixinRenderHandler",
"client.tweakeroo.MixinRenderUtils"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 35b0d44

Please sign in to comment.