mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed the spellbook
This commit is contained in:
parent
797dbb8e38
commit
e3c5f6fc4b
9 changed files with 42 additions and 42 deletions
|
@ -17,27 +17,22 @@ import net.minecraft.client.gui.screen.ingame.ContainerScreen;
|
||||||
import net.minecraft.client.texture.MissingSprite;
|
import net.minecraft.client.texture.MissingSprite;
|
||||||
import net.minecraft.container.Slot;
|
import net.minecraft.container.Slot;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.text.LiteralText;
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.PacketByteBuf;
|
||||||
|
|
||||||
public class SpellBookScreen extends ContainerScreen<SpellBookContainer> implements IPageUnlockListener {
|
public class SpellBookScreen extends ContainerScreen<SpellBookContainer> implements IPageUnlockListener {
|
||||||
|
|
||||||
private static Page currentPage;
|
private static Page currentPage;
|
||||||
|
|
||||||
public static final Identifier spellBookGuiTextures = new Identifier("unicopia", "textures/gui/container/book.png");
|
public static final Identifier TEXTURE = new Identifier("unicopia", "textures/gui/container/book.png");
|
||||||
|
|
||||||
private Pony player;
|
private Pony player;
|
||||||
|
|
||||||
private PageButton nextPage;
|
private PageButton nextPage;
|
||||||
private PageButton prevPage;
|
private PageButton prevPage;
|
||||||
|
|
||||||
public SpellBookScreen(PlayerEntity player) {
|
public SpellBookScreen(int sync, Identifier id, PlayerEntity player, PacketByteBuf buf) {
|
||||||
super(
|
super(new SpellBookContainer(sync, id, player, buf), player.inventory, buf.readText());
|
||||||
new SpellBookContainer(0, null, player, null),
|
|
||||||
player.inventory,
|
|
||||||
new LiteralText("item.spellbook.name")
|
|
||||||
);
|
|
||||||
player.container = container;
|
|
||||||
|
|
||||||
containerWidth = 405;
|
containerWidth = 405;
|
||||||
containerHeight = 219;
|
containerHeight = 219;
|
||||||
|
@ -108,7 +103,7 @@ public class SpellBookScreen extends ContainerScreen<SpellBookContainer> impleme
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||||
|
|
||||||
minecraft.getTextureManager().bindTexture(spellBookGuiTextures);
|
minecraft.getTextureManager().bindTexture(TEXTURE);
|
||||||
blit(slot.xPosition - 1, slot.yPosition - 1, 74, 223, 18, 18, 512, 256);
|
blit(slot.xPosition - 1, slot.yPosition - 1, 74, 223, 18, 18, 512, 256);
|
||||||
|
|
||||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||||
|
@ -143,13 +138,13 @@ public class SpellBookScreen extends ContainerScreen<SpellBookContainer> impleme
|
||||||
int left = (width - containerWidth) / 2;
|
int left = (width - containerWidth) / 2;
|
||||||
int top = (height - containerHeight) / 2;
|
int top = (height - containerHeight) / 2;
|
||||||
|
|
||||||
minecraft.getTextureManager().bindTexture(spellBookGuiTextures);
|
minecraft.getTextureManager().bindTexture(TEXTURE);
|
||||||
blit(left, top, 0, 0, containerWidth, containerHeight, 512, 256);
|
blit(left, top, 0, 0, containerWidth, containerHeight, 512, 256);
|
||||||
|
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||||
|
|
||||||
minecraft.getTextureManager().bindTexture(spellBookGuiTextures);
|
minecraft.getTextureManager().bindTexture(TEXTURE);
|
||||||
blit(left + 147, top + 49, 407, 2, 100, 101, 512, 256);
|
blit(left + 147, top + 49, 407, 2, 100, 101, 512, 256);
|
||||||
|
|
||||||
if (player.getPages().getPageState(currentPage) != PageState.LOCKED) {
|
if (player.getPages().getPageState(currentPage) != PageState.LOCKED) {
|
||||||
|
@ -205,7 +200,7 @@ public class SpellBookScreen extends ContainerScreen<SpellBookContainer> impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
GlStateManager.color4f(1, 1, 1, 1);
|
GlStateManager.color4f(1, 1, 1, 1);
|
||||||
minecraft.getTextureManager().bindTexture(spellBookGuiTextures);
|
minecraft.getTextureManager().bindTexture(TEXTURE);
|
||||||
|
|
||||||
int u = 0;
|
int u = 0;
|
||||||
int v = 220;
|
int v = 220;
|
||||||
|
|
|
@ -8,5 +8,6 @@ public interface UScreens {
|
||||||
|
|
||||||
static void bootstrap() {
|
static void bootstrap() {
|
||||||
ScreenProviderRegistry.INSTANCE.registerFactory(UContainers.BAG_OF_HOLDING, BagOfHoldingScreen::new);
|
ScreenProviderRegistry.INSTANCE.registerFactory(UContainers.BAG_OF_HOLDING, BagOfHoldingScreen::new);
|
||||||
|
ScreenProviderRegistry.INSTANCE.registerFactory(UContainers.SPELL_BOOK, SpellBookScreen::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class SpellBookContainer extends Container {
|
||||||
private final PlayerEntity player;
|
private final PlayerEntity player;
|
||||||
|
|
||||||
public SpellBookContainer(int sync, Identifier id, PlayerEntity player, PacketByteBuf buf) {
|
public SpellBookContainer(int sync, Identifier id, PlayerEntity player, PacketByteBuf buf) {
|
||||||
super(null, 0);
|
super(null, sync);
|
||||||
worldObj = player.world;
|
worldObj = player.world;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,9 @@ class PageInstance implements Page {
|
||||||
@Override
|
@Override
|
||||||
public Page next() {
|
public Page next() {
|
||||||
int i = Math.min(Pages.instance().getTotalPages() - 1, index + 1);
|
int i = Math.min(Pages.instance().getTotalPages() - 1, index + 1);
|
||||||
|
if (i == index) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
return Pages.instance().getByIndex(i);
|
return Pages.instance().getByIndex(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +94,6 @@ class PageInstance implements Page {
|
||||||
if (index <= 0) {
|
if (index <= 0) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pages.instance().getByIndex(index - 1);
|
return Pages.instance().getByIndex(index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,12 +32,14 @@ public interface PageOwner extends Transmittable {
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean hasPageStateRelative(Page page, PageState state, Function<Page, Page> iter) {
|
default boolean hasPageStateRelative(Page page, PageState state, Function<Page, Page> iter) {
|
||||||
while ((page = iter.apply(page)) != null) {
|
for (Page prev = null;
|
||||||
|
(page = iter.apply(page)) != null && page != prev;
|
||||||
|
prev = page
|
||||||
|
) {
|
||||||
if (getPageState(page) == state) {
|
if (getPageState(page) == state) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,9 @@ public class Pages extends JsonDataLoader implements IdentifiableResourceReloadL
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Page getByIndex(int index) {
|
public Page getByIndex(int index) {
|
||||||
|
if (index < 0 || index >= pagesByIndex.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return pagesByIndex.get(index);
|
return pagesByIndex.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.minelittlepony.unicopia.entity;
|
package com.minelittlepony.unicopia.entity;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.EquinePredicates;
|
import com.minelittlepony.unicopia.EquinePredicates;
|
||||||
|
import com.minelittlepony.unicopia.container.UContainers;
|
||||||
import com.minelittlepony.unicopia.ducks.PickedItemSupplier;
|
import com.minelittlepony.unicopia.ducks.PickedItemSupplier;
|
||||||
import com.minelittlepony.unicopia.item.UItems;
|
import com.minelittlepony.unicopia.item.UItems;
|
||||||
|
|
||||||
import net.minecraft.container.Container;
|
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
|
||||||
import net.minecraft.container.NameableContainerFactory;
|
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.damage.DamageSource;
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
import net.minecraft.entity.data.DataTracker;
|
import net.minecraft.entity.data.DataTracker;
|
||||||
|
@ -13,11 +13,11 @@ import net.minecraft.entity.data.TrackedData;
|
||||||
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
||||||
import net.minecraft.entity.mob.MobEntity;
|
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.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
import net.minecraft.predicate.entity.EntityPredicates;
|
import net.minecraft.predicate.entity.EntityPredicates;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.sound.BlockSoundGroup;
|
import net.minecraft.sound.BlockSoundGroup;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
|
@ -27,7 +27,7 @@ import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.GameRules;
|
import net.minecraft.world.GameRules;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class SpellbookEntity extends MobEntity implements NameableContainerFactory, IMagicals, PickedItemSupplier {
|
public class SpellbookEntity extends MobEntity implements IMagicals, PickedItemSupplier {
|
||||||
|
|
||||||
private static final TrackedData<Boolean> OPENED = DataTracker.registerData(SpellbookEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
|
private static final TrackedData<Boolean> OPENED = DataTracker.registerData(SpellbookEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
|
||||||
private static final TrackedData<Boolean> ALTERED = DataTracker.registerData(SpellbookEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
|
private static final TrackedData<Boolean> ALTERED = DataTracker.registerData(SpellbookEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
|
||||||
|
@ -175,19 +175,18 @@ public class SpellbookEntity extends MobEntity implements NameableContainerFacto
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EquinePredicates.PLAYER_UNICORN.test(player)) {
|
if (EquinePredicates.PLAYER_UNICORN.test(player)) {
|
||||||
|
if (player instanceof ServerPlayerEntity) {
|
||||||
|
ContainerProviderRegistry.INSTANCE.openContainer(UContainers.SPELL_BOOK, player, o -> {
|
||||||
|
o.writeText(getName());
|
||||||
|
});
|
||||||
|
}
|
||||||
player.playSound(SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, 2, 1);
|
player.playSound(SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, 2, 1);
|
||||||
player.openContainer(this);
|
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readCustomDataFromTag(CompoundTag compound) {
|
public void readCustomDataFromTag(CompoundTag compound) {
|
||||||
super.readCustomDataFromTag(compound);
|
super.readCustomDataFromTag(compound);
|
||||||
|
|
|
@ -36,9 +36,7 @@ public class PredicatedIngredient {
|
||||||
.filter(s -> matches(s, 1))
|
.filter(s -> matches(s, 1))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
});
|
});
|
||||||
this.preview = new Lazy<>(() -> {
|
this.preview = new Lazy<>(() -> Ingredient.ofStacks(getMatchingStacks().toArray(ItemStack[]::new)));
|
||||||
return net.minecraft.recipe.Ingredient.ofStacks(getMatchingStacks().toArray(ItemStack[]::new));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<ItemStack> getMatchingStacks() {
|
public Stream<ItemStack> getMatchingStacks() {
|
||||||
|
@ -82,17 +80,17 @@ public class PredicatedIngredient {
|
||||||
if (primary != Predicate.EMPTY && secondary != Predicate.EMPTY) {
|
if (primary != Predicate.EMPTY && secondary != Predicate.EMPTY) {
|
||||||
throw new JsonParseException("Invalid ingredient. Cannot have both an item and a tag requirement.");
|
throw new JsonParseException("Invalid ingredient. Cannot have both an item and a tag requirement.");
|
||||||
}
|
}
|
||||||
if (primary == secondary) {
|
|
||||||
throw new JsonParseException("Invalid ingredient. Must have either an item or tag requirement.");
|
|
||||||
}
|
|
||||||
|
|
||||||
DefaultedList<Predicate> predicates = DefaultedList.of();
|
DefaultedList<Predicate> predicates = Stream.concat(
|
||||||
predicates.add(primary);
|
Stream.of(primary, secondary),
|
||||||
predicates.add(secondary);
|
PredicateSerializer.JSON_READERS.stream().map(reader -> reader.read(obj))
|
||||||
PredicateSerializer.JSON_READERS.stream()
|
)
|
||||||
.map(reader -> reader.read(obj))
|
|
||||||
.filter(i -> i != Predicate.EMPTY)
|
.filter(i -> i != Predicate.EMPTY)
|
||||||
.forEach(predicates::add);
|
.collect(Collectors.toCollection(DefaultedList::of));
|
||||||
|
|
||||||
|
if (predicates.isEmpty()) {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
return new PredicatedIngredient(predicates);
|
return new PredicatedIngredient(predicates);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
"type": "unicopia:enchanting_spell",
|
"type": "unicopia:enchanting_spell",
|
||||||
"input": { "item": "unicopia:corrupted_gem" },
|
"input": { "item": "unicopia:corrupted_gem" },
|
||||||
"ingredients": [
|
"ingredients": [
|
||||||
{ "item": "unicopia:gem", "spell": "inferno" },
|
{ "spell": "inferno" },
|
||||||
{ "item": "unicopia:gem", "spell": "darkness" },
|
{ "spell": "darkness" },
|
||||||
{ "item": "unicopia:gem", "spell": "necromancy" }
|
{ "spell": "necromancy" }
|
||||||
],
|
],
|
||||||
"result": { "item": "unicopia:alicorn_amulet" }
|
"result": { "item": "unicopia:alicorn_amulet" }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue