Add missed files

This commit is contained in:
2022-05-12 00:20:18 +02:00
parent 16c24ce795
commit a49903cc69
40 changed files with 728 additions and 367 deletions

45
.gitignore vendored
View File

@@ -1,29 +1,24 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
# eclipse
bin
*.launch
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
.metadata
.classpath
.project
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
# idea
out
*.ipr
*.iws
*.iml
.idea
### VS Code ###
.vscode/
# gradle
build
.gradle
### Mac OS ###
.DS_Store
# other
eclipse
run
artifacts

14
.idea/misc.xml generated
View File

@@ -1,6 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<list size="4">
<item index="0" class="java.lang.String" itemvalue="net.minecraftforge.fml.common.Mod" />
<item index="1" class="java.lang.String" itemvalue="net.minecraftforge.fml.common.Mod.EventHandler" />
<item index="2" class="java.lang.String" itemvalue="net.minecraftforge.fml.common.eventhandler.SubscribeEvent" />
<item index="3" class="java.lang.String" itemvalue="net.minecraftforge.eventbus.api.SubscribeEvent" />
</list>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SwUserDefinedSpecifications">
<option name="specTypeByUrl">
<map />
</option>
</component>
</project>

View File

@@ -26,11 +26,9 @@ dependencies {
}
processResources {
def buildProps = project.properties.clone()
filesMatching(['pack.mcmeta']) {
expand buildProps
}
}

View File

@@ -1,4 +1,4 @@
package com.example.examplemod;
package me.hypherionmc.craterlib;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@@ -1,4 +1,4 @@
package me.hypherionmc.craterlib.api;
package me.hypherionmc.craterlib.api.blockentities;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;

View File

@@ -1,2 +1,12 @@
package me.hypherionmc.craterlib.api.blockentities;public interface ITickable {
package me.hypherionmc.craterlib.api.blockentities;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
public interface ITickable {
public void tick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity);
}

View File

@@ -1,2 +1,9 @@
package me.hypherionmc.craterlib.api.rendering;public interface CustomRenderType {
package me.hypherionmc.craterlib.api.rendering;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
public interface CustomRenderType {
RenderLayer getCustomRenderType();
}

View File

@@ -3,7 +3,7 @@ package me.hypherionmc.craterlib.api.rendering;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.world.item.DyeColor;
public interface DyeAble {
public interface DyableBlock {
BlockColors dyeHandler();

View File

@@ -1,2 +1,9 @@
package me.hypherionmc.craterlib.api.rendering;public interface ItemDyable {
package me.hypherionmc.craterlib.api.rendering;
import net.minecraft.world.item.DyeColor;
public interface ItemDyable {
public DyeColor getColor();
}

View File

@@ -1,2 +1,48 @@
package me.hypherionmc.craterlib.client.gui.widgets;public class TimeSliderWidget {
package me.hypherionmc.craterlib.client.gui.widgets;
import net.minecraft.client.gui.components.AbstractSliderButton;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
public class TimeSliderWidget extends AbstractSliderButton {
private final double maxValue;
private final ISliderChanged sliderChanged;
public TimeSliderWidget(int x, int y, int width, int height, Component text, double value, double maxValue, ISliderChanged sliderChanged) {
super(x, y, width, height, text, value / maxValue);
this.maxValue = maxValue;
this.sliderChanged = sliderChanged;
this.updateMessage();
}
@Override
protected void updateMessage() {
this.setMessage(getDisplayString());
}
@Override
protected void applyValue() {
this.sliderChanged.onSliderChange(this);
}
private Component getDisplayString() {
long seconds = Math.round(this.value * this.maxValue / 20);
long minutes = Math.round(seconds / 60);
if (this.value * this.maxValue >= 1200) {
String appendString = (minutes == 1) ? "Minute" : "Minutes";
String doSeconds = ((seconds - (minutes * 60)) > 0) ? ", " + (seconds - (minutes * 60)) + " Seconds" : "";
return new TextComponent(minutes + " " + appendString + doSeconds);
} else {
return new TextComponent(seconds + " Seconds");
}
}
public double getValue() {
return this.value;
}
public interface ISliderChanged {
void onSliderChange(TimeSliderWidget slider);
}
}

View File

@@ -1,2 +1,22 @@
package me.hypherionmc.craterlib.client.rendering;public class ItemColorHandler {
package me.hypherionmc.craterlib.client.rendering;
import me.hypherionmc.craterlib.api.rendering.DyableBlock;
import me.hypherionmc.craterlib.api.rendering.ItemDyable;
import me.hypherionmc.craterlib.common.item.BlockItemDyable;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.world.item.ItemStack;
public class ItemColorHandler extends ItemColors {
@Override
public int getColor(ItemStack stack, int tintIndex) {
return this.getColorFromStack(stack);
}
private int getColorFromStack(ItemStack stack) {
if (stack.getItem() instanceof ItemDyable itemDyable) {
return itemDyable.getColor().getMaterialColor().col;
}
return 0;
}
}

View File

@@ -1,2 +1,22 @@
package me.hypherionmc.craterlib.common.item;public class BlockItemDyable {
package me.hypherionmc.craterlib.common.item;
import me.hypherionmc.craterlib.api.rendering.DyableBlock;
import me.hypherionmc.craterlib.api.rendering.ItemDyable;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.Block;
public class BlockItemDyable extends BlockItem implements ItemDyable {
public BlockItemDyable(Block block, Properties properties) {
super(block, properties);
}
@Override
public DyeColor getColor() {
if (this.getBlock() instanceof DyableBlock dyableBlock) {
return dyableBlock.defaultDyeColor();
}
return DyeColor.BLACK;
}
}

View File

@@ -1,2 +1,93 @@
package me.hypherionmc.craterlib.common.item;public class DyableWaterBottle {
package me.hypherionmc.craterlib.common.item;
import me.hypherionmc.craterlib.api.rendering.ItemDyable;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.gameevent.GameEvent;
import java.util.List;
public class DyableWaterBottle extends DyeItem implements ItemDyable {
private final DyeColor color;
private final boolean isGlowing;
public DyableWaterBottle(DyeColor color, boolean isGlowing, Properties properties) {
super(color, properties);
this.color = color;
this.isGlowing = isGlowing;
}
@Override
public boolean isFoil(ItemStack stack) {
return this.isGlowing;
}
@Override
public DyeColor getColor() {
return this.color;
}
@Override
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity user) {
Player playerEntity;
Player playerEntity2 = playerEntity = user instanceof Player ? (Player) user : null;
if (playerEntity instanceof ServerPlayer) {
CriteriaTriggers.CONSUME_ITEM.trigger((ServerPlayer) playerEntity, stack);
}
if (!level.isClientSide()) {
List<MobEffectInstance> list = PotionUtils.getMobEffects(stack);
for (MobEffectInstance statusEffectInstance : list) {
if (statusEffectInstance.getEffect().isInstantenous()) {
statusEffectInstance.getEffect().applyInstantenousEffect(playerEntity, playerEntity, user, statusEffectInstance.getAmplifier(), 1.0);
continue;
}
user.addEffect(new MobEffectInstance(statusEffectInstance));
}
if (stack.getItem() == this && isGlowing) {
user.addEffect(new MobEffectInstance(MobEffects.NIGHT_VISION, 3600));
}
}
if (playerEntity != null) {
playerEntity.awardStat(Stats.ITEM_USED.get(this));
if (!playerEntity.getAbilities().instabuild) {
stack.shrink(1);
}
}
if (playerEntity == null || !playerEntity.getAbilities().instabuild) {
if (stack.isEmpty()) {
return new ItemStack(Items.GLASS_BOTTLE);
}
if (playerEntity != null) {
playerEntity.getInventory().add(new ItemStack(Items.GLASS_BOTTLE));
}
}
level.gameEvent(user, GameEvent.DRINKING_FINISH, user.getOnPos());
return stack;
}
@Override
public int getUseDuration(ItemStack stack) {
return 32;
}
@Override
public UseAnim getUseAnimation(ItemStack stack) {
return UseAnim.DRINK;
}
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
return ItemUtils.startUsingInstantly(level, player, hand);
}
}

View File

@@ -1,2 +1,33 @@
package me.hypherionmc.craterlib.common.item;public class DyableWaterBucker {
package me.hypherionmc.craterlib.common.item;
import me.hypherionmc.craterlib.api.rendering.ItemDyable;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.material.Fluid;
public class DyableWaterBucket extends BucketItem implements ItemDyable {
private final DyeColor color;
private final boolean isGlowing;
public DyableWaterBucket(Fluid fluid, Properties properties, DyeColor color, boolean isGlowing) {
super(fluid, properties);
this.color = color;
this.isGlowing = isGlowing;
}
@Override
public boolean isFoil(ItemStack stack) {
return this.isGlowing;
}
@Override
public DyeColor getColor() {
return this.color;
}
public boolean isGlowing() {
return isGlowing;
}
}

View File

@@ -1,7 +1,7 @@
package com.example.examplemod.platform;
package me.hypherionmc.craterlib.platform;
import com.example.examplemod.Constants;
import com.example.examplemod.platform.services.IPlatformHelper;
import me.hypherionmc.craterlib.Constants;
import me.hypherionmc.craterlib.platform.services.IPlatformHelper;
import java.util.ServiceLoader;

View File

@@ -1,26 +1,10 @@
package com.example.examplemod.platform.services;
package me.hypherionmc.craterlib.platform.services;
public interface IPlatformHelper {
/**
* Gets the name of the current platform
*
* @return The name of the current platform.
*/
String getPlatformName();
/**
* Checks if a mod with the given id is loaded.
*
* @param modId The mod to check if it is loaded.
* @return True if the mod is loaded, false otherwise.
*/
boolean isModLoaded(String modId);
/**
* Check if the game is currently in a development environment.
*
* @return True if in a development environment, false otherwise.
*/
boolean isDevelopmentEnvironment();
}

View File

@@ -1,4 +1,4 @@
package me.hypherionmc.craterlib.systems;
package me.hypherionmc.craterlib.systems.energy;
import net.minecraft.nbt.CompoundTag;

View File

@@ -1,2 +1,18 @@
package me.hypherionmc.craterlib.util;public class BlockStateUtils {
package me.hypherionmc.craterlib.util;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import java.util.function.ToIntFunction;
public class BlockStateUtils {
public static ToIntFunction<BlockState> createLightLevelFromLitBlockState(int litLevel) {
return state -> state.getValue(BlockStateProperties.LIT) ? litLevel : 0;
}
public static ToIntFunction<BlockState> createLightLevelFromPoweredBlockState(int litLevel) {
return state -> state.getValue(BlockStateProperties.POWERED) ? litLevel : 0;
}
}

View File

@@ -1,26 +1,26 @@
package me.hypherionmc.hyperlighting.utils;
package me.hypherionmc.craterlib.util;
import net.minecraft.text.BaseText;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
public class LangUtils {
public static BaseText getTooltipTitle(String key) {
return new LiteralText(Formatting.YELLOW + new TranslatableText(key).getString());
public static Component getTooltipTitle(String key) {
return new TextComponent(ChatFormatting.YELLOW + new TranslatableComponent(key).getString());
}
public static String resolveTranslation(String key) {
return new TranslatableText(key).getString();
return new TranslatableComponent(key).getString();
}
public static BaseText getTranslation(String key) {
return new TranslatableText(key);
public static Component getTranslation(String key) {
return new TranslatableComponent(key);
}
public static BaseText makeComponent(String text) {
return new LiteralText(text);
public static Component makeComponent(String text) {
return new TranslatableComponent(text);
}
}

View File

@@ -1,21 +1,37 @@
package me.hypherionmc.hyperlighting.utils;
package me.hypherionmc.craterlib.util;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
public class MathUtils {
public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };
VoxelShape[] buffer = new VoxelShape[]{ shape, Shapes.empty() };
int times = (to.ordinal() - from.ordinal() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.box(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = VoxelShapes.empty();
buffer[1] = Shapes.empty();
}
return buffer[0];
}
public static void writeBlockPosToNBT(BlockPos pos, CompoundTag tag) {
tag.putInt("block_x", pos.getX());
tag.putInt("block_y", pos.getY());
tag.putInt("block_z", pos.getZ());
}
public static BlockPos readBlockPosFromNBT(CompoundTag tag) {
int x, y, z;
x = tag.getInt("block_x");
y = tag.getInt("block_y");
z = tag.getInt("block_z");
return new BlockPos(x, y, z);
}
}

View File

@@ -1,2 +1,41 @@
package me.hypherionmc.craterlib.util;public class OptifineUtils {
package me.hypherionmc.craterlib.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class OptifineUtils {
private static boolean hasOptifine = false;
public static void checkOptifine() {
try {
Class ofConfigClass = Class.forName("net.optifine.Config");
hasOptifine = true;
} catch (ClassNotFoundException e) {
// Optifine is probably not present. Ignore the error
hasOptifine = false;
} catch (Exception e) {
e.printStackTrace();
}
hasOptifine = false;
}
public static boolean isRenderRegions() {
try {
Class ofConfigClass = Class.forName("net.optifine.Config");
Method rrField = ofConfigClass.getMethod("isRenderRegions");
return (boolean) rrField.invoke(null);
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
// Optifine is probably not present. Ignore the error
return false;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static boolean hasOptifine() {
return hasOptifine;
}
}

View File

@@ -1,2 +1,52 @@
package me.hypherionmc.craterlib.util;public class RenderUtils {
package me.hypherionmc.craterlib.util;
import com.mojang.math.Vector4f;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
public class RenderUtils {
public static Vector4f colorIntToRGBA(int color) {
float a = 1.0F;
float r = (color >> 16 & 0xFF) / 255.0F;
float g = (color >> 8 & 0xFF) / 255.0F;
float b = (color & 0xFF) / 255.0F;
return new Vector4f(r, g, b, a);
}
public static Component getFluidAmount(long amount, long capacity) {
amount = amount / 81;
capacity = capacity / 81;
String text = "" + (int) (((float) amount / capacity) * 100);
return amount > 0 ? new TextComponent(ChatFormatting.AQUA + text + "%") : new TextComponent(text + "%");
}
public static Component getTimeDisplayString(double value) {
long seconds = Math.round((value / 20));
long minutes = Math.round(seconds / 60);
if (seconds >= 60) {
String appendString = (minutes == 1) ? "Minute" : "Minutes";
String doSeconds = ((seconds - (minutes * 60)) > 0) ? ", " + (seconds - (minutes * 60)) + " Seconds" : "";
return new TextComponent(minutes + " " + appendString + doSeconds);
} else {
return new TextComponent(seconds + " Seconds");
}
}
public static class ARGB32 {
public static int alpha(int pPackedColor) {
return pPackedColor >>> 24;
}
public static int red(int pPackedColor) {
return pPackedColor >> 16 & 255;
}
public static int green(int pPackedColor) {
return pPackedColor >> 8 & 255;
}
public static int blue(int pPackedColor) {
return pPackedColor & 255;
}
}
}

View File

@@ -1,12 +1,11 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.example.examplemod.mixin",
"package": "me.hypherionmc.craterlib.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"ExampleCommonMixin"
],
"server": [
],

View File

@@ -71,3 +71,20 @@ publishing {
}
}
}
task delDevJar {
doLast {
def tree = fileTree('build/libs')
tree.include '**/*-dev.jar'
tree.each { it.delete() }
}
}
build.finalizedBy delDevJar
task copyAllArtifacts(type: Copy) {
from "$buildDir/libs"
into "$rootDir/artifacts"
include("*.jar")
}
build.finalizedBy(copyAllArtifacts);

View File

@@ -1,2 +1,11 @@
package me.hypherionmc.craterlib;public class CraterLibInitializer {
package me.hypherionmc.craterlib;
import net.fabricmc.api.ModInitializer;
public class CraterLibInitializer implements ModInitializer {
@Override
public void onInitialize() {
}
}

View File

@@ -1,2 +1,11 @@
package me.hypherionmc.craterlib.client;public class CraterLibClientInitializer {
package me.hypherionmc.craterlib.client;
import net.fabricmc.api.ClientModInitializer;
public class CraterLibClientInitializer implements ClientModInitializer {
@Override
public void onInitializeClient() {
}
}

View File

@@ -1,2 +1,95 @@
package me.hypherionmc.craterlib.client.gui.widgets;public class FluidStackWidget {
package me.hypherionmc.craterlib.client.gui.widgets;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import me.hypherionmc.craterlib.systems.fluid.FluidTank;
import me.hypherionmc.craterlib.util.LangUtils;
import me.hypherionmc.craterlib.util.RenderUtils;
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.network.chat.TextComponent;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Supplier;
/**
* Modified from https://github.com/SleepyTrousers/EnderIO-Rewrite/blob/dev/1.18.x/enderio-machines/src/main/java/com/enderio/machines/client/FluidStackWidget.java
*/
public class FluidStackWidget extends AbstractWidget {
private final Screen displayOn;
private final Supplier<FluidTank> getFluid;
private final String toolTipTitle;
public FluidStackWidget(Screen displayOn, Supplier<FluidTank> getFluid, int pX, int pY, int pWidth, int pHeight, String tooltipTitle) {
super(pX, pY, pWidth, pHeight, TextComponent.EMPTY);
this.displayOn = displayOn;
this.getFluid = getFluid;
this.toolTipTitle = tooltipTitle;
}
@Override
public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) {
Minecraft minecraft = Minecraft.getInstance();
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();
FluidTank fluidTank = getFluid.get();
if (!fluidTank.getResource().isBlank()) {
FluidVariant fluidStack = fluidTank.getResource();
TextureAtlasSprite still = FluidVariantRendering.getSprite(fluidStack);
if (still != null) {
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
int color = FluidVariantRendering.getColor(fluidStack);
RenderSystem.setShaderColor(
RenderUtils.ARGB32.red(color) / 255.0F,
RenderUtils.ARGB32.green(color) / 255.0F,
RenderUtils.ARGB32.blue(color) / 255.0F,
RenderUtils.ARGB32.alpha(color) / 255.0F);
RenderSystem.enableBlend();
long stored = fluidTank.getAmount();
float capacity = fluidTank.getCapacity();
float filledVolume = stored / capacity;
int renderableHeight = (int) (filledVolume * height);
int atlasWidth = (int) (still.getWidth() / (still.getU1() - still.getU0()));
int atlasHeight = (int) (still.getHeight() / (still.getV1() - still.getV0()));
matrices.pushPose();
matrices.translate(0, height - 16, 0);
for (int i = 0; i < Math.ceil(renderableHeight / 16f); i++) {
int drawingHeight = Math.min(16, renderableHeight - 16 * i);
int notDrawingHeight = 16 - drawingHeight;
blit(matrices, x, y + notDrawingHeight, displayOn.getBlitOffset(), still.getU0() * atlasWidth, still.getV0() * atlasHeight + notDrawingHeight, this.width, drawingHeight, atlasWidth, atlasHeight);
matrices.translate(0, -16, 0);
}
RenderSystem.setShaderColor(1, 1, 1, 1);
matrices.popPose();
}
renderToolTip(matrices, mouseX, mouseY);
}
}
@Override
public void renderToolTip(PoseStack poseStack, int mouseX, int mouseY) {
if (this.visible && this.isFocused() && isHoveredOrFocused()) {
displayOn.renderTooltip(poseStack, Arrays.asList(LangUtils.getTooltipTitle(toolTipTitle), new TextComponent((int) (((float) this.getFluid.get().getAmount() / this.getFluid.get().getCapacity()) * 100) + "%")), Optional.empty(), mouseX, mouseY);
}
}
@Override
public void updateNarration(NarrationElementOutput narrationElementOutput) {
}
}

View File

@@ -1,29 +1,28 @@
package me.hypherionmc.hyperlighting.api.fluid;
package me.hypherionmc.craterlib.systems.fluid;
import me.hypherionmc.hyperlighting.utils.ModUtils;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions;
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleViewIterator;
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.CompoundTag;
import java.util.Iterator;
import java.util.function.Predicate;
public class FluidStorageTank implements Storage<FluidVariant>, StorageView<FluidVariant> {
public class FluidTank implements Storage<FluidVariant>, StorageView<FluidVariant> {
private final long capacity;
private final Predicate<FluidVariant> validFluid;
private long level = 0;
private FluidVariant fluid = FluidVariant.blank();
public FluidStorageTank(long capacity) {
public FluidTank(long capacity) {
this(capacity, e -> true);
}
public FluidStorageTank(long capacity, Predicate<FluidVariant> validFluid) {
public FluidTank(long capacity, Predicate<FluidVariant> validFluid) {
this.capacity = capacity;
this.validFluid = validFluid;
}
@@ -87,14 +86,14 @@ public class FluidStorageTank implements Storage<FluidVariant>, StorageView<Flui
return SingleViewIterator.create(this, transaction);
}
public NbtCompound writeNbt(NbtCompound compound) {
ModUtils.putFluid(compound, "fluid", getResource());
public CompoundTag writeNbt(CompoundTag compound) {
FluidUtils.putFluid(compound, "fluid", getResource());
compound.putLong("amt", level);
return compound;
}
public void readNbt(NbtCompound nbtCompound) {
fluid = ModUtils.getFluidCompatible(nbtCompound, "fluid");
public void readNbt(CompoundTag nbtCompound) {
fluid = FluidUtils.getFluidCompatible(nbtCompound, "fluid");
level = nbtCompound.getLong("amt");
}
}

View File

@@ -1,2 +1,54 @@
package me.hypherionmc.craterlib.systems.fluid;public class FluidUtils {
package me.hypherionmc.craterlib.systems.fluid;
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
public class FluidUtils {
public static int fluidColorFromDye(DyeColor color) {
return color.getMaterialColor().col | 0xFF000000;
}
public static void putFluid(CompoundTag compound, String key, FluidVariant fluidVariant) {
CompoundTag savedTag = new CompoundTag();
savedTag.put("fk", fluidVariant.toNbt());
compound.put(key, savedTag);
}
public static FluidVariant getFluidCompatible(CompoundTag tag, String key) {
if (tag == null || !tag.contains(key))
return FluidVariant.blank();
if (tag.get(key) instanceof StringTag) {
return FluidVariant.of(Registry.FLUID.get(new ResourceLocation(tag.getString(key))));
} else {
CompoundTag compound = tag.getCompound(key);
if (compound.contains("fk")) {
return FluidVariant.fromNbt(compound.getCompound("fk"));
} else {
return FluidVariant.of(readLbaTag(tag.getCompound(key)));
}
}
}
private static Fluid readLbaTag(CompoundTag tag) {
if (tag.contains("ObjName") && tag.getString("Registry").equals("f")) {
return Registry.FLUID.get(new ResourceLocation(tag.getString("ObjName")));
} else {
return Fluids.EMPTY;
}
}
public static TextureAtlasSprite getFluidTexture(FluidVariant fluidStack) {
return FluidVariantRendering.getSprite(fluidStack);
}
}

View File

@@ -1,12 +1,11 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.example.examplemod.mixin",
"package": "me.hypherionmc.craterlib.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"ExampleFabricMixin"
],
"server": [
],
@@ -14,4 +13,3 @@
"defaultRequire": 1
}
}

View File

@@ -1,10 +1,10 @@
{
"schemaVersion": 1,
"id": "modid",
"id": "craterlib",
"version": "${version}",
"name": "Example Mod",
"description": "This is an example description! Tell everyone what your mod is about!",
"name": "CraterLib",
"description": "A library mod used by HypherionSA's Mods",
"authors": [
"Me!"
],
@@ -13,18 +13,21 @@
"sources": "https://github.com/FabricMC/fabric-example-mod"
},
"license": "CC0-1.0",
"license": "MIT",
"icon": "assets/modid/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"com.example.examplemod.ExampleMod"
"me.hypherionmc.craterlib.CraterLibInitializer"
],
"client": [
"me.hypherionmc.craterlib.client.CraterLibClientInitializer"
]
},
"mixins": [
"multiloader.mixins.json",
"multiloader.fabric.mixins.json"
"craterlib.mixins.json",
"craterlib.fabric.mixins.json"
],
"depends": {
@@ -37,4 +40,3 @@
"another-mod": "*"
}
}

View File

@@ -115,3 +115,11 @@ publishing {
}
}
}
task copyAllArtifacts(type: Copy) {
from "$buildDir/libs"
into "$rootDir/artifacts"
include("*.jar")
}
build.finalizedBy(copyAllArtifacts);

View File

@@ -1,34 +1,11 @@
package com.example.examplemod;
package me.hypherionmc.craterlib;
import me.hypherionmc.craterlib.Constants;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.Mod;
@Mod(Constants.MOD_ID)
public class ExampleMod {
public class CraterLib {
public ExampleMod() {
// This method is invoked by the Forge mod loader when it is ready
// to load your mod. You can access Forge and Common code in this
// project.
// Use Forge to bootstrap the Common mod.
Constants.LOG.info("Hello Forge world!");
CommonClass.init();
// Some code like events require special initialization from the
// loader specific code.
MinecraftForge.EVENT_BUS.addListener(this::onItemTooltip);
public CraterLib() {
}
// This method exists as a wrapper for the code in the Common project.
// It takes Forge's event object and passes the parameters along to
// the Common listener.
private void onItemTooltip(ItemTooltipEvent event) {
CommonClass.onItemTooltip(event.getItemStack(), event.getFlags(), event.getToolTip());
}
}

View File

@@ -1,62 +1,31 @@
# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[38,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license="All rights reserved"
# A URL to refer people to when problems occur with this mod
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="multiloader" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="${file.jarVersion}" #mandatory
# A display name for the mod
displayName="Example Mod" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional
# A file name (in the root of the mod JAR) containing a logo for display
logoFile="multiloader.png" #optional
# A text field displayed in the mod UI
credits="Thanks for this example mod goes to Java" #optional
# A text field displayed in the mod UI
authors="Love, Cheese and small house plants" #optional
# The description text for the mod (multi line!) (#mandatory)
modLoader="javafml"
loaderVersion="[40,)"
license="MIT"
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/"
[[mods]]
modId="craterlib"
version="${file.jarVersion}"
displayName="CraterLib"
#updateJSONURL="https://change.me.example.invalid/updates.json"
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/"
logoFile="multiloader.png"
#credits="Thanks for this example mod goes to Java"
authors="HypherionSA, Misha"
description='''
This is a long form description of the mod. You can write whatever you want here
Have some lorem ipsum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis luctus odio eu tempus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque volutpat ligula eget lacus auctor sagittis. In hac habitasse platea dictumst. Nunc gravida elit vitae sem vehicula efficitur. Donec mattis ipsum et arcu lobortis, eleifend sagittis sem rutrum. Cras pharetra quam eget posuere fermentum. Sed id tincidunt justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
A library mod used by HypherionSA's Mods
'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.multiloader]] #optional
# the modid of the dependency
modId="forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[38,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
[[dependencies.craterlib]]
modId="forge"
mandatory=true
versionRange="[40,)"
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
side="BOTH"
# Here's another dependency
[[dependencies.multiloader]]
[[dependencies.craterlib]]
modId="minecraft"
mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.18,1.19)"
versionRange="[1.18.2,1.19)"
ordering="NONE"
side="BOTH"

View File

@@ -1,12 +1,11 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.example.examplemod.mixin",
"package": "me.hypherionmc.craterlib.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"ExampleForgeMixin"
],
"server": [
],

134
LICENSE
View File

@@ -1,121 +1,21 @@
Creative Commons Legal Code
The MIT License (MIT)
CC0 1.0 Universal
Copyright (c) 2021
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Statement of Purpose
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,25 +1,7 @@
# MultiLoader Template
# CraterLib
This project provides a Gradle project template that can compile mods for both Forge and Fabric using a common sourceset. This project does not require any third party libraries or dependencies.
A library mod used by HypherionSA's mods. Mostly used by Hyper Lighting 2.
## Getting Started
## Setup Instructions
## IntelliJ IDEA
This guide will show how to import the MultiLoader Template into IntelliJ IDEA. The setup process is roughly equivalent to setting up Forge and Fabric independently and should be very familiar to anyone who has worked with their MDKs.
1. Clone or download this repository to your computer.
2. Configure the project by editing the `group`, `mod_name`, `mod_author`, and `mod_id` properties in the `gradle.properties` file. You will also need to change the `rootProject.name` property in `settings.gradle`.
3. Open the template's root folder as a new project in IDEA. This is the folder that contains this README file and the gradlew executable.
4. If your default JVM/JDK is not Java 16 you will encounter an error when opening the project. This error is fixed by going to `File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JVM`and changing the value to a valid Java 16 JVM. You will also need to set the Project SDK to Java 16. This can be done by going to `File > Project Structure > Project SDK`. Once both have been set open the Gradle tab in IDEA and click the refresh button to reload the project.
5. Open the Gradle tab in IDEA if it has not already been opened. Navigate to `Your Project > Common > Tasks > vanilla gradle > decompile`. Run this task to decompile Minecraft.
6. Open the Gradle tab in IDEA if it has not already been opened. Navigate to `Your Project > Forge > Tasks > forgegradle runs > genIntellijRuns`. Run this task to set up run configurations for Forge.
7. Open your Run/Debug Configurations. Under the Application category there should now be options to run Forge and Fabric projects. Select one of the client options and try to run it.
8. Assuming you were able to run the game in step 7 your workspace should now be set up.
### Eclipse
While it is possible to use this template in Eclipse it is not recommended. During the development of this template multiple critical bugs and quirks related to Eclipse were found at nearly every level of the required build tools. While we continue to work with these tools to report and resolve issues support for projects like these are not there yet. For now Eclipse is considered unsupported by this project. The development cycle for build tools is notoriously slow so there are no ETAs available.
## Development Guide
When using this template the majority of your mod is developed in the Common project. The Common project is compiled against the vanilla game and is used to hold code that is shared between the different loader-specific versions of your mod. The Common project has no knwoledge or access to ModLoader specific code, apis, or concepts. Code that requires something from a specific loader must be done through the project that is specific to that loader, such as the Forge or Fabric project.
Loader specific projects such as the Forge and Fabric project are used to load the Common project into the game. These projects also define code that is specific to that loader. Loader specific projects can access all of the code in the Common project. It is important to remember that the Common project can not access code from loader specific projects.
*Coming Soon*

View File

@@ -1,10 +1,18 @@
subprojects {
def version_base = "${project.version_major}.${project.version_minor}"
version = "${version_base}.${project.version_patch}"
// Jenkins
if (System.getenv('BUILD_NUMBER') != null) {
version = version_base + "." + System.getenv('BUILD_NUMBER') + "d"
}
apply plugin: 'java'
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.withSourcesJar()
java.withJavadocJar()
//java.withSourcesJar()
//java.withJavadocJar()
jar {
manifest {
@@ -24,23 +32,14 @@ subprojects {
}
repositories {
mavenCentral()
maven {
name = 'Sponge / Mixin'
url = 'https://repo.spongepowered.org/repository/maven-public/'
}
maven {
name = 'BlameJared Maven (CrT / Bookshelf)'
url = 'https://maven.blamejared.com'
}
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = 'UTF-8'
it.options.release = 17
}
@@ -49,7 +48,10 @@ subprojects {
// metadata includes mapped dependencies which are not reasonably consumable by
// other mod developers.
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
clean {
delete "$rootDir/artifacts"
}
}

View File

@@ -1,26 +1,28 @@
# Project
version=1.0.0
group=com.example.examplemod
version_major=1
version_minor=0
version_patch=0
group=me.hypherionmc.craterlib
# Common
minecraft_version=1.18.1
minecraft_version=1.18.2
common_runs_enabled=false
common_client_run_name=Common Client
common_server_run_name=Common Server
# Forge
forge_version=39.0.7
forge_version=40.1.0
//forge_ats_enabled=true
# Fabric
fabric_version=0.44.0+1.18
fabric_loader_version=0.12.12
fabric_version=0.51.1+1.18.2
fabric_loader_version=0.13.3
# Mod options
mod_name=MultiLoader
mod_author=Jared
mod_id=multiloader
mod_name=CraterLib
mod_author=HypherionSA
mod_id=craterlib
# Gradle
org.gradle.jvmargs=-Xmx3G

View File

@@ -12,5 +12,5 @@ pluginManagement {
}
}
rootProject.name = 'MultiLoader'
rootProject.name = 'CraterLib'
include("Common", "Fabric", "Forge")