Skip to content

Commit

Permalink
feat: project structure and some machines for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 committed Oct 25, 2023
1 parent b06f182 commit 5d1d0a6
Show file tree
Hide file tree
Showing 24 changed files with 1,379 additions and 69 deletions.
6 changes: 6 additions & 0 deletions LOCALES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Locales

This addon is available in the following languages:

- English (US) `en-US`
- 简体中文 `zh-CN`
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# FastMachines

[English](README.md) | [中文](README.zh_CN.md)

This Slimefun addon extracts the manual machines from [FinalTECH](https://github.com/ecro-fun/FinalTECH) and made some changes to put them into a separate addon.
Fast machines are Slimefun basic machines, but they cost energy to run and can craft items without recipe to be in order.

Credit: Final_Root

## Download

(WIP)

## Configuration

### General Config (config.yml)

- `auto-update`: Whether to enable auto update from TheBusyBiscuit's builds page. (default: `true`)
- `lang`: The language of the addon, check available languages [here](LOCALES.md). (default: `en-US`)
- `enable-researches`: Whether to enable researches for fast machines. (default: `true`)
- `debug`: Whether to enable debug mode. (default: `false`)
- `fast-machines.use-energy`: Whether to enable energy cost of Fast Machines' crafting. (default: `true`)

### Item-specific config (/plugins/Slimefun/Items.yml)

The following settings are available for each individual Fast Machines:

- `energy-per-use`: The energy cost of each crafting operation. (default: `8`, range: `0` - `33554431`(2^25-1))

## Thanks

Thanks to anyone who helped me during the development of this addon.

Thanks to [minecraft-heads.com](https://minecraft-heads.com/) for the heads used in this addon.

[![](https://minecraft-heads.com/images/banners/minecraft-heads_fullbanner_468x60.png)](https://minecraft-heads.com/)

36 changes: 36 additions & 0 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# FastMachines 快捷机器

[English](README.md) | [中文](README.zh_CN.md)

该粘液科技附属将快速机器的玩法从[乱序技艺](https://github.com/ecro-fun/FinalTECH)中提取出来,并进行了一些改动,使其作为一个单独的附属。

鸣谢:Final_Root

## 下载

(WIP)

## 配置

### 通用配置 (config.yml)

- `auto-update`: 是否启用从TheBusyBiscuit的构建页面进行自动更新(默认值:`true`
- `lang`: 插件的语言,可在此处查看可用语言[here](LOCALES.md)(默认值:`en-US`
- `enable-researches`: 是否启用快速机器的研究(默认值:`true`
- `debug`: 是否启用调试模式(默认值:`false`
- `fast-machines.use-energy`: 是否启用快速机器的能量消耗(默认值:`true`

### 物品特定配置(/plugins/Slimefun/Items.yml)

以下设置适用于每个独立的快速机器:

- `energy-per-use`:每个制作操作的能量消耗(默认值:`8`,范围:`0` - `33554431`(2^25-1))

## 感谢

感谢在开发此插件过程中帮助我的所有人。

感谢[minecraft-heads.com](https://minecraft-heads.com/)提供此插件中使用的头颅。

[![](https://minecraft-heads.com/images/banners/minecraft-heads_fullbanner_468x60.png)](https://minecraft-heads.com/)

36 changes: 26 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>net.guizhanss</groupId>
<artifactId>GuizhanSlimefunAddon</artifactId>
<artifactId>FastMachines</artifactId>
<version>UNOFFICIAL</version>
<packaging>jar</packaging>

Expand Down Expand Up @@ -45,7 +45,11 @@
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>net.guizhanss.guizhanslimefunaddon.bstats</shadedPattern>
<shadedPattern>net.guizhanss.fastmachines.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>net.guizhanss.guizhanlib</pattern>
<shadedPattern>net.guizhanss.fastmachines.guizhanlib</shadedPattern>
</relocation>
</relocations>
</configuration>
Expand All @@ -58,7 +62,8 @@
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>*</include>
<include>*.yml</include>
<include>lang/*.yml</include>
</includes>
</resource>
</resources>
Expand All @@ -70,8 +75,12 @@
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
<id>sonatype-snapshot</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
Expand All @@ -90,7 +99,7 @@
<dependency>
<groupId>io.github.Slimefun</groupId>
<artifactId>Slimefun4</artifactId>
<version>RC-34</version>
<version>RC-35</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand All @@ -103,7 +112,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>

Expand All @@ -116,9 +125,16 @@

<dependency>
<groupId>net.guizhanss</groupId>
<artifactId>GuizhanLibPlugin</artifactId>
<version>1.3.1</version>
<scope>provided</scope>
<artifactId>GuizhanLib-api</artifactId>
<version>1.5.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.github.MockBukkit</groupId>
<artifactId>MockBukkit</artifactId>
<version>v1.20-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
114 changes: 114 additions & 0 deletions src/main/java/net/guizhanss/fastmachines/FastMachines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package net.guizhanss.fastmachines;

import java.io.File;
import java.lang.reflect.Method;
import java.util.logging.Level;

import javax.annotation.Nonnull;

import com.google.common.base.Preconditions;

import org.bukkit.plugin.Plugin;

import io.github.thebusybiscuit.slimefun4.libraries.dough.updater.GitHubBuildsUpdater;

import net.guizhanss.fastmachines.setup.Items;
import net.guizhanss.guizhanlib.slimefun.addon.AbstractAddon;
import net.guizhanss.guizhanlib.slimefun.addon.AddonConfig;
import net.guizhanss.guizhanlib.slimefun.addon.SlimefunLocalization;
import net.guizhanss.guizhanlib.updater.GuizhanBuildsUpdater;

import org.bstats.bukkit.Metrics;

public final class FastMachines extends AbstractAddon {

private static final String DEFAULT_LANG = "en-US";

private SlimefunLocalization localization;
private boolean debugEnabled = false;

public FastMachines() {
super("ybw0014", "FastMachines", "master", "auto-update");
}

@Nonnull
public static SlimefunLocalization getLocalization() {
return inst().localization;
}

public static void debug(@Nonnull String message, @Nonnull Object... args) {
Preconditions.checkNotNull(message, "message cannot be null");

if (inst().debugEnabled) {
inst().getLogger().log(Level.INFO, "[DEBUG] " + message, args);
}
}

@Nonnull
private static FastMachines inst() {
return getInstance();
}

@Override
public void enable() {
log(Level.INFO, "====================");
log(Level.INFO, " FastMachines ");
log(Level.INFO, " by ybw0014 ");
log(Level.INFO, "====================");

// config
AddonConfig config = getAddonConfig();

// debug
debugEnabled = config.getBoolean("debug", false);

// localization
log(Level.INFO, "Loading language...");
String lang = config.getString("lang", DEFAULT_LANG);
localization = new SlimefunLocalization(this);
localization.addLanguage(lang);
if (!lang.equals(DEFAULT_LANG)) {
localization.addLanguage(DEFAULT_LANG);
}
localization.setPrefix("FM_");
log(Level.INFO, localization.getString("console.loaded-language"), lang);

// items
log(Level.INFO, localization.getString("console.loading-items"));
Items.setup(this);

// researches
if (config.getBoolean("enable-researches", true)) {
// TODO: add researches
}

setupMetrics();
}

@Override
public void disable() {
// nothing to do here for now
}

private void setupMetrics() {
new Metrics(this, 20046);
}

@Override
protected void autoUpdate() {
if (getPluginVersion().startsWith("DEV")) {
String path = getGithubUser() + "/" + getGithubRepo() + "/" + getGithubBranch();
new GitHubBuildsUpdater(this, getFile(), path).start();
} else if (getPluginVersion().startsWith("Build")) {
try {
// use updater in lib plugin
Class<?> clazz = Class.forName("net.guizhanss.guizhanlibplugin.updater.GuizhanUpdater");
Method updaterStart = clazz.getDeclaredMethod("start", Plugin.class, File.class, String.class, String.class, String.class);
updaterStart.invoke(null, this, getFile(), getGithubUser(), getGithubRepo(), getGithubBranch());
} catch (Exception ignored) {
// use updater in lib
new GuizhanBuildsUpdater(this, getFile(), getGithubUser(), getGithubRepo(), getGithubBranch()).start();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.guizhanss.fastmachines.core.recipes;

import java.util.Map;

import javax.annotation.Nonnull;

import org.bukkit.World;
import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;

import net.guizhanss.fastmachines.utils.RecipeUtils;

import lombok.Getter;

/**
* A {@link StandardRecipe} is a recipe that contains only one fixed output {@link ItemStack}.
*
* @author ybw0014
*/
@Getter
public class StandardRecipe {
private final ItemStack output;
private final Map<ItemStack, Integer> input;

public StandardRecipe(ItemStack output, ItemStack... input) {
this.output = output;
this.input = RecipeUtils.calculateItems(input);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StandardRecipe other = (StandardRecipe) o;
return this.input.equals(other.input) && this.output.equals(other.output);
}

@Override
public int hashCode() {
int result = output.hashCode();
result = 31 * result + input.hashCode();
return result;
}

@Override
public String toString() {
return "StandardRecipe{" +
"output=" + output +
", input=" + input +
'}';
}

/**
* Check whether the output item is disabled in the given {@link World}.
*
* @param world
* The world to check.
*
* @return True if output item is disabled in the given {@link World}.
*/
public boolean isDisabledInWorld(@Nonnull World world) {
SlimefunItem sfItem = SlimefunItem.getByItem(output);
return sfItem != null && sfItem.isDisabledIn(world);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.guizhanss.fastmachines.items;

import org.bukkit.Material;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;

import net.guizhanss.fastmachines.FastMachines;

import lombok.experimental.UtilityClass;

@UtilityClass
public final class FastMachinesItems {
// <editor-fold desc="Materials">
public static final SlimefunItemStack ETERNAL_FIRE = FastMachines.getLocalization().getItem(
"ETERNAL_FIRE",
Material.IRON_INGOT
);
// </editor-fold>

// <editor-fold desc="Machines">
public static final SlimefunItemStack FAST_ENHANCED_CRAFTING_TABLE = FastMachines.getLocalization().getItem(
"FAST_ENHANCED_CRAFTING_TABLE",
Material.CRAFTING_TABLE
);
public static final SlimefunItemStack FAST_SMELTERY = FastMachines.getLocalization().getItem(
"FAST_SMELTERY",
Material.FURNACE
);
public static final SlimefunItemStack FAST_ORE_WASHER = FastMachines.getLocalization().getItem(
"FAST_ORE_WASHER",
Material.CAULDRON
);
// </editor-fold>
}
Loading

0 comments on commit 5d1d0a6

Please sign in to comment.