Skip to content

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Feb 23, 2024
1 parent 21077f7 commit 2e479e0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
13 changes: 6 additions & 7 deletions common/src/main/java/miyucomics/hexical/Hexical.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ public static void init() {

NetworkManager.registerReceiver(NetworkManager.Side.C2S, CAST_CONJURED_STAFF_PACKET, (buf, context) -> {
PlayerEntity player = context.getPlayer();
ItemStack stack = player.getMainHandStack();
if (stack.getItem() instanceof ConjuredStaffItem) {
int size = buf.readInt();
List<Iota> initStack = new ArrayList<>();
for (int i = 0; i < size; i++)
initStack.add(new BooleanIota(buf.readBoolean()));
((ConjuredStaffItem) stack.getItem()).cast(context.getPlayer().world, player, stack, initStack);
ItemStack itemInHand = player.getMainHandStack();
if (itemInHand.getItem() instanceof ConjuredStaffItem) {
List<Iota> stack = new ArrayList<>();
for (int i = 0; i < buf.readInt(); i++)
stack.add(new BooleanIota(buf.readBoolean()));
((ConjuredStaffItem) itemInHand.getItem()).cast(context.getPlayer().world, player, itemInHand, stack);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import net.minecraft.text.Text
import net.minecraft.util.DyeColor
import net.minecraft.util.Hand

class MishapNeedLamp() : Mishap() {
class MishapNeedLamp : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer = dyeColor(DyeColor.RED)
override fun particleSpray(ctx: CastingContext) = ParticleSpray.burst(ctx.caster.pos, 1.0)
override fun errorMessage(ctx: CastingContext, errorCtx: Context): Text = error(Hexical.MOD_ID + ":needs_lamp")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ class ConjuredStaffItem : ItemPackagedHex(Settings().maxCount(1)) {
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>) {
fun cast(world: World, user: LivingEntity, stack: ItemStack, castStack: 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.stack = castStack
harness.executeIotas(hex, world)
}
}
2 changes: 0 additions & 2 deletions common/src/main/java/miyucomics/hexical/items/LampItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class LampItem : ItemPackagedHex(Settings()) {
override fun use(world: World, player: PlayerEntity, usedHand: Hand): TypedActionResult<ItemStack> {
val stack = player.getStackInHand(usedHand)
if (!hasHex(stack)) return TypedActionResult.fail(stack)

if (!world.isClient) {
stack.nbt?.putLongArray("startPosition", player.eyePos.serializeToNBT().longArray);
stack.nbt?.putLongArray("startRotation", player.rotationVector.serializeToNBT().longArray);
Expand All @@ -32,7 +31,6 @@ class LampItem : ItemPackagedHex(Settings()) {
override fun usageTick(world: World, user: LivingEntity, stack: ItemStack, remainingUseTicks: Int) {
if (world.isClient) return
if (getMedia(stack) == 0) return

val hex = getHex(stack, world as ServerWorld) ?: return
val harness = CastingHarness(CastingContext((user as ServerPlayerEntity), user.getActiveHand(), CastingContext.CastSource.PACKAGED_HEX))
harness.executeIotas(hex, world)
Expand Down

0 comments on commit 2e479e0

Please sign in to comment.