mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fix crash when loading without trinkets. Fixes #60
This commit is contained in:
parent
69772d084d
commit
534a9d000a
3 changed files with 17 additions and 9 deletions
|
@ -5,7 +5,8 @@ import org.spongepowered.asm.mixin.*;
|
|||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import dev.emi.trinkets.TrinketSlot;
|
||||
import com.minelittlepony.unicopia.trinkets.TrinketsDelegate;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
|
@ -37,7 +38,7 @@ abstract class MixinScreenHandler {
|
|||
)
|
||||
// redirect slot.getMaxItemCount() to stack aware version
|
||||
protected int onGetMaxItemCount(Slot sender, ItemStack stack) {
|
||||
return canApply(sender) ? sender.getMaxItemCount(stack) : sender.getMaxItemCount();
|
||||
return TrinketsDelegate.getInstance().isTrinketSlot(sender) ? sender.getMaxItemCount(stack) : sender.getMaxItemCount();
|
||||
}
|
||||
|
||||
@Redirect(method = "insertItem",
|
||||
|
@ -49,7 +50,7 @@ abstract class MixinScreenHandler {
|
|||
)
|
||||
// redirect "if (!itemStack.isEmpty() && ItemStack.canCombine(stack, itemStack))" -> "if (!canNotInsert(itemStack, slot) && ItemStack.canCombine(stack, itemStack))"
|
||||
protected boolean canNotInsert(ItemStack sender) {
|
||||
return sender.isEmpty() || (canApply(currentSlot) && (currentSlot.getStack().getCount() + sender.getCount()) <= currentSlot.getMaxItemCount(sender));
|
||||
return sender.isEmpty() || (TrinketsDelegate.getInstance().isTrinketSlot(currentSlot) && (currentSlot.getStack().getCount() + sender.getCount()) <= currentSlot.getMaxItemCount(sender));
|
||||
}
|
||||
|
||||
@Redirect(method = "canInsertItemIntoSlot",
|
||||
|
@ -58,11 +59,7 @@ abstract class MixinScreenHandler {
|
|||
target = "Lnet/minecraft/item/ItemStack;getMaxCount()I"
|
||||
)
|
||||
)
|
||||
private static int onCanInsertItemIntoSlot(ItemStack sender, @Nullable Slot slot) {
|
||||
return canApply(slot) ? slot.getMaxItemCount(sender) : sender.getMaxCount();
|
||||
}
|
||||
|
||||
private static boolean canApply(Slot slot) {
|
||||
return slot instanceof TrinketSlot;
|
||||
private static int onGetMaxCount(ItemStack sender, @Nullable Slot slot) {
|
||||
return TrinketsDelegate.getInstance().isTrinketSlot(slot) ? slot.getMaxItemCount(sender) : sender.getMaxCount();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public interface TrinketsDelegate {
|
||||
|
@ -69,4 +70,8 @@ public interface TrinketsDelegate {
|
|||
default void registerTrinket(Item item) {
|
||||
|
||||
}
|
||||
|
||||
default boolean isTrinketSlot(Slot slot) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.event.GameEvent;
|
||||
|
@ -80,6 +81,11 @@ public class TrinketsDelegateImpl implements TrinketsDelegate {
|
|||
.flatMap(group -> group.values().stream());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrinketSlot(Slot slot) {
|
||||
return slot instanceof TrinketSlot;
|
||||
}
|
||||
|
||||
private static Identifier getSlotId(SlotType slotType) {
|
||||
return new Identifier(slotType.getGroup(), slotType.getName());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue