Skip to content

Commit

Permalink
update to 1.0.0-alpha.4
Browse files Browse the repository at this point in the history
  • Loading branch information
plusls committed Nov 6, 2020
1 parent 35b0d44 commit 973d45a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ tweakeroo 的灵魂出窍默认情况下是不支持容器预览的,在安装

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

注:由于作者忙于学业,功能全部都没有做开关,即全部默认开启,这意味着服务器中容器内的空潜影盒也是会堆叠的,会影响漏斗投掷器的行为
只有玩家操作才能让潜影盒堆叠,例如手动堆叠,shift + 左键到容器,从地上拾起均会自动堆叠

但是不会影响投掷器和漏斗的行为,也不会影响比较器的输出

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

Expand Down
2 changes: 1 addition & 1 deletion 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.1+build.209

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.github.plusls.MasaGadget.mixin.server.item;

import io.github.plusls.MasaGadget.MasaGadgetMod;
import net.minecraft.advancement.criterion.InventoryChangedCriterion;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.entity.player.PlayerInventory;
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 net.minecraft.screen.ScreenHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -18,22 +20,44 @@ public abstract class MixinItemStack {
@Shadow
public abstract Item getItem();

private static final int SHULKERBOX_MAX_STACK_AMOUNT = 64;

@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();
// new Exception().printStackTrace(System.out);
// 效率很低 但是 it works
// 通过栈帧判断调用者来过滤返回值
StackTraceElement[] steArray = Thread.currentThread().getStackTrace();
if (checkStackTrace(steArray, InventoryChangedCriterion.class.getName(), "method_8950", new int[]{3}) || // method_8950 -> InventoryChangedCriterion.trigger
checkStackTrace(steArray, PlayerInventory.class.getName(), "method_7393", new int[]{3, 4}) || // method_7393-> PlayerInventory.canStackAddMore
checkStackTrace(steArray, PlayerInventory.class.getName(), "method_7385", new int[]{3, 4}) || // method_7385 -> PlayerInventory.addStack
checkStackTrace(steArray, ScreenHandler.class.getName(), "method_7616", new int[]{3, 4}) || // method_7616 -> ScreenHandler.insertItem
checkStackTrace(steArray, ScreenHandler.class.getName(), "method_30010", new int[]{3}) // method_30010 -> ScreenHandler.method_30010
) {
ci.setReturnValue(SHULKERBOX_MAX_STACK_AMOUNT);
return;
}
}
}

private static boolean checkStackTrace(StackTraceElement[] steArray, String className, String methodName, int[] indexArray) {
for (int i : indexArray) {
if (steArray.length < i + 1) {
return false;
}
if (steArray[i].getClassName().equals(className) && steArray[i].getMethodName().equals(methodName)) {
return true;
}
}
return false;
}

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");
Expand Down

0 comments on commit 973d45a

Please sign in to comment.