Skip to content

Commit

Permalink
Merge branch 'devvv'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooy1 committed Oct 20, 2020
2 parents f259d9e + 524d493 commit 37dd7f8
Show file tree
Hide file tree
Showing 11 changed files with 350 additions and 73 deletions.
34 changes: 34 additions & 0 deletions src/main/java/me/mooy1/infinityexpansion/InfinityExpansion.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package me.mooy1.infinityexpansion;

import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import me.mooy1.infinityexpansion.lists.InfinityRecipes;
import me.mooy1.infinityexpansion.setup.ItemSetup;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.cscorelib2.config.Config;
import me.mrCookieSlime.Slimefun.cscorelib2.updater.GitHubBuildsUpdater;
import me.mrCookieSlime.Slimefun.cscorelib2.updater.Updater;
import org.bstats.bukkit.Metrics;

import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

public class InfinityExpansion extends JavaPlugin implements SlimefunAddon {
Expand Down Expand Up @@ -43,6 +48,12 @@ public void onEnable() {

ItemSetup.setup(this);

//get enabled infinity recipes

setupInfinityRecipes();

//spam console

getLogger().log(Level.INFO, "######################################");
getLogger().log(Level.INFO, " Infinity Expansion v" + getDescription().getVersion() + " ");
getLogger().log(Level.INFO, " ----------------------------- ");
Expand All @@ -54,6 +65,29 @@ public void onEnable() {

}

private static void setupInfinityRecipes() {
List<ItemStack> enabledOutputs = new ArrayList<>();
List<ItemStack[]> enabledRecipes = new ArrayList<>();

int i = 0;
for (ItemStack output : InfinityRecipes.OUTPUTS) {
SlimefunItem slimefunItem = SlimefunItem.getByItem(output);
assert slimefunItem != null;

if (!slimefunItem.isDisabled()) {
enabledOutputs.add(output);
enabledRecipes.add(InfinityRecipes.RECIPES[i]);
} else {
instance.getLogger().log(Level.INFO, "Infinity Item " + slimefunItem.getId() + " disabled!");
}
i++;
}

InfinityRecipes.OUTPUTS = enabledOutputs.toArray(new ItemStack[0]);
InfinityRecipes.RECIPES = enabledRecipes.toArray(new ItemStack[0][]);

}

@Override
public void onDisable() {
instance = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*
*/

public class Generators extends SlimefunItem implements EnergyNetProvider {
public class EnergyGenerator extends SlimefunItem implements EnergyNetProvider {

public static final int WATER_RATE = 12;
public static final int WATER_STORAGE = 2_000;
Expand All @@ -74,7 +74,7 @@ public class Generators extends SlimefunItem implements EnergyNetProvider {

private final Type type;

public Generators(Type type) {
public EnergyGenerator(Type type) {
super(type.getCategory(), type.getItem(), type.getRecipeType(), type.getRecipe());
this.type = type;

Expand Down Expand Up @@ -122,7 +122,7 @@ public void setupInv(BlockMenuPreset blockMenuPreset) {
public void preRegister() {
this.addItemHandler(new BlockTicker() {
public void tick(Block b, SlimefunItem sf, Config data) {
Generators.this.tick(b);
EnergyGenerator.this.tick(b);
}

public boolean isSynchronized() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.mooy1.infinityexpansion.implementation.machines;

import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
Expand Down Expand Up @@ -36,11 +35,10 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class InfinityWorkbench extends SlimefunItem implements EnergyNetComponent, RecipeDisplayItem {
public class InfinityWorkbench extends SlimefunItem implements EnergyNetComponent {

public static final int ENERGY = 10_000_000;

Expand Down Expand Up @@ -174,7 +172,9 @@ public void tick(Block b) {
inv.replaceExistingItem(STATUS_SLOT, PresetUtils.invalidRecipe);

} else { //correct recipe

inv.replaceExistingItem(STATUS_SLOT, getDisplayItem(output));

}
}
}
Expand Down Expand Up @@ -207,25 +207,23 @@ public void craft(Block b, Player p) {
inv.replaceExistingItem(STATUS_SLOT, PresetUtils.invalidRecipe);
MessageUtils.message(p, ChatColor.RED + "Invalid Recipe!");

} else { //correct recipe
} else if (!inv.fits(output, OUTPUT_SLOTS)) { //not enough room

if (!inv.fits(output, OUTPUT_SLOTS)) { //not enough room
inv.replaceExistingItem(STATUS_SLOT, PresetUtils.notEnoughRoom);
MessageUtils.message(p, ChatColor.GOLD + "Not enough room!");

inv.replaceExistingItem(STATUS_SLOT, PresetUtils.notEnoughRoom);
MessageUtils.message(p, ChatColor.GOLD + "Not enough room!");
} else { //enough room

} else { //enough room

for (int slot : INPUT_SLOTS) {
if (inv.getItemInSlot(slot) != null) {
inv.consumeItem(slot);
}
for (int slot : INPUT_SLOTS) {
if (inv.getItemInSlot(slot) != null) {
inv.consumeItem(slot);
}
MessageUtils.message(p, ChatColor.GREEN + "Successfully crafted: " + ChatColor.WHITE + ItemUtils.getItemName(output));

inv.pushItem(output, OUTPUT_SLOTS);
setCharge(b.getLocation(), 0);
}
MessageUtils.message(p, ChatColor.GREEN + "Successfully crafted: " + ChatColor.WHITE + ItemUtils.getItemName(output));

inv.pushItem(output, OUTPUT_SLOTS);
setCharge(b.getLocation(), 0);

}
}
}
Expand Down Expand Up @@ -280,16 +278,4 @@ public EnergyNetComponentType getEnergyComponentType() {
public int getCapacity() {
return ENERGY;
}

@Nonnull
@Override
public List<ItemStack> getDisplayRecipes() {
return new ArrayList<>(Arrays.asList(InfinityRecipes.OUTPUTS));
}

@Nonnull
@Override
public String getRecipeSectionLabel(@Nonnull Player p) {
return "&7Crafts:";
}
}

0 comments on commit 37dd7f8

Please sign in to comment.