Skip to content

Commit

Permalink
Bunch of things. JEI now has "Energy Required" text for recipes (ener…
Browse files Browse the repository at this point in the history
…gy per tick * time), and a bunch of other things
  • Loading branch information
wolfieboy09 committed Oct 27, 2024
1 parent 573621e commit e4861e9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.wolfieboy09.qstorage.api.util;

public class FormattingUtil {
public static String formatNumber(int number) {
if (number >= 1_000_000_000) {
return String.format("%.1fB", number / 1_000_000_000.0);
} else if (number >= 1_000_000) {
return String.format("%.1fM", number / 1_000_000.0);
} else if (number >= 1_000) {
return String.format("%.1fk", number / 1_000.0);
} else {
return String.valueOf(number);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

public class DiskAssemblerBlockEntity extends AbstractEnergyBlockEntity {
private int progress = 0;
private int crafting_duration = 0;
private int energy_required = 0;

public DiskAssemblerBlockEntity(BlockPos pos, BlockState blockState) {
super(QSBlockEntities.DISK_ASSEMBLER.get(), pos, blockState, 20000, 1000, 0);
Expand Down Expand Up @@ -64,9 +66,17 @@ public boolean canReceive() {
return true;
}

public static int getEnergyCapacity() {
return 20000;
}

public EnergyStorage getEnergyHandler(Direction side) {
if (side == null) return this.getEnergyStorage();
if (side == null) return this.getEnergyStorage(); // for special cases
Direction blockFacing = this.getBlockState().getValue(DiskAssemblerBlock.FACING);
return side == blockFacing.getOpposite() ? this.getEnergyStorage() : null;
}

public ItemStackHandler getInventoryHandler() {
return this.inventory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ protected void renderBg(@NotNull GuiGraphics graphics, float v, int i, int i1) {
this.leftPos + 167,
this.topPos + 69,
0xFFCC2222);


}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package dev.wolfieboy09.qstorage.intergration.jei.disk_assembeler;

import com.mojang.serialization.Codec;
import dev.wolfieboy09.qstorage.QuantiumizedStorage;
import dev.wolfieboy09.qstorage.api.annotation.NothingNullByDefault;
import dev.wolfieboy09.qstorage.api.util.FormattingUtil;
import dev.wolfieboy09.qstorage.api.util.ResourceHelper;
import dev.wolfieboy09.qstorage.block.disk_assembler.DiskAssemblerRecipe;
import dev.wolfieboy09.qstorage.registries.QSBlocks;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
Expand All @@ -25,10 +28,12 @@ public class DiskAssemblerCategory implements IRecipeCategory<DiskAssemblerRecip
public static final RecipeType<DiskAssemblerRecipe> RECIPE_TYPE = RecipeType.create(QuantiumizedStorage.MOD_ID, "disk_assembler", DiskAssemblerRecipe.class);
private final IDrawable background;
private final IDrawable icon;
private final int guiUOffset = 13;
private final int guiVOffset = 4;

public DiskAssemblerCategory(@NotNull IGuiHelper guiHelper) {
ResourceLocation location = ResourceHelper.asResource("textures/gui/disk_assembler.png");
background = guiHelper.createDrawable(location, 0, 0, 176, 76);
background = guiHelper.createDrawable(location, guiUOffset, guiVOffset, 160, 76);
icon = guiHelper.createDrawableItemStack(new ItemStack(QSBlocks.DISK_ASSEMBLER.get()));
}

Expand All @@ -54,18 +59,32 @@ public IDrawable getBackground() {

@Override
public void setRecipe(IRecipeLayoutBuilder builder, DiskAssemblerRecipe recipe, IFocusGroup focuses) {
builder.addSlot(RecipeIngredientRole.INPUT, 17, 27).addIngredients(recipe.diskPort());
builder.addSlot(RecipeIngredientRole.INPUT, 17, 45).addIngredients(recipe.diskCasing());
builder.addSlot(RecipeIngredientRole.INPUT, 35, 36).addIngredients(recipe.screws());
builder.addSlot(RecipeIngredientRole.INPUT, 17 - guiUOffset, 27 - guiVOffset).addIngredients(recipe.diskPort());
builder.addSlot(RecipeIngredientRole.INPUT, 17 - guiUOffset, 45 - guiVOffset).addIngredients(recipe.diskCasing());
builder.addSlot(RecipeIngredientRole.INPUT, 35 - guiUOffset, 36 - guiVOffset).addIngredients(recipe.screws());

builder.addSlot(RecipeIngredientRole.INPUT, 116, 27).addIngredients(recipe.extras().getFirst());
builder.addSlot(RecipeIngredientRole.INPUT, 134, 27).addIngredients(recipe.extras().get(1));
builder.addSlot(RecipeIngredientRole.INPUT, 116, 45).addIngredients(recipe.extras().get(2));
builder.addSlot(RecipeIngredientRole.INPUT, 134, 45).addIngredients(recipe.extras().get(3));
builder.addSlot(RecipeIngredientRole.INPUT, 116 - guiUOffset, 27 - guiVOffset).addIngredients(recipe.extras().getFirst());
builder.addSlot(RecipeIngredientRole.INPUT, 134 - guiUOffset, 27 - guiVOffset).addIngredients(recipe.extras().get(1));
builder.addSlot(RecipeIngredientRole.INPUT, 116 - guiUOffset, 45 - guiVOffset).addIngredients(recipe.extras().get(2));
builder.addSlot(RecipeIngredientRole.INPUT, 134 - guiUOffset, 45 - guiVOffset).addIngredients(recipe.extras().get(3));

builder.addSlot(RecipeIngredientRole.OUTPUT, 80, 36).addIngredient(
builder.addSlot(RecipeIngredientRole.OUTPUT, 80 - guiUOffset, 36 - guiVOffset).addIngredient(
VanillaTypes.ITEM_STACK,
recipe.result()
);
}

@Override
public void draw(DiskAssemblerRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics graphics, double mouseX, double mouseY) {
// get correct numbers
// graphics.fill(
// 150,
// 100 - (20000 / 10),
// 154,
// 65,
// 0xFFCC2222
//);

graphics.drawCenteredString(Minecraft.getInstance().font, "Energy Cost: " + FormattingUtil.formatNumber(recipe.energyCost() * recipe.timeInTicks()) + " FE", 57, 65, 0xFFFFFFFF);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public class QSCapabilities {
@SubscribeEvent
public static void register(@NotNull RegisterCapabilitiesEvent event) {
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, QSBlockEntities.DISK_ASSEMBLER.get(), DiskAssemblerBlockEntity::getEnergyHandler);
// event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, QSBlockEntities.DISK_ASSEMBLER.get(), (block, dir) -> block.getInventoryHandler());
}
}

0 comments on commit e4861e9

Please sign in to comment.