Skip to content

Commit

Permalink
🐛 临时修复 #111
Browse files Browse the repository at this point in the history
  • Loading branch information
1024-byteeeee committed Jul 13, 2024
1 parent 355a99f commit 13fea0f
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
package club.mcams.carpet.mixin.rule.largeShulkerBox;

import club.mcams.carpet.AmsServerSettings;
import club.mcams.carpet.screen.LargeShulkerBoxScreenHandler;

import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.block.entity.ShulkerBoxBlockEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.SidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand Down Expand Up @@ -92,4 +95,12 @@ private void getAvailableSlots(Direction side, CallbackInfoReturnable<int[]> cir
cir.cancel();
}
}

@Inject(method = "createScreenHandler", at = @At("HEAD"), cancellable = true)
private void createLargeShulkerBoxScreen(int syncId, PlayerInventory playerInventory, CallbackInfoReturnable<ScreenHandler> cir) {
if (AmsServerSettings.largeShulkerBox) {
cir.setReturnValue(new LargeShulkerBoxScreenHandler(syncId, playerInventory, this));
cir.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,41 @@ public abstract class ShulkerBoxScreenHandlerMixin extends ScreenHandler {
protected ShulkerBoxScreenHandlerMixin(@Nullable ScreenHandlerType<?> type, int syncId) {
super(type, syncId);
}
//
// @ModifyArg(
// method = "<init>(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/Inventory;)V",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/screen/ScreenHandler;<init>(Lnet/minecraft/screen/ScreenHandlerType;I)V"
// ),
// index = 0
// )
// private static ScreenHandlerType<?> getScreenHandlerType(ScreenHandlerType<?> type) {
// if (!AmsServerSettings.largeShulkerBox) {
// return type;
// }
// return ScreenHandlerType.GENERIC_9X6;
// }

@ModifyArg(
method = "<init>(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/Inventory;)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/screen/ScreenHandler;<init>(Lnet/minecraft/screen/ScreenHandlerType;I)V"
),
index = 0
)
private static ScreenHandlerType<?> getScreenHandlerType(ScreenHandlerType<?> type) {
if (!AmsServerSettings.largeShulkerBox) {
return type;
}
return ScreenHandlerType.GENERIC_9X6;
}

@Inject(
method = "<init>(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/Inventory;)V",
at = @At(
value = "JUMP",
opcode = Opcodes.GOTO,
ordinal = 1,
shift = At.Shift.BY,
by = 2
)
)
private void init(int syncId, PlayerInventory playerInventory, Inventory inventory, CallbackInfo ci) {
if (!AmsServerSettings.largeShulkerBox || this.slots.size() != 9 * 3) {
return;
}
checkSize(inventory, 9 * 6);
for (int row = 3; row < 6; ++row) {
for (int column = 0; column < 9; ++column) {
this.addSlot(new ShulkerBoxSlot(inventory, column + row * 9, 8 + column * 18, 18 + row * 18));
}
}
}
// @Inject(
// method = "<init>(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/Inventory;)V",
// at = @At(
// value = "JUMP",
// opcode = Opcodes.GOTO,
// ordinal = 1,
// shift = At.Shift.BY,
// by = 2
// )
// )
// private void init(int syncId, PlayerInventory playerInventory, Inventory inventory, CallbackInfo ci) {
// if (!AmsServerSettings.largeShulkerBox || this.slots.size() != 9 * 3) {
// return;
// }
// checkSize(inventory, 9 * 6);
// for (int row = 3; row < 6; ++row) {
// for (int column = 0; column < 9; ++column) {
// this.addSlot(new ShulkerBoxSlot(inventory, column + row * 9, 8 + column * 18, 18 + row * 18));
// }
// }
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package club.mcams.carpet.screen;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.ShulkerBoxSlot;
import net.minecraft.screen.slot.Slot;

public class LargeShulkerBoxScreenHandler extends ScreenHandler {
private final Inventory inventory;
public LargeShulkerBoxScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory) {
super(ScreenHandlerType.GENERIC_9X6, syncId);
checkSize(inventory, 9 * 6);
this.inventory = inventory;
inventory.onOpen(playerInventory.player);

int i;
int j;

for (i = 0; i < 6; ++i) {
for (j = 0; j < 9; ++j) {
this.addSlot(new ShulkerBoxSlot(inventory, j + i * 9, 8 + j * 18, 18 + i * 18));
}
}

for (i = 0; i < 3; ++i) {
for (j = 0; j < 9; ++j) {
this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 140 + i * 18));
}
}

for (i = 0; i < 9; ++i) {
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 198));
}
}

public boolean canUse(PlayerEntity player) {
return this.inventory.canPlayerUse(player);
}

public ItemStack transferSlot(PlayerEntity player, int index) {
ItemStack itemStack = ItemStack.EMPTY;
Slot slot = this.slots.get(index);
if (slot.hasStack()) {
ItemStack itemStack2 = slot.getStack();
itemStack = itemStack2.copy();
if (index < this.inventory.size()) {
if (!this.insertItem(itemStack2, this.inventory.size(), this.slots.size(), true)) {
return ItemStack.EMPTY;
}
} else if (!this.insertItem(itemStack2, 0, this.inventory.size(), false)) {
return ItemStack.EMPTY;
}
if (itemStack2.isEmpty()) {
slot.setStack(ItemStack.EMPTY);
} else {
slot.markDirty();
}
}
return itemStack;
}

public void close(PlayerEntity player) {
super.close(player);
this.inventory.onClose(player);
}
}

0 comments on commit 13fea0f

Please sign in to comment.