Implement Item Properties and get Forge Version up to date
This commit is contained in:
@@ -3,7 +3,7 @@ package me.hypherionmc.craterlib;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class Constants {
|
||||
public class CraterConstants {
|
||||
public static final String MOD_ID = "craterlib";
|
||||
public static final String MOD_NAME = "CraterLib";
|
||||
public static final Logger LOG = LogManager.getLogger(MOD_NAME);
|
@@ -7,6 +7,7 @@ import net.minecraft.client.color.item.ItemColors;
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 17/06/2022
|
||||
* A wrapped event to allow Block and Item Color Registration
|
||||
*/
|
||||
public class ColorRegistrationEvent {
|
||||
|
||||
|
@@ -3,13 +3,13 @@ package me.hypherionmc.craterlib.client.gui.tabs;
|
||||
import me.hypherionmc.craterlib.platform.Services;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 16/06/2022
|
||||
* Provides a wrapper around Forge/Fabric to create a new Creative Tab
|
||||
*/
|
||||
public class CreativeTabBuilder {
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package me.hypherionmc.craterlib.client.rendering;
|
||||
|
||||
import me.hypherionmc.craterlib.api.rendering.ItemDyable;
|
||||
import me.hypherionmc.craterlib.util.RenderUtils;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
@@ -28,7 +29,7 @@ public class ItemColorHandler implements ItemColor {
|
||||
*/
|
||||
private int getColorFromStack(ItemStack stack) {
|
||||
if (stack.getItem() instanceof ItemDyable itemDyable) {
|
||||
return itemDyable.getColor(stack).getMaterialColor().col;
|
||||
return RenderUtils.renderColorFromDye(itemDyable.getColor(stack));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package me.hypherionmc.craterlib.common.config;
|
||||
|
||||
import me.hypherionmc.craterlib.Constants;
|
||||
import me.hypherionmc.craterlib.CraterConstants;
|
||||
import me.hypherionmc.nightconfig.core.file.FileWatcher;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -23,19 +23,19 @@ public class ConfigController implements Serializable {
|
||||
*/
|
||||
static void register_config(ModuleConfig config) {
|
||||
if (monitoredConfigs.containsKey(config)) {
|
||||
Constants.LOG.error("Failed to register " + config.getConfigPath().getName() + ". Config already registered");
|
||||
CraterConstants.LOG.error("Failed to register " + config.getConfigPath().getName() + ". Config already registered");
|
||||
} else {
|
||||
FileWatcher configWatcher = new FileWatcher();
|
||||
try {
|
||||
configWatcher.setWatch(config.getConfigPath(), () -> {
|
||||
Constants.LOG.info("Sending Reload Event for: " + config.getConfigPath().getName());
|
||||
CraterConstants.LOG.info("Sending Reload Event for: " + config.getConfigPath().getName());
|
||||
config.configReloaded();
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Constants.LOG.error("Failed to register " + config.getConfigPath().getName() + " for auto reloading. " + e.getMessage());
|
||||
CraterConstants.LOG.error("Failed to register " + config.getConfigPath().getName() + " for auto reloading. " + e.getMessage());
|
||||
}
|
||||
monitoredConfigs.put(config, configWatcher);
|
||||
Constants.LOG.info("Registered " + config.getConfigPath().getName() + " successfully!");
|
||||
CraterConstants.LOG.info("Registered " + config.getConfigPath().getName() + " successfully!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,18 +2,16 @@ package me.hypherionmc.craterlib.common.item;
|
||||
|
||||
import me.hypherionmc.craterlib.api.rendering.DyableBlock;
|
||||
import me.hypherionmc.craterlib.api.rendering.ItemDyable;
|
||||
import me.hypherionmc.craterlib.platform.Services;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.StringUtil;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -25,6 +23,7 @@ public class BlockItemDyable extends BlockItem implements ItemDyable {
|
||||
|
||||
public BlockItemDyable(Block block, Properties properties) {
|
||||
super(block, properties);
|
||||
Services.CLIENT_HELPER.registerItemProperty(this, "color");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +46,7 @@ public class BlockItemDyable extends BlockItem implements ItemDyable {
|
||||
);
|
||||
}
|
||||
|
||||
private DyeColor getColorFromNBT(ItemStack stack) {
|
||||
public DyeColor getColorFromNBT(ItemStack stack) {
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
if (tag.contains("color")) {
|
||||
return DyeColor.byName(tag.getString("color"), DyeColor.BLACK);
|
||||
@@ -71,4 +70,5 @@ public class BlockItemDyable extends BlockItem implements ItemDyable {
|
||||
}
|
||||
return state != null && this.canPlace(ctx, state) ? state : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,14 +1,13 @@
|
||||
package me.hypherionmc.craterlib.platform;
|
||||
|
||||
import me.hypherionmc.craterlib.Constants;
|
||||
import me.hypherionmc.craterlib.platform.services.IPlatformHelper;
|
||||
import me.hypherionmc.craterlib.CraterConstants;
|
||||
import me.hypherionmc.craterlib.platform.services.LibClientHelper;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public class Services {
|
||||
|
||||
public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class);
|
||||
//public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class);
|
||||
|
||||
public static final LibClientHelper CLIENT_HELPER = load(LibClientHelper.class);
|
||||
|
||||
@@ -17,7 +16,7 @@ public class Services {
|
||||
final T loadedService = ServiceLoader.load(clazz)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||
Constants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
||||
CraterConstants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
||||
return loadedService;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package me.hypherionmc.craterlib.platform.services;
|
||||
|
||||
import me.hypherionmc.craterlib.common.item.BlockItemDyable;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
@@ -13,4 +14,6 @@ public interface LibClientHelper {
|
||||
|
||||
public CreativeModeTab tabBuilder(String modid, String tabid, Supplier<ItemStack> icon, String backgroundSuf);
|
||||
|
||||
public void registerItemProperty(BlockItemDyable item, String property);
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,35 @@
|
||||
package me.hypherionmc.craterlib.util;
|
||||
|
||||
import me.hypherionmc.craterlib.common.item.BlockItemDyable;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 03/07/2022
|
||||
*/
|
||||
public class ColorPropertyFunction implements ClampedItemPropertyFunction {
|
||||
|
||||
private final BlockItemDyable item;
|
||||
|
||||
public ColorPropertyFunction(BlockItemDyable item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float call(ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i) {
|
||||
return Mth.clamp(this.unclampedCall(itemStack, clientLevel, livingEntity, i), 0.0F, 15.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float unclampedCall(ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i) {
|
||||
DyeColor color = item.getColorFromNBT(itemStack);
|
||||
return color.getId();
|
||||
}
|
||||
|
||||
}
|
@@ -3,6 +3,7 @@ package me.hypherionmc.craterlib.util;
|
||||
import com.mojang.math.Vector4f;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
|
||||
public class RenderUtils {
|
||||
|
||||
@@ -51,4 +52,8 @@ public class RenderUtils {
|
||||
return pPackedColor & 255;
|
||||
}
|
||||
}
|
||||
|
||||
public static int renderColorFromDye(DyeColor color) {
|
||||
return color.getMaterialColor().col | 0xFF000000;
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
accessWidener v1 named
|
||||
|
||||
accessible class net/minecraft/client/renderer/LevelRenderer$RenderChunkInfo
|
||||
accessible method net/minecraft/client/renderer/item/ItemProperties register (Lnet/minecraft/world/item/Item;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/renderer/item/ClampedItemPropertyFunction;)V
|
||||
|
Reference in New Issue
Block a user