Implement various parts of the spellbook screen

This commit is contained in:
Sollace 2021-11-17 21:00:59 +02:00
parent 60d5d56864
commit 68bcd5a467
12 changed files with 416 additions and 35 deletions

View file

@ -17,4 +17,4 @@ org.gradle.daemon=false
# Dependencies # Dependencies
modmenu_version=2.0.0-beta.7 modmenu_version=2.0.0-beta.7
minelp_version=4.3.6 minelp_version=4.3.6
kirin_version=1.9.1 kirin_version=1.9.2-beta.1

View file

@ -29,6 +29,7 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtElement;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
@ -105,7 +106,7 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
public NbtCompound toNbt() { public NbtCompound toNbt() {
NbtCompound nbt = new NbtCompound(); NbtCompound nbt = new NbtCompound();
traits.forEach((key, value) -> nbt.putFloat(key.name(), value)); traits.forEach((key, value) -> nbt.putFloat(key.getId().toString(), value));
return nbt; return nbt;
} }
@ -176,11 +177,15 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
} }
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Trait trait = Trait.REGISTRY.getOrDefault(buf.readIdentifier(), null); Identifier id = buf.readIdentifier();
float value = buf.readFloat(); float value = buf.readFloat();
if (trait != null) { if (value == 0) {
entries.compute(trait, (k, v) -> v == null ? value : (v + value)); continue;
} }
Trait.fromId(id).ifPresent(trait -> {
entries.compute(trait, (k, v) -> v == null ? value : (v + value));
});
} }
if (entries.isEmpty()) { if (entries.isEmpty()) {
return Optional.empty(); return Optional.empty();
@ -190,8 +195,8 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
public static Stream<Map.Entry<Trait, Float>> streamFromNbt(NbtCompound traits) { public static Stream<Map.Entry<Trait, Float>> streamFromNbt(NbtCompound traits) {
return traits.getKeys().stream().map(key -> { return traits.getKeys().stream().map(key -> {
Trait trait = Trait.REGISTRY.get(key.toUpperCase()); Trait trait = Trait.fromId(key).orElse(null);
if (trait == null && !traits.contains(key, NbtElement.NUMBER_TYPE)) { if (trait == null || !traits.contains(key, NbtElement.NUMBER_TYPE)) {
return null; return null;
} }
return Map.entry(trait, traits.getFloat(key)); return Map.entry(trait, traits.getFloat(key));
@ -200,7 +205,7 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
public static Stream<Map.Entry<Trait, Float>> streamFromJson(JsonObject traits) { public static Stream<Map.Entry<Trait, Float>> streamFromJson(JsonObject traits) {
return traits.entrySet().stream().map(entry -> { return traits.entrySet().stream().map(entry -> {
Trait trait = Trait.REGISTRY.get(entry.getKey().toUpperCase()); Trait trait = Trait.fromName(entry.getKey()).orElse(null);
if (trait == null || !entry.getValue().isJsonPrimitive() && !entry.getValue().getAsJsonPrimitive().isNumber()) { if (trait == null || !entry.getValue().isJsonPrimitive() && !entry.getValue().getAsJsonPrimitive().isNumber()) {
return null; return null;
} }

View file

@ -1,7 +1,9 @@
package com.minelittlepony.unicopia.ability.magic.spell.trait; package com.minelittlepony.unicopia.ability.magic.spell.trait;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -33,14 +35,14 @@ public enum Trait {
POISON(TraitGroup.DARKNESS), POISON(TraitGroup.DARKNESS),
BLOOD(TraitGroup.DARKNESS); BLOOD(TraitGroup.DARKNESS);
public static final Map<String, Trait> REGISTRY = Arrays.stream(values()).collect(Collectors.toMap(Trait::name, Function.identity())); private static final Map<String, Trait> REGISTRY = Arrays.stream(values()).collect(Collectors.toMap(Trait::name, Function.identity()));
private static final Map<Identifier, Trait> IDS = Arrays.stream(values()).collect(Collectors.toMap(Trait::getId, Function.identity()));
private final Identifier id; private final Identifier id;
private final Identifier sprite; private final Identifier sprite;
private final TraitGroup group; private final TraitGroup group;
Trait(TraitGroup group) { Trait(TraitGroup group) {
this.id = new Identifier("unicopia", "spell/trait/" + name().toLowerCase()); this.id = new Identifier("unicopia", name().toLowerCase());
this.sprite = new Identifier("unicopia", "textures/gui/trait/" + name().toLowerCase() + ".png"); this.sprite = new Identifier("unicopia", "textures/gui/trait/" + name().toLowerCase() + ".png");
this.group = group; this.group = group;
} }
@ -56,4 +58,20 @@ public enum Trait {
public Identifier getSprite() { public Identifier getSprite() {
return sprite; return sprite;
} }
public static Collection<Trait> all() {
return IDS.values();
}
public static Optional<Trait> fromId(Identifier id) {
return Optional.ofNullable(IDS.getOrDefault(id, null));
}
public static Optional<Trait> fromId(String name) {
return Optional.ofNullable(Identifier.tryParse(name)).flatMap(Trait::fromId);
}
public static Optional<Trait> fromName(String name) {
return Optional.ofNullable(REGISTRY.getOrDefault(name.toUpperCase(), null));
}
} }

View file

@ -27,9 +27,9 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.world.World; import net.minecraft.world.World;
public class TraitDiscovery implements NbtSerialisable { public class TraitDiscovery implements NbtSerialisable {
private final Set<Identifier> unreadTraits = new HashSet<>(); private final Set<Trait> unreadTraits = new HashSet<>();
private final Set<Identifier> traits = new HashSet<>(); private final Set<Trait> traits = new HashSet<>();
private final Map<Identifier, SpellTraits> items = new HashMap<>(); private final Map<Identifier, SpellTraits> items = new HashMap<>();
private final Pony pony; private final Pony pony;
@ -57,8 +57,8 @@ public class TraitDiscovery implements NbtSerialisable {
SpellTraits traits = SpellTraits.of(item); SpellTraits traits = SpellTraits.of(item);
items.put(Registry.ITEM.getId(item), traits); items.put(Registry.ITEM.getId(item), traits);
traits.entries().forEach(e -> { traits.entries().forEach(e -> {
if (this.traits.add(e.getKey().getId())) { if (this.traits.add(e.getKey())) {
unreadTraits.add(e.getKey().getId()); unreadTraits.add(e.getKey());
} }
}); });
pony.setDirty(); pony.setDirty();
@ -68,6 +68,14 @@ public class TraitDiscovery implements NbtSerialisable {
return items.getOrDefault(Registry.ITEM.getId(item), SpellTraits.EMPTY); return items.getOrDefault(Registry.ITEM.getId(item), SpellTraits.EMPTY);
} }
public boolean isUnread(Trait trait) {
return unreadTraits.contains(trait);
}
public boolean isKnown(Trait trait) {
return traits.contains(trait);
}
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip) { public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip) {
getKnownTraits(stack.getItem()).appendTooltip(tooltip); getKnownTraits(stack.getItem()).appendTooltip(tooltip);
@ -82,11 +90,11 @@ public class TraitDiscovery implements NbtSerialisable {
compound.put("items", disco); compound.put("items", disco);
NbtList a = new NbtList(); NbtList a = new NbtList();
this.traits.forEach(id -> a.add(NbtString.of(id.toString()))); this.traits.forEach(id -> a.add(NbtString.of(id.getId().toString())));
compound.put("traits", a); compound.put("traits", a);
NbtList b = new NbtList(); NbtList b = new NbtList();
unreadTraits.forEach(id -> b.add(NbtString.of(id.toString()))); unreadTraits.forEach(id -> b.add(NbtString.of(id.getId().toString())));
compound.put("unreadTraits", b); compound.put("unreadTraits", b);
} }
@ -101,12 +109,18 @@ public class TraitDiscovery implements NbtSerialisable {
}); });
}); });
}); });
compound.getList("traits", NbtElement.STRING_TYPE).forEach(el -> { compound.getList("traits", NbtElement.STRING_TYPE).stream()
Optional.ofNullable(Identifier.tryParse(el.asString())).ifPresent(this.traits::add); .map(NbtElement::asString)
}); .map(Trait::fromId)
compound.getList("unreadTraits", NbtElement.STRING_TYPE).forEach(el -> { .filter(Optional::isPresent)
Optional.ofNullable(Identifier.tryParse(el.asString())).ifPresent(this.unreadTraits::add); .map(Optional::get)
}); .forEach(this.traits::add);
compound.getList("unreadTraits", NbtElement.STRING_TYPE).stream()
.map(NbtElement::asString)
.map(Trait::fromId)
.filter(Optional::isPresent)
.map(Optional::get)
.forEach(this.unreadTraits::add);
} }
public void copyFrom(TraitDiscovery old) { public void copyFrom(TraitDiscovery old) {

View file

@ -55,7 +55,7 @@ public class TraitLoader extends SinglePreparationResourceReloader<Map<Identifie
try { try {
Identifier id = new Identifier(name); Identifier id = new Identifier(name);
SpellTraits.fromEntries(Arrays.stream(set.split(" ")).map(a -> a.split(":")).map(pair -> { SpellTraits.fromEntries(Arrays.stream(set.split(" ")).map(a -> a.split(":")).map(pair -> {
Trait key = Trait.REGISTRY.get(pair[0].toUpperCase()); Trait key = Trait.fromName(pair[0]).orElse(null);
if (key == null) { if (key == null) {
Unicopia.LOGGER.warn("Failed to load trait entry for item {} in {}. {} is not a valid trait", id, resource.getResourcePackName(), pair[0]); Unicopia.LOGGER.warn("Failed to load trait entry for item {} in {}. {} is not a valid trait", id, resource.getResourcePackName(), pair[0]);
return null; return null;

View file

@ -0,0 +1,36 @@
package com.minelittlepony.unicopia.container;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.MathHelper;
public enum SpellbookPage {
INVENTORY,
DISCOVERIES,
RECIPES;
public static final SpellbookPage[] VALUES = values();
private static int current;
private final Text label = new TranslatableText("gui.unicopia.spellbook.page." + name().toLowerCase());
public Text getLabel() {
return label;
}
public boolean isFirst() {
return ordinal() == 0;
}
public boolean isLast() {
return ordinal() == VALUES.length - 1;
}
public static SpellbookPage getCurrent() {
return VALUES[current];
}
public static void swap(int increment) {
current = MathHelper.clamp(current + increment, 0, VALUES.length - 1);
}
}

View file

@ -1,27 +1,93 @@
package com.minelittlepony.unicopia.container; package com.minelittlepony.unicopia.container;
import java.util.List;
import com.minelittlepony.common.client.gui.IViewRoot;
import com.minelittlepony.common.client.gui.ScrollContainer;
import com.minelittlepony.common.client.gui.element.Button;
import com.minelittlepony.common.client.gui.sprite.TextureSprite;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.ability.magic.spell.trait.TraitDiscovery;
import com.minelittlepony.unicopia.container.SpellbookScreenHandler.SpellbookSlot; import com.minelittlepony.unicopia.container.SpellbookScreenHandler.SpellbookSlot;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.Slot;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> { public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> {
public static final Identifier TEXTURE = new Identifier("unicopia", "textures/gui/container/book.png"); public static final Identifier TEXTURE = new Identifier("unicopia", "textures/gui/container/book.png");
public static final Identifier SLOT = new Identifier("unicopia", "textures/gui/container/slot.png");
private final ScrollContainer container = new ScrollContainer() {
{
backgroundColor = 0xFFf9efd3;
scrollbar.layoutToEnd = true;
}
@Override
public void init(Runnable contentInitializer) {
margin.left = SpellbookScreen.this.x + backgroundWidth / 2 + 10;
margin.top = SpellbookScreen.this.y + 35;
margin.right = SpellbookScreen.this.width - backgroundWidth - SpellbookScreen.this.x + 30;
margin.bottom = SpellbookScreen.this.height - backgroundHeight - SpellbookScreen.this.y + 40;
super.init(contentInitializer);
}
@Override
public void drawOverlays(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
matrices.push();
matrices.translate(margin.left, margin.top, 0);
matrices.translate(-2, -2, 0);
RenderSystem.enableBlend();
RenderSystem.setShaderTexture(0, TEXTURE);
int tileSize = 25;
final int bottom = height - tileSize + 4;
final int right = width - tileSize + 9;
drawTexture(matrices, 0, 0, 405, 62, tileSize, tileSize, 512, 256);
drawTexture(matrices, right, 0, 425, 62, tileSize, tileSize, 512, 256);
drawTexture(matrices, 0, bottom, 405, 72, tileSize, tileSize, 512, 256);
drawTexture(matrices, right, bottom, 425, 72, tileSize, tileSize, 512, 256);
for (int i = tileSize; i < right; i += tileSize) {
drawTexture(matrices, i, 0, 415, 62, tileSize, tileSize, 512, 256);
drawTexture(matrices, i, bottom, 415, 72, tileSize, tileSize, 512, 256);
}
for (int i = tileSize; i < bottom; i += tileSize) {
drawTexture(matrices, 0, i, 405, 67, tileSize, tileSize, 512, 256);
drawTexture(matrices, right, i, 425, 67, tileSize, tileSize, 512, 256);
}
matrices.pop();
super.drawOverlays(matrices, mouseX, mouseY, partialTicks);
}
};
public SpellbookScreen(SpellbookScreenHandler handler, PlayerInventory inventory, Text title) { public SpellbookScreen(SpellbookScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title); super(handler, inventory, title);
backgroundWidth = 405; backgroundWidth = 405;
backgroundHeight = 219; backgroundHeight = 219;
titleX = 30;
titleY = 20;
} }
@Override @Override
public void init() { public void init() {
super.init(); super.init();
container.init(this::initPageContent);
addDrawableChild(new PageButton(x + 350, y + 187, 1));
addDrawableChild(new PageButton(x + 300, y + 187, -1));
} }
@Override @Override
@ -34,30 +100,172 @@ public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> {
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
renderBackground(matrices, 0); renderBackground(matrices, 0);
RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.setShaderTexture(0, TEXTURE);
int left = (width - backgroundWidth) / 2; int left = (width - backgroundWidth) / 2;
int top = (height - backgroundHeight) / 2; int top = (height - backgroundHeight) / 2;
RenderSystem.setShaderTexture(0, TEXTURE);
drawTexture(matrices, left, top, 0, 0, backgroundWidth, backgroundHeight, 512, 256); drawTexture(matrices, left, top, 0, 0, backgroundWidth, backgroundHeight, 512, 256);
}
matrices.push(); @Override
matrices.translate(this.x, this.y, 0); protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) {
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.setShaderTexture(0, SLOT);
RenderSystem.enableBlend(); RenderSystem.enableBlend();
for (Slot slot : handler.slots) { for (Slot slot : handler.slots) {
if (slot.isEnabled() && slot instanceof SpellbookSlot) { if (slot.isEnabled() && slot instanceof SpellbookSlot) {
drawTexture(matrices, slot.x - 1, slot.y - 1, 74, 223, 18, 18, 512, 256); drawTexture(matrices, slot.x - 8, slot.y - 8, 0, 0, 32, 32, 32, 32);
// drawStringWithShadow(matrices, this.textRenderer, ((SpellbookSlot)slot).getRing() + "", slot.x, slot.y, 0x000000FF);
} }
} }
RenderSystem.disableBlend(); RenderSystem.disableBlend();
RenderSystem.enableBlend(); textRenderer.draw(matrices, title, titleX, titleY, 4210752);
drawTexture(matrices, 56, 50, 407, 2, 100, 101, 512, 256); textRenderer.draw(matrices, SpellbookPage.getCurrent().getLabel(), 220, this.titleY, 4210752);
RenderSystem.disableBlend(); }
matrices.pop(); private void initPageContent() {
container.getContentPadding().setVertical(10);
addDrawable(container);
((IViewRoot)this).getChildElements().add(container);
switch (SpellbookPage.getCurrent()) {
case DISCOVERIES: {
int top = 10;
int left = 25;
int i = 0;
int cols = 4;
for (Trait trait : Trait.all()) {
int x = i % cols;
int y = i / cols;
container.addButton(new TraitButton(left + x * 32, top + y * 32, trait));
i++;
}
break;
}
case INVENTORY:
case RECIPES:
}
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
return hoveredElement(mouseX, mouseY).filter((element) -> {
setDragging(false);
return element.mouseReleased(mouseX, mouseY, button);
}).isPresent() || super.mouseReleased(mouseX, mouseY, button);
}
@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
return (getFocused() != null && isDragging() && button == 0 && getFocused().mouseDragged(mouseX, mouseY, button, deltaX, deltaY))
|| super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}
class PageButton extends ImageButton {
private final int increment;
private final TextureSprite sprite = new TextureSprite()
.setSize(25, 13)
.setTextureSize(256, 512)
.setTextureOffset(0, 479)
.setTexture(TEXTURE);
public PageButton(int x, int y, int increment) {
super(x, y, 25, 20);
this.increment = increment;
getStyle().setIcon(sprite);
onClick(sender -> {
SpellbookPage.swap(increment);
init(client, SpellbookScreen.this.width, SpellbookScreen.this.height);
});
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
setEnabled(increment < 0 ? !SpellbookPage.getCurrent().isFirst() : !SpellbookPage.getCurrent().isLast());
if (!active) {
return;
}
int state = hovered ? 1 : 0;
sprite.setTextureOffset(23 * state, (int)(479 + 6.5F - (increment * 6.5F)));
super.renderButton(matrices, mouseX, mouseY, partialTicks);
}
}
class TraitButton extends ImageButton {
private final Trait trait;
public TraitButton(int x, int y, Trait trait) {
super(x, y, 16, 16);
this.trait = trait;
getStyle().setIcon(new TextureSprite()
.setTextureSize(16, 16)
.setSize(16, 16)
.setTexture(trait.getSprite()));
getStyle().setTooltip(List.of(
new TranslatableText("trait." + trait.getId().getNamespace() + "." + trait.getId().getPath() + ".name"),
new TranslatableText("trait." + trait.getId().getNamespace() + "." + trait.getId().getPath() + ".description")
));
getStyle().setTooltip(List.of(
new LiteralText(trait.name()),
new LiteralText("Test description")
));
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
TraitDiscovery discoveries = Pony.of(client.player).getDiscoveries();
setEnabled(discoveries.isKnown(trait));
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.setShaderTexture(0, TEXTURE);
RenderSystem.enableBlend();
drawTexture(matrices, x - 2, y - 8, 204, 219, 22, 32, 512, 256);
drawTexture(matrices, x - 2, y - 1, 74, 223, 18, 18, 512, 256);
super.renderButton(matrices, mouseX, mouseY, partialTicks);
hovered &= active;
}
@Override
public Button setEnabled(boolean enable) {
alpha = enable ? 1 : 0.1125F;
return super.setEnabled(enable);
}
}
class ImageButton extends Button {
public ImageButton(int x, int y) {
super(x, y);
}
public ImageButton(int x, int y, int width, int height) {
super(x, y, width, height);
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1, 1, 1, alpha);
RenderSystem.defaultBlendFunc();
RenderSystem.blendFunc(
GlStateManager.SrcFactor.SRC_ALPHA,
GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
if (getStyle().hasIcon()) {
getStyle().getIcon().render(matrices, x, y, mouseX, mouseY, partialTicks);
}
RenderSystem.setShaderColor(1, 1, 1, 1);
}
} }
} }

View file

@ -10,7 +10,11 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.item.URecipes; import com.minelittlepony.unicopia.item.URecipes;
import com.minelittlepony.unicopia.util.InventoryUtil; import com.minelittlepony.unicopia.util.InventoryUtil;
import com.mojang.datafixers.util.Pair;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.CraftingInventory; import net.minecraft.inventory.CraftingInventory;
@ -18,6 +22,7 @@ import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerContext; import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.slot.CraftingResultSlot; import net.minecraft.screen.slot.CraftingResultSlot;
@ -25,10 +30,18 @@ import net.minecraft.screen.slot.Slot;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
public class SpellbookScreenHandler extends ScreenHandler { public class SpellbookScreenHandler extends ScreenHandler {
private static final Identifier[] EMPTY_ARMOR_SLOT_TEXTURES = new Identifier[]{
PlayerScreenHandler.EMPTY_BOOTS_SLOT_TEXTURE,
PlayerScreenHandler.EMPTY_LEGGINGS_SLOT_TEXTURE,
PlayerScreenHandler.EMPTY_CHESTPLATE_SLOT_TEXTURE,
PlayerScreenHandler.EMPTY_HELMET_SLOT_TEXTURE
};
private final int MAX_INGREDIENTS; private final int MAX_INGREDIENTS;
private final int GEM_SLOT_INDEX; private final int GEM_SLOT_INDEX;
@ -73,6 +86,47 @@ public class SpellbookScreenHandler extends ScreenHandler {
for (int i = 0; i < 9; ++i) { for (int i = 0; i < 9; ++i) {
addSlot(new Slot(inventory, i, 121 + i * 18, 195)); addSlot(new Slot(inventory, i, 121 + i * 18, 195));
} }
for (int i = 0; i < PlayerInventory.MAIN_SIZE - 9; ++i) {
int x = i % 5;
int y = i / 5;
addSlot(new InventorySlot(inventory, i + 9, 225 + x * 20, 50 + y * 20));
}
for (int i = 0; i < 4; i++) {
final EquipmentSlot eq = EquipmentSlot.values()[5 - i];
addSlot(new InventorySlot(inventory, PlayerInventory.OFF_HAND_SLOT - i - 1, 340, 50 + (i * 20)) {
@Override
public int getMaxItemCount() {
return 1;
}
@Override
public boolean canInsert(ItemStack stack) {
return eq == MobEntity.getPreferredEquipmentSlot(stack);
}
@Override
public boolean canTakeItems(PlayerEntity playerEntity) {
ItemStack stack = getStack();
if (!stack.isEmpty() && !playerEntity.isCreative() && EnchantmentHelper.hasBindingCurse(stack)) {
return false;
}
return super.canTakeItems(playerEntity);
}
@Override
public Pair<Identifier, Identifier> getBackgroundSprite() {
return Pair.of(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, EMPTY_ARMOR_SLOT_TEXTURES[eq.getEntitySlotId()]);
}
});
}
addSlot(new InventorySlot(inventory, PlayerInventory.OFF_HAND_SLOT, 340, 150) {
@Override
public Pair<Identifier, Identifier> getBackgroundSprite() {
return Pair.of(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, PlayerScreenHandler.EMPTY_OFFHAND_ARMOR_SLOT);
}
});
onContentChanged(input); onContentChanged(input);
} }
@ -126,6 +180,18 @@ public class SpellbookScreenHandler extends ScreenHandler {
onContentChanged(input); onContentChanged(input);
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
if (insertItem(transferredStack, HOTBAR_END + 27, HOTBAR_END + 27 + 4, false)) {
sourceSlot.onQuickTransfer(transferredStack, stack);
onContentChanged(input);
return ItemStack.EMPTY;
}
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()) {
@ -279,6 +345,22 @@ public class SpellbookScreenHandler extends ScreenHandler {
} }
} }
public class InventorySlot extends Slot implements SpellbookSlot {
public InventorySlot(Inventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
}
@Override
public int getRing() {
return 0;
}
@Override
public boolean isEnabled() {
return SpellbookPage.getCurrent() == SpellbookPage.INVENTORY;
}
}
public class InputSlot extends Slot implements SpellbookSlot { public class InputSlot extends Slot implements SpellbookSlot {
private final int ring; private final int ring;

View file

@ -257,6 +257,10 @@
"gui.unicopia.tribe_selection.confirm.bads.2.changeling": " - Require love, collected from ponies or other hostile mobs to subsidise their diet", "gui.unicopia.tribe_selection.confirm.bads.2.changeling": " - Require love, collected from ponies or other hostile mobs to subsidise their diet",
"gui.unicopia.tribe_selection.confirm.bads.3.changeling": " - Becomes sick from eating regular food and must eat love hasten a cure", "gui.unicopia.tribe_selection.confirm.bads.3.changeling": " - Becomes sick from eating regular food and must eat love hasten a cure",
"gui.unicopia.spellbook.page.inventory": "Inventory",
"gui.unicopia.spellbook.page.discoveries": "Discoveries",
"gui.unicopia.spellbook.page.recipes": "Recipes",
"unicopia.category.name": "Pony Abilities", "unicopia.category.name": "Pony Abilities",
"key.unicopia.primary": "Primary Ability", "key.unicopia.primary": "Primary Ability",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View file

@ -0,0 +1,14 @@
{
"type": "unicopia:spellbook/crafting",
"material": {
"item": {
"item": "unicopia:gemstone"
}
},
"traits": {
"pestilence": 1
},
"result": {
"item": "unicopia:burned_juice"
}
}