Skip to content

Commit

Permalink
Lamp mishap detection improvement!
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Mar 8, 2024
1 parent ccfb525 commit 3331f41
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
3 changes: 1 addition & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
modCompileOnly "at.petra-k.paucal:paucal-common-$minecraftVersion:$paucalVersion"
implementation("at.petra-k.hexcasting:hexcasting-fabric-$minecraftVersion:$hexcastingVersion") {
modCompileOnly("at.petra-k.hexcasting:hexcasting-fabric-$minecraftVersion:$hexcastingVersion") {
exclude module: "phosphor"
exclude module: "emi"
}
modCompileOnly "vazkii.patchouli:Patchouli-xplat:$minecraftVersion-$patchouliVersion"
compileOnly(annotationProcessor("com.github.llamalad7.mixinextras:mixinextras-common:${mixinExtrasVersion}"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package miyucomics.hexical.interfaces;

public interface PlayerEntityMixinInterface {
boolean getArchLampCastedThisTick();
void lampCastedThisTick();
}
28 changes: 15 additions & 13 deletions common/src/main/java/miyucomics/hexical/items/ArchLampItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package miyucomics.hexical.items
import at.petrak.hexcasting.api.spell.iota.NullIota
import at.petrak.hexcasting.common.items.magic.ItemPackagedHex
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes
import miyucomics.hexical.interfaces.PlayerEntityMixinInterface
import miyucomics.hexical.persistent_state.PersistentStateHandler
import miyucomics.hexical.registry.HexicalItems
import miyucomics.hexical.registry.HexicalSounds
Expand All @@ -22,7 +23,6 @@ class ArchLampItem : ItemPackagedHex(Settings().maxCount(1)) {
val stack = user.getStackInHand(usedHand)
if (!hasHex(stack)) return TypedActionResult.fail(stack)


val stackNbt = stack.orCreateNbt
if (!stackNbt.contains("active"))
stackNbt.putBoolean("active", false)
Expand All @@ -32,21 +32,13 @@ class ArchLampItem : ItemPackagedHex(Settings().maxCount(1)) {
return TypedActionResult.success(stack)
}

val currentlyUsingArchLamp = CastingUtils.doesPlayerHaveActiveArchLamp(user as ServerPlayerEntity)
if (currentlyUsingArchLamp) {
if (stackNbt.getBoolean("active")) {
stackNbt.putBoolean("active", false)
return TypedActionResult.success(stack)
} else {
for (slot in user.inventory.main)
if (slot.item == HexicalItems.ARCH_LAMP_ITEM)
slot.orCreateNbt.putBoolean("active", false)
user.getItemCooldownManager()[this] = 100
return TypedActionResult.fail(stack)
}
if (stackNbt.getBoolean("active")) {
stackNbt.putBoolean("active", false)
return TypedActionResult.success(stack)
}

stackNbt.putBoolean("active", true)

val state = PersistentStateHandler.getPlayerState(user)
state.position = user.eyePos
state.rotation = user.rotationVector
Expand All @@ -62,7 +54,17 @@ class ArchLampItem : ItemPackagedHex(Settings().maxCount(1)) {
if (getMedia(stack) == 0) return
if (user !is ServerPlayerEntity) return
if (!stack.orCreateNbt.getBoolean("active")) return

if ((user as PlayerEntityMixinInterface).archLampCastedThisTick) {
for (itemSlot in user.inventory.main)
if (itemSlot.item == HexicalItems.ARCH_LAMP_ITEM)
itemSlot.orCreateNbt.putBoolean("active", false)
user.itemCooldownManager[this] = 100
return
}

CastingUtils.castInvisibly(world as ServerWorld, user, getHex(stack, world) ?: return, true)
(user as PlayerEntityMixinInterface).lampCastedThisTick()
if (getMedia(stack) == 0)
user.inventory.setStack(slot, ItemStack(HexicalItems.LAMP_ITEM))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package miyucomics.hexical.mixin;

import miyucomics.hexical.interfaces.PlayerEntityMixinInterface;
import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerEntity.class)
public class PlayerEntityMixin implements PlayerEntityMixinInterface {
@Unique private boolean hexical$archLampCastedThisTick = false;

@Override public boolean getArchLampCastedThisTick() {
return hexical$archLampCastedThisTick;
}

@Override public void lampCastedThisTick() {
hexical$archLampCastedThisTick = true;
}

@Inject(method = "tick", at = @At("TAIL"))
void tick(CallbackInfo ci) {
hexical$archLampCastedThisTick = false;
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/hexical-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"CastingContextMixin",
"CastingHarnessMixin",
"ItemAbacusMixin",
"PlayerEntityMixin",
"WanderingTraderEntityMixin"
],
"injectors": {
Expand Down

0 comments on commit 3331f41

Please sign in to comment.