Skip to content

Commit

Permalink
Merge pull request #46 from Sefiraat/chore/tech_generator_performance
Browse files Browse the repository at this point in the history
TechGenerator Performance
  • Loading branch information
RelativoBR committed May 13, 2023
2 parents a7fe0bd + c44f0ae commit f9e7005
Showing 1 changed file with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.springframework.scheduling.annotation.Async;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -108,6 +109,7 @@ public static void preSetup(Supreme plugin, int tierCard, SlimefunItemStack item
TechGenerator.addRecipesToProcess(item, output);
}

@Nonnull
private static ItemStack getCardTier(int tierCard) {
if (tierCard >= 3) {
return SupremeComponents.CENTER_CARD_ULTIMATE;
Expand Down Expand Up @@ -206,7 +208,7 @@ public void tick(Block b, SlimefunItem sf, Config data) {
}

public boolean isSynchronized() {
return true;
return false;
}
});
}
Expand All @@ -215,9 +217,14 @@ public void tick(Block b) {

BlockMenu inv = BlockStorage.getInventory(b);

final ItemStack validRecipeItem = validRecipeItem(inv);
// Unlikely but blockmenus can be null
if (inv == null) {
return;
}

final ItemStack itemProduction = processing.get(b);
if (itemProduction == null) {
final ItemStack validRecipeItem = validRecipeItem(inv);

if (validRecipeItem != null) {

Expand All @@ -243,6 +250,7 @@ public void tick(Block b) {
invalidStatus(inv, Material.BLACK_STAINED_GLASS_PANE, " ");

} else {
final ItemStack validRecipeItem = validRecipeItem(inv);

if (SlimefunUtils.isItemSimilar(validRecipeItem, itemProduction, false, false)) {

Expand Down Expand Up @@ -297,7 +305,6 @@ public int getProgressTime(Block b) {
}

private void processTicks(Block b, BlockMenu inv, ItemStack result) {
int ticksTotal = getTimeProcess() * 2;
int ticksLeft = this.getProgressTime(b);
if (ticksLeft > 0) {

Expand All @@ -310,6 +317,8 @@ private void processTicks(Block b, BlockMenu inv, ItemStack result) {
}
progressTime.put(b, time);

int ticksTotal = getTimeProcess() * 2;

for (int i : InventoryRecipe.TECH_GENERATOR_PROGRESS_BAR_SLOT) {
ChestMenuUtils.updateProgressbar(inv, i, Math.round(ticksLeft / this.getSpeed()),
Math.round(ticksTotal / this.getSpeed()), result);
Expand Down Expand Up @@ -386,11 +395,12 @@ private int checkConsumptionSlot(ItemStack input, int consumption) {
MobTechType mobTechType = MobTechType.valueOf(PersistentDataAPI.getString(itemMeta, type));
int mobTechTier = PersistentDataAPI.getInt(itemMeta, tier);
float perceptual = (mobTechTier + 1) * input.getAmount() * 0.15625F;
int adjustEnergy = Math.round(consumption / 100F * perceptual);
if (mobTechType == MobTechType.ROBOTIC_EFFICIENCY || mobTechType == MobTechType.MUTATION_INTELLIGENCE) {
int adjustEnergy = Math.round(consumption / 100F * perceptual);
consumption = consumption - adjustEnergy;
}
if (mobTechType == MobTechType.ROBOTIC_ACCELERATION || mobTechType == MobTechType.MUTATION_BERSERK) {
int adjustEnergy = Math.round(consumption / 100F * perceptual);
consumption = consumption + adjustEnergy;
}
} else {
Expand All @@ -405,6 +415,7 @@ private int checkConsumptionSlot(ItemStack input, int consumption) {
return consumption;
}

@Nullable
private ItemStack validRecipeItem(BlockMenu inv) {

for (AbstractItemRecipe produce : this.getRecipeProcess()) {
Expand All @@ -421,15 +432,14 @@ private ItemStack validRecipeItem(BlockMenu inv) {
@Override
public List<ItemStack> getDisplayRecipes() {
List<ItemStack> displayRecipes = new ArrayList();
this.getRecipeShow()
.stream().filter(Objects::nonNull)
.forEach(recipe -> {
ItemStack itemStack = recipe.getFirstItemOutput().clone();
itemStack.setAmount(Supreme.getSupremeOptions().getMaxAmountTechGenerator());
displayRecipes.add(recipe.getFirstItemInput());
displayRecipes.add(itemStack);

});
for (AbstractItemRecipe recipe : this.getRecipeShow()) {
if (recipe != null) {
ItemStack itemStack = recipe.getFirstItemOutput().clone();
itemStack.setAmount(Supreme.getSupremeOptions().getMaxAmountTechGenerator());
displayRecipes.add(recipe.getFirstItemInput());
displayRecipes.add(itemStack);
}
}
return displayRecipes;
}

Expand Down

0 comments on commit f9e7005

Please sign in to comment.