Skip to content

Commit

Permalink
Cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Feb 22, 2024
1 parent 673f7f5 commit 8d0db26
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ class OpConjureStaff : SpellAction {

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 battery = args.getInt(1, argc)
val rank = 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)))
return Triple(Spell(position, battery, rank, instructions), battery + MediaConstants.CRYSTAL_UNIT + MediaConstants.SHARD_UNIT * rank, listOf(ParticleSpray.burst(position, 1.0)))
}

private data class Spell(val position: Vec3d, val media: Int, val inputLength: Int, val instructions: List<Iota>) : RenderedSpell {
private data class Spell(val position: Vec3d, val battery: Int, val rank: Int, val instructions: List<Iota>) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val stack = ItemStack(HexicalItems.CONJURED_STAFF_ITEM, 1)
stack.orCreateNbt.putInt("length", inputLength)
stack.orCreateNbt.putInt("rank", rank)
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(stack)
hexHolder?.writeHex(instructions, media)
hexHolder?.writeHex(instructions, battery)
ctx.world.spawnEntity(ItemEntity(ctx.world, position.x, position.y, position.z, stack))
}
}
Expand Down
14 changes: 3 additions & 11 deletions common/src/main/java/miyucomics/hexical/items/ConjuredStaffItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@ 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));
}
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,40 @@

@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
@Unique private static final int COOLDOWN = 10;
@Unique private int timer = 0;
@Unique private static final int hexical$COOLDOWN = 20;
@Unique private final List<Boolean> hexical$clicks = new ArrayList<>();
@Unique private int hexical$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();
if (hexical$timer < 0) {
player.world.playSound(player, player.getX(), player.getY(), player.getZ(), HexSounds.FAIL_PATTERN, SoundCategory.PLAYERS, 1f, 1f);
hexical$clicks.clear();
return;
}
timer--;
hexical$timer--;

if (!(player.getMainHandStack().getItem() instanceof ConjuredStaffItem))
return;

int neededLength = player.getMainHandStack().getOrCreateNbt().getInt("length");
int neededLength = player.getMainHandStack().getOrCreateNbt().getInt("rank");
if (neededLength == 0)
return;

if (clicks.size() == neededLength) {
timer = 0;
if (hexical$clicks.size() == neededLength) {
hexical$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));
buf.writeBoolean(hexical$clicks.get(i));
NetworkManager.sendToServer(Hexical.CAST_CONJURED_STAFF_PACKET, buf);

clicks.clear();
hexical$clicks.clear();
}
}

Expand All @@ -64,8 +65,8 @@ public void onLeftClick(CallbackInfo info) {
if (player == null || player.isSpectator())
return;
if (player.getMainHandStack().getItem() instanceof ConjuredStaffItem) {
timer = COOLDOWN;
clicks.add(false);
hexical$timer = hexical$COOLDOWN;
hexical$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();
Expand All @@ -77,8 +78,8 @@ public void onRightClick(CallbackInfo info) {
if (player == null || player.isSpectator())
return;
if (player.getMainHandStack().getItem() instanceof ConjuredStaffItem) {
timer = COOLDOWN;
clicks.add(true);
hexical$timer = hexical$COOLDOWN;
hexical$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();
Expand Down

0 comments on commit 8d0db26

Please sign in to comment.