Fixed the spellbook

This commit is contained in:
Sollace 2020-06-01 17:00:22 +02:00
parent 797dbb8e38
commit e3c5f6fc4b
9 changed files with 42 additions and 42 deletions

View file

@ -17,27 +17,22 @@ import net.minecraft.client.gui.screen.ingame.ContainerScreen;
import net.minecraft.client.texture.MissingSprite;
import net.minecraft.container.Slot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
public class SpellBookScreen extends ContainerScreen<SpellBookContainer> implements IPageUnlockListener {
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 PageButton nextPage;
private PageButton prevPage;
public SpellBookScreen(PlayerEntity player) {
super(
new SpellBookContainer(0, null, player, null),
player.inventory,
new LiteralText("item.spellbook.name")
);
player.container = container;
public SpellBookScreen(int sync, Identifier id, PlayerEntity player, PacketByteBuf buf) {
super(new SpellBookContainer(sync, id, player, buf), player.inventory, buf.readText());
containerWidth = 405;
containerHeight = 219;
@ -108,7 +103,7 @@ public class SpellBookScreen extends ContainerScreen<SpellBookContainer> impleme
GlStateManager.enableBlend();
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);
GL11.glEnable(GL11.GL_ALPHA_TEST);
@ -143,13 +138,13 @@ public class SpellBookScreen extends ContainerScreen<SpellBookContainer> impleme
int left = (width - containerWidth) / 2;
int top = (height - containerHeight) / 2;
minecraft.getTextureManager().bindTexture(spellBookGuiTextures);
minecraft.getTextureManager().bindTexture(TEXTURE);
blit(left, top, 0, 0, containerWidth, containerHeight, 512, 256);
GlStateManager.enableBlend();
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);
if (player.getPages().getPageState(currentPage) != PageState.LOCKED) {
@ -205,7 +200,7 @@ public class SpellBookScreen extends ContainerScreen<SpellBookContainer> impleme
}
GlStateManager.color4f(1, 1, 1, 1);
minecraft.getTextureManager().bindTexture(spellBookGuiTextures);
minecraft.getTextureManager().bindTexture(TEXTURE);
int u = 0;
int v = 220;

View file

@ -8,5 +8,6 @@ public interface UScreens {
static void bootstrap() {
ScreenProviderRegistry.INSTANCE.registerFactory(UContainers.BAG_OF_HOLDING, BagOfHoldingScreen::new);
ScreenProviderRegistry.INSTANCE.registerFactory(UContainers.SPELL_BOOK, SpellBookScreen::new);
}
}

View file

@ -38,7 +38,7 @@ public class SpellBookContainer extends Container {
private final PlayerEntity player;
public SpellBookContainer(int sync, Identifier id, PlayerEntity player, PacketByteBuf buf) {
super(null, 0);
super(null, sync);
worldObj = player.world;
this.player = player;

View file

@ -83,6 +83,9 @@ class PageInstance implements Page {
@Override
public Page next() {
int i = Math.min(Pages.instance().getTotalPages() - 1, index + 1);
if (i == index) {
return this;
}
return Pages.instance().getByIndex(i);
}
@ -91,7 +94,6 @@ class PageInstance implements Page {
if (index <= 0) {
return this;
}
return Pages.instance().getByIndex(index - 1);
}

View file

@ -32,12 +32,14 @@ public interface PageOwner extends Transmittable {
}
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) {
return true;
}
}
return false;
}
}

View file

@ -103,6 +103,9 @@ public class Pages extends JsonDataLoader implements IdentifiableResourceReloadL
@Nullable
public Page getByIndex(int index) {
if (index < 0 || index >= pagesByIndex.size()) {
return null;
}
return pagesByIndex.get(index);
}

View file

@ -1,11 +1,11 @@
package com.minelittlepony.unicopia.entity;
import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.container.UContainers;
import com.minelittlepony.unicopia.ducks.PickedItemSupplier;
import com.minelittlepony.unicopia.item.UItems;
import net.minecraft.container.Container;
import net.minecraft.container.NameableContainerFactory;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.damage.DamageSource;
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.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
@ -27,7 +27,7 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameRules;
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> 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 (player instanceof ServerPlayerEntity) {
ContainerProviderRegistry.INSTANCE.openContainer(UContainers.SPELL_BOOK, player, o -> {
o.writeText(getName());
});
}
player.playSound(SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, 2, 1);
player.openContainer(this);
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
@Override
public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) {
return null;
}
@Override
public void readCustomDataFromTag(CompoundTag compound) {
super.readCustomDataFromTag(compound);

View file

@ -36,9 +36,7 @@ public class PredicatedIngredient {
.filter(s -> matches(s, 1))
.collect(Collectors.toList());
});
this.preview = new Lazy<>(() -> {
return net.minecraft.recipe.Ingredient.ofStacks(getMatchingStacks().toArray(ItemStack[]::new));
});
this.preview = new Lazy<>(() -> Ingredient.ofStacks(getMatchingStacks().toArray(ItemStack[]::new)));
}
public Stream<ItemStack> getMatchingStacks() {
@ -82,17 +80,17 @@ public class PredicatedIngredient {
if (primary != Predicate.EMPTY && secondary != Predicate.EMPTY) {
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();
predicates.add(primary);
predicates.add(secondary);
PredicateSerializer.JSON_READERS.stream()
.map(reader -> reader.read(obj))
DefaultedList<Predicate> predicates = Stream.concat(
Stream.of(primary, secondary),
PredicateSerializer.JSON_READERS.stream().map(reader -> reader.read(obj))
)
.filter(i -> i != Predicate.EMPTY)
.forEach(predicates::add);
.collect(Collectors.toCollection(DefaultedList::of));
if (predicates.isEmpty()) {
return EMPTY;
}
return new PredicatedIngredient(predicates);
}

View file

@ -2,9 +2,9 @@
"type": "unicopia:enchanting_spell",
"input": { "item": "unicopia:corrupted_gem" },
"ingredients": [
{ "item": "unicopia:gem", "spell": "inferno" },
{ "item": "unicopia:gem", "spell": "darkness" },
{ "item": "unicopia:gem", "spell": "necromancy" }
{ "spell": "inferno" },
{ "spell": "darkness" },
{ "spell": "necromancy" }
],
"result": { "item": "unicopia:alicorn_amulet" }
}