helpers
This commit is contained in:
10
build.gradle
10
build.gradle
@@ -119,6 +119,9 @@ repositories {
|
||||
flatDir {
|
||||
dirs 'libs'
|
||||
}
|
||||
maven { // Registrate
|
||||
url "https://maven.ithundxr.dev/snapshots"
|
||||
}
|
||||
maven {
|
||||
url = "https://maven.theillusivec4.top/"
|
||||
}
|
||||
@@ -146,4 +149,11 @@ dependencies {
|
||||
implementation "com.tterrag.registrate:Registrate:${registrate_version}"
|
||||
implementation "dev.xkmc:l2serial:${l2serial_ver}"
|
||||
implementation "vazkii.patchouli:Patchouli:${patchouli_ver}"
|
||||
|
||||
|
||||
runtimeOnly "dev.xkmc:l2damagetracker:3.0.2"
|
||||
runtimeOnly "dev.xkmc:l2menustacker:3.0.9"
|
||||
runtimeOnly "dev.xkmc:l2itemselector:3.0.7"
|
||||
runtimeOnly "dev.xkmc:l2library:3.0.2"
|
||||
runtimeOnly "dev.xkmc:l2complements:3.0.2+3"
|
||||
}
|
||||
@@ -10,7 +10,7 @@ neogradle.subsystems.parchment.mappingsVersion=2024.06.02
|
||||
|
||||
minecraft_version=1.21
|
||||
minecraft_version_range=[1.21,1.22)
|
||||
neo_version=21.0.112-beta
|
||||
neo_version=21.0.147
|
||||
neo_version_range=[21.0,)
|
||||
loader_version_range=[2,)
|
||||
|
||||
@@ -18,7 +18,7 @@ loader_version_range=[2,)
|
||||
mod_id=l2core
|
||||
mod_name=L2Core
|
||||
mod_license=LGPL-2.1
|
||||
mod_version=3.0.7+6
|
||||
mod_version=3.0.7+13
|
||||
mod_group_id=dev.xkmc
|
||||
mod_authors=lcy0x1
|
||||
mod_description=Core Library mod for all L2 mods
|
||||
@@ -26,7 +26,7 @@ mod_description=Core Library mod for all L2 mods
|
||||
|
||||
jei_minecraft_version = 1.21-neoforge
|
||||
jei_version = 19.5.0.44
|
||||
registrate_version = MC1.21-1.4.7+5e718e9
|
||||
registrate_version = MC1.21-1.3.0+50
|
||||
patchouli_ver = 1.21-87-NEOFORGE-SNAPSHOT
|
||||
|
||||
lljij = false
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
libs/l2complements-3.0.2+3-sources.jar
Normal file
BIN
libs/l2complements-3.0.2+3-sources.jar
Normal file
Binary file not shown.
BIN
libs/l2complements-3.0.2+3.jar
Normal file
BIN
libs/l2complements-3.0.2+3.jar
Normal file
Binary file not shown.
BIN
libs/l2damagetracker-3.0.2-sources.jar
Normal file
BIN
libs/l2damagetracker-3.0.2-sources.jar
Normal file
Binary file not shown.
BIN
libs/l2damagetracker-3.0.2.jar
Normal file
BIN
libs/l2damagetracker-3.0.2.jar
Normal file
Binary file not shown.
BIN
libs/l2itemselector-3.0.7-sources.jar
Normal file
BIN
libs/l2itemselector-3.0.7-sources.jar
Normal file
Binary file not shown.
BIN
libs/l2itemselector-3.0.7.jar
Normal file
BIN
libs/l2itemselector-3.0.7.jar
Normal file
Binary file not shown.
BIN
libs/l2library-3.0.2-sources.jar
Normal file
BIN
libs/l2library-3.0.2-sources.jar
Normal file
Binary file not shown.
BIN
libs/l2library-3.0.2.jar
Normal file
BIN
libs/l2library-3.0.2.jar
Normal file
Binary file not shown.
BIN
libs/l2menustacker-3.0.9-sources.jar
Normal file
BIN
libs/l2menustacker-3.0.9-sources.jar
Normal file
Binary file not shown.
BIN
libs/l2menustacker-3.0.9.jar
Normal file
BIN
libs/l2menustacker-3.0.9.jar
Normal file
Binary file not shown.
@@ -4,8 +4,10 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
public record DelayedEntityRender(LivingEntity entity, IconRenderRegion region, ResourceLocation rl,
|
||||
double xo, double yo, double zo,
|
||||
float tx, float ty, float tw, float th) {
|
||||
|
||||
|
||||
public static DelayedEntityRender icon(LivingEntity entity, ResourceLocation rl) {
|
||||
return icon(entity, IconRenderRegion.identity(), rl);
|
||||
}
|
||||
@@ -14,7 +16,13 @@ public record DelayedEntityRender(LivingEntity entity, IconRenderRegion region,
|
||||
return new DelayedEntityRender(entity, r, rl, 0, 0, 1, 1);
|
||||
}
|
||||
|
||||
public DelayedEntityRender resize(IconRenderRegion r) {
|
||||
return new DelayedEntityRender(entity, r.resize(region), rl, tx, ty, tw, th);
|
||||
public DelayedEntityRender(LivingEntity entity, IconRenderRegion region, ResourceLocation rl,
|
||||
float tx, float ty, float tw, float th) {
|
||||
this(entity, region, rl, entity.xOld, entity.yOld, entity.zOld, tx, ty, tw, th);
|
||||
}
|
||||
|
||||
public DelayedEntityRender resize(IconRenderRegion r) {
|
||||
return new DelayedEntityRender(entity, r.resize(region), rl, xo, yo, zo, tx, ty, tw, th);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class ClientEffectRenderEvents {
|
||||
AbstractClientPlayer player = Proxy.getClientPlayer();
|
||||
if (player != null) {
|
||||
for (var entry : player.getActiveEffectsMap().entrySet()) {
|
||||
if (entry.getKey() instanceof FirstPlayerRenderEffect effect) {
|
||||
if (entry.getValue().getEffect().value() instanceof FirstPlayerRenderEffect effect) {
|
||||
effect.onClientLevelRender(player, entry.getValue());
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,9 @@ public class ClientEffectRenderEvents {
|
||||
|
||||
// cache the previous handler
|
||||
for (DelayedEntityRender icon : ICONS) {
|
||||
renderIcon(stack, buffers, icon, event.getPartialTick().getGameTimeDeltaTicks(), camera, renderer.entityRenderDispatcher);
|
||||
renderIcon(stack, buffers, icon,
|
||||
event.getPartialTick().getGameTimeDeltaPartialTick(true),
|
||||
camera, renderer.entityRenderDispatcher);
|
||||
}
|
||||
buffers.endBatch();
|
||||
|
||||
@@ -115,10 +117,9 @@ public class ClientEffectRenderEvents {
|
||||
float partial, Camera camera, EntityRenderDispatcher dispatcher) {
|
||||
LivingEntity entity = icon.entity();
|
||||
float f = entity.getBbHeight() / 2;
|
||||
|
||||
double x0 = Mth.lerp(partial, entity.xOld, entity.getX());
|
||||
double y0 = Mth.lerp(partial, entity.yOld, entity.getY());
|
||||
double z0 = Mth.lerp(partial, entity.zOld, entity.getZ());
|
||||
double x0 = Mth.lerp(partial, icon.xo(), entity.getX());
|
||||
double y0 = Mth.lerp(partial, icon.yo(), entity.getY());
|
||||
double z0 = Mth.lerp(partial, icon.zo(), entity.getZ());
|
||||
Vec3 offset = dispatcher.getRenderer(entity).getRenderOffset(entity, partial);
|
||||
Vec3 cam_pos = camera.getPosition();
|
||||
double d2 = x0 - cam_pos.x + offset.x();
|
||||
@@ -140,17 +141,15 @@ public class ClientEffectRenderEvents {
|
||||
float u1 = icon.tx() + icon.tw();
|
||||
float v1 = icon.ty() + icon.th();
|
||||
|
||||
iconVertex(entry, ivertexbuilder, ix1, iy0, u0, v1);
|
||||
iconVertex(entry, ivertexbuilder, ix0, iy0, u1, v1);
|
||||
iconVertex(entry, ivertexbuilder, ix0, iy1, u1, v0);
|
||||
iconVertex(entry, ivertexbuilder, ix1, iy1, u0, v0);
|
||||
iconVertex(entry, ivertexbuilder, ix0, iy0, u0, v1);
|
||||
iconVertex(entry, ivertexbuilder, ix1, iy0, u1, v1);
|
||||
iconVertex(entry, ivertexbuilder, ix1, iy1, u1, v0);
|
||||
iconVertex(entry, ivertexbuilder, ix0, iy1, u0, v0);
|
||||
pose.popPose();
|
||||
}
|
||||
|
||||
private static void iconVertex(PoseStack.Pose entry, VertexConsumer builder, float x, float y, float u, float v) {
|
||||
builder.addVertex(entry.pose(), x, y, 0)
|
||||
.setUv(u, v)
|
||||
.setNormal(entry, 0.0F, 1.0F, 0.0F);
|
||||
builder.addVertex(entry.pose(), x, y, 0).setUv(u, v);
|
||||
}
|
||||
|
||||
public static RenderType get2DIcon(ResourceLocation rl) {
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package dev.xkmc.l2core.init.reg.registrate;
|
||||
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface LegacyHolder<T> extends Holder<T>, Supplier<T> {
|
||||
|
||||
ResourceKey<T> key();
|
||||
|
||||
Holder<T> holder();
|
||||
|
||||
@Override
|
||||
default T value() {
|
||||
return get();
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean isBound() {
|
||||
return holder().isBound();
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean is(ResourceLocation id) {
|
||||
return key().location().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean is(ResourceKey<T> id) {
|
||||
return key().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean is(Predicate<ResourceKey<T>> pred) {
|
||||
return pred.test(key());
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean is(TagKey<T> tag) {
|
||||
return holder().is(tag);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default boolean is(Holder<T> holder) {
|
||||
return holder().is(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Stream<TagKey<T>> tags() {
|
||||
return holder().tags();
|
||||
}
|
||||
|
||||
@Override
|
||||
default Either<ResourceKey<T>, T> unwrap() {
|
||||
return Either.left(key());
|
||||
}
|
||||
|
||||
@Override
|
||||
default Optional<ResourceKey<T>> unwrapKey() {
|
||||
return Optional.of(key());
|
||||
}
|
||||
|
||||
@Override
|
||||
default Kind kind() {
|
||||
return Kind.REFERENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean canSerializeIn(HolderOwner<T> pOwner) {
|
||||
return holder().canSerializeIn(pOwner);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,9 +4,7 @@ import com.tterrag.registrate.util.entry.RegistryEntry;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public record SimpleEntry<T>(RegistryEntry<T, ? extends T> val) implements Supplier<T> {
|
||||
public record SimpleEntry<T>(RegistryEntry<T, ? extends T> val) implements LegacyHolder<T> {
|
||||
|
||||
public ResourceKey<T> key() {
|
||||
return val.getKey();
|
||||
@@ -16,8 +14,22 @@ public record SimpleEntry<T>(RegistryEntry<T, ? extends T> val) implements Suppl
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder<T> holder() {
|
||||
return val.getDelegate();
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return key().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
return obj instanceof Holder<?> h &&
|
||||
h.kind() == Kind.REFERENCE &&
|
||||
key().equals(h.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,6 +77,10 @@ public record DCReg(DeferredRegister<DataComponentType<?>> reg) {
|
||||
return reg(id, Codec.STRING, ByteBufCodecs.STRING_UTF8, false);
|
||||
}
|
||||
|
||||
public <T> DCVal<T> enumVal(String id, EnumCodec<T> codec) {
|
||||
return reg(id, codec.codec(), codec.stream(), true);
|
||||
}
|
||||
|
||||
public DCVal<ResourceLocation> loc(String id) {
|
||||
return reg(id, ResourceLocation.CODEC, ResourceLocation.STREAM_CODEC, false);
|
||||
}
|
||||
@@ -91,8 +95,8 @@ public record DCReg(DeferredRegister<DataComponentType<?>> reg) {
|
||||
}
|
||||
|
||||
public DCVal<DCStack> stack(String id) {
|
||||
return reg(id, ItemStack.CODEC.xmap(DCStack::new, DCStack::stack),
|
||||
ItemStack.STREAM_CODEC.map(DCStack::new, DCStack::stack), true);
|
||||
return reg(id, ItemStack.OPTIONAL_CODEC.xmap(DCStack::new, DCStack::stack),
|
||||
ItemStack.OPTIONAL_STREAM_CODEC.map(DCStack::new, DCStack::stack), true);
|
||||
}
|
||||
|
||||
public DCVal<Component> component(String id) {
|
||||
|
||||
29
src/main/java/dev/xkmc/l2core/init/reg/simple/EnumCodec.java
Normal file
29
src/main/java/dev/xkmc/l2core/init/reg/simple/EnumCodec.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package dev.xkmc.l2core.init.reg.simple;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import dev.xkmc.l2serial.util.Wrappers;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record EnumCodec<T>(Codec<T> codec, StreamCodec<? super RegistryFriendlyByteBuf, T> stream) {
|
||||
|
||||
public static <T extends Enum<T>> EnumCodec<T> of(Class<T> cls, T[] vals) {
|
||||
var codec = Codec.STRING.xmap((e) -> {
|
||||
try {
|
||||
return Enum.valueOf(cls, e);
|
||||
} catch (Exception var4) {
|
||||
throw new IllegalArgumentException(e + " is not a valid " + cls.getSimpleName() + ". Valid values are: " + List.of(vals));
|
||||
}
|
||||
}, Enum::name);
|
||||
var stream = ByteBufCodecs.INT.map(e -> vals[e], Enum::ordinal);
|
||||
return new EnumCodec<>(codec, stream);
|
||||
}
|
||||
|
||||
public EnumCodec<List<T>> toList() {
|
||||
return new EnumCodec<>(codec.listOf(), stream.apply(Wrappers.cast(ByteBufCodecs.list())));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.item.alchemy.PotionContents;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.neoforged.neoforge.common.crafting.ICustomIngredient;
|
||||
import net.neoforged.neoforge.common.crafting.IngredientType;
|
||||
|
||||
@@ -14,6 +15,10 @@ import java.util.stream.Stream;
|
||||
|
||||
public record PotionIngredient(Holder<Potion> potion) implements ICustomIngredient {
|
||||
|
||||
public static Ingredient of(Holder<Potion> potion){
|
||||
return new PotionIngredient(potion).toVanilla();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<ItemStack> getItems() {
|
||||
ItemStack stack = new ItemStack(Items.POTION);
|
||||
|
||||
73
src/main/java/dev/xkmc/l2core/serial/loot/LootHelper.java
Normal file
73
src/main/java/dev/xkmc/l2core/serial/loot/LootHelper.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package dev.xkmc.l2core.serial.loot;
|
||||
|
||||
import com.tterrag.registrate.providers.loot.RegistrateBlockLootTables;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.advancements.critereon.*;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.storage.loot.functions.ApplyBonusCount;
|
||||
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
|
||||
import net.minecraft.world.level.storage.loot.predicates.BonusLevelTableCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.MatchTool;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public record LootHelper(RegistrateBlockLootTables pvd) {
|
||||
|
||||
public <T> Holder<T> resolve(ResourceKey<T> key) {
|
||||
return pvd.getRegistries().holderOrThrow(key);
|
||||
}
|
||||
|
||||
public EnchantmentPredicate hasEnch(ResourceKey<Enchantment> enchant, int min) {
|
||||
return new EnchantmentPredicate(resolve(enchant), MinMaxBounds.Ints.atLeast(min));
|
||||
}
|
||||
|
||||
public LootItemCondition.Builder toolHasEnch(ResourceKey<Enchantment> enchant, int min) {
|
||||
return MatchTool.toolMatches(ItemPredicate.Builder.item().withSubPredicate(
|
||||
ItemSubPredicates.ENCHANTMENTS, ItemEnchantmentsPredicate.enchantments(
|
||||
List.of(hasEnch(enchant, min)))));
|
||||
}
|
||||
|
||||
public LootItemCondition.Builder silk() {
|
||||
return toolHasEnch(Enchantments.SILK_TOUCH, 1);
|
||||
}
|
||||
|
||||
public LootItemCondition.Builder intState(Block block, Property<Integer> prop, int val) {
|
||||
return LootItemBlockStatePropertyCondition.hasBlockStateProperties(block)
|
||||
.setProperties(StatePropertiesPredicate.Builder.properties()
|
||||
.hasProperty(prop, val));
|
||||
}
|
||||
|
||||
public <T extends Comparable<T> & StringRepresentable> LootItemCondition.Builder enumState(Block block, Property<T> prop, T val) {
|
||||
return LootItemBlockStatePropertyCondition.hasBlockStateProperties(block)
|
||||
.setProperties(StatePropertiesPredicate.Builder.properties()
|
||||
.hasProperty(prop, val));
|
||||
}
|
||||
|
||||
public LootItemCondition.Builder intRangeState(Block block, Property<Integer> prop, int min, int max) {
|
||||
return LootItemBlockStatePropertyCondition.hasBlockStateProperties(block)
|
||||
.setProperties(Util.make(StatePropertiesPredicate.Builder.properties(),
|
||||
e -> e.matchers.add(new StatePropertiesPredicate.PropertyMatcher(prop.getName(),
|
||||
new StatePropertiesPredicate.RangedMatcher(
|
||||
Optional.of("" + min), Optional.of("" + max))))));
|
||||
}
|
||||
|
||||
public LootItemFunction.Builder fortuneCount(int factor) {
|
||||
return ApplyBonusCount.addUniformBonusCount(resolve(Enchantments.FORTUNE), factor);
|
||||
}
|
||||
|
||||
public LootItemCondition.Builder fortuneChance(int... denominators) {
|
||||
float[] fracs = new float[denominators.length];
|
||||
for (int i = 0; i < fracs.length; i++) fracs[i] = 1f / denominators[i];
|
||||
return BonusLevelTableCondition.bonusLevelFlatChance(resolve(Enchantments.FORTUNE), fracs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Deprecated
|
||||
public class LootTableTemplate {
|
||||
|
||||
public static LootPool.Builder getPool(int roll, int bonus) {
|
||||
|
||||
Reference in New Issue
Block a user