This commit is contained in:
gamma-delta 2022-06-09 20:32:39 -05:00
commit 6109fffc32
21 changed files with 91 additions and 56 deletions

View file

@ -1,7 +1,6 @@
package at.petrak.hexcasting.api.misc;
import at.petrak.hexcasting.api.addldata.Colorizer;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer;
import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
@ -45,7 +44,7 @@ public record FrozenColorizer(ItemStack item, UUID owner) {
public CompoundTag serializeToNBT() {
var out = new CompoundTag();
out.put(TAG_STACK, HexUtils.serializeToNBT(this.item));
out.put(TAG_STACK, this.item.save(new CompoundTag()));
out.putUUID(TAG_OWNER, this.owner);
return out;
}

View file

@ -159,7 +159,7 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
SpellDatum(SpellList.fromNBT(nbt.getList(key, Tag.TAG_COMPOUND), world))
}
TAG_WIDGET -> {
SpellDatum(Widget.valueOf(nbt.getString(key)))
SpellDatum(Widget.fromString(nbt.getString(key)))
}
TAG_PATTERN -> {
SpellDatum(HexPattern.fromNBT(nbt.getCompound(TAG_PATTERN)))
@ -214,7 +214,8 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
out += "]".white
}
TAG_WIDGET -> {
val widget = Widget.valueOf(nbt.getString(key))
val widget = Widget.fromString(nbt.getString(key))
out += if (widget == Widget.GARBAGE)
"arimfexendrapuse".darkGray.obfuscated
else

View file

@ -1,6 +1,7 @@
package at.petrak.hexcasting.api.spell
import at.petrak.hexcasting.api.spell.casting.CastingContext
import java.util.*
/**
* Miscellaneous spell datums used as markers, etc.
@ -17,4 +18,12 @@ enum class Widget : ConstManaOperator {
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> =
this.asSpellResult
companion object {
@JvmStatic
fun fromString(key: String): Widget {
val lowercaseKey = key.lowercase(Locale.ROOT)
return values().firstOrNull { it.name.lowercase(Locale.ROOT) == lowercaseKey } ?: GARBAGE
}
}
}

View file

@ -20,11 +20,7 @@ data class ResolvedPattern(val pattern: HexPattern, val origin: HexCoord, var ty
fun fromNBT(tag: CompoundTag): ResolvedPattern {
val pattern = HexPattern.fromNBT(tag.getCompound("Pattern"))
val origin = HexCoord(tag.getInt("OriginQ"), tag.getInt("OriginR"))
val valid = try {
ResolvedPatternType.valueOf(tag.getString("Valid").uppercase(Locale.ROOT))
} catch (e: IllegalArgumentException) {
ResolvedPatternType.UNRESOLVED
}
val valid = ResolvedPatternType.fromString(tag.getString("Valid"))
return ResolvedPattern(pattern, origin, valid)
}
}

View file

@ -1,9 +1,19 @@
package at.petrak.hexcasting.api.spell.casting
import java.util.*
enum class ResolvedPatternType(val color: Int, val fadeColor: Int, val success: Boolean) {
UNRESOLVED(0x7f7f7f, 0xcccccc, false),
EVALUATED(0x7385de, 0xfecbe6, true),
ESCAPED(0xddcc73, 0xfffae5, true),
ERRORED(0xde6262, 0xffc7a0, false),
INVALID(0xb26b6b, 0xcca88e, false)
INVALID(0xb26b6b, 0xcca88e, false);
companion object {
@JvmStatic
fun fromString(key: String): ResolvedPatternType {
val lowercaseKey = key.lowercase(Locale.ROOT)
return values().firstOrNull { it.name.lowercase(Locale.ROOT) == lowercaseKey } ?: UNRESOLVED
}
}
}

View file

@ -1,5 +1,7 @@
package at.petrak.hexcasting.api.spell.math
import java.util.*
enum class HexDir {
NORTH_EAST, EAST, SOUTH_EAST, SOUTH_WEST, WEST, NORTH_WEST;
@ -22,4 +24,12 @@ enum class HexDir {
WEST -> HexCoord(-1, 0)
NORTH_WEST -> HexCoord(0, -1)
}
companion object {
@JvmStatic
fun fromString(key: String): HexDir {
val lowercaseKey = key.lowercase(Locale.ROOT)
return values().firstOrNull { it.name.lowercase(Locale.ROOT) == lowercaseKey } ?: WEST
}
}
}

View file

@ -1,28 +1,23 @@
package at.petrak.hexcasting.client;
import net.minecraft.client.Minecraft;
public class ClientTickCounter {
public static long ticksInGame = 0L;
public static float partialTicks = 0.0F;
public static float delta = 0.0F;
public static float total = 0.0F;
public static float getTotal() {
return (float)ticksInGame + partialTicks;
}
public static void renderTickStart(float renderTickTime) {
partialTicks = renderTickTime;
}
public static void renderTickEnd() {
calcDelta();
}
public static void clientTickEnd() {
if (!Minecraft.getInstance().isPaused()) {
++ticksInGame;
partialTicks = 0.0F;
calcDelta();
}
private static void calcDelta() {
float oldTotal = total;
total = (float)ticksInGame + partialTicks;
delta = total - oldTotal;
}
}
}

View file

@ -60,7 +60,7 @@ public class HexAdditionalRenderers {
sentinel.position().y - playerPos.y,
sentinel.position().z - playerPos.z);
var time = ClientTickCounter.total / 2;
var time = ClientTickCounter.getTotal() / 2;
var bobSpeed = 1f / 20;
var magnitude = 0.1f;
ps.translate(0, Mth.sin(bobSpeed * time) * magnitude, 0);

View file

@ -185,7 +185,7 @@ fun makeZappy(points: List<Vec2>, hops: Int, variance: Float, speed: Float, flow
return emptyList()
}
val scaleVariance = { it: Double -> 1.0.coerceAtMost(8 * (0.5 - abs(0.5 - it))) }
val zSeed = ClientTickCounter.total.toDouble() * speed
val zSeed = ClientTickCounter.getTotal().toDouble() * speed
// Create our output list of zap points
val zappyPts = mutableListOf(points[0])
// For each segment in the original...

View file

@ -77,7 +77,7 @@ public class PatternTooltipGreeble implements ClientTooltipComponent, TooltipCom
outer, outer, null);
RenderLib.drawLineSeq(mat, this.zappyPoints, 2f, 0,
innerDark, innerLight,
ClientTickCounter.total / 40f);
ClientTickCounter.getTotal() / 40f);
RenderLib.drawSpot(mat, this.zappyPoints.get(0), 2.5f, 1f, 0.1f, 0.15f, 0.6f);
for (var dot : this.pathfinderDots) {

View file

@ -33,13 +33,11 @@ public class ConjureParticle extends TextureSheetParticle {
this.quadSize *= light ? 0.9f : 0.75f;
this.setParticleSpeed(dx, dy, dz);
var lightness = light ? 0.3f : 1.0f;
var r = FastColor.ARGB32.red(color);
var g = FastColor.ARGB32.green(color);
var b = FastColor.ARGB32.blue(color);
var a = FastColor.ARGB32.alpha(color);
this.setColor(r / 255f * lightness, g / 255f * lightness, b / 255f * lightness);
this.setAlpha(a / 255f * lightness);
this.setColor(r / 255f, g / 255f, b / 255f);
this.setAlpha(light ? 0.3f : 1.0f);
this.friction = 0.96F;
this.gravity = light && dy != 0 && dx != 0 && dz != 0 ? -0.01F : 0F;
@ -63,6 +61,7 @@ public class ConjureParticle extends TextureSheetParticle {
this.setSpriteFromAge(this.sprites);
this.alpha = 1.0f - ((float) this.age / (float) this.lifetime);
if (light) {
this.alpha *= 0.3f;
this.quadSize *= 0.96f;
}
}

View file

@ -73,7 +73,6 @@ public class BlockEntityConjured extends HexBlockEntity {
}
public void landParticle(Entity entity, int number) {
if (getBlockState().getBlock() instanceof BlockConjuredLight) {
for (int i = 0; i < number * 2; i++) {
int color = this.colorizer.getColor(entity.tickCount, entity.position()
.add(new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale(
@ -86,7 +85,6 @@ public class BlockEntityConjured extends HexBlockEntity {
0.0, 0.0, 0.0);
}
}
}
@Override
protected void saveModData(CompoundTag tag) {

View file

@ -34,7 +34,7 @@ public class ManualPatternComponent extends AbstractPatternComponent {
JsonElement json = ivar.unwrap();
RawPattern raw = new Gson().fromJson(json, RawPattern.class);
var dir = HexDir.valueOf(raw.startdir);
var dir = HexDir.fromString(raw.startdir);
var pat = HexPattern.fromAngles(raw.signature, dir);
var origin = new HexCoord(raw.q, raw.r);
out.add(new Pair<>(pat, origin));

View file

@ -31,7 +31,6 @@ object FabricHexClientInitializer : ClientModInitializer {
}
HudRenderCallback.EVENT.register(HexAdditionalRenderers::overlayGui)
WorldRenderEvents.START.register { ClientTickCounter.renderTickStart(it.tickDelta()) }
WorldRenderEvents.END.register { ClientTickCounter.renderTickEnd() }
ClientTickEvents.END_CLIENT_TICK.register { ClientTickCounter.clientTickEnd() }
MouseScrollCallback.EVENT.register(ShiftScrollListener::onScroll)

View file

@ -3,7 +3,6 @@ package at.petrak.hexcasting.fabric.event;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.npc.Villager;
// https://fabricmc.net/wiki/tutorial:events
@ -20,5 +19,5 @@ public interface VillagerConversionCallback {
}
});
void interact(Villager original, LivingEntity outcome);
void interact(LivingEntity original, LivingEntity outcome);
}

View file

@ -164,7 +164,7 @@ public class VillagerEmiStack extends EmiStack {
RenderSystem.enableBlend();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
renderEntity(poseStack, villager, level, x + 8, y + 16, ClientTickCounter.total, 8, 0,
renderEntity(poseStack, villager, level, x + 8, y + 16, ClientTickCounter.getTotal(), 8, 0,
mindless ? (it) -> new FakeBufferSource(it, HexRenderTypes::getGrayscaleLayer) : it -> it);
}
}

View file

@ -38,7 +38,7 @@ public class VillagerWidget extends Widget {
RenderSystem.enableBlend();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
renderEntity(poseStack, displayVillager, level, 50 + x, 62.5f + y, ClientTickCounter.total, 20, 0);
renderEntity(poseStack, displayVillager, level, 50 + x, 62.5f + y, ClientTickCounter.getTotal(), 20, 0);
}
if (isMouseOver(mouseX, mouseY))

View file

@ -0,0 +1,21 @@
package at.petrak.hexcasting.fabric.mixin;
import at.petrak.hexcasting.fabric.event.VillagerConversionCallback;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(Mob.class)
public class FabricMobMixin {
@Inject(method = "convertTo", at = @At("RETURN"))
public <T extends Mob> void onThunderHit(EntityType<T> entityType, boolean bl, CallbackInfoReturnable<T> cir) {
var self = (Mob) (Object) this;
var mob = cir.getReturnValue();
if (mob != null) {
VillagerConversionCallback.EVENT.invoker().interact(self, mob);
}
}
}

View file

@ -10,12 +10,13 @@
"FabricEnchantmentTableBlockMixin",
"FabricItemEntityMixin",
"FabricLivingEntityMixin",
"FabricVillagerTurnIntoWitchMixin"
"FabricVillagerTurnIntoWitchMixin",
"FabricMobMixin"
],
"client": [
"client.FabricAbstractTextureMixin",
"client.FabricMixinGameRenderer",
"client.FabricMouseHandlerMixin",
"client.FabricParticleEngineMixin",
"client.FabricMixinGameRenderer"
"client.FabricParticleEngineMixin"
]
}

View file

@ -34,8 +34,6 @@ public class ForgeHexClientInitializer {
evBus.addListener((TickEvent.RenderTickEvent e) -> {
if (e.phase == TickEvent.Phase.START) {
ClientTickCounter.renderTickStart(e.renderTickTime);
} else {
ClientTickCounter.renderTickEnd();
}
});

View file

@ -82,7 +82,7 @@ public class BrainsweepRecipeCategory implements IRecipeCategory<BrainsweepRecip
RenderSystem.enableBlend();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
renderEntity(stack, villager, level, 50, 62.5f, ClientTickCounter.total, 20, 0);
renderEntity(stack, villager, level, 50, 62.5f, ClientTickCounter.getTotal(), 20, 0);
}
}