mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Added some documentation and two guide item ui ids
This commit is contained in:
parent
174bd8b4d8
commit
7f9bed54ff
4
.github/workflows/url-checker.yml
vendored
4
.github/workflows/url-checker.yml
vendored
@ -6,7 +6,7 @@ on:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
check:
|
||||
|
||||
name: URL Checker
|
||||
runs-on: ubuntu-latest
|
||||
@ -17,7 +17,7 @@ jobs:
|
||||
with:
|
||||
git_path: https://github.com/Slimefun/Slimefun4
|
||||
file_types: .md,.java,.yml
|
||||
print_all: False
|
||||
print_all: false
|
||||
retry_count: 2
|
||||
## These URLs will always be correct, even if their services may be offline right now
|
||||
white_listed_patterns: http://textures.minecraft.net/texture/,https://pastebin.com/,https://www.spigotmc.org/threads/spigot-bungeecord-1-16-1.447405/#post-3852349,https://gitlocalize.com/repo/3841
|
||||
|
@ -49,6 +49,7 @@ public class CustomTextureService {
|
||||
config.setDefaultValue("SLIMEFUN_GUIDE", 0);
|
||||
|
||||
config.setDefaultValue("_UI_BACKGROUND", 0);
|
||||
config.setDefaultValue("_UI_NOT_RESEARCHED", 0);
|
||||
config.setDefaultValue("_UI_INPUT_SLOT", 0);
|
||||
config.setDefaultValue("_UI_OUTPUT_SLOT", 0);
|
||||
config.setDefaultValue("_UI_BACK", 0);
|
||||
|
@ -271,10 +271,10 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
|
||||
|
||||
if (isSurvivalMode() && !Slimefun.hasPermission(p, sfitem, false)) {
|
||||
List<String> message = SlimefunPlugin.getPermissionsService().getLore(sfitem);
|
||||
menu.addItem(index, new CustomItem(Material.BARRIER, sfitem.getItemName(), message.toArray(new String[0])));
|
||||
menu.addItem(index, new CustomItem(ChestMenuUtils.getNoPermissionItem(), sfitem.getItemName(), message.toArray(new String[0])));
|
||||
menu.addMenuClickHandler(index, ChestMenuUtils.getEmptyClickHandler());
|
||||
} else if (isSurvivalMode() && research != null && !profile.hasUnlocked(research)) {
|
||||
menu.addItem(index, new CustomItem(Material.BARRIER, ChatColor.WHITE + ItemUtils.getItemName(sfitem.getItem()), "&4&l" + SlimefunPlugin.getLocalization().getMessage(p, "guide.locked"), "", "&a> Click to unlock", "", "&7Cost: &b" + research.getCost() + " Level(s)"));
|
||||
menu.addItem(index, new CustomItem(ChestMenuUtils.getNotResearchedItem(), ChatColor.WHITE + ItemUtils.getItemName(sfitem.getItem()), "&4&l" + SlimefunPlugin.getLocalization().getMessage(p, "guide.locked"), "", "&a> Click to unlock", "", "&7Cost: &b" + research.getCost() + " Level(s)"));
|
||||
menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
|
||||
if (!SlimefunPlugin.getRegistry().getCurrentlyResearchingPlayers().contains(pl.getUniqueId())) {
|
||||
if (research.canUnlock(pl)) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.androids;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* This enum holds all the different types a {@link ProgrammableAndroid} can represent.
|
||||
*
|
||||
@ -55,7 +57,7 @@ public enum AndroidType {
|
||||
*/
|
||||
NON_FIGHTER;
|
||||
|
||||
boolean isType(AndroidType type) {
|
||||
boolean isType(@Nonnull AndroidType type) {
|
||||
return type == NONE || type == this || (type == NON_FIGHTER && this != FIGHTER);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Ageable;
|
||||
@ -20,126 +21,223 @@ import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
|
||||
/**
|
||||
* This enum holds every {@link Instruction} for the {@link ProgrammableAndroid}
|
||||
* added by Slimefun itself.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
public enum Instruction {
|
||||
|
||||
// Start and End Parts
|
||||
/**
|
||||
* This {@link Instruction} is the starting point of a {@link Script}.
|
||||
*/
|
||||
START(AndroidType.NONE, HeadTexture.SCRIPT_START),
|
||||
|
||||
/**
|
||||
* This {@link Instruction} is the end token of a {@link Script}.
|
||||
* Once this {@link Instruction} is reached, the {@link Script} will start again.
|
||||
*/
|
||||
REPEAT(AndroidType.NONE, HeadTexture.SCRIPT_REPEAT),
|
||||
|
||||
/**
|
||||
* This {@link Instruction} will make the {@link ProgrammableAndroid} wait
|
||||
* for one Slimefun tick.
|
||||
*/
|
||||
WAIT(AndroidType.NONE, HeadTexture.SCRIPT_WAIT),
|
||||
|
||||
// Movement
|
||||
/**
|
||||
* This will make the {@link ProgrammableAndroid} go forward.
|
||||
*/
|
||||
GO_FORWARD(AndroidType.NON_FIGHTER, HeadTexture.SCRIPT_FORWARD, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(face);
|
||||
android.move(b, face, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make the {@link ProgrammableAndroid} go up.
|
||||
*/
|
||||
GO_UP(AndroidType.NON_FIGHTER, HeadTexture.SCRIPT_UP, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(BlockFace.UP);
|
||||
android.move(b, face, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make the {@link ProgrammableAndroid} go down.
|
||||
*/
|
||||
GO_DOWN(AndroidType.NON_FIGHTER, HeadTexture.SCRIPT_DOWN, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(BlockFace.DOWN);
|
||||
android.move(b, face, target);
|
||||
}),
|
||||
|
||||
// Directions
|
||||
/**
|
||||
* This will make the {@link ProgrammableAndroid} rotate to the left side.
|
||||
*/
|
||||
TURN_LEFT(AndroidType.NONE, HeadTexture.SCRIPT_LEFT, (android, b, inv, face) -> {
|
||||
int mod = -1;
|
||||
android.rotate(b, face, mod);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make the {@link ProgrammableAndroid} rotate to the right side.
|
||||
*/
|
||||
TURN_RIGHT(AndroidType.NONE, HeadTexture.SCRIPT_RIGHT, (android, b, inv, face) -> {
|
||||
int mod = 1;
|
||||
android.rotate(b, face, mod);
|
||||
}),
|
||||
|
||||
// Action - Pickaxe
|
||||
/**
|
||||
* This will make a {@link MinerAndroid} dig the {@link Block} above.
|
||||
*/
|
||||
DIG_UP(AndroidType.MINER, HeadTexture.SCRIPT_DIG_UP, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(BlockFace.UP);
|
||||
android.dig(b, inv, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make a {@link MinerAndroid} dig the {@link Block} ahead.
|
||||
*/
|
||||
DIG_FORWARD(AndroidType.MINER, HeadTexture.SCRIPT_DIG_FORWARD, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(face);
|
||||
android.dig(b, inv, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make a {@link MinerAndroid} dig the {@link Block} below.
|
||||
*/
|
||||
DIG_DOWN(AndroidType.MINER, HeadTexture.SCRIPT_DIG_DOWN, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(BlockFace.DOWN);
|
||||
android.dig(b, inv, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make a {@link MinerAndroid} dig the {@link Block} above
|
||||
* and then move itself to that new {@link Location}.
|
||||
*/
|
||||
MOVE_AND_DIG_UP(AndroidType.MINER, HeadTexture.SCRIPT_DIG_UP, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(BlockFace.UP);
|
||||
android.moveAndDig(b, inv, face, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make a {@link MinerAndroid} dig the {@link Block} ahead
|
||||
* and then move itself to that new {@link Location}.
|
||||
*/
|
||||
MOVE_AND_DIG_FORWARD(AndroidType.MINER, HeadTexture.SCRIPT_DIG_FORWARD, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(face);
|
||||
android.moveAndDig(b, inv, face, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make a {@link MinerAndroid} dig the {@link Block} below
|
||||
* and then move itself to that new {@link Location}.
|
||||
*/
|
||||
MOVE_AND_DIG_DOWN(AndroidType.MINER, HeadTexture.SCRIPT_DIG_DOWN, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(BlockFace.DOWN);
|
||||
android.moveAndDig(b, inv, face, target);
|
||||
}),
|
||||
|
||||
// Action - Sword
|
||||
/**
|
||||
* This will make a {@link ButcherAndroid} attack any {@link LivingEntity}
|
||||
* ahead of them.
|
||||
*/
|
||||
ATTACK_MOBS_ANIMALS(AndroidType.FIGHTER, HeadTexture.SCRIPT_ATTACK, (android, b, inv, face) -> {
|
||||
Predicate<LivingEntity> predicate = e -> true;
|
||||
android.attack(b, face, predicate);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make a {@link ButcherAndroid} attack any {@link Monster}
|
||||
* ahead of them.
|
||||
*/
|
||||
ATTACK_MOBS(AndroidType.FIGHTER, HeadTexture.SCRIPT_ATTACK, (android, b, inv, face) -> {
|
||||
Predicate<LivingEntity> predicate = e -> e instanceof Monster;
|
||||
android.attack(b, face, predicate);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make a {@link ButcherAndroid} attack any {@link Animals Animal}
|
||||
* ahead of them.
|
||||
*/
|
||||
ATTACK_ANIMALS(AndroidType.FIGHTER, HeadTexture.SCRIPT_ATTACK, (android, b, inv, face) -> {
|
||||
Predicate<LivingEntity> predicate = e -> e instanceof Animals;
|
||||
android.attack(b, face, predicate);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This will make a {@link ButcherAndroid} attack any <strong>adult</strong>
|
||||
* {@link Animals Animal} ahead of them.
|
||||
*/
|
||||
ATTACK_ANIMALS_ADULT(AndroidType.FIGHTER, HeadTexture.SCRIPT_ATTACK, (android, b, inv, face) -> {
|
||||
Predicate<LivingEntity> predicate = e -> e instanceof Animals && ((Ageable) e).isAdult();
|
||||
android.attack(b, face, predicate);
|
||||
}),
|
||||
|
||||
// Action - Axe
|
||||
/**
|
||||
* This will make a {@link WoodcutterAndroid} chop down the tree in front of them.
|
||||
*/
|
||||
CHOP_TREE(AndroidType.WOODCUTTER, HeadTexture.SCRIPT_CHOP_TREE),
|
||||
|
||||
// Action - Fishing Rod
|
||||
/**
|
||||
* This {@link Instruction} makes a {@link FisherAndroid} try to catch fish from
|
||||
* the water below.
|
||||
*/
|
||||
CATCH_FISH(AndroidType.FISHERMAN, HeadTexture.SCRIPT_FISH, (android, b, inv, face) -> android.fish(b, inv)),
|
||||
|
||||
// Action - Hoe
|
||||
/**
|
||||
* This {@link Instruction} will make a {@link FarmerAndroid} try to harvest
|
||||
* the {@link Block} in front of them.
|
||||
*/
|
||||
FARM_FORWARD(AndroidType.FARMER, HeadTexture.SCRIPT_FARM_FORWARD, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(face);
|
||||
android.farm(inv, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This {@link Instruction} will make a {@link FarmerAndroid} try to harvest
|
||||
* the {@link Block} below.
|
||||
*/
|
||||
FARM_DOWN(AndroidType.FARMER, HeadTexture.SCRIPT_FARM_DOWN, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(BlockFace.DOWN);
|
||||
android.farm(inv, target);
|
||||
}),
|
||||
|
||||
// Action - ExoticGarden
|
||||
/**
|
||||
* This {@link Instruction} will make a {@link FarmerAndroid} try to harvest
|
||||
* the {@link Block} in front of them.
|
||||
*
|
||||
* <strong>This includes plants from ExoticGarden.</strong>
|
||||
*/
|
||||
FARM_EXOTIC_FORWARD(AndroidType.ADVANCED_FARMER, HeadTexture.SCRIPT_FARM_FORWARD, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(face);
|
||||
android.exoticFarm(inv, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This {@link Instruction} will make a {@link FarmerAndroid} try to harvest
|
||||
* the {@link Block} below.
|
||||
*
|
||||
* <strong>This includes plants from ExoticGarden.</strong>
|
||||
*/
|
||||
FARM_EXOTIC_DOWN(AndroidType.ADVANCED_FARMER, HeadTexture.SCRIPT_FARM_DOWN, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(BlockFace.DOWN);
|
||||
android.exoticFarm(inv, target);
|
||||
}),
|
||||
|
||||
// Action - Interface
|
||||
/**
|
||||
* This {@link Instruction} will force the {@link ProgrammableAndroid} to push their
|
||||
* items into an {@link AndroidInterface} ahead of them.
|
||||
*/
|
||||
INTERFACE_ITEMS(AndroidType.NONE, HeadTexture.SCRIPT_PUSH_ITEMS, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(face);
|
||||
android.depositItems(inv, target);
|
||||
}),
|
||||
|
||||
/**
|
||||
* This {@link Instruction} will force the {@link ProgrammableAndroid} to pull
|
||||
* fuel from an {@link AndroidInterface} ahead of them.
|
||||
*/
|
||||
INTERFACE_FUEL(AndroidType.NONE, HeadTexture.SCRIPT_PULL_FUEL, (android, b, inv, face) -> {
|
||||
Block target = b.getRelative(face);
|
||||
android.refuel(inv, target);
|
||||
|
@ -543,6 +543,15 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock,
|
||||
public void setScript(@Nonnull Location l, @Nonnull String script) {
|
||||
Validate.notNull(l, "Location for android not specified");
|
||||
Validate.notNull(script, "No script given");
|
||||
|
||||
if (!script.startsWith(Instruction.START.name())) {
|
||||
throw new IllegalArgumentException("A script must begin with a 'START' token.");
|
||||
}
|
||||
|
||||
if (!script.startsWith(Instruction.REPEAT.name())) {
|
||||
throw new IllegalArgumentException("A script must end with a 'REPEAT' token.");
|
||||
}
|
||||
|
||||
BlockStorage.addBlockInfo(l, "script", script);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,9 @@ public final class ChestMenuUtils {
|
||||
private static final ItemStack INPUT_SLOT = new SlimefunItemStack("_UI_INPUT_SLOT", Material.CYAN_STAINED_GLASS_PANE, " ");
|
||||
private static final ItemStack OUTPUT_SLOT = new SlimefunItemStack("_UI_OUTPUT_SLOT", Material.ORANGE_STAINED_GLASS_PANE, " ");
|
||||
|
||||
private static final ItemStack NO_PERMISSION = new SlimefunItemStack("_UI_NO_PERMISSION", Material.BARRIER, "No Permission");
|
||||
private static final ItemStack NOT_RESEARCHED = new SlimefunItemStack("_UI_NOT_RESEARCHED", Material.BARRIER, "Not researched");
|
||||
|
||||
private static final ItemStack BACK_BUTTON = new SlimefunItemStack("_UI_BACK", Material.ENCHANTED_BOOK, "&7\u21E6 Back", meta -> meta.addItemFlags(ItemFlag.HIDE_ENCHANTS));
|
||||
private static final ItemStack MENU_BUTTON = new SlimefunItemStack("_UI_MENU", Material.COMPARATOR, "&eSettings / Info", "", "&7\u21E8 Click to see more");
|
||||
private static final ItemStack SEARCH_BUTTON = new SlimefunItemStack("_UI_SEARCH", Material.NAME_TAG, "&bSearch");
|
||||
@ -46,6 +49,16 @@ public final class ChestMenuUtils {
|
||||
return UI_BACKGROUND;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static ItemStack getNoPermissionItem() {
|
||||
return NO_PERMISSION;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static ItemStack getNotResearchedItem() {
|
||||
return NOT_RESEARCHED;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static ItemStack getInputSlotTexture() {
|
||||
return INPUT_SLOT;
|
||||
|
Loading…
Reference in New Issue
Block a user