generated from ybw0014/GuizhanSlimefunAddon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: project structure and some machines for testing
- Loading branch information
Showing
24 changed files
with
1,379 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/main/java/net/guizhanss/fastmachines/FastMachines.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/net/guizhanss/fastmachines/core/recipes/StandardRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/net/guizhanss/fastmachines/items/FastMachinesItems.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
Oops, something went wrong.