Skip to content

Commit

Permalink
nightly-20200310
Browse files Browse the repository at this point in the history
  • Loading branch information
ClayCoffee committed Mar 10, 2020
1 parent 3115068 commit 328e171
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 228 deletions.
13 changes: 5 additions & 8 deletions src/main/java/club/claycoffee/ClayTech/ClayTech.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ClayTech extends JavaPlugin implements SlimefunAddon{
public static String locale;
public static DataYML currentLangYML;
public static FileConfiguration currentLang;
public static String highrailspeed;

@SuppressWarnings({ "unused", "static-access" })
@Override
Expand All @@ -38,6 +39,9 @@ public void onEnable() {
locale = config.getString("Locale");
if (locale == null)
locale = "en-US";
highrailspeed = config.getString("Locale");
if (highrailspeed == null)
highrailspeed = "3";
if (!Utils.ExitsInList(locale, Lang.LocaleList)) {
Utils.info("§cLoading Error: Locale not found.Disableing plugin..");
this.getServer().getPluginManager().disablePlugin(this);
Expand Down Expand Up @@ -91,12 +95,6 @@ public void onEnable() {
currentLangYML.reloadCustomConfig();
Utils.info(Lang.readGeneralText("startTip"));
Config cfg = new Config(this);
if(this.getServer().getVersion().equals("1.15")) {

}
else {

}
Utils.info(Lang.readGeneralText("registeringItems"));
try {
registerSlimefun();
Expand Down Expand Up @@ -173,7 +171,6 @@ public JavaPlugin getJavaPlugin() {

@Override
public String getBugTrackerURL() {
// TODO 自动生成的方法存根
return null;
return "https://github.com/ClayCoffee/ClayTech/issues";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;

@SuppressWarnings("deprecation")
public abstract class AElementExtracter extends SlimefunItem implements InventoryBlock, EnergyNetComponent {
public abstract class AExtracter extends SlimefunItem implements InventoryBlock, EnergyNetComponent {
public static Map<Block, MachineRecipe> processing = new HashMap<>();
public static Map<Block, Integer> progress = new HashMap<>();
public final static int[] inputslots = new int[] { 20 };
Expand All @@ -53,7 +53,7 @@ public abstract class AElementExtracter extends SlimefunItem implements Inventor
private static final ItemStack BORDERB_ITEM = Utils.newItemD(Material.MAGENTA_STAINED_GLASS_PANE, Lang.readMachinesText("SPLIT_LINE"));
SlimefunItemStack items;

public AElementExtracter(Category category, SlimefunItemStack item, String id, RecipeType recipeType,
public AExtracter(Category category, SlimefunItemStack item, String id, RecipeType recipeType,
ItemStack[] recipe) {

super(category, item, recipeType, recipe);
Expand Down Expand Up @@ -190,7 +190,7 @@ public void preRegister() {
addItemHandler(new BlockTicker() {
@Override
public void tick(Block b, SlimefunItem sf, Config data) {
AElementExtracter.this.tick(b);
AExtracter.this.tick(b);
}

@Override
Expand Down
215 changes: 5 additions & 210 deletions src/main/java/club/claycoffee/ClayTech/Machines/ANewContainer.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,20 @@
package club.claycoffee.ClayTech.Machines;

// This code is from Slimefun main branch by TheBusyBiscuit.
// A little change.

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;

import club.claycoffee.ClayTech.utils.Utils;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;

@SuppressWarnings("deprecation")
public abstract class ANewContainer extends SlimefunItem implements InventoryBlock, EnergyNetComponent {

public static Map<Block, MachineRecipe> processing = new HashMap<>();
public static Map<Block, Integer> progress = new HashMap<>();

protected final List<MachineRecipe> recipes = new ArrayList<>();
public abstract class ANewContainer extends AContainer implements InventoryBlock, EnergyNetComponent {

private static final int[] BORDER = {0, 1, 2, 3, 4, 5, 6, 7, 8, 13, 31, 36, 37, 38, 39, 40, 41, 42, 43, 44};
private static final int[] BORDER_IN = {9, 10, 11, 12, 18, 21, 27, 28, 29, 30};
private static final int[] BORDER_OUT = {14, 15, 16, 17, 23, 26, 32, 33, 34, 35};

@SuppressWarnings("static-access")
public ANewContainer(Category category, SlimefunItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {

super(category, item, recipeType, recipe);
Expand All @@ -70,185 +39,11 @@ public ANewContainer(Category category, SlimefunItemStack item, String id, Recip
}
}

progress.remove(b);
processing.remove(b);
super.progress.remove(b);
super.processing.remove(b);
return true;
});

this.registerDefaultRecipes();
}


protected void constructMenu(BlockMenuPreset preset) {
for (int i : BORDER) {
preset.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}

for (int i : BORDER_IN) {
preset.addItem(i, Utils.newItemD(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}

for (int i : BORDER_OUT) {
preset.addItem(i, Utils.newItemD(Material.ORANGE_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}

preset.addItem(22, Utils.newItemD(Material.BLACK_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());

for (int i : getOutputSlots()) {
preset.addMenuClickHandler(i, new AdvancedMenuClickHandler() {

@Override
public boolean onClick(Player p, int slot, ItemStack cursor, ClickAction action) {
return false;
}

@Override
public boolean onClick(InventoryClickEvent e, Player p, int slot, ItemStack cursor, ClickAction action) {
return cursor == null || cursor.getType() == null || cursor.getType() == Material.AIR;
}
});
}
}

public abstract String getInventoryTitle();
public abstract ItemStack getProgressBar();
public abstract int getEnergyConsumption();
public abstract int getSpeed();
public abstract String getMachineIdentifier();

public void registerDefaultRecipes() {
// Override this method to register your machine recipes
}

public List<ItemStack> getDisplayRecipes() {
List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() * 2);

for (MachineRecipe recipe: recipes) {
if (recipe.getInput().length != 1) continue;

displayRecipes.add(recipe.getInput()[0]);
displayRecipes.add(recipe.getOutput()[0]);
}

return displayRecipes;
}

@Override
public int[] getInputSlots() {
return new int[] {19, 20};
}

@Override
public int[] getOutputSlots() {
return new int[] {24, 25};
}

public MachineRecipe getProcessing(Block b) {
return processing.get(b);
}

public boolean isProcessing(Block b) {
return getProcessing(b) != null;
}

public void registerRecipe(MachineRecipe recipe) {
recipe.setTicks(recipe.getTicks() / getSpeed());
this.recipes.add(recipe);
}

public void registerRecipe(int seconds, ItemStack[] input, ItemStack[] output) {
this.registerRecipe(new MachineRecipe(seconds, input, output));
}

@Override
public void preRegister() {
addItemHandler(new BlockTicker() {

@Override
public void tick(Block b, SlimefunItem sf, Config data) {
ANewContainer.this.tick(b);
}

@Override
public boolean isSynchronized() {
return false;
}
});
}
@Override
public EnergyNetComponentType getEnergyComponentType() {
return EnergyNetComponentType.CONSUMER;
}
@Override
public int getCapacity() {
// Absolutely override this.
// This is just a temporary compiler-workaround.
// This default implementation will soon be removed.
return 0;
}

protected void tick(Block b) {
BlockMenu inv = BlockStorage.getInventory(b);

if (isProcessing(b)) {
int timeleft = progress.get(b);

if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(b).getTicks(), getProgressBar());

if (ChargableBlock.isChargable(b)) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
ChargableBlock.addCharge(b, -getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else progress.put(b, timeleft - 1);
}
else {
inv.replaceExistingItem(22, Utils.newItemD(Material.BLACK_STAINED_GLASS_PANE, " "));

for (ItemStack output : processing.get(b).getOutput()) {
inv.pushItem(output.clone(), getOutputSlots());
}

progress.remove(b);
processing.remove(b);
}
}
else {
MachineRecipe r = null;
Map<Integer, Integer> found = new HashMap<>();

for (MachineRecipe recipe : recipes) {
for (ItemStack input : recipe.getInput()) {
for (int slot : getInputSlots()) {
if (SlimefunManager.isItemSimilar(inv.getItemInSlot(slot), input, true)) {
found.put(slot, input.getAmount());
break;
}
}
}
if (found.size() == recipe.getInput().length) {
r = recipe;
break;
}
else found.clear();
}

if (r != null) {
if (!fits(b, r.getOutput())) return;
// need dl
if (ChargableBlock.isChargable(b)) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
ChargableBlock.addCharge(b, -getEnergyConsumption());
}
for (Map.Entry<Integer, Integer> entry : found.entrySet()) {
inv.consumeItem(entry.getKey(), entry.getValue());
}

processing.put(b, r);
progress.put(b, r.getTicks());
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package club.claycoffee.ClayTech.items;

import club.claycoffee.ClayTech.Defines;
import club.claycoffee.ClayTech.Machines.AElementExtracter;
import club.claycoffee.ClayTech.Machines.AExtracter;
import club.claycoffee.ClayTech.utils.Lang;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.LockedCategory;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

public class ElementExtracter extends AElementExtracter{
public class ElementExtracter extends AExtracter{
public ElementExtracter(LockedCategory category, SlimefunItemStack item, String id, RecipeType recipeType,
ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/club/claycoffee/ClayTech/items/Railways.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;

public class Railways {
@SuppressWarnings("deprecation")
public Railways() {
Slimefunutils.registerItem(Defines.C_OTHER, "CLAY_HIGHSPEED_RAILWAY", Defines.HIGHSPEED_RAILWAY, "notresearch", 10,
TRecipe.CLAY_CRAFTING_TABLE, Recipes.HIGHSPEED_RAILWAY, false);
ItemStack elem8 = Defines.ELECTRIC_MOTOR_8;
elem8.setAmount(8);
SlimefunItemStack motor_8 = new SlimefunItemStack("ELECTRIC_MOTOR_8", elem8);
SlimefunItem motor_8_i = new SlimefunItem(Defines.C_OTHER, motor_8, TRecipe.CLAY_CRAFTING_TABLE, Recipes.ELECTRIC_MOTOR_8);
motor_8_i.register();
motor_8_i.register(ClayTech.plugin);
Research railway_basic = new Research(new NamespacedKey(ClayTech.plugin, "CLAYTECH_RAILWAY_BASIC"), 9920, Lang.readResearchesText("CLAYTECH_RAILWAY_I"),
40);
railway_basic.addItems(SlimefunItem.getByItem(Defines.HIGHSPEED_RAILWAY),SlimefunItem.getByItem(Defines.ELECTRIC_MOTOR_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.bukkit.event.player.PlayerFishEvent.State;
import org.bukkit.event.vehicle.VehicleMoveEvent;

import club.claycoffee.ClayTech.ClayTech;
import club.claycoffee.ClayTech.Defines;
import club.claycoffee.ClayTech.utils.Affect;
import club.claycoffee.ClayTech.utils.Food;
Expand Down Expand Up @@ -164,7 +165,7 @@ public void VehicleMoveEvent(VehicleMoveEvent e) {
if (rail.getBlockData().getMaterial() == Material.POWERED_RAIL) {
if (BlockStorage.checkID(rail) != null) {
if (BlockStorage.checkID(rail).equalsIgnoreCase("CLAY_HIGHSPEED_RAILWAY")) {
ve.setMaxSpeed(1.2d);
ve.setMaxSpeed(0.4d * new Integer(ClayTech.highrailspeed).doubleValue());
} else {
ve.setMaxSpeed(0.4d);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Locale: "en-US"
Locale: "en-US"
highrailspeed: "3"
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ClayTech
main: club.claycoffee.ClayTech.ClayTech
version: nightly-20200309
version: nightly-20200310
api-version: 1.15
depend: [CS-CoreLib, Slimefun]

0 comments on commit 328e171

Please sign in to comment.