mirror of
https://github.com/wisplite/crystalline-sky.git
synced 2026-10-30 13:32:18 -05:00
Multiloader V
fabric is working
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
package io.github.slimeistdev.crystalline_sky;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.CatnipRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CrystallineSky {
|
||||
public static final String ID = "crystalline_sky";
|
||||
public static final Logger LOG = LoggerFactory.getLogger(ID);
|
||||
private static final CatnipRegistry REGISTRY = new CatnipRegistry(ID);
|
||||
|
||||
public static void init() {
|
||||
ModSetup.init();
|
||||
@@ -21,4 +24,9 @@ public class CrystallineSky {
|
||||
public static <T> ResourceKey<T> key(ResourceKey<? extends Registry<T>> registryKey, String path) {
|
||||
return ResourceKey.create(registryKey, id(path));
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static CatnipRegistry registry() {
|
||||
return REGISTRY;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class CrystallineSkyClient {
|
||||
|
||||
public static void init() {
|
||||
ClientPlatformHelper.registerItemProperty(
|
||||
CrystallineItems.SKY_LIGHT,
|
||||
CrystallineItems.SKY_LIGHT.value(),
|
||||
ResourceLocation.withDefaultNamespace("level"),
|
||||
(stack, world, entity, seed) -> {
|
||||
BlockItemStateProperties state = stack.getOrDefault(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.github.slimeistdev.crystalline_sky.compat;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
@@ -14,7 +14,12 @@ public enum Mods {
|
||||
|
||||
Mods(String id) {
|
||||
this.id = id;
|
||||
this.isLoaded = FabricLoader.getInstance().isModLoaded(id);
|
||||
this.isLoaded = isModLoaded(id);
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static boolean isModLoaded(String id) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-4
@@ -53,10 +53,8 @@ public class SkyShaderInterface implements ChunkShaderInterface {
|
||||
Minecraft client = Minecraft.getInstance();
|
||||
if (client.level != null
|
||||
&& client.player != null
|
||||
&& (client.player.getMainHandItem().is(CrystallineItems.SKY)
|
||||
|| client.player.getOffhandItem().is(CrystallineItems.SKY)
|
||||
|| client.player.getMainHandItem().is(CrystallineItems.WEEPING_SKY)
|
||||
|| client.player.getOffhandItem().is(CrystallineItems.WEEPING_SKY))) {
|
||||
&& (CrystallineItems.isSky(client.player.getMainHandItem())
|
||||
|| CrystallineItems.isSky(client.player.getOffhandItem()))) {
|
||||
|
||||
float f = client.level.getGameTime() + client.getTimer().getGameTimeDeltaPartialTick(true);
|
||||
float alpha = (Mth.sin(f / 10.0f) + 1.0f) / 2.0f;
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package io.github.slimeistdev.crystalline_sky.content.blocks;
|
||||
|
||||
import net.minecraft.world.level.block.TransparentBlock;
|
||||
|
||||
public class SkyBlock extends TransparentBlock {
|
||||
public SkyBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
}
|
||||
+6
-7
@@ -1,14 +1,13 @@
|
||||
package io.github.slimeistdev.crystalline_sky.content.blocks;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.registry.CrystallineItems;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.LightBlock;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.LightBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public class SkyLightBlock extends LightBlock {
|
||||
public SkyLightBlock(Properties settings) {
|
||||
@@ -17,6 +16,6 @@ public class SkyLightBlock extends LightBlock {
|
||||
|
||||
@Override
|
||||
protected VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
|
||||
return context.isHoldingItem(CrystallineItems.SKY_LIGHT) ? Shapes.block() : Shapes.empty();
|
||||
return context.isHoldingItem(CrystallineItems.SKY_LIGHT.value()) ? Shapes.block() : Shapes.empty();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-14
@@ -1,23 +1,22 @@
|
||||
package io.github.slimeistdev.crystalline_sky.content.blocks;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.registry.CrystallineItems;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public class WeepingSkyLightBlock extends Block implements SimpleWaterloggedBlock {
|
||||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
||||
@@ -34,7 +33,7 @@ public class WeepingSkyLightBlock extends Block implements SimpleWaterloggedBloc
|
||||
|
||||
@Override
|
||||
protected VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
|
||||
return context.isHoldingItem(CrystallineItems.WEEPING_SKY_LIGHT) ? Shapes.block() : Shapes.empty();
|
||||
return context.isHoldingItem(CrystallineItems.WEEPING_SKY_LIGHT.value()) ? Shapes.block() : Shapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
@javax.annotation.ParametersAreNonnullByDefault
|
||||
@net.minecraft.MethodsReturnNonnullByDefault
|
||||
package io.github.slimeistdev.crystalline_sky.content.blocks;
|
||||
+11
-11
@@ -1,18 +1,18 @@
|
||||
package io.github.slimeistdev.crystalline_sky.content.items;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.registry.CrystallineDataComponentTypes;
|
||||
import net.minecraft.world.item.Item.Properties;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ColumnPos;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ColumnPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WeepingSkyBlockItem extends BlockItem {
|
||||
public WeepingSkyBlockItem(Block block, Properties settings) {
|
||||
@@ -20,9 +20,9 @@ public class WeepingSkyBlockItem extends BlockItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
public @NotNull InteractionResult useOn(UseOnContext context) {
|
||||
ItemStack stack = context.getItemInHand();
|
||||
if (stack.get(CrystallineDataComponentTypes.WEEPING_SKY_DEBUG_COLUMN_TOOL) != null) {
|
||||
if (stack.get(CrystallineDataComponentTypes.WEEPING_SKY_DEBUG_COLUMN_TOOL.value()) != null) {
|
||||
if (context.getLevel().isClientSide) {
|
||||
BlockPos pos = context.getClickedPos();
|
||||
WeepingSkyBlockItemClient.setSelectedColumn(new ColumnPos(pos.getX(), pos.getZ()));
|
||||
@@ -34,9 +34,9 @@ public class WeepingSkyBlockItem extends BlockItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
|
||||
public @NotNull InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
|
||||
ItemStack stack = user.getItemInHand(hand);
|
||||
if (stack.get(CrystallineDataComponentTypes.WEEPING_SKY_DEBUG_COLUMN_TOOL) != null) {
|
||||
if (stack.get(CrystallineDataComponentTypes.WEEPING_SKY_DEBUG_COLUMN_TOOL.value()) != null) {
|
||||
if (world.isClientSide) {
|
||||
WeepingSkyBlockItemClient.setSelectedColumn(null);
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
@javax.annotation.ParametersAreNonnullByDefault
|
||||
@net.minecraft.MethodsReturnNonnullByDefault
|
||||
package io.github.slimeistdev.crystalline_sky.content.items;
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.builder.BlockBuilder;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.builder.DataComponentTypeBuilder;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.builder.ItemBuilder;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.BaseHolder;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.BlockHolder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CatnipRegistry {
|
||||
public final String modId;
|
||||
|
||||
private static final Multimap<Registry<?>, Registration<?, ?, ?>> REGISTRATIONS = HashMultimap.create();
|
||||
public static final Multimap<Registry<?>, Registration<?, ?, ?>> REGISTRATIONS_VIEW = Multimaps.unmodifiableMultimap(REGISTRATIONS);
|
||||
|
||||
public CatnipRegistry(String modId) {
|
||||
this.modId = modId;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static <R, T extends R, H extends BaseHolder<T>> void addToRegistrationMap(Registry<R> registry, Registration<R, T, H> registration) {
|
||||
REGISTRATIONS.put(registry, registration);
|
||||
}
|
||||
|
||||
public <T> DataComponentTypeBuilder<T> dataComponentType(String id) {
|
||||
return new DataComponentTypeBuilder<>(this, id);
|
||||
}
|
||||
|
||||
public BlockBuilder<Block> block(String id) {
|
||||
return block(id, Block::new);
|
||||
}
|
||||
|
||||
public <R extends Block> BlockBuilder<R> block(String id, Function<BlockBehaviour.Properties, R> factory) {
|
||||
return new BlockBuilder<>(this, id, factory);
|
||||
}
|
||||
|
||||
public ItemBuilder<Item> item(String id) {
|
||||
return item(id, Item::new);
|
||||
}
|
||||
|
||||
public <R extends Item> ItemBuilder<R> item(String id, Function<Item.Properties, R> factory) {
|
||||
return new ItemBuilder<>(this, id, factory);
|
||||
}
|
||||
|
||||
public <B extends Block> ItemBuilder<BlockItem> item(BlockHolder<B> block) {
|
||||
return item(block, BlockItem::new);
|
||||
}
|
||||
|
||||
public <R extends BlockItem, B extends Block> ItemBuilder<R> item(BlockHolder<B> block, BiFunction<? super B, Item.Properties, R> factory) {
|
||||
return new ItemBuilder<>(this, block.getRegisteredNamePath(), properties -> factory.apply(block.value(), properties));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.BaseHolder;
|
||||
import io.github.slimeistdev.crystalline_sky.mixin.Holder$ReferenceAccessor;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public record Registration<R, T extends R, H extends BaseHolder<T>>(
|
||||
ResourceLocation id,
|
||||
Registry<R> registry,
|
||||
Supplier<T> value,
|
||||
H holder,
|
||||
Consumer<H> afterRegisterCallback
|
||||
) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void register() {
|
||||
T registered = Registry.register(registry, id, value.get());
|
||||
((Holder$ReferenceAccessor<T>) holder).crystalline_sky$bindValue(registered);
|
||||
afterRegisterCallback.accept(holder);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RegistrationListeners<T> {
|
||||
private @Nullable T obj;
|
||||
private @Nullable Consumer<T> cons;
|
||||
|
||||
public void registered(T obj) {
|
||||
this.obj = obj;
|
||||
if (cons != null) {
|
||||
cons.accept(obj);
|
||||
cons = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(Consumer<? super T> consumer) {
|
||||
if (obj != null) {
|
||||
consumer.accept(obj);
|
||||
} else if (cons == null) {
|
||||
cons = consumer::accept;
|
||||
} else {
|
||||
cons = cons.andThen(consumer);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.builder;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.CatnipRegistry;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.Registration;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.BaseHolder;
|
||||
import io.github.slimeistdev.crystalline_sky.multiloader.Loader;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class AbstractBuilder<R, T extends R, H extends BaseHolder<T>> {
|
||||
protected final CatnipRegistry owner;
|
||||
protected final ResourceLocation id;
|
||||
protected final Registry<R> registry;
|
||||
protected @Nullable H holder;
|
||||
private Consumer<H> afterRegisterCallback = h -> h.getInternalRegistrationListener().accept(h.value());
|
||||
|
||||
public AbstractBuilder(CatnipRegistry owner, String name, Registry<R> registry) {
|
||||
this.owner = owner;
|
||||
this.id = ResourceLocation.fromNamespaceAndPath(owner.modId, name);
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public void chainAfterRegisterCallback(Consumer<H> callback) {
|
||||
afterRegisterCallback = afterRegisterCallback.andThen(callback);
|
||||
}
|
||||
|
||||
abstract T build();
|
||||
|
||||
abstract H getHolder(HolderOwner<R> owner, ResourceKey<R> key);
|
||||
|
||||
public H register() {
|
||||
ResourceKey<R> key = ResourceKey.create(registry.key(), id);
|
||||
holder = getHolder(registry.holderOwner(), key);
|
||||
Registration<R, T, H> registration = new Registration<>(id, registry, this::build, holder, afterRegisterCallback);
|
||||
|
||||
if (Loader.FABRIC.isCurrent()) {
|
||||
registration.register();
|
||||
} else {
|
||||
CatnipRegistry.addToRegistrationMap(registry, registration);
|
||||
}
|
||||
|
||||
return holder;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.builder;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.CatnipRegistry;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.BlockHolder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BlockBuilder<T extends Block> extends AbstractBuilder<Block, T, BlockHolder<T>> {
|
||||
private final Function<Properties, T> factory;
|
||||
private Supplier<Properties> initialProperties = Properties::of;
|
||||
private Function<Properties, Properties> properties = Function.identity();
|
||||
|
||||
public BlockBuilder(CatnipRegistry owner, String name, Function<Properties, T> factory) {
|
||||
super(owner, name, BuiltInRegistries.BLOCK);
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public BlockBuilder<T> initialProperties(Supplier<? extends BlockBehaviour> block) {
|
||||
initialProperties = () -> Properties.ofFullCopy(block.get());
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockBuilder<T> properties(Function<Properties, Properties> properties) {
|
||||
this.properties = this.properties.andThen(properties);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
T build() {
|
||||
Properties properties = initialProperties.get();
|
||||
properties = this.properties.apply(properties);
|
||||
return factory.apply(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
BlockHolder<T> getHolder(HolderOwner<Block> owner, ResourceKey<Block> key) {
|
||||
//noinspection unchecked
|
||||
return (BlockHolder<T>) new BlockHolder<>(owner, key);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.builder;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.CatnipRegistry;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.DataComponentTypeHolder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
||||
public class DataComponentTypeBuilder<T> extends AbstractBuilder<DataComponentType<?>, DataComponentType<T>, DataComponentTypeHolder<T>> {
|
||||
private final DataComponentType.Builder<T> builder;
|
||||
|
||||
public DataComponentTypeBuilder(CatnipRegistry owner, String name) {
|
||||
super(owner, name, BuiltInRegistries.DATA_COMPONENT_TYPE);
|
||||
this.builder = DataComponentType.builder();
|
||||
}
|
||||
|
||||
public DataComponentTypeBuilder<T> persistent(Codec<T> codec) {
|
||||
this.builder.persistent(codec);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataComponentTypeBuilder<T> networkSynchronized(StreamCodec<? super RegistryFriendlyByteBuf, T> streamCodec) {
|
||||
this.builder.networkSynchronized(streamCodec);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataComponentTypeBuilder<T> cacheEncoding() {
|
||||
this.builder.cacheEncoding();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
DataComponentType<T> build() {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
DataComponentTypeHolder<T> getHolder(HolderOwner<DataComponentType<?>> owner, ResourceKey<DataComponentType<?>> key) {
|
||||
//noinspection rawtypes,unchecked
|
||||
return new DataComponentTypeHolder<T>((HolderOwner) owner, (ResourceKey) key);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.builder;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.CatnipRegistry;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.ItemHolder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Item.Properties;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ItemBuilder<T extends Item> extends AbstractBuilder<Item, T, ItemHolder<T>> {
|
||||
private final Function<Properties, T> factory;
|
||||
private Function<Properties, Properties> properties = Function.identity();
|
||||
|
||||
public ItemBuilder(CatnipRegistry owner, String name, Function<Properties, T> factory) {
|
||||
super(owner, name, BuiltInRegistries.ITEM);
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public ItemBuilder<T> properties(Function<Properties, Properties> properties) {
|
||||
this.properties = this.properties.andThen(properties);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
T build() {
|
||||
Properties properties = new Properties();
|
||||
properties = this.properties.apply(properties);
|
||||
return factory.apply(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
ItemHolder<T> getHolder(HolderOwner<Item> owner, ResourceKey<Item> key) {
|
||||
//noinspection unchecked
|
||||
return (ItemHolder<T>) new ItemHolder<>(owner, key);
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@net.minecraft.FieldsAreNonnullByDefault
|
||||
@javax.annotation.ParametersAreNonnullByDefault
|
||||
@net.minecraft.MethodsReturnNonnullByDefault
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.builder;
|
||||
// Copied from IThundxr's 1.21.1/registration branch of https://github.com/Creators-of-Create/Ponder/
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.holder;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.RegistrationListeners;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BaseHolder<T> extends Holder.Reference<T> {
|
||||
private final RegistrationListeners<T> registrationListeners = new RegistrationListeners<>();
|
||||
|
||||
protected BaseHolder(HolderOwner<T> owner, ResourceKey<T> key) {
|
||||
super(Type.STAND_ALONE, owner, key, null);
|
||||
}
|
||||
|
||||
public <V> boolean is(V value) {
|
||||
return value() == value;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Consumer<T> getInternalRegistrationListener() {
|
||||
return registrationListeners::registered;
|
||||
}
|
||||
|
||||
public void onRegistered(Consumer<? super T> consumer) {
|
||||
registrationListeners.addListener(consumer);
|
||||
}
|
||||
|
||||
public static <T> Holder<T> downcast(Holder<? extends T> holder) {
|
||||
//noinspection unchecked
|
||||
return (Holder<T>) holder;
|
||||
}
|
||||
|
||||
public String getRegisteredNamePath() {
|
||||
return this.unwrapKey().map((resourceKey) -> resourceKey.location().getPath()).orElse("[unregistered]");
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.holder;
|
||||
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BlockHolder<T extends Block> extends ItemLikeHolder.NonItem<T> {
|
||||
public BlockHolder(HolderOwner<T> owner, ResourceKey<T> key) {
|
||||
super(owner, key);
|
||||
}
|
||||
|
||||
public BlockState defaultBlockState() {
|
||||
return value().defaultBlockState();
|
||||
}
|
||||
|
||||
public boolean is(BlockState state) {
|
||||
return is(state.getBlock());
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.holder;
|
||||
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
||||
public class DataComponentTypeHolder<T> extends BaseHolder<DataComponentType<T>> {
|
||||
public DataComponentTypeHolder(HolderOwner<DataComponentType<T>> owner, ResourceKey<DataComponentType<T>> key) {
|
||||
super(owner, key);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.holder;
|
||||
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
public class ItemHolder<T extends Item> extends ItemLikeHolder<T> {
|
||||
public ItemHolder(HolderOwner<T> owner, ResourceKey<T> key) {
|
||||
super(owner, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(Item item) {
|
||||
return asItem() == item;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.holder;
|
||||
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
abstract class ItemLikeHolder<T extends ItemLike> extends BaseHolder<T> implements ItemLike {
|
||||
protected ItemLikeHolder(HolderOwner<T> owner, ResourceKey<T> key) {
|
||||
super(owner, key);
|
||||
}
|
||||
|
||||
public ItemStack asStack() {
|
||||
return new ItemStack(this);
|
||||
}
|
||||
|
||||
public ItemStack asStack(int count) {
|
||||
return new ItemStack(this, count);
|
||||
}
|
||||
|
||||
public boolean is(ItemStack stack) {
|
||||
return is(stack.getItem());
|
||||
}
|
||||
|
||||
public abstract boolean is(Item item);
|
||||
|
||||
@Override
|
||||
public Item asItem() {
|
||||
return value().asItem();
|
||||
}
|
||||
|
||||
static class NonItem<T extends ItemLike> extends ItemLikeHolder<T> {
|
||||
protected NonItem(HolderOwner<T> owner, ResourceKey<T> key) {
|
||||
super(owner, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(Item item) {
|
||||
return asItem() == item;
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@net.minecraft.FieldsAreNonnullByDefault
|
||||
@javax.annotation.ParametersAreNonnullByDefault
|
||||
@net.minecraft.MethodsReturnNonnullByDefault
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration.holder;
|
||||
// Copied from IThundxr's 1.21.1/registration branch of https://github.com/Creators-of-Create/Ponder/
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@net.minecraft.FieldsAreNonnullByDefault
|
||||
@javax.annotation.ParametersAreNonnullByDefault
|
||||
@net.minecraft.MethodsReturnNonnullByDefault
|
||||
package io.github.slimeistdev.crystalline_sky.foundation.registration;
|
||||
// Copied from IThundxr's 1.21.1/registration branch of https://github.com/Creators-of-Create/Ponder/
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package io.github.slimeistdev.crystalline_sky.mixin;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(Holder.Reference.class)
|
||||
public interface Holder$ReferenceAccessor<T> {
|
||||
@Accessor("owner")
|
||||
HolderOwner<T> crystalline_sky$getOwner();
|
||||
|
||||
@Invoker("bindValue")
|
||||
void crystalline_sky$bindValue(T value);
|
||||
}
|
||||
+4
-4
@@ -24,9 +24,9 @@ public class ClientLevelMixin {
|
||||
@Inject(method = "<clinit>", at = @At("RETURN"))
|
||||
private static void modifyBlockMarkerItems(CallbackInfo ci) {
|
||||
MARKER_PARTICLE_ITEMS = new HashSet<>(MARKER_PARTICLE_ITEMS);
|
||||
MARKER_PARTICLE_ITEMS.add(CrystallineItems.SKY_LIGHT);
|
||||
MARKER_PARTICLE_ITEMS.add(CrystallineItems.WEEPING_SKY_LIGHT);
|
||||
MARKER_PARTICLE_ITEMS.add(CrystallineItems.SKY);
|
||||
MARKER_PARTICLE_ITEMS.add(CrystallineItems.WEEPING_SKY);
|
||||
MARKER_PARTICLE_ITEMS.add(CrystallineItems.SKY_LIGHT.value());
|
||||
MARKER_PARTICLE_ITEMS.add(CrystallineItems.WEEPING_SKY_LIGHT.value());
|
||||
MARKER_PARTICLE_ITEMS.add(CrystallineItems.SKY.value());
|
||||
MARKER_PARTICLE_ITEMS.add(CrystallineItems.WEEPING_SKY.value());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -39,10 +39,8 @@ public class LevelRenderer_NoSodium_Mixin {
|
||||
if (renderLayer == CrystallineRenderTypes.SKY
|
||||
&& instance.COLOR_MODULATOR != null
|
||||
&& minecraft.player != null
|
||||
&& (minecraft.player.getMainHandItem().is(CrystallineItems.SKY)
|
||||
|| minecraft.player.getOffhandItem().is(CrystallineItems.SKY)
|
||||
|| minecraft.player.getMainHandItem().is(CrystallineItems.WEEPING_SKY)
|
||||
|| minecraft.player.getOffhandItem().is(CrystallineItems.WEEPING_SKY))) {
|
||||
&& (CrystallineItems.isSky(minecraft.player.getMainHandItem())
|
||||
|| CrystallineItems.isSky(minecraft.player.getOffhandItem()))) {
|
||||
|
||||
float f = ticks + minecraft.getTimer().getGameTimeDeltaPartialTick(true);
|
||||
float alpha = (Mth.sin(f / 10.0f) + 1.0f) / 2.0f;
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package io.github.slimeistdev.crystalline_sky.mixin.client.compat.axiom;
|
||||
|
||||
import com.moulberry.axiom.render.ChunkRenderOverrider;
|
||||
import io.github.slimeistdev.crystalline_sky.annotation.mixin.ConditionalMixin;
|
||||
import io.github.slimeistdev.crystalline_sky.compat.Mods;
|
||||
import io.github.slimeistdev.crystalline_sky.registry.client.CrystallineRenderTypes;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@ConditionalMixin(mods = Mods.AXIOM)
|
||||
@Mixin(ChunkRenderOverrider.AxiomChunkOverrideLayer.class)
|
||||
public class ChunkRenderOverrider_AxiomChunkOverrideLayerMixin {
|
||||
@Inject(method = "fromVanilla", at = @At("HEAD"), cancellable = true)
|
||||
private static void unexplodeSky(RenderType layer, CallbackInfoReturnable<ChunkRenderOverrider.AxiomChunkOverrideLayer> cir) {
|
||||
if (layer == CrystallineRenderTypes.SKY) {
|
||||
cir.setReturnValue(ChunkRenderOverrider.AxiomChunkOverrideLayer.CUTOUT_MIPPED);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package io.github.slimeistdev.crystalline_sky.multiloader;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ItemGroupRegistrationEvent {
|
||||
ResourceKey<CreativeModeTab> getTab();
|
||||
boolean hasPermissions();
|
||||
void addAfter(ItemLike reference, List<ItemStack> stacks);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Steam 'n' Rails
|
||||
* Copyright (c) 2022-2024 The Railways Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.github.slimeistdev.crystalline_sky.multiloader;
|
||||
|
||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||
import io.github.slimeistdev.crystalline_sky.compat.Mods;
|
||||
import io.github.slimeistdev.crystalline_sky.util.TextUtils;
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public enum Loader {
|
||||
NEOFORGE, FABRIC, QUILT;
|
||||
|
||||
public static final Loader CURRENT = getCurrent();
|
||||
|
||||
public boolean isCurrent() {
|
||||
return this == CURRENT;
|
||||
}
|
||||
|
||||
public void runIfCurrent(Supplier<Runnable> run) {
|
||||
if (isCurrent())
|
||||
run.get().run();
|
||||
}
|
||||
|
||||
public static String getFormatted() {
|
||||
return TextUtils.titleCaseConversion(getActual().name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
// Returns the actual loader, ex: quilt on quilt instead of fabric for quilt
|
||||
public static Loader getActual() {
|
||||
//noinspection ConstantValue
|
||||
if (FABRIC.isCurrent() && Mods.isModLoaded("quilt_loader"))
|
||||
return QUILT;
|
||||
return CURRENT;
|
||||
}
|
||||
|
||||
@Internal
|
||||
@ExpectPlatform
|
||||
private static Loader getCurrent() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
+53
-46
@@ -1,76 +1,63 @@
|
||||
package io.github.slimeistdev.crystalline_sky.registry;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.CrystallineSky;
|
||||
import io.github.slimeistdev.crystalline_sky.content.blocks.SkyBlock;
|
||||
import io.github.slimeistdev.crystalline_sky.content.blocks.SkyLightBlock;
|
||||
import io.github.slimeistdev.crystalline_sky.content.blocks.WeepingSkyLightBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.CatnipRegistry;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.BlockHolder;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.LightBlock;
|
||||
import net.minecraft.world.level.block.TransparentBlock;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
public class CrystallineBlocks {
|
||||
public static final Block SKY = register("sky", TransparentBlock::new, Properties.of()
|
||||
.strength(0.3f)
|
||||
.sound(SoundType.AMETHYST)
|
||||
.noOcclusion()
|
||||
.isValidSpawn(Blocks::never)
|
||||
.isRedstoneConductor(Blocks::never)
|
||||
.isSuffocating(Blocks::never)
|
||||
.isViewBlocking(Blocks::never)
|
||||
.emissiveRendering(Blocks::always));
|
||||
private static final CatnipRegistry REGISTRY = CrystallineSky.registry();
|
||||
|
||||
public static final Block WEEPING_SKY = register("weeping_sky", TransparentBlock::new, Properties.ofFullCopy(SKY));
|
||||
public static final BlockHolder<SkyBlock> SKY = REGISTRY.block("sky", SkyBlock::new)
|
||||
.properties(p -> p
|
||||
.strength(0.3f)
|
||||
.sound(SoundType.AMETHYST)
|
||||
.noOcclusion()
|
||||
.isValidSpawn(CrystallineBlocks::never)
|
||||
.isRedstoneConductor(CrystallineBlocks::never)
|
||||
.isSuffocating(CrystallineBlocks::never)
|
||||
.isViewBlocking(CrystallineBlocks::never)
|
||||
.emissiveRendering(CrystallineBlocks::always))
|
||||
.register();
|
||||
|
||||
public static final Block SKY_LIGHT = register(
|
||||
"sky_light",
|
||||
SkyLightBlock::new,
|
||||
BlockBehaviour.Properties.of()
|
||||
public static final BlockHolder<SkyBlock> WEEPING_SKY = REGISTRY.block("weeping_sky", SkyBlock::new)
|
||||
.initialProperties(SKY::value)
|
||||
.register();
|
||||
|
||||
public static final BlockHolder<SkyLightBlock> SKY_LIGHT = REGISTRY.block("sky_light", SkyLightBlock::new)
|
||||
.properties(p -> p
|
||||
.replaceable()
|
||||
.strength(-1.0F, 3600000.8F)
|
||||
.mapColor(state -> state.getValue(BlockStateProperties.WATERLOGGED) ? MapColor.WATER : MapColor.NONE)
|
||||
.mapColor(CrystallineBlocks::waterloggedColor)
|
||||
.noLootTable()
|
||||
.noOcclusion()
|
||||
);
|
||||
.noOcclusion())
|
||||
.register();
|
||||
|
||||
public static final Block WEEPING_SKY_LIGHT = register(
|
||||
"weeping_sky_light",
|
||||
WeepingSkyLightBlock::new,
|
||||
BlockBehaviour.Properties.of()
|
||||
.replaceable()
|
||||
.strength(-1.0F, 3600000.8F)
|
||||
.mapColor(state -> state.getValue(BlockStateProperties.WATERLOGGED) ? MapColor.WATER : MapColor.NONE)
|
||||
.noLootTable()
|
||||
.noOcclusion()
|
||||
);
|
||||
public static final BlockHolder<WeepingSkyLightBlock> WEEPING_SKY_LIGHT = REGISTRY.block("weeping_sky_light", WeepingSkyLightBlock::new)
|
||||
.initialProperties(SKY_LIGHT::value)
|
||||
.register();
|
||||
|
||||
public static void init() {}
|
||||
|
||||
private static <T extends Block> T register(String id, Function<Properties, T> factory, Properties settings) {
|
||||
ResourceKey<Block> key = CrystallineSky.key(Registries.BLOCK, id);
|
||||
return Registry.register(BuiltInRegistries.BLOCK, key, factory.apply(settings));
|
||||
}
|
||||
|
||||
public static boolean isCrystallineSky(BlockState state) {
|
||||
return getSkyLightLevel(state) > 0;
|
||||
}
|
||||
|
||||
public static int getSkyLightLevel(BlockState state) {
|
||||
if (state.is(SKY_LIGHT)) {
|
||||
if (SKY_LIGHT.is(state)) {
|
||||
return state.getValue(LightBlock.LEVEL);
|
||||
} else if (state.is(SKY)) { // weeping sky explicitly excluded, that's handled differently
|
||||
} else if (SKY.is(state)) { // weeping sky explicitly excluded, that's handled differently
|
||||
return 15;
|
||||
}
|
||||
|
||||
@@ -78,6 +65,26 @@ public class CrystallineBlocks {
|
||||
}
|
||||
|
||||
public static boolean isWeepingSky(BlockState state) {
|
||||
return state.is(WEEPING_SKY) || state.is(WEEPING_SKY_LIGHT);
|
||||
return WEEPING_SKY.is(state) || WEEPING_SKY_LIGHT.is(state);
|
||||
}
|
||||
|
||||
private static Boolean never(BlockState state, BlockGetter blockGetter, BlockPos pos, EntityType<?> entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Boolean always(BlockState state, BlockGetter blockGetter, BlockPos pos, EntityType<?> entity) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean always(BlockState state, BlockGetter blockGetter, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean never(BlockState state, BlockGetter blockGetter, BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static MapColor waterloggedColor(BlockState state) {
|
||||
return state.getValue(BlockStateProperties.WATERLOGGED) ? MapColor.WATER : MapColor.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-14
@@ -1,26 +1,19 @@
|
||||
package io.github.slimeistdev.crystalline_sky.registry;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.CrystallineSky;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.CatnipRegistry;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.DataComponentTypeHolder;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.util.Unit;
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class CrystallineDataComponentTypes {
|
||||
public static final DataComponentType<Unit> WEEPING_SKY_DEBUG_COLUMN_TOOL = register(
|
||||
"weeping_sky_debug_column_tool",
|
||||
b -> b
|
||||
private static final CatnipRegistry REGISTRY = CrystallineSky.registry();
|
||||
|
||||
public static final DataComponentTypeHolder<Unit> WEEPING_SKY_DEBUG_COLUMN_TOOL =
|
||||
REGISTRY.<Unit>dataComponentType("weeping_sky_debug_column_tool")
|
||||
.networkSynchronized(StreamCodec.unit(Unit.INSTANCE))
|
||||
.persistent(Unit.CODEC)
|
||||
);
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static <T> DataComponentType<T> register(String id, UnaryOperator<DataComponentType.Builder<T>> builderOperator) {
|
||||
return Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, CrystallineSky.id(id), builderOperator.apply(DataComponentType.builder()).build());
|
||||
}
|
||||
.register();
|
||||
|
||||
public static void init() {}
|
||||
}
|
||||
|
||||
+38
-32
@@ -1,54 +1,54 @@
|
||||
package io.github.slimeistdev.crystalline_sky.registry;
|
||||
|
||||
import io.github.slimeistdev.crystalline_sky.CrystallineSky;
|
||||
import io.github.slimeistdev.crystalline_sky.content.blocks.SkyLightBlock;
|
||||
import io.github.slimeistdev.crystalline_sky.content.items.WeepingSkyBlockItem;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.LightBlock;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.CatnipRegistry;
|
||||
import io.github.slimeistdev.crystalline_sky.foundation.registration.holder.ItemHolder;
|
||||
import io.github.slimeistdev.crystalline_sky.multiloader.ItemGroupRegistrationEvent;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.world.item.component.BlockItemStateProperties;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.component.BlockItemStateProperties;
|
||||
import net.minecraft.world.level.block.LightBlock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CrystallineItems {
|
||||
public static final Item SKY = Items.registerBlock(
|
||||
CrystallineBlocks.SKY,
|
||||
settings -> settings.rarity(Rarity.EPIC)
|
||||
);
|
||||
private static final CatnipRegistry REGISTRY = CrystallineSky.registry();
|
||||
|
||||
public static final Item WEEPING_SKY = register(
|
||||
CrystallineBlocks.WEEPING_SKY,
|
||||
(block, settings) -> new WeepingSkyBlockItem(block, settings.rarity(Rarity.EPIC))
|
||||
);
|
||||
public static final ItemHolder<BlockItem> SKY = REGISTRY.item(CrystallineBlocks.SKY)
|
||||
.properties(p -> p.rarity(Rarity.EPIC))
|
||||
.register();
|
||||
|
||||
public static final Item SKY_LIGHT = Items.registerBlock(
|
||||
CrystallineBlocks.SKY_LIGHT,
|
||||
settings -> settings.rarity(Rarity.EPIC)
|
||||
.component(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(LightBlock.LEVEL, 15))
|
||||
);
|
||||
public static final ItemHolder<WeepingSkyBlockItem> WEEPING_SKY = REGISTRY.item(CrystallineBlocks.WEEPING_SKY, WeepingSkyBlockItem::new)
|
||||
.properties(p -> p.rarity(Rarity.EPIC))
|
||||
.register();
|
||||
|
||||
public static final Item WEEPING_SKY_LIGHT = Items.registerBlock(
|
||||
CrystallineBlocks.WEEPING_SKY_LIGHT,
|
||||
settings -> settings.rarity(Rarity.EPIC)
|
||||
);
|
||||
public static final ItemHolder<BlockItem> SKY_LIGHT = REGISTRY.item(CrystallineBlocks.SKY_LIGHT)
|
||||
.properties(p -> p
|
||||
.rarity(Rarity.EPIC)
|
||||
.component(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(LightBlock.LEVEL, 15)))
|
||||
.register();
|
||||
|
||||
public static final ItemHolder<BlockItem> WEEPING_SKY_LIGHT = REGISTRY.item(CrystallineBlocks.WEEPING_SKY_LIGHT)
|
||||
.properties(p -> p.rarity(Rarity.EPIC))
|
||||
.register();
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static Item register(Block block, BiFunction<Block, Item.Properties, BlockItem> factory) {
|
||||
return Items.registerBlock(factory.apply(block, new Item.Properties()));
|
||||
private static ResourceKey<CreativeModeTab> tabKey(String name) {
|
||||
return ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.withDefaultNamespace(name));
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.OP_BLOCKS).register(entries -> {
|
||||
if (!entries.getContext().hasPermissions()) return;
|
||||
|
||||
public static void onItemGroupRegistration(ItemGroupRegistrationEvent event) {
|
||||
if (event.getTab().equals(tabKey("op_blocks")) && event.hasPermissions()) {
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
|
||||
stacks.add(new ItemStack(SKY));
|
||||
@@ -60,7 +60,13 @@ public class CrystallineItems {
|
||||
|
||||
stacks.add(new ItemStack(WEEPING_SKY_LIGHT));
|
||||
|
||||
entries.addAfter(Items.LIGHT, stacks);
|
||||
});
|
||||
event.addAfter(Items.LIGHT, stacks);
|
||||
}
|
||||
}
|
||||
|
||||
public static void init() {}
|
||||
|
||||
public static boolean isSky(ItemStack stack) {
|
||||
return SKY.is(stack) || WEEPING_SKY.is(stack);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-8
@@ -1,21 +1,18 @@
|
||||
package io.github.slimeistdev.crystalline_sky.registry.client;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import io.github.slimeistdev.crystalline_sky.mixin_ducks.client.RenderType_Duck;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import io.github.slimeistdev.crystalline_sky.mixin_ducks.client.LevelRenderer_Duck;
|
||||
import io.github.slimeistdev.crystalline_sky.mixin_ducks.client.RenderType_Duck;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.RenderStateShard;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
|
||||
import static net.minecraft.client.renderer.RenderType.create;
|
||||
import static net.minecraft.client.renderer.RenderStateShard.LIGHTMAP;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class CrystallineRenderTypes {
|
||||
public abstract class CrystallineRenderTypes extends RenderType {
|
||||
private static final RenderStateShard.EmptyTextureStateShard SKY_TEXTURE = new SkyBufferTexture();
|
||||
private static final RenderStateShard.ShaderStateShard SKY_PROGRAM = new RenderStateShard.ShaderStateShard(CrystallineShaderInstances::getRenderTypeSkyProgram);
|
||||
|
||||
@@ -38,6 +35,10 @@ public class CrystallineRenderTypes {
|
||||
((RenderType_Duck) SKY).crystalline_sky$markAsBlockLayer();
|
||||
}
|
||||
|
||||
private CrystallineRenderTypes(String name, VertexFormat format, VertexFormat.Mode mode, int bufferSize, boolean affectsCrumbling, boolean sortOnUpload, Runnable setupState, Runnable clearState) {
|
||||
super(name, format, mode, bufferSize, affectsCrumbling, sortOnUpload, setupState, clearState);
|
||||
}
|
||||
|
||||
private static class SkyBufferTexture extends RenderStateShard.EmptyTextureStateShard {
|
||||
public SkyBufferTexture() {
|
||||
super(() -> {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Steam 'n' Rails
|
||||
* Copyright (c) 2022-2026 The Railways Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.github.slimeistdev.crystalline_sky.util;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class TextUtils {
|
||||
public static String snakeCaseToTitleCase(String inputString) {
|
||||
return titleCaseConversion(inputString.replace("_", " "));
|
||||
}
|
||||
|
||||
public static String titleCaseConversion(String inputString) {
|
||||
if (StringUtils.isBlank(inputString)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (StringUtils.length(inputString) == 1) {
|
||||
return inputString.toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
StringBuffer resultPlaceHolder = new StringBuffer(inputString.length());
|
||||
|
||||
Stream.of(inputString.split(" ")).forEach(stringPart -> {
|
||||
if (stringPart.length() > 1)
|
||||
resultPlaceHolder.append(stringPart.substring(0, 1)
|
||||
.toUpperCase(Locale.ROOT))
|
||||
.append(stringPart.substring(1)
|
||||
.toLowerCase(Locale.ROOT));
|
||||
else
|
||||
resultPlaceHolder.append(stringPart.toUpperCase(Locale.ROOT));
|
||||
|
||||
resultPlaceHolder.append(" ");
|
||||
});
|
||||
return StringUtils.trim(resultPlaceHolder.toString());
|
||||
}
|
||||
|
||||
public static Component translateWithFormatting(String key, Object... args) {
|
||||
MutableComponent base = Component.translatable(key, args);
|
||||
StringBuilder partsStringBuilder = new StringBuilder();
|
||||
base.visit((style, part) -> {
|
||||
partsStringBuilder.append(part);
|
||||
return Optional.empty();
|
||||
}, Style.EMPTY);
|
||||
return Component.literal(partsStringBuilder.toString());
|
||||
}
|
||||
|
||||
public static String joinSpace(@Nullable String... strings) {
|
||||
return join(" ", strings);
|
||||
}
|
||||
|
||||
public static String joinUnderscore(@Nullable String... strings) {
|
||||
return join("_", strings);
|
||||
}
|
||||
|
||||
public static String join(final String separator, final @Nullable String... strings) {
|
||||
String[] filtered = Stream.of(strings).filter(s -> s != null && !s.isEmpty()).toArray(String[]::new);
|
||||
StringBuilder out = new StringBuilder();
|
||||
for (int i = 0; i < filtered.length; i++) {
|
||||
out.append(filtered[i]);
|
||||
if (i < filtered.length - 1) out.append(separator);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static String stripPrefix(String string, String prefix) {
|
||||
if (string.startsWith(prefix)) {
|
||||
return string.substring(prefix.length());
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String ensureEndsWith(String string, String suffix) {
|
||||
if (!string.endsWith(suffix)) {
|
||||
return string + suffix;
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String prefixToFolder(String name, @NotNull String prefix) {
|
||||
return prefix + "/" + stripPrefix(name, ensureEndsWith(prefix, "_"));
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,20 @@
|
||||
"plugin": "io.github.slimeistdev.crystalline_sky.mixin.CrystallineSkyMixinPlugin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"LightEngineMixin",
|
||||
"ChunkSkyLightSourcesMixin",
|
||||
"SkyLightEngineMixin",
|
||||
"Holder$ReferenceAccessor",
|
||||
"LayerLightSectionStorageAccessor",
|
||||
"LightEngineMixin",
|
||||
"SkyLightEngineMixin",
|
||||
"SkyLightSectionStorageAccessor"
|
||||
],
|
||||
"client": [
|
||||
"client.ClientLevelMixin",
|
||||
"client.DebugRendererMixin",
|
||||
"client.RenderTargetMixin",
|
||||
"client.GameRendererMixin",
|
||||
"client.LevelRenderer_NoSodium_Mixin",
|
||||
"client.LevelRendererMixin",
|
||||
"client.compat.axiom.ChunkRenderOverrider_AxiomChunkOverrideLayerMixin",
|
||||
"client.RenderTargetMixin",
|
||||
"client.compat.sodium.DefaultMaterialsMixin",
|
||||
"client.compat.sodium.DefaultTerrainRenderPassesMixin",
|
||||
"client.compat.sodium.ShaderChunkRendererMixin",
|
||||
|
||||
Reference in New Issue
Block a user