mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fix quick moving items in the spellbook. Fixes #348
This commit is contained in:
parent
f0b57a2bbf
commit
09cecef68e
8 changed files with 74 additions and 59 deletions
|
@ -18,6 +18,8 @@ import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.item.TooltipContext;
|
import net.minecraft.client.item.TooltipContext;
|
||||||
import net.minecraft.client.render.*;
|
import net.minecraft.client.render.*;
|
||||||
import com.minelittlepony.unicopia.client.render.RenderLayers;
|
import com.minelittlepony.unicopia.client.render.RenderLayers;
|
||||||
|
import com.minelittlepony.unicopia.container.SpellbookState;
|
||||||
|
|
||||||
import net.minecraft.client.render.item.ItemRenderer;
|
import net.minecraft.client.render.item.ItemRenderer;
|
||||||
import net.minecraft.client.render.model.json.ModelTransformationMode;
|
import net.minecraft.client.render.model.json.ModelTransformationMode;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
@ -324,7 +326,7 @@ public class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
if (MinecraftClient.getInstance().currentScreen instanceof SpellbookScreen spellbook) {
|
if (MinecraftClient.getInstance().currentScreen instanceof SpellbookScreen spellbook) {
|
||||||
spellbook.getState().setCurrentPageId(SpellbookChapterList.TRAIT_DEX_ID);
|
spellbook.getState().setCurrentPageId(SpellbookState.TRAIT_DEX_ID);
|
||||||
spellbook.getTraitDex().pageTo(spellbook, trait);
|
spellbook.getTraitDex().pageTo(spellbook, trait);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,10 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.minelittlepony.common.client.gui.IViewRoot;
|
import com.minelittlepony.common.client.gui.IViewRoot;
|
||||||
import com.minelittlepony.unicopia.Debug;
|
import com.minelittlepony.unicopia.Debug;
|
||||||
import com.minelittlepony.unicopia.Unicopia;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class SpellbookChapterList {
|
public class SpellbookChapterList {
|
||||||
public static final Identifier CRAFTING_ID = Unicopia.id("crafting");
|
|
||||||
public static final Identifier PROFILE_ID = Unicopia.id("profile");
|
|
||||||
public static final Identifier TRAIT_DEX_ID = Unicopia.id("traits");
|
|
||||||
|
|
||||||
private final SpellbookScreen screen;
|
private final SpellbookScreen screen;
|
||||||
|
|
||||||
private final Chapter craftingChapter;
|
private final Chapter craftingChapter;
|
||||||
|
@ -73,10 +67,6 @@ public class SpellbookChapterList {
|
||||||
|
|
||||||
default void copyStateFrom(Content old) {}
|
default void copyStateFrom(Content old) {}
|
||||||
|
|
||||||
default boolean showInventory() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
default Identifier getIcon(Chapter chapter, Identifier icon) {
|
default Identifier getIcon(Chapter chapter, Identifier icon) {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,11 +58,6 @@ public class SpellbookCraftingPageContent extends ScrollContainer implements Spe
|
||||||
init(this::initPageContent);
|
init(this::initPageContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean showInventory() {
|
|
||||||
return state.getOffset() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initPageContent() {
|
private void initPageContent() {
|
||||||
getContentPadding().setVertical(10);
|
getContentPadding().setVertical(10);
|
||||||
getContentPadding().bottom = 30;
|
getContentPadding().bottom = 30;
|
||||||
|
|
|
@ -58,11 +58,6 @@ public class SpellbookProfilePageContent implements SpellbookChapterList.Content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean showInventory() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(DrawContext context, int mouseX, int mouseY, IViewRoot container) {
|
public void draw(DrawContext context, int mouseX, int mouseY, IViewRoot container) {
|
||||||
|
|
||||||
|
|
|
@ -52,12 +52,11 @@ public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> imple
|
||||||
|
|
||||||
private final RecipeBookWidget recipeBook = new RecipeBookWidget();
|
private final RecipeBookWidget recipeBook = new RecipeBookWidget();
|
||||||
|
|
||||||
private final Chapter craftingChapter;
|
|
||||||
private final SpellbookTraitDexPageContent traitDex = new SpellbookTraitDexPageContent(this);
|
private final SpellbookTraitDexPageContent traitDex = new SpellbookTraitDexPageContent(this);
|
||||||
private final SpellbookChapterList chapters = new SpellbookChapterList(this,
|
private final SpellbookChapterList chapters = new SpellbookChapterList(this,
|
||||||
craftingChapter = new Chapter(SpellbookChapterList.CRAFTING_ID, TabSide.LEFT, 0, 0, Optional.of(new SpellbookCraftingPageContent(this))),
|
new Chapter(SpellbookState.CRAFTING_ID, TabSide.LEFT, 0, 0, Optional.of(new SpellbookCraftingPageContent(this))),
|
||||||
new Chapter(SpellbookChapterList.PROFILE_ID, TabSide.LEFT, 1, 0, Optional.of(new SpellbookProfilePageContent(this))),
|
new Chapter(SpellbookState.PROFILE_ID, TabSide.LEFT, 1, 0, Optional.of(new SpellbookProfilePageContent(this))),
|
||||||
new Chapter(SpellbookChapterList.TRAIT_DEX_ID, TabSide.LEFT, 3, 0, Optional.of(traitDex))
|
new Chapter(SpellbookState.TRAIT_DEX_ID, TabSide.LEFT, 3, 0, Optional.of(traitDex))
|
||||||
);
|
);
|
||||||
private final SpellbookTabBar tabs = new SpellbookTabBar(this, chapters);
|
private final SpellbookTabBar tabs = new SpellbookTabBar(this, chapters);
|
||||||
|
|
||||||
|
@ -68,13 +67,6 @@ public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> imple
|
||||||
backgroundWidth = 405;
|
backgroundWidth = 405;
|
||||||
backgroundHeight = 219;
|
backgroundHeight = 219;
|
||||||
contentBounds = new Bounds(CONTENT_PADDING, CONTENT_PADDING, backgroundWidth - CONTENT_PADDING * 2, backgroundHeight - CONTENT_PADDING * 3 - 2);
|
contentBounds = new Bounds(CONTENT_PADDING, CONTENT_PADDING, backgroundWidth - CONTENT_PADDING * 2, backgroundHeight - CONTENT_PADDING * 3 - 2);
|
||||||
|
|
||||||
handler.addSlotShowingCondition(slotType -> {
|
|
||||||
if (slotType == SlotType.INVENTORY) {
|
|
||||||
return chapters.getCurrentChapter().content().filter(Content::showInventory).isPresent();
|
|
||||||
}
|
|
||||||
return chapters.getCurrentChapter() == craftingChapter;
|
|
||||||
});
|
|
||||||
handler.getSpellbookState().setSynchronizer(state -> {
|
handler.getSpellbookState().setSynchronizer(state -> {
|
||||||
Channel.CLIENT_SPELLBOOK_UPDATE.sendToServer(MsgSpellbookStateChanged.create(handler, state));
|
Channel.CLIENT_SPELLBOOK_UPDATE.sendToServer(MsgSpellbookStateChanged.create(handler, state));
|
||||||
});
|
});
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class SpellbookTraitDexPageContent implements SpellbookChapterList.Conten
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
page /= 2;
|
page /= 2;
|
||||||
state = screen.getState().getState(SpellbookChapterList.TRAIT_DEX_ID);
|
state = screen.getState().getState(SpellbookState.TRAIT_DEX_ID);
|
||||||
state.setOffset(page);
|
state.setOffset(page);
|
||||||
leftPage.verticalScrollbar.scrollBy(leftPage.verticalScrollbar.getScrubber().getPosition());
|
leftPage.verticalScrollbar.scrollBy(leftPage.verticalScrollbar.getScrubber().getPosition());
|
||||||
rightPage.verticalScrollbar.scrollBy(rightPage.verticalScrollbar.getScrubber().getPosition());
|
rightPage.verticalScrollbar.scrollBy(rightPage.verticalScrollbar.getScrubber().getPosition());
|
||||||
|
@ -84,7 +84,7 @@ public class SpellbookTraitDexPageContent implements SpellbookChapterList.Conten
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRecipesChanged() {
|
public void onRecipesChanged() {
|
||||||
init(screen, SpellbookChapterList.TRAIT_DEX_ID);
|
init(screen, SpellbookState.TRAIT_DEX_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class DexPage extends ScrollContainer {
|
private final class DexPage extends ScrollContainer {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package com.minelittlepony.unicopia.container;
|
package com.minelittlepony.unicopia.container;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellbookRecipe;
|
import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellbookRecipe;
|
||||||
|
@ -55,8 +53,6 @@ public class SpellbookScreenHandler extends ScreenHandler {
|
||||||
|
|
||||||
private final ScreenHandlerContext context;
|
private final ScreenHandlerContext context;
|
||||||
|
|
||||||
private Predicate<SlotType> canShowSlots;
|
|
||||||
|
|
||||||
private final SpellbookState state;
|
private final SpellbookState state;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -166,12 +162,13 @@ public class SpellbookScreenHandler extends ScreenHandler {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSlotShowingCondition(Predicate<SlotType> canShowSlots) {
|
|
||||||
this.canShowSlots = canShowSlots;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canShowSlots(SlotType type) {
|
public boolean canShowSlots(SlotType type) {
|
||||||
return canShowSlots == null || canShowSlots.test(type);
|
Identifier pageId = state.getCurrentPageId().orElse(null);
|
||||||
|
boolean isCraftingPage = SpellbookState.CRAFTING_ID.equals(pageId);
|
||||||
|
return switch (type) {
|
||||||
|
case INVENTORY -> isCraftingPage ? state.getState(pageId).getOffset() == 0 : SpellbookState.PROFILE_ID.equals(pageId);
|
||||||
|
case CRAFTING -> isCraftingPage;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOutputSlotId() {
|
public int getOutputSlotId() {
|
||||||
|
@ -212,11 +209,16 @@ public class SpellbookScreenHandler extends ScreenHandler {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInsertIntoSlot(ItemStack stack, Slot slot) {
|
||||||
|
return slot != null && slot.canInsert(stack) && slot.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack quickMove(PlayerEntity player, int index) {
|
public ItemStack quickMove(PlayerEntity player, int index) {
|
||||||
Slot sourceSlot = slots.get(index);
|
Slot sourceSlot = slots.get(index);
|
||||||
|
|
||||||
if (sourceSlot == null || !sourceSlot.hasStack()) {
|
if (sourceSlot == null || !sourceSlot.hasStack() || (sourceSlot instanceof SpellSlot)) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,6 +230,8 @@ public class SpellbookScreenHandler extends ScreenHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index >= HOTBAR_START && !(sourceSlot instanceof OutputSlot || sourceSlot instanceof InputSlot)) {
|
if (index >= HOTBAR_START && !(sourceSlot instanceof OutputSlot || sourceSlot instanceof InputSlot)) {
|
||||||
|
// hotbar or inventory -> crafting grid
|
||||||
|
if (canShowSlots(SlotType.CRAFTING)) {
|
||||||
if (!gemSlot.hasStack() && gemSlot.canInsert(stack)) {
|
if (!gemSlot.hasStack() && gemSlot.canInsert(stack)) {
|
||||||
if (insertItem(transferredStack, GEM_SLOT_INDEX, GEM_SLOT_INDEX + 1, false)) {
|
if (insertItem(transferredStack, GEM_SLOT_INDEX, GEM_SLOT_INDEX + 1, false)) {
|
||||||
onContentChanged(input);
|
onContentChanged(input);
|
||||||
|
@ -240,25 +244,57 @@ public class SpellbookScreenHandler extends ScreenHandler {
|
||||||
onContentChanged(input);
|
onContentChanged(input);
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (insertItem(transferredStack, HOTBAR_START, HOTBAR_END, true)) {
|
|
||||||
sourceSlot.onQuickTransfer(transferredStack, stack);
|
|
||||||
onContentChanged(input);
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index < HOTBAR_END) {
|
||||||
|
if (canShowSlots(SlotType.INVENTORY)) {
|
||||||
|
// hotbar -> inventory
|
||||||
|
// insert into inventory - armor
|
||||||
if (insertItem(transferredStack, HOTBAR_END + 27, HOTBAR_END + 27 + 4, false)) {
|
if (insertItem(transferredStack, HOTBAR_END + 27, HOTBAR_END + 27 + 4, false)) {
|
||||||
sourceSlot.onQuickTransfer(transferredStack, stack);
|
sourceSlot.onQuickTransfer(transferredStack, stack);
|
||||||
onContentChanged(input);
|
onContentChanged(input);
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// insert into inventory - inventory
|
||||||
if (insertItem(transferredStack, HOTBAR_END, HOTBAR_END + 27, false)) {
|
if (insertItem(transferredStack, HOTBAR_END, HOTBAR_END + 27, false)) {
|
||||||
sourceSlot.onQuickTransfer(transferredStack, stack);
|
sourceSlot.onQuickTransfer(transferredStack, stack);
|
||||||
onContentChanged(input);
|
onContentChanged(input);
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// inventory -> hotbar
|
||||||
|
if (insertItem(transferredStack, HOTBAR_START, HOTBAR_END, true)) {
|
||||||
|
sourceSlot.onQuickTransfer(transferredStack, stack);
|
||||||
|
onContentChanged(input);
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// crafting grid -> hotbar
|
||||||
|
if (insertItem(transferredStack, HOTBAR_START, HOTBAR_END, true)) {
|
||||||
|
sourceSlot.onQuickTransfer(transferredStack, stack);
|
||||||
|
onContentChanged(input);
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canShowSlots(SlotType.INVENTORY)) {
|
||||||
|
// crafting grid -> armor
|
||||||
|
if (insertItem(transferredStack, HOTBAR_END + 27, HOTBAR_END + 27 + 4, false)) {
|
||||||
|
sourceSlot.onQuickTransfer(transferredStack, stack);
|
||||||
|
onContentChanged(input);
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// crafting grid -> inventory
|
||||||
|
if (insertItem(transferredStack, HOTBAR_END, HOTBAR_END + 27, false)) {
|
||||||
|
sourceSlot.onQuickTransfer(transferredStack, stack);
|
||||||
|
onContentChanged(input);
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (transferredStack.getCount() == stack.getCount()) {
|
if (transferredStack.getCount() == stack.getCount()) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.container;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
import com.minelittlepony.unicopia.network.datasync.Synchronizable;
|
import com.minelittlepony.unicopia.network.datasync.Synchronizable;
|
||||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||||
|
|
||||||
|
@ -13,6 +14,10 @@ import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
public class SpellbookState extends Synchronizable<SpellbookState> implements NbtSerialisable {
|
public class SpellbookState extends Synchronizable<SpellbookState> implements NbtSerialisable {
|
||||||
|
public static final Identifier CRAFTING_ID = Unicopia.id("crafting");
|
||||||
|
public static final Identifier PROFILE_ID = Unicopia.id("profile");
|
||||||
|
public static final Identifier TRAIT_DEX_ID = Unicopia.id("traits");
|
||||||
|
|
||||||
private Optional<Identifier> currentPageId = Optional.empty();
|
private Optional<Identifier> currentPageId = Optional.empty();
|
||||||
|
|
||||||
private boolean dirty;
|
private boolean dirty;
|
||||||
|
|
Loading…
Reference in a new issue