-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
825a2e4
commit 673f7f5
Showing
11 changed files
with
200 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
common/src/main/java/miyucomics/hexical/casting/patterns/spells/OpConjureStaff.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package miyucomics.hexical.casting.patterns.spells | ||
|
||
import at.petrak.hexcasting.api.misc.MediaConstants | ||
import at.petrak.hexcasting.api.spell.* | ||
import at.petrak.hexcasting.api.spell.casting.CastingContext | ||
import at.petrak.hexcasting.api.spell.iota.Iota | ||
import at.petrak.hexcasting.xplat.IXplatAbstractions | ||
import miyucomics.hexical.registry.HexicalItems | ||
import net.minecraft.entity.ItemEntity | ||
import net.minecraft.item.ItemStack | ||
import net.minecraft.util.math.Vec3d | ||
|
||
class OpConjureStaff : SpellAction { | ||
override val argc = 4 | ||
|
||
override fun execute(args: List<Iota>, ctx: CastingContext): Triple<RenderedSpell, Int, List<ParticleSpray>> { | ||
val position = args.getVec3(0, argc) | ||
val media = args.getInt(1, argc) | ||
val inputLength = args.getPositiveInt(2, argc) | ||
val instructions = args.getList(3, argc).toList() | ||
return Triple(Spell(position, media, inputLength, instructions), media + MediaConstants.SHARD_UNIT, listOf(ParticleSpray.burst(position, 1.0))) | ||
} | ||
|
||
private data class Spell(val position: Vec3d, val media: Int, val inputLength: Int, val instructions: List<Iota>) : RenderedSpell { | ||
override fun cast(ctx: CastingContext) { | ||
val stack = ItemStack(HexicalItems.CONJURED_STAFF_ITEM, 1) | ||
stack.orCreateNbt.putInt("length", inputLength) | ||
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(stack) | ||
hexHolder?.writeHex(instructions, media) | ||
ctx.world.spawnEntity(ItemEntity(ctx.world, position.x, position.y, position.z, stack)) | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
common/src/main/java/miyucomics/hexical/items/ConjuredStaffItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package miyucomics.hexical.items | ||
|
||
import at.petrak.hexcasting.api.spell.casting.CastingContext | ||
import at.petrak.hexcasting.api.spell.casting.CastingHarness | ||
import at.petrak.hexcasting.api.spell.iota.Iota | ||
import at.petrak.hexcasting.common.items.magic.ItemPackagedHex | ||
import net.minecraft.entity.LivingEntity | ||
import net.minecraft.entity.player.PlayerEntity | ||
import net.minecraft.item.ItemStack | ||
import net.minecraft.server.network.ServerPlayerEntity | ||
import net.minecraft.server.world.ServerWorld | ||
import net.minecraft.util.Hand | ||
import net.minecraft.util.TypedActionResult | ||
import net.minecraft.world.World | ||
|
||
class ConjuredStaffItem : ItemPackagedHex(Settings().maxCount(1)) { | ||
override fun canDrawMediaFromInventory(stack: ItemStack?): Boolean { | ||
return false | ||
} | ||
|
||
override fun breakAfterDepletion(): Boolean { | ||
return true | ||
} | ||
|
||
override fun use(world: World?, player: PlayerEntity?, usedHand: Hand?): TypedActionResult<ItemStack> { | ||
return TypedActionResult.pass(player?.getStackInHand(usedHand)); | ||
} | ||
|
||
fun cast(world: World, user: LivingEntity, stack: ItemStack, initStack: MutableList<Iota>) { | ||
val hex = getHex(stack, world as ServerWorld) ?: return | ||
val harness = CastingHarness(CastingContext((user as ServerPlayerEntity), user.getActiveHand(), CastingContext.CastSource.PACKAGED_HEX)) | ||
harness.stack = initStack | ||
println(initStack) | ||
harness.executeIotas(hex, world) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
common/src/main/java/miyucomics/hexical/mixin/MinecraftClientMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package miyucomics.hexical.mixin; | ||
|
||
import at.petrak.hexcasting.common.lib.HexSounds; | ||
import dev.architectury.networking.NetworkManager; | ||
import io.netty.buffer.Unpooled; | ||
import miyucomics.hexical.Hexical; | ||
import miyucomics.hexical.items.ConjuredStaffItem; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.util.Hand; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
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; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Mixin(MinecraftClient.class) | ||
public class MinecraftClientMixin { | ||
@Unique private static final int COOLDOWN = 10; | ||
@Unique private int timer = 0; | ||
@Shadow @Nullable public ClientPlayerEntity player; | ||
@Unique private final List<Boolean> clicks = new ArrayList<>(); | ||
|
||
@Inject(method = "tick", at = @At("HEAD")) | ||
public void tick(CallbackInfo info) { | ||
if (player == null) | ||
return; | ||
if (timer < 0) { | ||
clicks.clear(); | ||
return; | ||
} | ||
timer--; | ||
|
||
if (!(player.getMainHandStack().getItem() instanceof ConjuredStaffItem)) | ||
return; | ||
|
||
int neededLength = player.getMainHandStack().getOrCreateNbt().getInt("length"); | ||
if (neededLength == 0) | ||
return; | ||
|
||
if (clicks.size() == neededLength) { | ||
timer = 0; | ||
player.world.playSound(player, player.getX(), player.getY(), player.getZ(), HexSounds.CAST_THOTH, SoundCategory.PLAYERS, 1f, 1f); | ||
|
||
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); | ||
buf.writeInt(neededLength); | ||
for (int i = 0; i < neededLength; i++) | ||
buf.writeBoolean(clicks.get(i)); | ||
NetworkManager.sendToServer(Hexical.CAST_CONJURED_STAFF_PACKET, buf); | ||
|
||
clicks.clear(); | ||
} | ||
} | ||
|
||
@Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;doAttack()Z", ordinal = 0), cancellable = true) | ||
public void onLeftClick(CallbackInfo info) { | ||
if (player == null || player.isSpectator()) | ||
return; | ||
if (player.getMainHandStack().getItem() instanceof ConjuredStaffItem) { | ||
timer = COOLDOWN; | ||
clicks.add(false); | ||
player.swingHand(Hand.MAIN_HAND); | ||
player.world.playSound(player, player.getX(), player.getY(), player.getZ(), HexSounds.SPELL_CIRCLE_CAST, SoundCategory.PLAYERS, 1f, 1f); | ||
info.cancel(); | ||
} | ||
} | ||
|
||
@Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;doItemUse()V", ordinal = 0), cancellable = true) | ||
public void onRightClick(CallbackInfo info) { | ||
if (player == null || player.isSpectator()) | ||
return; | ||
if (player.getMainHandStack().getItem() instanceof ConjuredStaffItem) { | ||
timer = COOLDOWN; | ||
clicks.add(true); | ||
player.swingHand(Hand.MAIN_HAND); | ||
player.world.playSound(player, player.getX(), player.getY(), player.getZ(), HexSounds.SPELL_CIRCLE_CAST, SoundCategory.PLAYERS, 1f, 1f); | ||
info.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/hexical/models/item/conjured_staff.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "hexical:item/conjured_staff" | ||
} | ||
} |
Binary file added
BIN
+357 Bytes
common/src/main/resources/assets/hexical/textures/item/conjured_staff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters