Fix several container problem (#115)

This commit is contained in:
IzzelAliz 2021-01-25 00:19:04 +08:00
parent 678c8e886c
commit cfc83f9aea
5 changed files with 17 additions and 11 deletions

View File

@ -705,10 +705,12 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen
ArclightCaptures.resetContainerOwner(); ArclightCaptures.resetContainerOwner();
} }
@Inject(method = "closeScreen", at = @At("HEAD")) @Inject(method = "closeContainer", at = @At("HEAD"))
private void arclight$invClose(CallbackInfo ci) { private void arclight$invClose(CallbackInfo ci) {
if (this.openContainer != this.container) {
CraftEventFactory.handleInventoryCloseEvent((ServerPlayerEntity) (Object) this); CraftEventFactory.handleInventoryCloseEvent((ServerPlayerEntity) (Object) this);
} }
}
@Redirect(method = "addStat", at = @At(value = "INVOKE", target = "Lnet/minecraft/scoreboard/Scoreboard;forAllObjectives(Lnet/minecraft/scoreboard/ScoreCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V")) @Redirect(method = "addStat", at = @At(value = "INVOKE", target = "Lnet/minecraft/scoreboard/Scoreboard;forAllObjectives(Lnet/minecraft/scoreboard/ScoreCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V"))
private void arclight$addStats(Scoreboard scoreboard, ScoreCriteria p_197893_1_, String p_197893_2_, Consumer<Score> p_197893_3_) { private void arclight$addStats(Scoreboard scoreboard, ScoreCriteria p_197893_1_, String p_197893_2_, Consumer<Score> p_197893_3_) {

View File

@ -87,19 +87,21 @@ public abstract class ContainerMixin implements ContainerBridge {
public final ITextComponent getTitle() { public final ITextComponent getTitle() {
if (this.title == null) { if (this.title == null) {
if (this.containerType != null && this.containerType.getRegistryName() != null) {
this.title = new StringTextComponent(this.containerType.getRegistryName().toString());
} else {
this.title = new StringTextComponent(this.toString());
}
ArclightMod.LOGGER.warn("Container {}/{} has no title.", this, this.getClass().getName()); ArclightMod.LOGGER.warn("Container {}/{} has no title.", this, this.getClass().getName());
if (this.containerType != null && this.containerType.getRegistryName() != null) {
return new StringTextComponent(this.containerType.getRegistryName().toString());
} else {
return new StringTextComponent(this.toString());
}
} }
return this.title; return this.title;
} }
public final void setTitle(ITextComponent title) { public final void setTitle(ITextComponent title) {
if (this.title == null) {
this.title = title; this.title = title;
} }
}
@Redirect(method = "onContainerClosed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;dropItem(Lnet/minecraft/item/ItemStack;Z)Lnet/minecraft/entity/item/ItemEntity;")) @Redirect(method = "onContainerClosed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;dropItem(Lnet/minecraft/item/ItemStack;Z)Lnet/minecraft/entity/item/ItemEntity;"))
private ItemEntity arclight$cleanBeforeDrop(PlayerEntity playerEntity, ItemStack itemStackIn, boolean unused) { private ItemEntity arclight$cleanBeforeDrop(PlayerEntity playerEntity, ItemStack itemStackIn, boolean unused) {

View File

@ -1208,9 +1208,8 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB
private void arclight$invClose(CCloseWindowPacket packetIn, CallbackInfo ci) { private void arclight$invClose(CCloseWindowPacket packetIn, CallbackInfo ci) {
if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
ci.cancel(); ci.cancel();
return;
} }
CraftEventFactory.handleInventoryCloseEvent(this.player); // CraftEventFactory.handleInventoryCloseEvent(this.player); handled in ServerPlayerEntity#closeContainer
} }
/** /**

View File

@ -1,6 +1,7 @@
package io.izzel.arclight.common.mixin.forge; package io.izzel.arclight.common.mixin.forge;
import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge; import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
@ -24,7 +25,9 @@ public class NetworkHooksMixin {
private static void arclight$openContainer(ServerPlayerEntity player, INamedContainerProvider containerSupplier, Consumer<PacketBuffer> extraDataWriter, CallbackInfo ci, private static void arclight$openContainer(ServerPlayerEntity player, INamedContainerProvider containerSupplier, Consumer<PacketBuffer> extraDataWriter, CallbackInfo ci,
int currentId, PacketBuffer extraData, PacketBuffer output, Container container) { int currentId, PacketBuffer extraData, PacketBuffer output, Container container) {
((ContainerBridge) container).bridge$setTitle(containerSupplier.getDisplayName()); ((ContainerBridge) container).bridge$setTitle(containerSupplier.getDisplayName());
ArclightCaptures.captureContainerOwner(player);
container = CraftEventFactory.callInventoryOpenEvent(player, container); container = CraftEventFactory.callInventoryOpenEvent(player, container);
ArclightCaptures.resetContainerOwner();
if (container == null) { if (container == null) {
if (containerSupplier instanceof IInventory) { if (containerSupplier instanceof IInventory) {
((IInventory) containerSupplier).closeInventory(player); ((IInventory) containerSupplier).closeInventory(player);

View File

@ -106,7 +106,7 @@ public class ArclightContainer {
if (candidate == null) { if (candidate == null) {
throw new RuntimeException("candidate cannot be null, " + container + "/" + container.getClass()); throw new RuntimeException("candidate cannot be null, " + container + "/" + container.getClass());
} }
if (bottomBegin < bottomEnd) { if (bottomBegin < bottomEnd || bottomBegin == -1) {
bottomBegin = container.inventorySlots.size(); bottomBegin = container.inventorySlots.size();
} }
Inventory viewing = new CraftInventory(new ContainerInvWrapper(container, bottomBegin, candidate)); Inventory viewing = new CraftInventory(new ContainerInvWrapper(container, bottomBegin, candidate));