Skip to content

Commit

Permalink
Rework integration code for ME Requester in preparation for future ad…
Browse files Browse the repository at this point in the history
…d-on integration
  • Loading branch information
62832 committed May 7, 2024
1 parent 8fa2072 commit 29df5e6
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import gripe._90.fulleng.FullblockEnergistics;
import gripe._90.fulleng.integration.Addons;
import gripe._90.fulleng.integration.requester.RequesterIntegration;
import gripe._90.fulleng.integration.tooltips.TooltipProvider;

public class FullLanguageProvider extends LanguageProvider {
Expand All @@ -19,8 +18,8 @@ public FullLanguageProvider(PackOutput output) {
public void addTranslations() {
add("config.jade.plugin_fulleng." + TooltipProvider.STORAGE_MONITOR, "Fullblock Storage Monitor");

if (Addons.REQUESTER.isLoaded()) {
add(RequesterIntegration.NOT_INSTALLED.getString(), "ME Requester not installed.");
for (var addon : Addons.values()) {
add(addon.getNotInstalledTooltip().getString(), addon.getModName() + " not installed.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jetbrains.annotations.NotNull;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
Expand All @@ -13,6 +14,7 @@
import gripe._90.fulleng.FullblockEnergistics;
import gripe._90.fulleng.block.FullBlock;
import gripe._90.fulleng.definition.FullEngBlocks;
import gripe._90.fulleng.integration.Addons;

public class FullRecipeProvider extends RecipeProvider {
public FullRecipeProvider(PackOutput output) {
Expand All @@ -28,11 +30,15 @@ public void buildRecipes(@NotNull RecipeOutput output) {

block(output, FullEngBlocks.STORAGE_MONITOR);
block(output, FullEngBlocks.CONVERSION_MONITOR);

if (Addons.REQUESTER.isLoaded()) {
block(Addons.REQUESTER.conditionalOutput(output), FullEngBlocks.REQUESTER_TERMINAL);
}
}

private void block(@NotNull RecipeOutput output, BlockDefinition<? extends FullBlock<?>> block) {
var part = block.block().getEquivalentPart();
var partId = part.id().getPath();
var partId = BuiltInRegistries.ITEM.getKey(part.asItem()).getPath();

ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, block)
.requires(part)
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gripe/_90/fulleng/block/FullBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jetbrains.annotations.NotNull;

import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
Expand All @@ -13,16 +14,15 @@
import appeng.api.orientation.IOrientationStrategy;
import appeng.api.orientation.OrientationStrategies;
import appeng.block.AEBaseEntityBlock;
import appeng.core.definitions.ItemDefinition;

import gripe._90.fulleng.block.entity.FullBlockEntity;

public abstract class FullBlock<F extends FullBlockEntity> extends AEBaseEntityBlock<F> {
public static final BooleanProperty POWERED = BooleanProperty.create("powered");

private final ItemDefinition<?> equivalentPart;
private final ItemLike equivalentPart;

public FullBlock(ItemDefinition<?> equivalentPart) {
public FullBlock(ItemLike equivalentPart) {
super(BlockBehaviour.Properties.of()
.strength(2.2f, 11.0f)
.mapColor(MapColor.METAL)
Expand All @@ -48,7 +48,7 @@ public IOrientationStrategy getOrientationStrategy() {
return OrientationStrategies.full();
}

public ItemDefinition<?> getEquivalentPart() {
public ItemLike getEquivalentPart() {
return equivalentPart;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gripe/_90/fulleng/block/MonitorBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -13,7 +14,6 @@
import net.minecraft.world.phys.BlockHitResult;

import appeng.api.util.DimensionalBlockPos;
import appeng.core.definitions.ItemDefinition;
import appeng.util.InteractionUtil;
import appeng.util.Platform;

Expand All @@ -22,7 +22,7 @@
public class MonitorBlock<M extends StorageMonitorBlockEntity> extends FullBlock<M> {
public static final BooleanProperty LOCKED = BooleanProperty.create("locked");

public MonitorBlock(ItemDefinition<?> equivalentPart) {
public MonitorBlock(ItemLike equivalentPart) {
super(equivalentPart);
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/gripe/_90/fulleng/definition/FullEngBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import gripe._90.fulleng.block.entity.terminal.PatternEncodingTerminalBlockEntity;
import gripe._90.fulleng.block.entity.terminal.StorageTerminalBlockEntity;
import gripe._90.fulleng.block.entity.terminal.TerminalBlockEntity;
import gripe._90.fulleng.integration.Addons;
import gripe._90.fulleng.integration.IntegrationBlockItem;
import gripe._90.fulleng.integration.requester.RequesterTerminalBlock;
import gripe._90.fulleng.integration.requester.RequesterTerminalBlockEntity;
import gripe._90.fulleng.integration.requester.RequesterTerminalBlockItem;

public class FullEngBlocks {
private static final List<BlockDefinition<?>> BLOCKS = new ArrayList<>();
Expand All @@ -53,7 +54,7 @@ public static List<BlockDefinition<?>> getBlocks() {
"ME Requester Terminal",
"requester_terminal",
RequesterTerminalBlock::new,
RequesterTerminalBlockItem::new);
block -> new IntegrationBlockItem(block, Addons.REQUESTER));

static <P extends AbstractMonitorPart, E extends StorageMonitorBlockEntity>
BlockDefinition<MonitorBlock<E>> monitor(ItemDefinition<PartItem<P>> equivalentPart) {
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/gripe/_90/fulleng/integration/Addons.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
package gripe._90.fulleng.integration;

import net.minecraft.ChatFormatting;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.network.chat.Component;
import net.neoforged.fml.ModList;
import net.neoforged.fml.loading.LoadingModList;
import net.neoforged.fml.loading.moddiscovery.ModInfo;
import net.neoforged.neoforge.common.conditions.ModLoadedCondition;

import gripe._90.fulleng.FullblockEnergistics;

public enum Addons {
REQUESTER("merequester");
REQUESTER("merequester", "ME Requester");

private final String modId;
private final String modName;

Addons(String modId) {
Addons(String modId, String modName) {
this.modId = modId;
this.modName = modName;
}

public String getModId() {
return modId;
}

public String getModName() {
return modName;
}

public boolean isLoaded() {
return ModList.get() != null
? ModList.get().isLoaded(getModId())
: LoadingModList.get().getMods().stream().map(ModInfo::getModId).anyMatch(getModId()::equals);
}

public Component getNotInstalledTooltip() {
return Component.translatable("gui." + FullblockEnergistics.MODID + ".not_installed." + modId)
.withStyle(ChatFormatting.GRAY);
}

public RecipeOutput conditionalOutput(RecipeOutput output) {
return output.withConditions(new ModLoadedCondition(modId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package gripe._90.fulleng.integration;

import java.util.List;

import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;

import appeng.block.AEBaseBlockItem;

public class IntegrationBlockItem extends AEBaseBlockItem {
private final Addons addon;

public IntegrationBlockItem(Block id, Addons addon) {
super(id, new Properties());
this.addon = addon;
}

@Override
public void addCheckedInformation(ItemStack stack, Level level, List<Component> lines, TooltipFlag advTooltips) {
if (!addon.isLoaded()) {
lines.add(addon.getNotInstalledTooltip());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package gripe._90.fulleng.integration.requester;

import com.almostreliable.merequester.Registration;
import com.almostreliable.merequester.client.RequesterTerminalScreen;

import net.minecraft.network.chat.Component;

import appeng.core.definitions.ItemDefinition;
import appeng.init.client.InitScreens;

import gripe._90.fulleng.FullblockEnergistics;

public final class RequesterIntegration {
public static final Component NOT_INSTALLED =
Component.translatable("gui." + FullblockEnergistics.MODID + ".RequesterNotInstalled");
static ItemDefinition<?> getRequesterTerminalPart() {
return Registration.REQUESTER_TERMINAL;
}

public static void initScreen() {
InitScreens.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import appeng.core.definitions.AEParts;

import gripe._90.fulleng.block.TerminalBlock;
import gripe._90.fulleng.integration.Addons;

public class RequesterTerminalBlock extends TerminalBlock<RequesterTerminalBlockEntity> {
public RequesterTerminalBlock() {
super(AEParts.TERMINAL);
super(Addons.REQUESTER.isLoaded() ? RequesterIntegration.getRequesterTerminalPart() : AEParts.TERMINAL);
}

@NotNull
@Override
public @NotNull String getDescriptionId() {
return "item.merequester.requester_terminal";
public String getDescriptionId() {
return "item." + Addons.REQUESTER.getModId() + ".requester_terminal";
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 29df5e6

Please sign in to comment.