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./$",

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"
} }
} }