Skip to content

Commit

Permalink
Port to Fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 9, 2024
1 parent 5142f60 commit 6434a0e
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 2 deletions.
4 changes: 2 additions & 2 deletions loader-common/src/main/resources/iconexporter.accesswidener
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
accessWidener v1 named

accessible field com/mojang/blaze3d/platform/NativeImage pixels i
accessible field com/mojang/blaze3d/platform/NativeImage pixels J

accessible method net/minecraft/util/thread/BlockableEventLoop submitAsync(Ljava/lang/Runnable;) Ljava/util/concurrent/CompletableFuture;
accessible method net/minecraft/util/thread/BlockableEventLoop submitAsync (Ljava/lang/Runnable;)Ljava/util/concurrent/CompletableFuture;
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.cyclops.iconexporter;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.fabricmc.api.ModInitializer;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import org.cyclops.cyclopscore.config.ConfigHandlerCommon;
import org.cyclops.cyclopscore.init.ModBaseFabric;
import org.cyclops.cyclopscore.proxy.IClientProxyCommon;
import org.cyclops.cyclopscore.proxy.ICommonProxyCommon;
import org.cyclops.iconexporter.command.CommandExport;
import org.cyclops.iconexporter.command.CommandExportMetadata;
import org.cyclops.iconexporter.helpers.IconExporterHelpersFabric;
import org.cyclops.iconexporter.proxy.ClientProxyFabric;
import org.cyclops.iconexporter.proxy.CommonProxyFabric;

/**
* The main mod class of IconExporter.
* @author rubensworks
*/
public class IconExporterFabric extends ModBaseFabric<IconExporterFabric> implements ModInitializer {

/**
* The unique instance of this mod.
*/
public static IconExporterFabric _instance;

public IconExporterFabric() {
super(Reference.MOD_ID, (instance) -> _instance = instance);
}

@Override
protected LiteralArgumentBuilder<CommandSourceStack> constructBaseCommand(Commands.CommandSelection selection, CommandBuildContext context) {
LiteralArgumentBuilder<CommandSourceStack> root = super.constructBaseCommand(selection, context);

if (getModHelpers().getMinecraftHelpers().isClientSide()) {
IconExporterHelpersFabric helpers = new IconExporterHelpersFabric();
root.then(CommandExport.make(context, this, helpers));
root.then(CommandExportMetadata.make(context, this, helpers));
}

return root;
}

@Override
protected IClientProxyCommon constructClientProxy() {
return new ClientProxyFabric();
}

@Override
protected ICommonProxyCommon constructCommonProxy() {
return new CommonProxyFabric();
}

@Override
protected boolean hasDefaultCreativeModeTab() {
return false;
}

@Override
protected void onConfigsRegister(ConfigHandlerCommon configHandler) {
super.onConfigsRegister(configHandler);

configHandler.addConfigurable(new GeneralConfig<>(this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.cyclops.iconexporter.helpers;

import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.level.material.Fluid;
import org.cyclops.cyclopscore.helper.IModHelpersFabric;

import java.util.List;

/**
* @author rubensworks
*/
public class IconExporterHelpersFabric extends IconExporterHelpersCommon {
@Override
public List<CreativeModeTab> getCreativeTabs() {
return BuiltInRegistries.CREATIVE_MODE_TAB.stream()
.filter(tab -> !tab.getBackgroundTexture().equals(CreativeModeTab.createTextureLocation("item_search")))
.toList();
}

@Override
public String getFluidLocalName(Fluid fluid) {
return FluidVariantAttributes.getName(FluidVariant.of(fluid)).getString();
}

@Override
public void renderFluidSlot(GuiGraphics gui, Fluid fluid) {
IModHelpersFabric.get().getGuiHelpers().renderFluidSlot(gui, FluidVariant.of(fluid), IModHelpersFabric.get().getFluidHelpers().getBucketVolume(), 0, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.cyclops.iconexporter.proxy;

import org.cyclops.iconexporter.IconExporterFabric;
import org.cyclops.cyclopscore.init.ModBaseFabric;
import org.cyclops.cyclopscore.proxy.ClientProxyComponentFabric;

/**
* Proxy for the client side.
*
* @author rubensworks
*
*/
public class ClientProxyFabric extends ClientProxyComponentFabric {

public ClientProxyFabric() {
super(new CommonProxyFabric());
}

@Override
public ModBaseFabric<?> getMod() {
return IconExporterFabric._instance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.cyclops.iconexporter.proxy;

import org.cyclops.cyclopscore.init.ModBaseFabric;
import org.cyclops.cyclopscore.proxy.CommonProxyComponentFabric;
import org.cyclops.iconexporter.IconExporterFabric;

/**
* Proxy for server and client side.
* @author rubensworks
*
*/
public class CommonProxyFabric extends CommonProxyComponentFabric {

@Override
public ModBaseFabric<?> getMod() {
return IconExporterFabric._instance;
}

}
33 changes: 33 additions & 0 deletions loader-fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"schemaVersion": 1,
"id": "${mod_id}",
"version": "${mod_version}",

"name": "${mod_name}",
"description": "${description}",
"authors": [
"${mod_author}"
],
"contact": {
"homepage": "${display_url}",
"sources": "${issue_tracker_url}"
},

"license": "${license}",
"icon": "logo.png",

"environment": "*",
"entrypoints": {
"main": [
"org.cyclops.iconexporter.IconExporterFabric"
]
},
"accessWidener" : "iconexporter.accesswidener",

"depends": {
"cyclopscore": ">=${cyclopscore_version_semver}",
"fabricloader": ">=${fabric_loader_version}",
"fabric-api": ">=${fabric_version}",
"java": ">=${java_version}"
}
}

0 comments on commit 6434a0e

Please sign in to comment.