format
This commit is contained in:
@@ -2,7 +2,6 @@ package dev.xkmc.l2core.base.effects;
|
|||||||
|
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.neoforged.bus.api.Event;
|
|
||||||
import net.neoforged.bus.api.ICancellableEvent;
|
import net.neoforged.bus.api.ICancellableEvent;
|
||||||
import net.neoforged.neoforge.event.entity.living.MobEffectEvent;
|
import net.neoforged.neoforge.event.entity.living.MobEffectEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import net.minecraft.nbt.CompoundTag;
|
|||||||
import net.neoforged.neoforge.attachment.AttachmentType;
|
import net.neoforged.neoforge.attachment.AttachmentType;
|
||||||
import net.neoforged.neoforge.attachment.IAttachmentHolder;
|
import net.neoforged.neoforge.attachment.IAttachmentHolder;
|
||||||
import net.neoforged.neoforge.attachment.IAttachmentSerializer;
|
import net.neoforged.neoforge.attachment.IAttachmentSerializer;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|||||||
@@ -3,5 +3,4 @@ package dev.xkmc.l2core.capability.attachment;
|
|||||||
public class BaseAttachment {
|
public class BaseAttachment {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,36 +15,36 @@ import java.util.function.Supplier;
|
|||||||
*/
|
*/
|
||||||
public class GeneralCapabilityHolder<E extends IAttachmentHolder, T extends GeneralCapabilityTemplate<E, T>> extends AttachmentDef<T> {
|
public class GeneralCapabilityHolder<E extends IAttachmentHolder, T extends GeneralCapabilityTemplate<E, T>> extends AttachmentDef<T> {
|
||||||
|
|
||||||
public static final Map<ResourceLocation, GeneralCapabilityHolder<?, ?>> INTERNAL_MAP = new ConcurrentHashMap<>();
|
public static final Map<ResourceLocation, GeneralCapabilityHolder<?, ?>> INTERNAL_MAP = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public final ResourceLocation id;
|
public final ResourceLocation id;
|
||||||
public final Class<E> entity_class;
|
public final Class<E> entity_class;
|
||||||
private final Predicate<E> pred;
|
private final Predicate<E> pred;
|
||||||
|
|
||||||
|
|
||||||
public GeneralCapabilityHolder(ResourceLocation id, Class<T> holder_class, Supplier<T> sup,
|
public GeneralCapabilityHolder(ResourceLocation id, Class<T> holder_class, Supplier<T> sup,
|
||||||
Class<E> entity_class, Predicate<E> pred) {
|
Class<E> entity_class, Predicate<E> pred) {
|
||||||
super(holder_class, sup);
|
super(holder_class, sup);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.entity_class = entity_class;
|
this.entity_class = entity_class;
|
||||||
this.pred = pred;
|
this.pred = pred;
|
||||||
INTERNAL_MAP.put(id, this);
|
INTERNAL_MAP.put(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getOrCreate(E e) {
|
public T getOrCreate(E e) {
|
||||||
return e.getData(type());
|
return e.getData(type());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<T> getExisting(E e) {
|
public Optional<T> getExisting(E e) {
|
||||||
return e.getExistingData(type());
|
return e.getExistingData(type());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFor(IAttachmentHolder holder) {
|
public boolean isFor(IAttachmentHolder holder) {
|
||||||
return entity_class.isInstance(holder) && isProper(Wrappers.cast(holder));
|
return entity_class.isInstance(holder) && isProper(Wrappers.cast(holder));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProper(E entity) {
|
public boolean isProper(E entity) {
|
||||||
return pred.test(entity);
|
return pred.test(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class ConditionalToken {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* return true to retain
|
* return true to retain
|
||||||
* */
|
*/
|
||||||
public boolean retainOnDeath(Player player) {
|
public boolean retainOnDeath(Player player) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,37 +13,37 @@ import java.util.TreeSet;
|
|||||||
@SerialClass
|
@SerialClass
|
||||||
public class PlayerFlagData extends PlayerCapabilityTemplate<PlayerFlagData> {
|
public class PlayerFlagData extends PlayerCapabilityTemplate<PlayerFlagData> {
|
||||||
|
|
||||||
public static void addFlag(LivingEntity entity, String str) {
|
public static void addFlag(LivingEntity entity, String str) {
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
L2LibReg.FLAGS.type().getOrCreate(player).addFlag(str);
|
L2LibReg.FLAGS.type().getOrCreate(player).addFlag(str);
|
||||||
if (player instanceof ServerPlayer sp)
|
if (player instanceof ServerPlayer sp)
|
||||||
L2LibReg.FLAGS.type().network.toClient(sp);
|
L2LibReg.FLAGS.type().network.toClient(sp);
|
||||||
} else {
|
} else {
|
||||||
entity.addTag(str);
|
entity.addTag(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasFlag(LivingEntity entity, String str) {
|
public static boolean hasFlag(LivingEntity entity, String str) {
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
return L2LibReg.FLAGS.type().getExisting(player).map(e -> e.hasFlag(str)).orElse(false);
|
return L2LibReg.FLAGS.type().getExisting(player).map(e -> e.hasFlag(str)).orElse(false);
|
||||||
} else {
|
} else {
|
||||||
return entity.getTags().contains(str);
|
return entity.getTags().contains(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SerialField
|
@SerialField
|
||||||
private final TreeSet<String> flags = new TreeSet<>();
|
private final TreeSet<String> flags = new TreeSet<>();
|
||||||
|
|
||||||
public void addFlag(String str) {
|
public void addFlag(String str) {
|
||||||
flags.add(str);
|
flags.add(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasFlag(String flag) {
|
public boolean hasFlag(String flag) {
|
||||||
return flags.contains(flag);
|
return flags.contains(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import dev.xkmc.l2serial.serialization.marker.SerialField;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|||||||
@@ -5,25 +5,25 @@ import net.minecraft.server.level.ServerPlayer;
|
|||||||
|
|
||||||
public class PlayerCapabilityNetworkHandler<T extends PlayerCapabilityTemplate<T>> {
|
public class PlayerCapabilityNetworkHandler<T extends PlayerCapabilityTemplate<T>> {
|
||||||
|
|
||||||
public final PlayerCapabilityHolder<T> holder;
|
public final PlayerCapabilityHolder<T> holder;
|
||||||
|
|
||||||
public PlayerCapabilityNetworkHandler(PlayerCapabilityHolder<T> holder) {
|
public PlayerCapabilityNetworkHandler(PlayerCapabilityHolder<T> holder) {
|
||||||
this.holder = holder;
|
this.holder = holder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toClient(ServerPlayer e) {
|
public void toClient(ServerPlayer e) {
|
||||||
holder.getExisting(e).ifPresent(x -> L2Core.PACKET_HANDLER.toClientPlayer(
|
holder.getExisting(e).ifPresent(x -> L2Core.PACKET_HANDLER.toClientPlayer(
|
||||||
PlayerCapToClient.of(e, PlayerCapToClient.Action.CLIENT, holder, x), e));
|
PlayerCapToClient.of(e, PlayerCapToClient.Action.CLIENT, holder, x), e));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toTracking(ServerPlayer e) {
|
public void toTracking(ServerPlayer e) {
|
||||||
holder.getExisting(e).ifPresent(x -> L2Core.PACKET_HANDLER.toTrackingOnly(
|
holder.getExisting(e).ifPresent(x -> L2Core.PACKET_HANDLER.toTrackingOnly(
|
||||||
PlayerCapToClient.of(e, PlayerCapToClient.Action.TRACK, holder, x), e));
|
PlayerCapToClient.of(e, PlayerCapToClient.Action.TRACK, holder, x), e));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTracking(ServerPlayer tracker, ServerPlayer target) {
|
public void startTracking(ServerPlayer tracker, ServerPlayer target) {
|
||||||
holder.getExisting(target).ifPresent(x -> L2Core.PACKET_HANDLER.toClientPlayer(
|
holder.getExisting(target).ifPresent(x -> L2Core.PACKET_HANDLER.toClientPlayer(
|
||||||
PlayerCapToClient.of(target, PlayerCapToClient.Action.TRACK, holder, x), tracker));
|
PlayerCapToClient.of(target, PlayerCapToClient.Action.TRACK, holder, x), tracker));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.tterrag.registrate.providers.ProviderType;
|
|||||||
import com.tterrag.registrate.util.DataIngredient;
|
import com.tterrag.registrate.util.DataIngredient;
|
||||||
import dev.xkmc.l2core.init.reg.registrate.L2Registrate;
|
import dev.xkmc.l2core.init.reg.registrate.L2Registrate;
|
||||||
import dev.xkmc.l2core.serial.recipe.ConditionalRecipeWrapper;
|
import dev.xkmc.l2core.serial.recipe.ConditionalRecipeWrapper;
|
||||||
import net.minecraft.Util;
|
|
||||||
import net.minecraft.data.recipes.RecipeBuilder;
|
import net.minecraft.data.recipes.RecipeBuilder;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
@@ -16,7 +15,6 @@ import net.minecraft.world.level.storage.loot.LootPool;
|
|||||||
import net.minecraft.world.level.storage.loot.LootTable;
|
import net.minecraft.world.level.storage.loot.LootTable;
|
||||||
import net.neoforged.neoforge.client.model.generators.ModelFile;
|
import net.neoforged.neoforge.client.model.generators.ModelFile;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class PatchouliHelper {
|
public class PatchouliHelper {
|
||||||
|
|||||||
@@ -40,144 +40,144 @@ import java.util.List;
|
|||||||
@EventBusSubscriber(value = Dist.CLIENT, modid = L2Core.MODID, bus = EventBusSubscriber.Bus.GAME)
|
@EventBusSubscriber(value = Dist.CLIENT, modid = L2Core.MODID, bus = EventBusSubscriber.Bus.GAME)
|
||||||
public class ClientEffectRenderEvents {
|
public class ClientEffectRenderEvents {
|
||||||
|
|
||||||
private static final ArrayList<DelayedEntityRender> ICONS = new ArrayList<>();
|
private static final ArrayList<DelayedEntityRender> ICONS = new ArrayList<>();
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void clientTick(ClientTickEvent.Post event) {
|
public static void clientTick(ClientTickEvent.Post event) {
|
||||||
AbstractClientPlayer player = Proxy.getClientPlayer();
|
AbstractClientPlayer player = Proxy.getClientPlayer();
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
for (var entry : player.getActiveEffectsMap().entrySet()) {
|
for (var entry : player.getActiveEffectsMap().entrySet()) {
|
||||||
if (entry.getKey() instanceof FirstPlayerRenderEffect effect) {
|
if (entry.getKey() instanceof FirstPlayerRenderEffect effect) {
|
||||||
effect.onClientLevelRender(player, entry.getValue());
|
effect.onClientLevelRender(player, entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void levelRenderLast(RenderLevelStageEvent event) {
|
public static void levelRenderLast(RenderLevelStageEvent event) {
|
||||||
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_WEATHER) return;
|
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_WEATHER) return;
|
||||||
LevelRenderer renderer = event.getLevelRenderer();
|
LevelRenderer renderer = event.getLevelRenderer();
|
||||||
MultiBufferSource.BufferSource buffers = Minecraft.getInstance().renderBuffers().bufferSource();
|
MultiBufferSource.BufferSource buffers = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||||
Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
|
Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
|
||||||
PoseStack stack = event.getPoseStack();
|
PoseStack stack = event.getPoseStack();
|
||||||
|
|
||||||
// cache the previous handler
|
// cache the previous handler
|
||||||
for (DelayedEntityRender icon : ICONS) {
|
for (DelayedEntityRender icon : ICONS) {
|
||||||
renderIcon(stack, buffers, icon, event.getPartialTick().getGameTimeDeltaTicks(), camera, renderer.entityRenderDispatcher);
|
renderIcon(stack, buffers, icon, event.getPartialTick().getGameTimeDeltaTicks(), camera, renderer.entityRenderDispatcher);
|
||||||
}
|
}
|
||||||
buffers.endBatch();
|
buffers.endBatch();
|
||||||
|
|
||||||
ICONS.clear();
|
ICONS.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onLivingEntityRender(RenderLivingEvent.Post<?, ?> event) {
|
public static void onLivingEntityRender(RenderLivingEvent.Post<?, ?> event) {
|
||||||
LivingEntity entity = event.getEntity();
|
LivingEntity entity = event.getEntity();
|
||||||
if (!L2LibReg.EFFECT.type().isProper(entity)) return;
|
if (!L2LibReg.EFFECT.type().isProper(entity)) return;
|
||||||
if (entity.getTags().contains("ClientOnly")) return;//TODO
|
if (entity.getTags().contains("ClientOnly")) return;//TODO
|
||||||
ClientEffectCap cap = L2LibReg.EFFECT.type().getOrCreate(entity);
|
ClientEffectCap cap = L2LibReg.EFFECT.type().getOrCreate(entity);
|
||||||
List<Pair<ClientRenderEffect, Integer>> l0 = new ArrayList<>();
|
List<Pair<ClientRenderEffect, Integer>> l0 = new ArrayList<>();
|
||||||
for (var entry : cap.map.entrySet()) {
|
for (var entry : cap.map.entrySet()) {
|
||||||
if (entry.getKey().value() instanceof ClientRenderEffect effect) {
|
if (entry.getKey().value() instanceof ClientRenderEffect effect) {
|
||||||
l0.add(Pair.of(effect, entry.getValue()));
|
l0.add(Pair.of(effect, entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (l0.isEmpty()) return;
|
if (l0.isEmpty()) return;
|
||||||
List<Pair<Integer, DelayedEntityRender>> l1 = new ArrayList<>();
|
List<Pair<Integer, DelayedEntityRender>> l1 = new ArrayList<>();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
for (var e : l0) {
|
for (var e : l0) {
|
||||||
int lv = e.getSecond();
|
int lv = e.getSecond();
|
||||||
int size = l1.size();
|
int size = l1.size();
|
||||||
int I = index;
|
int I = index;
|
||||||
e.getFirst().render(entity, lv, x -> l1.add(Pair.of(I, x)));
|
e.getFirst().render(entity, lv, x -> l1.add(Pair.of(I, x)));
|
||||||
if (l1.size() > size) {
|
if (l1.size() > size) {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int n = index;
|
int n = index;
|
||||||
int w = (int) Math.ceil(Math.sqrt(n));
|
int w = (int) Math.ceil(Math.sqrt(n));
|
||||||
int h = (int) Math.ceil(n * 1d / w);
|
int h = (int) Math.ceil(n * 1d / w);
|
||||||
|
|
||||||
for (var e : l1) {
|
for (var e : l1) {
|
||||||
int i = e.getFirst();
|
int i = e.getFirst();
|
||||||
int iy = i / w;
|
int iy = i / w;
|
||||||
int iw = Math.min(w, n - iy * w);
|
int iw = Math.min(w, n - iy * w);
|
||||||
int ix = i - iy * w;
|
int ix = i - iy * w;
|
||||||
ICONS.add(e.getSecond().resize(IconRenderRegion.of(w, ix, iy, iw, h)));
|
ICONS.add(e.getSecond().resize(IconRenderRegion.of(w, ix, iy, iw, h)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderIcon(PoseStack pose, MultiBufferSource buffer, DelayedEntityRender icon,
|
private static void renderIcon(PoseStack pose, MultiBufferSource buffer, DelayedEntityRender icon,
|
||||||
float partial, Camera camera, EntityRenderDispatcher dispatcher) {
|
float partial, Camera camera, EntityRenderDispatcher dispatcher) {
|
||||||
LivingEntity entity = icon.entity();
|
LivingEntity entity = icon.entity();
|
||||||
float f = entity.getBbHeight() / 2;
|
float f = entity.getBbHeight() / 2;
|
||||||
|
|
||||||
double x0 = Mth.lerp(partial, entity.xOld, entity.getX());
|
double x0 = Mth.lerp(partial, entity.xOld, entity.getX());
|
||||||
double y0 = Mth.lerp(partial, entity.yOld, entity.getY());
|
double y0 = Mth.lerp(partial, entity.yOld, entity.getY());
|
||||||
double z0 = Mth.lerp(partial, entity.zOld, entity.getZ());
|
double z0 = Mth.lerp(partial, entity.zOld, entity.getZ());
|
||||||
Vec3 offset = dispatcher.getRenderer(entity).getRenderOffset(entity, partial);
|
Vec3 offset = dispatcher.getRenderer(entity).getRenderOffset(entity, partial);
|
||||||
Vec3 cam_pos = camera.getPosition();
|
Vec3 cam_pos = camera.getPosition();
|
||||||
double d2 = x0 - cam_pos.x + offset.x();
|
double d2 = x0 - cam_pos.x + offset.x();
|
||||||
double d3 = y0 - cam_pos.y + offset.y();
|
double d3 = y0 - cam_pos.y + offset.y();
|
||||||
double d0 = z0 - cam_pos.z + offset.z();
|
double d0 = z0 - cam_pos.z + offset.z();
|
||||||
|
|
||||||
pose.pushPose();
|
pose.pushPose();
|
||||||
pose.translate(d2, d3 + f, d0);
|
pose.translate(d2, d3 + f, d0);
|
||||||
pose.mulPose(camera.rotation());
|
pose.mulPose(camera.rotation());
|
||||||
PoseStack.Pose entry = pose.last();
|
PoseStack.Pose entry = pose.last();
|
||||||
VertexConsumer ivertexbuilder = buffer.getBuffer(get2DIcon(icon.rl()));
|
VertexConsumer ivertexbuilder = buffer.getBuffer(get2DIcon(icon.rl()));
|
||||||
|
|
||||||
float ix0 = -0.5f + icon.region().x();
|
float ix0 = -0.5f + icon.region().x();
|
||||||
float ix1 = ix0 + icon.region().scale();
|
float ix1 = ix0 + icon.region().scale();
|
||||||
float iy0 = -0.5f + icon.region().y();
|
float iy0 = -0.5f + icon.region().y();
|
||||||
float iy1 = iy0 + icon.region().scale();
|
float iy1 = iy0 + icon.region().scale();
|
||||||
float u0 = icon.tx();
|
float u0 = icon.tx();
|
||||||
float v0 = icon.ty();
|
float v0 = icon.ty();
|
||||||
float u1 = icon.tx() + icon.tw();
|
float u1 = icon.tx() + icon.tw();
|
||||||
float v1 = icon.ty() + icon.th();
|
float v1 = icon.ty() + icon.th();
|
||||||
|
|
||||||
iconVertex(entry, ivertexbuilder, ix1, iy0, u0, v1);
|
iconVertex(entry, ivertexbuilder, ix1, iy0, u0, v1);
|
||||||
iconVertex(entry, ivertexbuilder, ix0, iy0, u1, v1);
|
iconVertex(entry, ivertexbuilder, ix0, iy0, u1, v1);
|
||||||
iconVertex(entry, ivertexbuilder, ix0, iy1, u1, v0);
|
iconVertex(entry, ivertexbuilder, ix0, iy1, u1, v0);
|
||||||
iconVertex(entry, ivertexbuilder, ix1, iy1, u0, v0);
|
iconVertex(entry, ivertexbuilder, ix1, iy1, u0, v0);
|
||||||
pose.popPose();
|
pose.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void iconVertex(PoseStack.Pose entry, VertexConsumer builder, float x, float y, float u, float v) {
|
private static void iconVertex(PoseStack.Pose entry, VertexConsumer builder, float x, float y, float u, float v) {
|
||||||
builder.addVertex(entry.pose(), x, y, 0)
|
builder.addVertex(entry.pose(), x, y, 0)
|
||||||
.setUv(u, v)
|
.setUv(u, v)
|
||||||
.setNormal(entry, 0.0F, 1.0F, 0.0F);
|
.setNormal(entry, 0.0F, 1.0F, 0.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RenderType get2DIcon(ResourceLocation rl) {
|
public static RenderType get2DIcon(ResourceLocation rl) {
|
||||||
return RenderType.create(
|
return RenderType.create(
|
||||||
"entity_body_icon",
|
"entity_body_icon",
|
||||||
DefaultVertexFormat.POSITION_TEX,
|
DefaultVertexFormat.POSITION_TEX,
|
||||||
VertexFormat.Mode.QUADS, 256, false, true,
|
VertexFormat.Mode.QUADS, 256, false, true,
|
||||||
RenderType.CompositeState.builder()
|
RenderType.CompositeState.builder()
|
||||||
.setShaderState(RenderStateShard.RENDERTYPE_ENTITY_GLINT_SHADER)
|
.setShaderState(RenderStateShard.RENDERTYPE_ENTITY_GLINT_SHADER)
|
||||||
.setTextureState(new RenderStateShard.TextureStateShard(rl, false, false))
|
.setTextureState(new RenderStateShard.TextureStateShard(rl, false, false))
|
||||||
.setTransparencyState(RenderStateShard.ADDITIVE_TRANSPARENCY)
|
.setTransparencyState(RenderStateShard.ADDITIVE_TRANSPARENCY)
|
||||||
.setDepthTestState(RenderStateShard.NO_DEPTH_TEST)
|
.setDepthTestState(RenderStateShard.NO_DEPTH_TEST)
|
||||||
.createCompositeState(false)
|
.createCompositeState(false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sync(EffectToClient eff) {
|
public static void sync(EffectToClient eff) {
|
||||||
if (Minecraft.getInstance().level == null) return;
|
if (Minecraft.getInstance().level == null) return;
|
||||||
Entity e = Minecraft.getInstance().level.getEntity(eff.entity());
|
Entity e = Minecraft.getInstance().level.getEntity(eff.entity());
|
||||||
if (!(e instanceof LivingEntity le)) return;
|
if (!(e instanceof LivingEntity le)) return;
|
||||||
if (!L2LibReg.EFFECT.type().isProper(le)) return;
|
if (!L2LibReg.EFFECT.type().isProper(le)) return;
|
||||||
ClientEffectCap cap = L2LibReg.EFFECT.type().getOrCreate(le);
|
ClientEffectCap cap = L2LibReg.EFFECT.type().getOrCreate(le);
|
||||||
if (eff.exist()) {
|
if (eff.exist()) {
|
||||||
cap.map.put(eff.effect(), eff.level());
|
cap.map.put(eff.effect(), eff.level());
|
||||||
} else {
|
} else {
|
||||||
cap.map.remove(eff.effect());
|
cap.map.remove(eff.effect());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ public interface EECVal<T> extends Val<DataComponentType<List<ConditionalEffect<
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Special<T> extends Val<DataComponentType<T>> {
|
interface Special<T> extends Val<DataComponentType<T>> {
|
||||||
|
|
||||||
record Impl<T>(
|
record Impl<T>(
|
||||||
|
|||||||
@@ -3,5 +3,4 @@ package dev.xkmc.l2core.init.reg.ench;
|
|||||||
public class LegacyEnchantment {
|
public class LegacyEnchantment {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ package dev.xkmc.l2core.serial.advancements;
|
|||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import dev.xkmc.l2serial.serialization.codec.CodecAdaptor;
|
import dev.xkmc.l2serial.serialization.codec.CodecAdaptor;
|
||||||
import net.minecraft.advancements.critereon.ContextAwarePredicate;
|
|
||||||
import net.minecraft.advancements.critereon.SimpleCriterionTrigger;
|
import net.minecraft.advancements.critereon.SimpleCriterionTrigger;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
public class BaseCriterion<T extends BaseCriterionInstance<T, R>, R extends BaseCriterion<T, R>> extends SimpleCriterionTrigger<T> {
|
public class BaseCriterion<T extends BaseCriterionInstance<T, R>, R extends BaseCriterion<T, R>> extends SimpleCriterionTrigger<T> {
|
||||||
|
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ public class CriterionBuilder implements IAdvBuilder {
|
|||||||
public static CriterionBuilder enchanted(TagKey<Item> item, Holder<Enchantment> enchantment) {
|
public static CriterionBuilder enchanted(TagKey<Item> item, Holder<Enchantment> enchantment) {
|
||||||
return one(InventoryChangeTrigger.TriggerInstance.hasItems(ItemPredicate.Builder.item().of(item)
|
return one(InventoryChangeTrigger.TriggerInstance.hasItems(ItemPredicate.Builder.item().of(item)
|
||||||
.withSubPredicate(ItemSubPredicates.ENCHANTMENTS,
|
.withSubPredicate(ItemSubPredicates.ENCHANTMENTS,
|
||||||
ItemEnchantmentsPredicate.enchantments(List.of(
|
ItemEnchantmentsPredicate.enchantments(List.of(
|
||||||
new EnchantmentPredicate(enchantment, MinMaxBounds.Ints.ANY))))));
|
new EnchantmentPredicate(enchantment, MinMaxBounds.Ints.ANY))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CriterionBuilder one(Criterion<?> instance) {
|
public static CriterionBuilder one(Criterion<?> instance) {
|
||||||
@@ -76,7 +76,7 @@ public class CriterionBuilder implements IAdvBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum RequirementsStrategy {
|
public enum RequirementsStrategy {
|
||||||
AND, OR;
|
AND, OR
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CriterionBuilder and() {
|
public static CriterionBuilder and() {
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface IAdvBuilder {
|
public interface IAdvBuilder {
|
||||||
|
|
||||||
void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions);
|
void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public record ModLoadedAdv(String... modid) implements IAdvBuilder {
|
public record ModLoadedAdv(String... modid) implements IAdvBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions) {
|
public void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions) {
|
||||||
for (var e : modid) {
|
for (var e : modid) {
|
||||||
conditions.add(new ModLoadedCondition(e));
|
conditions.add(new ModLoadedCondition(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class MergedConfigType<T extends BaseConfig> extends BaseConfigType<T> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = new ConfigMerger<>(cls).apply(configs.values());
|
result = new ConfigMerger<>(cls).apply(configs.values());
|
||||||
result.id = ResourceLocation.fromNamespaceAndPath(parent.modid, id);
|
result.id = ResourceLocation.fromNamespaceAndPath(parent.modid, id);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class AbstractConfigParser {
|
public class AbstractConfigParser {
|
||||||
|
|
||||||
public static Optional<Object> parse(String path, List<String> line) {
|
public static Optional<Object> parse(String path, List<String> line) {
|
||||||
return Optional.ofNullable(ConfigTracker.INSTANCE.fileMap().get(path))
|
return Optional.ofNullable(ConfigTracker.INSTANCE.fileMap().get(path))
|
||||||
.map(file -> file.getConfigData().get(line));
|
.map(file -> file.getConfigData().get(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,37 +9,37 @@ import java.util.function.BooleanSupplier;
|
|||||||
|
|
||||||
public record BooleanConfigValue(String path, List<String> line) implements BooleanSupplier {
|
public record BooleanConfigValue(String path, List<String> line) implements BooleanSupplier {
|
||||||
|
|
||||||
public static BooleanConfigValue of(String file, ModConfigSpec.ConfigValue<Double> config) {
|
public static BooleanConfigValue of(String file, ModConfigSpec.ConfigValue<Double> config) {
|
||||||
return new BooleanConfigValue(file, config.getPath());
|
return new BooleanConfigValue(file, config.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BooleanConfigValue of(String data) {
|
public static BooleanConfigValue of(String data) {
|
||||||
int last = data.lastIndexOf('/');
|
int last = data.lastIndexOf('/');
|
||||||
var line = data.substring(last + 1).split("\\.");
|
var line = data.substring(last + 1).split("\\.");
|
||||||
return new BooleanConfigValue(data.substring(0, last), List.of(line));
|
return new BooleanConfigValue(data.substring(0, last), List.of(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Codec<BooleanSupplier> CODEC = Codec.either(Codec.BOOL, Codec.STRING)
|
public static Codec<BooleanSupplier> CODEC = Codec.either(Codec.BOOL, Codec.STRING)
|
||||||
.xmap(e -> e.map(x -> (BooleanSupplier) (() -> x), BooleanConfigValue::of),
|
.xmap(e -> e.map(x -> (BooleanSupplier) (() -> x), BooleanConfigValue::of),
|
||||||
e -> e instanceof BooleanConfigValue val ?
|
e -> e instanceof BooleanConfigValue val ?
|
||||||
Either.right(val.toData()) :
|
Either.right(val.toData()) :
|
||||||
Either.left(e.getAsBoolean()));
|
Either.left(e.getAsBoolean()));
|
||||||
|
|
||||||
public boolean getAsBoolean() {
|
public boolean getAsBoolean() {
|
||||||
return AbstractConfigParser.parse(path, line)
|
return AbstractConfigParser.parse(path, line)
|
||||||
.map(e -> e instanceof Boolean val ? val : false)
|
.map(e -> e instanceof Boolean val ? val : false)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toData() {
|
public String toData() {
|
||||||
StringBuilder lines = new StringBuilder();
|
StringBuilder lines = new StringBuilder();
|
||||||
for (var e : line) {
|
for (var e : line) {
|
||||||
if (!lines.isEmpty()) {
|
if (!lines.isEmpty()) {
|
||||||
lines.append(".");
|
lines.append(".");
|
||||||
}
|
}
|
||||||
lines.append(e);
|
lines.append(e);
|
||||||
}
|
}
|
||||||
return path + "/" + lines;
|
return path + "/" + lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,19 +9,19 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public record BooleanValueCondition(String path, ArrayList<String> line, boolean expected) implements ICondition {
|
public record BooleanValueCondition(String path, ArrayList<String> line, boolean expected) implements ICondition {
|
||||||
|
|
||||||
public static BooleanValueCondition of(String file, ModConfigSpec.ConfigValue<Boolean> config, boolean value) {
|
public static BooleanValueCondition of(String file, ModConfigSpec.ConfigValue<Boolean> config, boolean value) {
|
||||||
return new BooleanValueCondition(file, new ArrayList<>(config.getPath()), value);
|
return new BooleanValueCondition(file, new ArrayList<>(config.getPath()), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(IContext context) {
|
public boolean test(IContext context) {
|
||||||
return AbstractConfigParser.parse(path, line)
|
return AbstractConfigParser.parse(path, line)
|
||||||
.map(e -> e instanceof Boolean bool && bool == expected).orElse(false);
|
.map(e -> e instanceof Boolean bool && bool == expected).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapCodec<BooleanValueCondition> codec() {
|
public MapCodec<BooleanValueCondition> codec() {
|
||||||
return L2LibReg.CONDITION_BOOL.get();
|
return L2LibReg.CONDITION_BOOL.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,38 +9,38 @@ import java.util.function.DoubleSupplier;
|
|||||||
|
|
||||||
public record DoubleConfigValue(String path, List<String> line) implements DoubleSupplier {
|
public record DoubleConfigValue(String path, List<String> line) implements DoubleSupplier {
|
||||||
|
|
||||||
public static DoubleConfigValue of(String file, ModConfigSpec.ConfigValue<Double> config) {
|
public static DoubleConfigValue of(String file, ModConfigSpec.ConfigValue<Double> config) {
|
||||||
return new DoubleConfigValue(file, config.getPath());
|
return new DoubleConfigValue(file, config.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DoubleConfigValue of(String data) {
|
public static DoubleConfigValue of(String data) {
|
||||||
int last = data.lastIndexOf('/');
|
int last = data.lastIndexOf('/');
|
||||||
var line = data.substring(last + 1).split("\\.");
|
var line = data.substring(last + 1).split("\\.");
|
||||||
return new DoubleConfigValue(data.substring(0, last), List.of(line));
|
return new DoubleConfigValue(data.substring(0, last), List.of(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Codec<DoubleSupplier> CODEC = Codec.either(Codec.DOUBLE, Codec.STRING)
|
public static Codec<DoubleSupplier> CODEC = Codec.either(Codec.DOUBLE, Codec.STRING)
|
||||||
.xmap(e -> e.map(x -> (DoubleSupplier) (() -> x), DoubleConfigValue::of),
|
.xmap(e -> e.map(x -> (DoubleSupplier) (() -> x), DoubleConfigValue::of),
|
||||||
e -> e instanceof DoubleConfigValue val ?
|
e -> e instanceof DoubleConfigValue val ?
|
||||||
Either.right(val.toData()) :
|
Either.right(val.toData()) :
|
||||||
Either.left(e.getAsDouble()));
|
Either.left(e.getAsDouble()));
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getAsDouble() {
|
public double getAsDouble() {
|
||||||
return AbstractConfigParser.parse(path, line)
|
return AbstractConfigParser.parse(path, line)
|
||||||
.map(e -> e instanceof Number val ? val.doubleValue() : 0d)
|
.map(e -> e instanceof Number val ? val.doubleValue() : 0d)
|
||||||
.orElse(0d);
|
.orElse(0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toData() {
|
public String toData() {
|
||||||
StringBuilder lines = new StringBuilder();
|
StringBuilder lines = new StringBuilder();
|
||||||
for (var e : line) {
|
for (var e : line) {
|
||||||
if (!lines.isEmpty()) {
|
if (!lines.isEmpty()) {
|
||||||
lines.append(".");
|
lines.append(".");
|
||||||
}
|
}
|
||||||
lines.append(e);
|
lines.append(e);
|
||||||
}
|
}
|
||||||
return path + "/" + lines;
|
return path + "/" + lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,19 +9,19 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public record DoubleValueCondition(String path, ArrayList<String> line, double low, double high) implements ICondition {
|
public record DoubleValueCondition(String path, ArrayList<String> line, double low, double high) implements ICondition {
|
||||||
|
|
||||||
public static DoubleValueCondition of(String file, ModConfigSpec.ConfigValue<Double> config, double low, double high) {
|
public static DoubleValueCondition of(String file, ModConfigSpec.ConfigValue<Double> config, double low, double high) {
|
||||||
return new DoubleValueCondition(file, new ArrayList<>(config.getPath()), low, high);
|
return new DoubleValueCondition(file, new ArrayList<>(config.getPath()), low, high);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(IContext context) {
|
public boolean test(IContext context) {
|
||||||
return AbstractConfigParser.parse(path, line)
|
return AbstractConfigParser.parse(path, line)
|
||||||
.map(e -> e instanceof Double val && low <= val && val <= high).orElse(false);
|
.map(e -> e instanceof Double val && low <= val && val <= high).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapCodec<DoubleValueCondition> codec() {
|
public MapCodec<DoubleValueCondition> codec() {
|
||||||
return L2LibReg.CONDITION_DOUBLE.get();
|
return L2LibReg.CONDITION_DOUBLE.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,37 +9,37 @@ import java.util.function.IntSupplier;
|
|||||||
|
|
||||||
public record IntConfigValue(String path, List<String> line) implements IntSupplier {
|
public record IntConfigValue(String path, List<String> line) implements IntSupplier {
|
||||||
|
|
||||||
public static IntConfigValue of(String file, ModConfigSpec.ConfigValue<Integer> config) {
|
public static IntConfigValue of(String file, ModConfigSpec.ConfigValue<Integer> config) {
|
||||||
return new IntConfigValue(file, config.getPath());
|
return new IntConfigValue(file, config.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IntConfigValue of(String data) {
|
public static IntConfigValue of(String data) {
|
||||||
int last = data.lastIndexOf('/');
|
int last = data.lastIndexOf('/');
|
||||||
var line = data.substring(last + 1).split("\\.");
|
var line = data.substring(last + 1).split("\\.");
|
||||||
return new IntConfigValue(data.substring(0, last), List.of(line));
|
return new IntConfigValue(data.substring(0, last), List.of(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Codec<IntSupplier> CODEC = Codec.either(Codec.INT, Codec.STRING)
|
public static Codec<IntSupplier> CODEC = Codec.either(Codec.INT, Codec.STRING)
|
||||||
.xmap(e -> e.map(x -> (IntSupplier) (() -> x), IntConfigValue::of),
|
.xmap(e -> e.map(x -> (IntSupplier) (() -> x), IntConfigValue::of),
|
||||||
e -> e instanceof IntConfigValue val ?
|
e -> e instanceof IntConfigValue val ?
|
||||||
Either.right(val.toData()) :
|
Either.right(val.toData()) :
|
||||||
Either.left(e.getAsInt()));
|
Either.left(e.getAsInt()));
|
||||||
|
|
||||||
public int getAsInt() {
|
public int getAsInt() {
|
||||||
return AbstractConfigParser.parse(path, line)
|
return AbstractConfigParser.parse(path, line)
|
||||||
.map(e -> e instanceof Number val ? val.intValue() : 0)
|
.map(e -> e instanceof Number val ? val.intValue() : 0)
|
||||||
.orElse(0);
|
.orElse(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toData() {
|
public String toData() {
|
||||||
StringBuilder lines = new StringBuilder();
|
StringBuilder lines = new StringBuilder();
|
||||||
for (var e : line) {
|
for (var e : line) {
|
||||||
if (!lines.isEmpty()) {
|
if (!lines.isEmpty()) {
|
||||||
lines.append(".");
|
lines.append(".");
|
||||||
}
|
}
|
||||||
lines.append(e);
|
lines.append(e);
|
||||||
}
|
}
|
||||||
return path + "/" + lines;
|
return path + "/" + lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public record IntValueCondition(String path, ArrayList<String> line, int low, in
|
|||||||
@Override
|
@Override
|
||||||
public boolean test(IContext context) {
|
public boolean test(IContext context) {
|
||||||
return AbstractConfigParser.parse(path, line)
|
return AbstractConfigParser.parse(path, line)
|
||||||
.map(e -> e instanceof Integer val && low <= val && val <= high).orElse(false);
|
.map(e -> e instanceof Integer val && low <= val && val <= high).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,19 +10,19 @@ import java.util.List;
|
|||||||
|
|
||||||
public record ListStringValueCondition(String path, ArrayList<String> line, String key) implements ICondition {
|
public record ListStringValueCondition(String path, ArrayList<String> line, String key) implements ICondition {
|
||||||
|
|
||||||
public static ListStringValueCondition of(String file, ModConfigSpec.ConfigValue<List<String>> config, String key) {
|
public static ListStringValueCondition of(String file, ModConfigSpec.ConfigValue<List<String>> config, String key) {
|
||||||
return new ListStringValueCondition(file, new ArrayList<>(config.getPath()), key);
|
return new ListStringValueCondition(file, new ArrayList<>(config.getPath()), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(IContext context) {
|
public boolean test(IContext context) {
|
||||||
return AbstractConfigParser.parse(path, line)
|
return AbstractConfigParser.parse(path, line)
|
||||||
.map(e -> e instanceof List<?> val && val.contains(key)).orElse(false);
|
.map(e -> e instanceof List<?> val && val.contains(key)).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapCodec<ListStringValueCondition> codec() {
|
public MapCodec<ListStringValueCondition> codec() {
|
||||||
return L2LibReg.CONDITION_LIST_STR.get();
|
return L2LibReg.CONDITION_LIST_STR.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,19 +9,19 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public record StringValueCondition(String path, ArrayList<String> line, String key) implements ICondition {
|
public record StringValueCondition(String path, ArrayList<String> line, String key) implements ICondition {
|
||||||
|
|
||||||
public static StringValueCondition of(String file, ModConfigSpec.ConfigValue<String> config, String key) {
|
public static StringValueCondition of(String file, ModConfigSpec.ConfigValue<String> config, String key) {
|
||||||
return new StringValueCondition(file, new ArrayList<>(config.getPath()), key);
|
return new StringValueCondition(file, new ArrayList<>(config.getPath()), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(IContext context) {
|
public boolean test(IContext context) {
|
||||||
return AbstractConfigParser.parse(path, line)
|
return AbstractConfigParser.parse(path, line)
|
||||||
.map(e -> e instanceof String val && val.equals(key)).orElse(false);
|
.map(e -> e instanceof String val && val.equals(key)).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapCodec<StringValueCondition> codec() {
|
public MapCodec<StringValueCondition> codec() {
|
||||||
return L2LibReg.CONDITION_STR.get();
|
return L2LibReg.CONDITION_STR.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class AddItemModifier extends LootModifier {
|
|||||||
|
|
||||||
public static final MapCodec<AddItemModifier> MAP_CODEC = RecordCodecBuilder.mapCodec(i -> LootModifier.codecStart(i).and(i.group(
|
public static final MapCodec<AddItemModifier> MAP_CODEC = RecordCodecBuilder.mapCodec(i -> LootModifier.codecStart(i).and(i.group(
|
||||||
BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(m -> m.item),
|
BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(m -> m.item),
|
||||||
BuiltInRegistries.ITEM.byNameCodec().optionalFieldOf("fail").forGetter(m -> m.fail == Items.AIR ? Optional.<Item>empty() : Optional.of(m.fail)),
|
BuiltInRegistries.ITEM.byNameCodec().optionalFieldOf("fail").forGetter(m -> m.fail == Items.AIR ? Optional.empty() : Optional.of(m.fail)),
|
||||||
DoubleConfigValue.CODEC.optionalFieldOf("chance")
|
DoubleConfigValue.CODEC.optionalFieldOf("chance")
|
||||||
.forGetter(m -> Optional.ofNullable(m.chance))
|
.forGetter(m -> Optional.ofNullable(m.chance))
|
||||||
)).apply(i, AddItemModifier::new));
|
)).apply(i, AddItemModifier::new));
|
||||||
|
|||||||
@@ -11,28 +11,28 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
|||||||
@SerialClass
|
@SerialClass
|
||||||
public class PlayerFlagCondition implements LootItemCondition {
|
public class PlayerFlagCondition implements LootItemCondition {
|
||||||
|
|
||||||
@SerialField
|
@SerialField
|
||||||
public String flag;
|
public String flag;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public PlayerFlagCondition() {
|
public PlayerFlagCondition() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerFlagCondition(String flag) {
|
public PlayerFlagCondition(String flag) {
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LootItemConditionType getType() {
|
public LootItemConditionType getType() {
|
||||||
return L2LibReg.LIC_FLAG.get();
|
return L2LibReg.LIC_FLAG.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(LootContext ctx) {
|
public boolean test(LootContext ctx) {
|
||||||
if (!ctx.hasParam(LootContextParams.LAST_DAMAGE_PLAYER)) return false;
|
if (!ctx.hasParam(LootContextParams.LAST_DAMAGE_PLAYER)) return false;
|
||||||
var player = ctx.getParam(LootContextParams.LAST_DAMAGE_PLAYER);
|
var player = ctx.getParam(LootContextParams.LAST_DAMAGE_PLAYER);
|
||||||
return L2LibReg.FLAGS.type().getExisting(player).map(e -> e.hasFlag(flag)).orElse(false);
|
return L2LibReg.FLAGS.type().getExisting(player).map(e -> e.hasFlag(flag)).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package dev.xkmc.l2core.serial.recipe;
|
package dev.xkmc.l2core.serial.recipe;
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package dev.xkmc.l2core.serial.recipe;
|
package dev.xkmc.l2core.serial.recipe;
|
||||||
|
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.core.RegistryAccess;
|
|
||||||
import net.minecraft.world.Container;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.Recipe;
|
import net.minecraft.world.item.crafting.Recipe;
|
||||||
import net.minecraft.world.item.crafting.RecipeInput;
|
import net.minecraft.world.item.crafting.RecipeInput;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import net.minecraft.core.registries.BuiltInRegistries;
|
|||||||
import net.minecraft.data.recipes.RecipeBuilder;
|
import net.minecraft.data.recipes.RecipeBuilder;
|
||||||
import net.minecraft.data.recipes.RecipeOutput;
|
import net.minecraft.data.recipes.RecipeOutput;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.Container;
|
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.crafting.RecipeInput;
|
import net.minecraft.world.item.crafting.RecipeInput;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|||||||
@@ -12,27 +12,27 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public record ConditionalRecipeWrapper(RecipeOutput pvd, ICondition... conditions) implements RecipeOutput {
|
public record ConditionalRecipeWrapper(RecipeOutput pvd, ICondition... conditions) implements RecipeOutput {
|
||||||
|
|
||||||
public static RecipeOutput mod(RecipeOutput pvd, String... modid) {
|
public static RecipeOutput mod(RecipeOutput pvd, String... modid) {
|
||||||
ICondition[] ans = new ICondition[modid.length];
|
ICondition[] ans = new ICondition[modid.length];
|
||||||
for (int i = 0; i < ans.length; ++i) {
|
for (int i = 0; i < ans.length; ++i) {
|
||||||
ans[i] = new ModLoadedCondition(modid[i]);
|
ans[i] = new ModLoadedCondition(modid[i]);
|
||||||
}
|
}
|
||||||
return new ConditionalRecipeWrapper(pvd, ans);
|
return new ConditionalRecipeWrapper(pvd, ans);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RecipeOutput of(RecipeOutput pvd, ICondition... cond) {
|
public static RecipeOutput of(RecipeOutput pvd, ICondition... cond) {
|
||||||
return new ConditionalRecipeWrapper(pvd, cond);
|
return new ConditionalRecipeWrapper(pvd, cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Advancement.Builder advancement() {
|
public Advancement.Builder advancement() {
|
||||||
return pvd.advancement();
|
return pvd.advancement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ResourceLocation id, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) {
|
public void accept(ResourceLocation id, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) {
|
||||||
pvd.accept(id, recipe, advancement, MathHelper.merge(conditions(), conditions));
|
pvd.accept(id, recipe, advancement, MathHelper.merge(conditions(), conditions));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,24 +13,24 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public record DataRecipeWrapper(RecipeOutput pvd, ItemStack stack) implements RecipeOutput {
|
public record DataRecipeWrapper(RecipeOutput pvd, ItemStack stack) implements RecipeOutput {
|
||||||
|
|
||||||
public static RecipeOutput of(RecipeOutput pvd, ItemStack stack) {
|
public static RecipeOutput of(RecipeOutput pvd, ItemStack stack) {
|
||||||
return new DataRecipeWrapper(pvd, stack);
|
return new DataRecipeWrapper(pvd, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Advancement.Builder advancement() {
|
public Advancement.Builder advancement() {
|
||||||
return pvd.advancement();
|
return pvd.advancement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ResourceLocation id, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) {
|
public void accept(ResourceLocation id, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) {
|
||||||
if (recipe instanceof ShapedRecipe r) {
|
if (recipe instanceof ShapedRecipe r) {
|
||||||
r.result.applyComponents(stack.getComponents());
|
r.result.applyComponents(stack.getComponents());
|
||||||
}
|
}
|
||||||
if (recipe instanceof ShapelessRecipe r) {
|
if (recipe instanceof ShapelessRecipe r) {
|
||||||
r.result.applyComponents(stack.getComponents());
|
r.result.applyComponents(stack.getComponents());
|
||||||
}
|
}
|
||||||
pvd.accept(id, recipe, advancement, conditions);
|
pvd.accept(id, recipe, advancement, conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import dev.xkmc.l2serial.util.Wrappers;
|
|||||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.Container;
|
|
||||||
import net.minecraft.world.item.crafting.Recipe;
|
import net.minecraft.world.item.crafting.Recipe;
|
||||||
import net.minecraft.world.item.crafting.RecipeInput;
|
import net.minecraft.world.item.crafting.RecipeInput;
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public final class DCStack {
|
|||||||
hashCode = stack.hashCode();
|
hashCode = stack.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack stack(){
|
public ItemStack stack() {
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user