Add missed files
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.example.examplemod;
|
||||
package me.hypherionmc.craterlib;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
||||
}
|
||||
|
@@ -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();
|
||||
|
||||
}
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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();
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package me.hypherionmc.craterlib.systems;
|
||||
package me.hypherionmc.craterlib.systems.energy;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user