class renaming, gui textures, lang builder, dynamic cycle

This commit is contained in:
2025-03-20 21:25:10 +01:00
parent 3b6df19189
commit c78c0a7c5f
14 changed files with 190 additions and 43 deletions

View File

@@ -14,7 +14,7 @@ parchment_version = 2024.11.17
mod_id=mechanicals
mod_name=Mechanicals Lib
mod_license=LGPL3
mod_version=0.1.0
mod_version=0.1.4
mod_group_id=com.oierbravo
mod_author=oierbravo
mod_description=Utility Library for Create Addons.

View File

@@ -40,6 +40,7 @@ public class DynamicCycleBehavior extends BlockEntityBehaviour {
public void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
currentTime = compound.getInt("CurrentTime");
processingTime = compound.getInt("ProcessingTime");
prevRunningTicks = runningTicks = compound.getInt("Ticks");
running = compound.getBoolean("Running");
finished = compound.getBoolean("Finished");
super.read(compound, registries, clientPacket);
@@ -63,6 +64,7 @@ public class DynamicCycleBehavior extends BlockEntityBehaviour {
}
public void stop(){
running = false;
finished = true;
currentTime = 0;
processingTime = 0;
specifics.setWorking(false);
@@ -95,22 +97,41 @@ public class DynamicCycleBehavior extends BlockEntityBehaviour {
blockEntity.sendData();
return;
}
if (level.isClientSide && runningTicks == -processingTime) {
prevRunningTicks = currentTime;
return;
}
if (runningTicks == processingTime && specifics.getKineticSpeed() != 0) {
apply();
specifics.playSound();
if (!level.isClientSide)
blockEntity.sendData();
}
specifics.setWorking(true);
running = true;
currentTime += getRunningTickSpeed();
if (currentTime >= getProccessingTime() && specifics.getKineticSpeed() != 0) {
specifics.playSound();
if (!level.isClientSide){
stop();
apply();
specifics.onCycleCompleted();
}
if (!level.isClientSide && runningTicks > processingTime) {
specifics.onCycleCompleted();
stop();
blockEntity.sendData();
return;
}
prevRunningTicks = runningTicks;
runningTicks += getRunningTickSpeed();
if (prevRunningTicks < processingTime && runningTicks >= processingTime) {
runningTicks = processingTime / 2;
// Pause the ticks until a packet is received
if (level.isClientSide && !blockEntity.isVirtual())
runningTicks = -(processingTime / 2);
}
blockEntity.sendData();
}
public float getProgress(float partialTicks){
@@ -141,10 +162,21 @@ public class DynamicCycleBehavior extends BlockEntityBehaviour {
public int getProgressPercent() {
if(!running)
return 0;
return Mth.clamp(currentTime * 100 / (getProccessingTime()), 0,100);
return Mth.clamp(runningTicks * 100 / (getProccessingTime()), 0,100);
}
public float getProgressPercentFloat() {
if(!running)
return 0;
return (float) runningTicks / getProccessingTime();
}
public float getProcessingRemainingPercentFloat() {
if(!running)
return 1;
return 1 - (float) (processingTime - runningTicks) / processingTime;
}
public int getCurrentTime(){
return currentTime;
return runningTicks;
}
public boolean isRunning(){

View File

@@ -66,6 +66,10 @@ public class RecipeRequirementsBehaviour<R extends IRecipeWithRequirements> exte
blockEntity.sendData();
return true;
}
public void cleanRequirements(){
missingRequirements.clear();
blockEntity.sendData();
}
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking, boolean added) {
if(missingRequirements.isEmpty())

View File

@@ -0,0 +1,46 @@
package com.oierbravo.mechanicals.foundation.data;
import com.oierbravo.mechanicals.foundation.recipe.AbstractMechanicalRecipeBuilder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
public abstract class AbstractMechanicalRecipeGenerator<MRB extends AbstractMechanicalRecipeBuilder<?,?,MRB>> extends RecipeProvider {
String namespace;
String displayName;
String recipeTypeId;
Supplier<MRB> builderSupplier;
public AbstractMechanicalRecipeGenerator(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, String namespace, String recipeTypeId , Supplier<MRB> builderSupplier,String displayName) {
super(output, registries);
this.namespace = namespace;
this.recipeTypeId = recipeTypeId;
this.displayName = displayName;
this.builderSupplier = builderSupplier;
}
abstract protected void buildRecipes(RecipeOutput recipeOutput);
private Block block(String resourceLocationString){
return block(ResourceLocation.parse(resourceLocationString));
}
private Block block(ResourceLocation resourceLocation){
return BuiltInRegistries.BLOCK.get(resourceLocation);
}
protected MRB create(String id){
return builderSupplier.get().create(ResourceLocation.fromNamespaceAndPath(namespace, recipeTypeId + "/" + id));
}
@Override
public final String getName() {
return displayName + " recipes.";
}
}

View File

@@ -0,0 +1,58 @@
package com.oierbravo.mechanicals.foundation.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import net.createmod.catnip.gui.UIRenderHelper;
import net.createmod.catnip.gui.element.ScreenElement;
import net.createmod.catnip.theme.Color;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
public enum MechanicalGUITextures implements ScreenElement {
JEI_SHORT_ARROW("jei/widgets", 20, 9);
public static final int FONT_COLOR = 5726074;
public final ResourceLocation location;
public int width;
public int height;
public int startX;
public int startY;
private MechanicalGUITextures(String location, int width, int height) {
this(location, 0, 0, width, height);
}
private MechanicalGUITextures(int startX, int startY) {
this("icons", startX * 16, startY * 16, 16, 16);
}
private MechanicalGUITextures(String location, int startX, int startY, int width, int height) {
this("mechanicals", location, startX, startY, width, height);
}
private MechanicalGUITextures(String namespace, String location, int startX, int startY, int width, int height) {
this.location = ResourceLocation.fromNamespaceAndPath(namespace, "textures/gui/" + location + ".png");
this.width = width;
this.height = height;
this.startX = startX;
this.startY = startY;
}
@OnlyIn(Dist.CLIENT)
public void bind() {
RenderSystem.setShaderTexture(0, this.location);
}
@OnlyIn(Dist.CLIENT)
public void render(GuiGraphics graphics, int x, int y) {
graphics.blit(location, x, y, startX, startY, width, height);
}
@OnlyIn(Dist.CLIENT)
public void render(GuiGraphics graphics, int x, int y, Color c) {
bind();
UIRenderHelper.drawColoredTexture(graphics, c, x, y, startX, startY, width, height);
}
}

View File

@@ -12,7 +12,7 @@ import java.util.List;
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public abstract class BaseRecipe<T extends RecipeInput, P extends BaseRecipeParams> implements Recipe<T>, IRecipeWithRequirements {
public abstract class AbstractMechanicalRecipe<T extends RecipeInput, P extends AbstractMechanicalRecipeParams> implements Recipe<T>, IRecipeWithRequirements {
protected ResourceLocation id;
@@ -20,7 +20,7 @@ public abstract class BaseRecipe<T extends RecipeInput, P extends BaseRecipePara
protected ArrayList<ICondition> conditions;
public BaseRecipe(P params){
public AbstractMechanicalRecipe(P params){
this.id = params.id;
recipeRequirements = params.recipeRequirements;
this.conditions = params.conditions;

View File

@@ -15,20 +15,22 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
public abstract class BaseRecipeBuilder<R extends BaseRecipe<?,P>, P extends BaseRecipeParams, BRB extends BaseRecipeBuilder<R,P,?>> {
public abstract class AbstractMechanicalRecipeBuilder<R extends AbstractMechanicalRecipe<?,P>, P extends AbstractMechanicalRecipeParams, BRB extends AbstractMechanicalRecipeBuilder<R,P,?>> {
protected final Map<String, Criterion<?>> criteria = new LinkedHashMap<>();
protected P params;
protected ArrayList<IRecipeRequirement> recipeRequirements;
protected ArrayList<ICondition> recipeConditions;
public BaseRecipeBuilder( ResourceLocation id){
public AbstractMechanicalRecipeBuilder(){
recipeRequirements = new ArrayList<>();
recipeConditions = new ArrayList<>();
}
public abstract R build();
public abstract BRB create(ResourceLocation id);
public BRB withRequirement(IRecipeRequirement requirement){
params.recipeRequirements.add(requirement);
@@ -64,4 +66,9 @@ public abstract class BaseRecipeBuilder<R extends BaseRecipe<?,P>, P extends Bas
public void save(RecipeOutput recipeOutput) {
save(recipeOutput, params.id);
}
public BRB with(Consumer<BRB> consummer){
consummer.accept((BRB) this);
return (BRB) this;
}
}

View File

@@ -5,12 +5,12 @@ import net.neoforged.neoforge.common.conditions.ICondition;
import java.util.ArrayList;
public abstract class BaseRecipeParams implements IBaseRecipeParams {
public abstract class AbstractMechanicalRecipeParams {
public ResourceLocation id;
public ArrayList<IRecipeRequirement> recipeRequirements;
protected ArrayList<ICondition> conditions;
protected BaseRecipeParams(ResourceLocation id) {
protected AbstractMechanicalRecipeParams(ResourceLocation id) {
this.id = id;
recipeRequirements = new ArrayList<>();
conditions = new ArrayList<>();

View File

@@ -1,5 +0,0 @@
package com.oierbravo.mechanicals.foundation.recipe;
public interface IBaseRecipeParams {
}

View File

@@ -1,20 +0,0 @@
package com.oierbravo.mechanicals.foundation.recipe;
public class RecipeRequirementsUtils {
/*public static List<String> getMissingRequirements(List<IRecipeRequirement> pRecipeRequirements, BlockEntity pBlockEntity){
ArrayList<String> missingRequirements = new ArrayList<>();
for( IRecipeRequirement requirement : pRecipeRequirements ){
if(!requirement.test(pBlockEntity.getLevel(), pBlockEntity)){
missingRequirements.add(requirement.getIdString());
}
}
return missingRequirements;
}*/
/*public static <BR extends IRecipeWithRequirements> List<Pair<Component,Component>> getRequirementsTooltips(BR recipe){
if(recipe.getRecipeRequirements().isEmpty())
return List.of();
return recipe.getRecipeRequirements().stream().map(IRecipeRequirement::toTooltipComponent).toList();
}*/
}

View File

@@ -0,0 +1,4 @@
package com.oierbravo.mechanicals.jei;
public class CreateRecipeCategoryBuilder {
}

View File

@@ -0,0 +1,21 @@
package com.oierbravo.mechanicals.utility;
import com.simibubi.create.foundation.data.CreateRegistrate;
public class RegistrateLangBuilder {
private final String namespace;
private final CreateRegistrate registrate;
public RegistrateLangBuilder(String namespace, CreateRegistrate registrate) {
this.namespace = namespace;
this.registrate = registrate;
}
public RegistrateLangBuilder add(String literal, String defaultTranslation){
registrate.addRawLang(namespace + "." + literal,defaultTranslation);
return this;
}
public RegistrateLangBuilder addRaw(String literal, String defaultTranslation){
registrate.addRawLang(literal,defaultTranslation);
return this;
}
}

View File

@@ -2,7 +2,7 @@
"mechanicals.ui.progress": "Progress: %d%%",
"itemGroup.mechanicals": "Mechanicals",
"mechanicals.ui.recipe.requirements.title": "Requirements:",
"mechanicals.ui.recipe_requirement.none.tooltip": "No specific requirement",
"mechanicals.ui.recipe_requirement.none.tooltip": "None",
"mechanicals.ui.recipe_requirement.biome.tooltip.title": "Biome:",
"mechanicals.ui.recipe_requirement.biome.tooltip.value": "%s",
"mechanicals.ui.recipe_requirement.biome_tag.tooltip.title": "Biome Tag:",

Binary file not shown.

After

Width:  |  Height:  |  Size: 1004 B