-
Notifications
You must be signed in to change notification settings - Fork 0
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
10b0df6
commit 283e7dd
Showing
53 changed files
with
800 additions
and
255 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
api/src/main/java/io/github/hiiragi283/mixin/EnchantmentHelperMixin.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,24 @@ | ||
package io.github.hiiragi283.mixin; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import io.github.hiiragi283.api.event.HTItemEvent; | ||
import net.minecraft.enchantment.EnchantmentHelper; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(EnchantmentHelper.class) | ||
public abstract class EnchantmentHelperMixin { | ||
|
||
@Redirect(method = { | ||
"calculateRequiredExperienceLevel", | ||
"generateEnchantments" | ||
}, at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getEnchantability()I")) | ||
private static int ht_api$getEnchantability(Item instance, @Local(argsOnly = true) ItemStack stack) { | ||
Integer enchantability = HTItemEvent.ENCHANTABILITY.invoker().getEnchantability(stack); | ||
return enchantability == null ? stack.getItem().getEnchantability() : enchantability; | ||
} | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
api/src/main/java/io/github/hiiragi283/mixin/PlayerEntityMixin.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,29 @@ | ||
package io.github.hiiragi283.mixin; | ||
|
||
import io.github.hiiragi283.api.event.HTPlayerEvents; | ||
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 abstract class PlayerEntityMixin { | ||
|
||
@Unique | ||
private PlayerEntity self() { | ||
return (PlayerEntity) (Object) this; | ||
} | ||
|
||
@Inject(method = "tick", at = @At("HEAD")) | ||
private void ht_api$startTick(CallbackInfo ci) { | ||
HTPlayerEvents.START_TICK.invoker().onStartTick(self()); | ||
} | ||
|
||
@Inject(method = "tick", at = @At("TAIL")) | ||
private void ht_api$endTick(CallbackInfo ci) { | ||
HTPlayerEvents.END_TICK.invoker().onEndTick(self()); | ||
} | ||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
api/src/main/kotlin/io/github/hiiragi283/api/effect/HTStatusEffect.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,9 @@ | ||
package io.github.hiiragi283.api.effect | ||
|
||
import net.minecraft.entity.effect.StatusEffect | ||
import net.minecraft.entity.effect.StatusEffectType | ||
import java.awt.Color | ||
|
||
class HTStatusEffect(type: StatusEffectType, color: Int) : StatusEffect(type, color) { | ||
constructor(type: StatusEffectType, color: Color) : this(type, color.rgb) | ||
} |
26 changes: 26 additions & 0 deletions
26
api/src/main/kotlin/io/github/hiiragi283/api/event/HTItemEvent.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,26 @@ | ||
package io.github.hiiragi283.api.event | ||
|
||
import net.fabricmc.fabric.api.event.Event | ||
import net.fabricmc.fabric.api.event.EventFactory | ||
import net.minecraft.item.ItemStack | ||
|
||
object HTItemEvent { | ||
|
||
@JvmField | ||
val ENCHANTABILITY: Event<CalculateEnchantability> = EventFactory.createArrayBacked(CalculateEnchantability::class.java) { listeners -> | ||
CalculateEnchantability { stack -> | ||
var ret: Int = stack.item.enchantability | ||
listeners.forEach { event -> | ||
event.getEnchantability(stack)?.let { ret = it } | ||
} | ||
ret | ||
} | ||
} | ||
|
||
// CalculateEnchantability // | ||
|
||
fun interface CalculateEnchantability { | ||
fun getEnchantability(stack: ItemStack): Int? | ||
} | ||
|
||
} |
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
64 changes: 64 additions & 0 deletions
64
api/src/main/kotlin/io/github/hiiragi283/api/extension/VariantContext.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,64 @@ | ||
package io.github.hiiragi283.api.extension | ||
|
||
import com.mojang.serialization.Codec | ||
import com.mojang.serialization.codecs.RecordCodecBuilder | ||
import io.github.hiiragi283.api.module.HTModuleType | ||
import io.github.hiiragi283.api.network.HTPacketCodec | ||
import io.github.hiiragi283.api.storage.HTSingleVariantStorage | ||
import io.github.hiiragi283.api.storage.HTStorageIO | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant | ||
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant | ||
import net.fabricmc.fabric.api.transfer.v1.storage.TransferVariant | ||
import net.minecraft.fluid.Fluid | ||
import net.minecraft.item.Item | ||
import net.minecraft.nbt.NbtCompound | ||
import net.minecraft.util.registry.Registry | ||
|
||
@Suppress("UnstableApiUsage") | ||
sealed class VariantContext<O : Any, T : TransferVariant<O>> private constructor( | ||
val key: String, | ||
val codec: Codec<T>, | ||
val packetCodec: HTPacketCodec<T>, | ||
val blank: () -> T, | ||
val simple: (O) -> T, | ||
val full: (O, NbtCompound) -> T, | ||
val storage: (HTStorageIO, Long) -> HTSingleVariantStorage<T>, | ||
) { | ||
data object ITEM : VariantContext<Item, ItemVariant>( | ||
"item", | ||
RecordCodecBuilder.create { instance -> | ||
instance.group( | ||
Registry.ITEM.fieldOf("item").forGetter(ItemVariant::getItem), | ||
NbtCompound.CODEC.orElse(NbtCompound()).fieldOf("nbt").forGetter(ItemVariant::getNbt), | ||
).apply(instance, ItemVariant::of) | ||
}, | ||
HTPacketCodec.createSimple( | ||
HTModuleType.API.id("variant/item"), | ||
ItemVariant::toPacket, | ||
ItemVariant::fromPacket, | ||
), | ||
ItemVariant::blank, | ||
ItemVariant::of, | ||
ItemVariant::of, | ||
HTSingleVariantStorage.Companion::ofItem, | ||
) | ||
|
||
data object FLUID : VariantContext<Fluid, FluidVariant>( | ||
"fluid", | ||
RecordCodecBuilder.create { instance -> | ||
instance.group( | ||
Registry.FLUID.fieldOf("fluid").forGetter(FluidVariant::getFluid), | ||
NbtCompound.CODEC.orElse(NbtCompound()).fieldOf("nbt").forGetter(FluidVariant::getNbt), | ||
).apply(instance, FluidVariant::of) | ||
}, | ||
HTPacketCodec.createSimple( | ||
HTModuleType.API.id("variant/fluid"), | ||
FluidVariant::toPacket, | ||
FluidVariant::fromPacket, | ||
), | ||
FluidVariant::blank, | ||
FluidVariant::of, | ||
FluidVariant::of, | ||
HTSingleVariantStorage.Companion::ofFluid, | ||
) | ||
} |
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
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
7 changes: 7 additions & 0 deletions
7
api/src/main/kotlin/io/github/hiiragi283/api/material/content/HTMaterialFluidContent.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,7 @@ | ||
package io.github.hiiragi283.api.material.content | ||
|
||
import io.github.hiiragi283.api.material.HTMaterialKey | ||
|
||
class HTMaterialFluidContent( | ||
val materialKey: HTMaterialKey, | ||
) |
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
Oops, something went wrong.