Skip to content

Commit 5550ba3

Browse files
committed
Rework hallucination rate to briefly spike after adding/triggering a mind
1 parent 28ffbe5 commit 5550ba3

File tree

9 files changed

+48
-7
lines changed

9 files changed

+48
-7
lines changed

common/src/main/java/robotgiggle/hierophantics/HierophanticsClient.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import robotgiggle.hierophantics.inits.HierophanticsConfig.GlobalConfig
1616
import me.shedaniel.autoconfig.AutoConfig
1717

1818
object HierophanticsClient {
19-
@JvmStatic
19+
@JvmField
2020
var clientOwnedMinds = 0;
21+
22+
var scalingTimestamp = 0L;
2123

2224
fun init() {
2325
HierophanticsConfig.initClient()
@@ -27,6 +29,18 @@ object HierophanticsClient {
2729
return AutoConfig.getConfigScreen(GlobalConfig::class.java, parent).get()
2830
}
2931

32+
@JvmStatic
33+
fun setHallucinationScaling(strength: Double) {
34+
scalingTimestamp = ClientTickCounter.ticksInGame + (2000*strength).toInt()
35+
}
36+
37+
@JvmStatic
38+
fun getHallucinationScaling(): Double {
39+
// when the timestamp is in the future, hallucination rate is increased
40+
// as the current time approaches the timestamp, the rate scales back down
41+
return Math.max((scalingTimestamp - ClientTickCounter.ticksInGame)/2000.0, 0.4)
42+
}
43+
3044
@JvmStatic
3145
fun hallucinateItem(original: ItemStack): ItemStack {
3246
val config = HierophanticsConfig.client.itemHallucinations;
@@ -36,7 +50,10 @@ object HierophanticsClient {
3650
val rng = Math.abs((hash + timeScramble * (150 + (hash % 300))) % 10000);
3751

3852
// hallucinate emeralds due to embedded minds
39-
val emeraldChance = Math.min(config.baseEmeraldRate * clientOwnedMinds, config.maxEmeraldRate);
53+
val emeraldChance = Math.min(
54+
config.baseEmeraldRate * clientOwnedMinds * getHallucinationScaling(),
55+
config.maxEmeraldRate
56+
);
4057
if (rng < emeraldChance * 10000) {
4158
if (original.getItem() is BlockItem)
4259
return ItemStack(Items.EMERALD_BLOCK, original.getCount());

common/src/main/java/robotgiggle/hierophantics/blocks/FlayBedBlockEntity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import robotgiggle.hierophantics.inits.HierophanticsBlockEntities
4444
import robotgiggle.hierophantics.inits.BaseCriterion
4545
import robotgiggle.hierophantics.blocks.FlayBedBlock
4646
import robotgiggle.hierophantics.networking.msg.MsgOwnedMindsS2C
47+
import robotgiggle.hierophantics.networking.msg.MsgHallucinationTriggerS2C
4748

4849
import at.petrak.hexcasting.api.casting.ParticleSpray
4950
import at.petrak.hexcasting.api.pigment.FrozenPigment
@@ -85,6 +86,7 @@ class FlayBedBlockEntity(pos: BlockPos, state: BlockState) : BlockEntity(Hieroph
8586
val villagerName = sacrifice.getCustomName()?.getString()
8687
val newTotal = HieroServerState.getPlayerState(subject).addMind(world.server, villagerName)
8788
MsgOwnedMindsS2C(newTotal).sendToPlayer(subject)
89+
MsgHallucinationTriggerS2C(4.0).sendToPlayer(subject)
8890

8991
HierophanticsAdvancements.EMBED_MIND.trigger(subject)
9092

common/src/main/java/robotgiggle/hierophantics/data/HieroMind.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import robotgiggle.hierophantics.data.HieroServerState
1212
import robotgiggle.hierophantics.inits.HierophanticsSounds
1313
import robotgiggle.hierophantics.iotas.MishapThrowerIota
1414
import robotgiggle.hierophantics.iotas.TriggerIota.Trigger
15+
import robotgiggle.hierophantics.networking.msg.MsgHallucinationTriggerS2C
1516
import net.minecraft.nbt.NbtCompound
1617
import net.minecraft.server.network.ServerPlayerEntity
1718
import net.minecraft.util.Hand
@@ -43,6 +44,7 @@ class HieroMind(var hex: NbtCompound, var trigger: Trigger, var muted: Boolean)
4344
val sound = if (ecv.resolutionType.success) HierophanticsSounds.HIEROMIND_CAST.value else HexSounds.CAST_FAILURE
4445
player.getWorld().playSound(null, pos.x, pos.y, pos.z, sound, SoundCategory.PLAYERS, 1f, 1f)
4546
}
47+
MsgHallucinationTriggerS2C(2.8).sendToPlayer(player)
4648
}
4749
}
4850

common/src/main/java/robotgiggle/hierophantics/data/HieroPlayerState.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import at.petrak.hexcasting.api.utils.serializeToNBT
77
import at.petrak.hexcasting.api.utils.vecFromNBT
88
import at.petrak.hexcasting.api.casting.iota.Iota
99
import robotgiggle.hierophantics.Hierophantics
10-
import robotgiggle.hierophantics.networking.msg.MsgOwnedMindsS2C
1110
import net.minecraft.nbt.NbtCompound
1211
import net.minecraft.nbt.NbtElement
1312
import net.minecraft.nbt.NbtList

common/src/main/java/robotgiggle/hierophantics/inits/HierophanticsConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ object HierophanticsConfig {
8585

8686
class AudioHallucinations {
8787
@Tooltip
88-
val baseVillagerRate: Double = 0.00006
88+
val baseVillagerRate: Double = 0.0002
8989
@Tooltip
9090
val maxVillagerRate: Double = 0.004
9191
@Tooltip

common/src/main/java/robotgiggle/hierophantics/mixin/PlayerEntityMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void playVillagerHurtNoise(CallbackInfoReturnable<SoundEvent> ci) {
7272
if (ci.getReturnValue() == SoundEvents.ENTITY_PLAYER_HURT) {
7373
PlayerEntity player = (PlayerEntity) (Object) this;
7474
int minds = 0;
75-
if (player.getWorld().isClient()) minds = HierophanticsClient.getClientOwnedMinds();
75+
if (player.getWorld().isClient()) minds = HierophanticsClient.clientOwnedMinds;
7676
else minds = HieroServerState.getPlayerState(player).getOwnedMinds();
7777
if (player.getRandom().nextDouble() < 0.3 - 1.0/(minds + 3)) {
7878
ci.setReturnValue(SoundEvents.ENTITY_VILLAGER_HURT);

common/src/main/java/robotgiggle/hierophantics/mixin/client/AbstractClientPlayerEntityMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private void hallucinateAudio(CallbackInfo ci) {
3535

3636
// hallucinate villager nosies due to embedded minds
3737
double villagerChance = Math.min(
38-
config.getBaseVillagerRate() * HierophanticsClient.getClientOwnedMinds(),
38+
config.getBaseVillagerRate() * HierophanticsClient.clientOwnedMinds * HierophanticsClient.getHallucinationScaling(),
3939
config.getMaxVillagerRate()
4040
);
4141
if (rand.nextDouble() < villagerChance) {

common/src/main/java/robotgiggle/hierophantics/networking/handler/ClientMessageHandler.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ fun HierophanticsMessageS2C.applyOnClient(ctx: PacketContext) = ctx.queue {
1414
is MsgOwnedMindsS2C -> {
1515
HierophanticsClient.clientOwnedMinds = ownedMinds
1616
}
17-
// add more client-side message handlers here
17+
18+
is MsgHallucinationTriggerS2C -> {
19+
HierophanticsClient.setHallucinationScaling(strength)
20+
}
1821
}
1922
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package robotgiggle.hierophantics.networking.msg
2+
3+
import robotgiggle.hierophantics.inits.HierophanticsConfig
4+
import net.minecraft.network.PacketByteBuf
5+
6+
data class MsgHallucinationTriggerS2C(val strength: Double) : HierophanticsMessageS2C {
7+
companion object : HierophanticsMessageCompanion<MsgHallucinationTriggerS2C> {
8+
override val type = MsgHallucinationTriggerS2C::class.java
9+
10+
override fun decode(buf: PacketByteBuf) = MsgHallucinationTriggerS2C(
11+
strength = buf.readDouble()
12+
)
13+
14+
override fun MsgHallucinationTriggerS2C.encode(buf: PacketByteBuf) {
15+
buf.writeDouble(strength)
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)