it was actually not that hard

This commit is contained in:
gamma-delta 2022-03-25 16:11:27 -05:00
parent f513e71d85
commit b17c304dc9
6 changed files with 136 additions and 27 deletions

View file

@ -20,7 +20,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.parchmentmc.librarian.forgegradle' apply plugin: 'org.parchmentmc.librarian.forgegradle'
apply plugin: 'org.spongepowered.mixin' apply plugin: 'org.spongepowered.mixin'
version = '0.7.0-dev.4' version = '0.7.0-dev.5'
group = 'at.petra-k.hexcasting' // http://maven.apache.org/guides/mini/guide-naming-conventions.html group = 'at.petra-k.hexcasting' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'hexcasting' archivesBaseName = 'hexcasting'

View file

@ -1,5 +1,6 @@
package at.petrak.hexcasting.client.entity; package at.petrak.hexcasting.client.entity;
import at.petrak.hexcasting.HexConfig;
import at.petrak.hexcasting.HexMod; import at.petrak.hexcasting.HexMod;
import at.petrak.hexcasting.common.entities.EntityWallScroll; import at.petrak.hexcasting.common.entities.EntityWallScroll;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
@ -98,6 +99,7 @@ public class WallScrollRenderer extends EntityRenderer<EntityWallScroll> {
} }
if (wallScroll.zappyPoints != null) { if (wallScroll.zappyPoints != null) {
var points = wallScroll.zappyPoints;
ps.pushPose(); ps.pushPose();
ps.mulPose(Vector3f.YP.rotationDegrees(180f)); ps.mulPose(Vector3f.YP.rotationDegrees(180f));
@ -111,9 +113,38 @@ public class WallScrollRenderer extends EntityRenderer<EntityWallScroll> {
var outer = 0xff_d2c8c8; var outer = 0xff_d2c8c8;
var inner = 0xc8_322b33; var inner = 0xc8_322b33;
var verts = bufSource.getBuffer(RenderType.entityCutout(WHITE)); var verts = bufSource.getBuffer(RenderType.entityCutout(WHITE));
theCoolerDrawLineSeq(mat, norm, light, verts, wallScroll.zappyPoints, 5, outer); theCoolerDrawLineSeq(mat, norm, light, verts, points, 5, outer);
ps.translate(0, 0, 0.01); ps.translate(0, 0, 0.01);
theCoolerDrawLineSeq(mat, norm, light, verts, wallScroll.zappyPoints, 2, inner); theCoolerDrawLineSeq(mat, norm, light, verts, points, 2, inner);
if (wallScroll.getShowsStrokeOrder()) {
var animTime = wallScroll.tickCount;
var pointCircuit =
(animTime * HexConfig.Client.patternPointSpeedMultiplier.get()) % (points.size() + 10);
if (pointCircuit < points.size() - 1) {
var pointMacro = Mth.floor(pointCircuit);
var pointMicro = pointCircuit - pointMacro;
var p1 = points.get(pointMacro);
var p2 = points.get((pointMacro + 1) % points.size());
var drawPos = new Vec2(
(float) (p1.x + (p2.x - p1.x) * pointMicro),
(float) (p1.y + (p2.y - p1.y) * pointMicro)
);
ps.translate(0, 0, 0.01);
theCoolerDrawSpot(mat, norm, light, verts, drawPos, 2.6666f, 0xff_cfa0f3);
ps.translate(0, 0, 0.01);
theCoolerDrawSpot(mat, norm, light, verts, drawPos, 2f, 0xff_8d6acc);
} else {
ps.translate(0, 0, 0.02);
}
ps.translate(0, 0, 0.01);
theCoolerDrawSpot(mat, norm, light, verts, points.get(0), 3f, 0xff_4946d3);
ps.translate(0, 0, 0.01);
theCoolerDrawSpot(mat, norm, light, verts, points.get(0), 2f, 0xff_5b7bd7);
}
ps.popPose(); ps.popPose();
} }
@ -203,4 +234,21 @@ public class WallScrollRenderer extends EntityRenderer<EntityWallScroll> {
prevYLo = yLo; prevYLo = yLo;
} }
} }
private static void theCoolerDrawSpot(Matrix4f mat, Matrix3f normal, int light, VertexConsumer verts,
Vec2 point, float radius, int color) {
var fracOfCircle = 6;
for (int i = 0; i < fracOfCircle; i++) {
// We do need rects, irritatingly
// so we do fake triangles
vertexCol(mat, normal, light, verts, color, point.x, point.y);
vertexCol(mat, normal, light, verts, color, point.x, point.y);
for (int j = 0; j <= 1; j++) {
var theta = (i - j) / (float) fracOfCircle * Mth.TWO_PI;
var rx = Mth.cos(theta) * radius + point.x;
var ry = Mth.sin(theta) * radius + point.y;
vertexCol(mat, normal, light, verts, color, rx, ry);
}
}
}
} }

View file

@ -1,14 +1,22 @@
package at.petrak.hexcasting.common.entities; package at.petrak.hexcasting.common.entities;
import at.petrak.hexcasting.client.RenderLib; import at.petrak.hexcasting.client.RenderLib;
import at.petrak.hexcasting.common.items.HexItems;
import at.petrak.hexcasting.common.items.ItemScroll; import at.petrak.hexcasting.common.items.ItemScroll;
import at.petrak.hexcasting.common.lib.HexSounds;
import at.petrak.hexcasting.hexmath.HexPattern; import at.petrak.hexcasting.hexmath.HexPattern;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.HangingEntity; import net.minecraft.world.entity.decoration.HangingEntity;
@ -18,6 +26,7 @@ import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.entity.IEntityAdditionalSpawnData; import net.minecraftforge.entity.IEntityAdditionalSpawnData;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -25,6 +34,10 @@ import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
public class EntityWallScroll extends HangingEntity implements IEntityAdditionalSpawnData { public class EntityWallScroll extends HangingEntity implements IEntityAdditionalSpawnData {
private static final EntityDataAccessor<Boolean> SHOWS_STROKE_ORDER = SynchedEntityData.defineId(
EntityWallScroll.class,
EntityDataSerializers.BOOLEAN);
public ItemStack scroll; public ItemStack scroll;
public HexPattern pattern; public HexPattern pattern;
public List<Vec2> zappyPoints; public List<Vec2> zappyPoints;
@ -58,6 +71,20 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
} }
} }
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(SHOWS_STROKE_ORDER, false);
}
public boolean getShowsStrokeOrder() {
return this.entityData.get(SHOWS_STROKE_ORDER);
}
public void setShowsStrokeOrder(boolean b) {
this.entityData.set(SHOWS_STROKE_ORDER, b);
}
@Override @Override
public int getWidth() { public int getWidth() {
return 48; return 48;
@ -82,6 +109,21 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
} }
} }
@Override
public InteractionResult interactAt(Player pPlayer, Vec3 pVec, InteractionHand pHand) {
var handStack = pPlayer.getItemInHand(pHand);
if (handStack.is(HexItems.AMETHYST_DUST.get()) && !this.getShowsStrokeOrder()) {
if (!pPlayer.getAbilities().instabuild) {
handStack.shrink(1);
}
this.setShowsStrokeOrder(true);
pPlayer.level.playSound(pPlayer, this, HexSounds.DUST_SCROLL.get(), SoundSource.PLAYERS, 1f, 1f);
return InteractionResult.SUCCESS;
}
return super.interactAt(pPlayer, pVec, pHand);
}
@Override @Override
public void playPlacementSound() { public void playPlacementSound() {
this.playSound(SoundEvents.PAINTING_PLACE, 1.0F, 1.0F); this.playSound(SoundEvents.PAINTING_PLACE, 1.0F, 1.0F);
@ -96,12 +138,15 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
public void writeSpawnData(FriendlyByteBuf buf) { public void writeSpawnData(FriendlyByteBuf buf) {
buf.writeVarInt(this.direction.ordinal()); buf.writeVarInt(this.direction.ordinal());
buf.writeItem(this.scroll); buf.writeItem(this.scroll);
buf.writeBoolean(this.getShowsStrokeOrder());
} }
@Override @Override
public void readSpawnData(FriendlyByteBuf buf) { public void readSpawnData(FriendlyByteBuf buf) {
this.direction = Direction.values()[buf.readVarInt()]; this.direction = Direction.values()[buf.readVarInt()];
var scroll = buf.readItem(); var scroll = buf.readItem();
this.setShowsStrokeOrder(buf.readBoolean());
this.loadDataFromScrollItem(scroll); this.loadDataFromScrollItem(scroll);
this.setDirection(this.direction); this.setDirection(this.direction);
} }
@ -110,6 +155,7 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
public void addAdditionalSaveData(CompoundTag tag) { public void addAdditionalSaveData(CompoundTag tag) {
tag.putByte("direction", (byte) this.direction.ordinal()); tag.putByte("direction", (byte) this.direction.ordinal());
tag.put("scroll", this.scroll.serializeNBT()); tag.put("scroll", this.scroll.serializeNBT());
tag.putBoolean("showsStrokeOrder", this.getShowsStrokeOrder());
super.addAdditionalSaveData(tag); super.addAdditionalSaveData(tag);
} }
@ -117,6 +163,8 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
public void readAdditionalSaveData(CompoundTag tag) { public void readAdditionalSaveData(CompoundTag tag) {
this.direction = Direction.values()[tag.getByte("direction")]; this.direction = Direction.values()[tag.getByte("direction")];
var scroll = ItemStack.of(tag.getCompound("scroll")); var scroll = ItemStack.of(tag.getCompound("scroll"));
this.setShowsStrokeOrder(tag.getBoolean("showsStrokeOrder"));
super.readAdditionalSaveData(tag); super.readAdditionalSaveData(tag);
this.setDirection(this.direction); this.setDirection(this.direction);
this.loadDataFromScrollItem(scroll); this.loadDataFromScrollItem(scroll);

View file

@ -27,6 +27,8 @@ public class HexSounds {
public static final RegistryObject<SoundEvent> SPELL_CIRCLE_FAIL = sound("spellcircle.fail"); public static final RegistryObject<SoundEvent> SPELL_CIRCLE_FAIL = sound("spellcircle.fail");
public static final RegistryObject<SoundEvent> SPELL_CIRCLE_CAST = sound("spellcircle.cast"); public static final RegistryObject<SoundEvent> SPELL_CIRCLE_CAST = sound("spellcircle.cast");
public static final RegistryObject<SoundEvent> DUST_SCROLL = sound("scroll.dust");
private static RegistryObject<SoundEvent> sound(String name) { private static RegistryObject<SoundEvent> sound(String name) {
return SOUNDS.register(name, () -> new SoundEvent(prefix(name))); return SOUNDS.register(name, () -> new SoundEvent(prefix(name)));
} }

View file

@ -239,6 +239,7 @@
"hexcasting.subtitles.spellcircle.add_pattern": "Spell circle crackles", "hexcasting.subtitles.spellcircle.add_pattern": "Spell circle crackles",
"hexcasting.subtitles.spellcircle.fail": "Spell circle fizzles out", "hexcasting.subtitles.spellcircle.fail": "Spell circle fizzles out",
"hexcasting.subtitles.spellcircle.cast": "Spell circle casts", "hexcasting.subtitles.spellcircle.cast": "Spell circle casts",
"hexcasting.subtitles.scroll.dust": "Scroll covers with dust",
"hexcasting.landing": "I seem to have discovered a new method of magical arts, in which one draws patterns strange and wild onto a hexagonal grid. It fascinates me. I've decided to start a journal of my thoughts and findings.$(br2)$(l:https://discord.gg/4xxHGYteWk)Discord Server Link/$", "hexcasting.landing": "I seem to have discovered a new method of magical arts, in which one draws patterns strange and wild onto a hexagonal grid. It fascinates me. I've decided to start a journal of my thoughts and findings.$(br2)$(l:https://discord.gg/4xxHGYteWk)Discord Server Link/$",
@ -372,7 +373,7 @@
"hexcasting.page.spellbook.2": "$(italic)Wizards love words. Most of them read a great deal, and indeed one strong sign of a potential wizard is the inability to get to sleep without reading something first.", "hexcasting.page.spellbook.2": "$(italic)Wizards love words. Most of them read a great deal, and indeed one strong sign of a potential wizard is the inability to get to sleep without reading something first.",
"hexcasting.entry.scroll": "Scrolls", "hexcasting.entry.scroll": "Scrolls",
"hexcasting.page.scroll.1": "A $(item)Scroll/$ is a convenient method of sharing a pattern with others. I can copy a pattern onto one with $(l:patterns/readwrite#hexcasting:write)Scribe's Gambit/$, after which it will display in a tooltip.$(br2)I can also place them on the wall as decoration, like a Painting.", "hexcasting.page.scroll.1": "A $(item)Scroll/$ is a convenient method of sharing a pattern with others. I can copy a pattern onto one with $(l:patterns/readwrite#hexcasting:write)$(action)Scribe's Gambit/$, after which it will display in a tooltip.$(br2)I can also place them on the wall as decoration, like a Painting. Using $(item)Amethyst Dust/$ on such a scroll will have it display the stroke order.",
"hexcasting.page.scroll.2": "In addition, I can also find so-called $(item)Ancient Scrolls/$ in the dungeons and strongholds of the world. These contain the stroke order of Great Spells, powerful magicks rumored to be too powerful for the hands and minds of mortals...$(br2)If those \"mortals\" couldn't cast them, I'm not sure they deserve to know them.", "hexcasting.page.scroll.2": "In addition, I can also find so-called $(item)Ancient Scrolls/$ in the dungeons and strongholds of the world. These contain the stroke order of Great Spells, powerful magicks rumored to be too powerful for the hands and minds of mortals...$(br2)If those \"mortals\" couldn't cast them, I'm not sure they deserve to know them.",
"hexcasting.page.scroll.3": "$(italic)I write upon clean white parchment with a sharp quill and the blood of my students, divining their secrets./$", "hexcasting.page.scroll.3": "$(italic)I write upon clean white parchment with a sharp quill and the blood of my students, divining their secrets./$",
@ -430,7 +431,7 @@
"hexcasting.page.spellcircles.5": "However, a spell cast from a circle does have one major limitation: it is unable to affect anything outside of the circle's bounds. That is, it cannot interact with anything outside of the cuboid of minimum size which encloses every block composing it (so a concave spell circle can still affect things in the concavity).", "hexcasting.page.spellcircles.5": "However, a spell cast from a circle does have one major limitation: it is unable to affect anything outside of the circle's bounds. That is, it cannot interact with anything outside of the cuboid of minimum size which encloses every block composing it (so a concave spell circle can still affect things in the concavity).",
"hexcasting.page.spellcircles.6": "There is also a limit on the number of blocks the wave can travel through before it disintegrates, but it is large enough I doubt I will have any trouble.$(br2)Conversely, there are some actions that can only be cast from a circle. Fortunately, none of them are spells; they all seem to deal with components of the circle itself. My notes on the subject are $(l:patterns/circle)here/$.", "hexcasting.page.spellcircles.6": "There is also a limit on the number of blocks the wave can travel through before it disintegrates, but it is large enough I doubt I will have any trouble.$(br2)Conversely, there are some actions that can only be cast from a circle. Fortunately, none of them are spells; they all seem to deal with components of the circle itself. My notes on the subject are $(l:patterns/circle)here/$.",
"hexcasting.page.spellcircles.7": "I also found a sketch of a spell circle used by the ancients buried in my notes. Facing this page is my (admittedly poor) copy of it.$(br2)The patterns there would have been executed counter-clockwise, starting with $(action)Mind's Reflection/$ and ending with $(action)Greater Teleport/$.", "hexcasting.page.spellcircles.7": "I also found a sketch of a spell circle used by the ancients buried in my notes. Facing this page is my (admittedly poor) copy of it.$(br2)The patterns there would have been executed counter-clockwise, starting with $(action)Mind's Reflection/$ and ending with $(action)Greater Teleport/$.",
"hexcasting.page.spellcircles.8.title": "Teleportation Circle", "hexcasting.page.spellcircles.8.title": "Teleportation Circle",
"hexcasting.entry.impetus": "Impetuses", "hexcasting.entry.impetus": "Impetuses",
"hexcasting.page.impetus.1": "The fluctuation of _media required to actuate a spell circle is complex. Even the mortal with sharpest eyes and steadiest hands could not serve as an $(item)Impetus/$ and weave _media into the self-sustaining ourobouros required.$(br2)The problem is that the mind is too full of other useless $(italics)garbage/$.", "hexcasting.page.impetus.1": "The fluctuation of _media required to actuate a spell circle is complex. Even the mortal with sharpest eyes and steadiest hands could not serve as an $(item)Impetus/$ and weave _media into the self-sustaining ourobouros required.$(br2)The problem is that the mind is too full of other useless $(italics)garbage/$.",
@ -554,7 +555,7 @@
"hexcasting.page.patterns_as_iotas.6": "If I draw another $(action)Introspection/$, it'll still be saved to the list, but I'll then have to draw $(italic)two/$ $(action)Retrospection/$s to get back to normal casting.", "hexcasting.page.patterns_as_iotas.6": "If I draw another $(action)Introspection/$, it'll still be saved to the list, but I'll then have to draw $(italic)two/$ $(action)Retrospection/$s to get back to normal casting.",
"hexcasting.page.patterns_as_iotas.7": "Also, I can escape the special behavior of $(action)Intro-/$ and $(action)Retrospection/$ by drawing a $(action)Consideration/$ before them, which will simply add them to the list without affecting which the number of Retrospections I need to return to casting.$(br2)If I draw two $(action)Consideration/$s in a row while introspecting, it will add a single $(action)Consideration/$ to the list.", "hexcasting.page.patterns_as_iotas.7": "Also, I can escape the special behavior of $(action)Intro-/$ and $(action)Retrospection/$ by drawing a $(action)Consideration/$ before them, which will simply add them to the list without affecting which the number of Retrospections I need to return to casting.$(br2)If I draw two $(action)Consideration/$s in a row while introspecting, it will add a single $(action)Consideration/$ to the list.",
"hexcasting.entry.readwrite": "Reading and Writing", "hexcasting.entry.readwrite": "Reading and Writing",
"hexcasting.page.readwrite.1": "Copy the iota stored in the item (such as a $(l:items/focus)$(item)Focus/$, $(l:items/abacus)$(item)Abacus/$ or $(l:items/spellbook)$(item)Spellbook/$) in my other hand, and add it to the stack.", "hexcasting.page.readwrite.1": "Copy the iota stored in the item (such as a $(l:items/focus)$(item)Focus/$, $(l:items/abacus)$(item)Abacus/$ or $(l:items/spellbook)$(item)Spellbook/$) in my other hand, and add it to the stack.",
"hexcasting.page.readwrite.2": "Like $(action)Scribe's Reflection/$, but the iota is read out of an item entity instead of my other hand.", "hexcasting.page.readwrite.2": "Like $(action)Scribe's Reflection/$, but the iota is read out of an item entity instead of my other hand.",
"hexcasting.page.readwrite.3": "Remove the top iota from the stack, and save it into the item in my other hand.", "hexcasting.page.readwrite.3": "Remove the top iota from the stack, and save it into the item in my other hand.",

View file

@ -82,5 +82,15 @@
"hexcasting:cast_hex" "hexcasting:cast_hex"
], ],
"subtitle": "hexcasting.subtitles.spellcircle.cast" "subtitle": "hexcasting.subtitles.spellcircle.cast"
},
"scroll.dust": {
"sounds": [
"minecraft:dig/sand1",
"minecraft:dig/sand2",
"minecraft:dig/sand3",
"minecraft:dig/sand4"
],
"subtitle": "hexcasting.subtitles.scroll.dust"
} }
} }