Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable factory I/O + fix a few bugs #58

Merged
merged 21 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
54c53d7
Simplify multiblock constructor
caucow Jun 4, 2021
d6facae
Bump version 2.5.1 -> 2.5.2 + CMC dep 1.8.2 -> 1.8.4
caucow Jun 6, 2021
c42779a
Add configurable factory IO
caucow Jun 6, 2021
5b1296d
Fix overlooked change in simplified code
caucow Jun 6, 2021
473c052
fix typo in multiinv + rename locals for clarity
caucow Jun 6, 2021
19e7dd2
Fix redstone detect direction for diode types
caucow Jun 6, 2021
0beaf52
Fix flashing diodes when factories are powered
caucow Jun 6, 2021
9c14c54
Default main factory chest to BOTH for unconfigured
caucow Jun 10, 2021
c6a8511
Make <no chest> bold because the barrier wasn't visible enough ? ? ? ?
caucow Jun 10, 2021
253c116
Cardinals mode for nerds with a killer mental compass but no eyes
caucow Jun 10, 2021
302431f
Make factory IO config section collapsible
caucow Jun 10, 2021
c70c397
Fix NPE - Initialize default UiMenuMode
caucow Jun 11, 2021
5f10830
Properly init default IO config +lazy init since getBlock called
caucow Jun 11, 2021
a5506c8
Add configurable fuel chests + I/O/F/total chest limit
caucow Jun 13, 2021
4e87c1f
Accommodate mid-version api compatibility change (come on paper ffs)
caucow Jun 16, 2021
a15ace0
Kleen up and tone down civtastic civtistic code (re: Max's reviews)
caucow Aug 19, 2021
a6d51f6
Fixes for potential fuel bug that hasn't presented yet
caucow Aug 20, 2021
2e24bc1
Fix furnace fuel level being reset a tick after consumption
caucow Aug 20, 2021
0f6a1e8
Fix scheduler exception when disabling furnaces while disabling plugin
caucow Aug 20, 2021
72801df
Bug fixes and code cleanup (see desc)
caucow Aug 20, 2021
2bd4f3e
FIx fix for autoselect not disabling factories
caucow Aug 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<groupId>com.github.igotyou</groupId>
<artifactId>FactoryMod</artifactId>
<packaging>jar</packaging>
<version>2.5.1</version>
<version>2.5.2</version>
<name>FactoryMod</name>
<url>https://github.com/Civclassic/FactoryMod</url>

Expand All @@ -39,7 +39,7 @@
<dependency>
<groupId>vg.civcraft.mc.civmodcore</groupId>
<artifactId>CivModCore</artifactId>
<version>1.8.2</version>
<version>1.8.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ public void run() {
int globalPylonLimit = config.getInt("global_pylon_limit");
PylonRecipe.setGlobalLimit(globalPylonLimit);
Map<String, String> factoryRenames = parseRenames(config.getConfigurationSection("renames"));
int maxInputChests = config.getInt("max_input_chests", 10);
int maxOutputChests = config.getInt("max_output_chests", 10);
int maxFuelChests = config.getInt("max_fuel_chests", 10);
int maxTotalIOFChests = config.getInt("max_iof_chests", 15);

manager = new FactoryModManager(plugin, factoryInteractionMaterial, citadelEnabled, nameLayerEnabled,
redstonePowerOn, redstoneRecipeChange, logInventories, factoryRenames);
redstonePowerOn, redstoneRecipeChange, logInventories, maxInputChests, maxOutputChests, maxFuelChests,
maxTotalIOFChests, factoryRenames);
upgradeEggs = new HashMap<>();
recipeLists = new HashMap<>();
recipeScalingUpgradeMapping = new HashMap<>();
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/github/igotyou/FactoryMod/FactoryModManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,27 @@ public class FactoryModManager {
private boolean logInventories;
private int redstonePowerOn;
private int redstoneRecipeChange;
private int maxInputChests;
private int maxOutputChests;
private int maxFuelChests;
private int maxTotalIOFChests;
private Set<String> compactLore;
private Set<String> forceInclude;
private FactoryModPlayerSettings playerSettings;

public FactoryModManager(FactoryMod plugin, Material factoryInteractionMaterial, boolean citadelEnabled,
boolean nameLayerEnabled, int redstonePowerOn, int redstoneRecipeChange, boolean logInventories,
int maxInputChests, int maxOutputChests, int maxFuelChests, int maxTotalIOFChests,
Map<String, String> factoryRenames) {
this.plugin = plugin;
this.factoryInteractionMaterial = factoryInteractionMaterial;
this.citadelEnabled = citadelEnabled;
this.redstonePowerOn = redstonePowerOn;
this.redstoneRecipeChange = redstoneRecipeChange;
this.maxInputChests = maxInputChests;
this.maxOutputChests = maxOutputChests;
this.maxFuelChests = maxFuelChests;
this.maxTotalIOFChests = maxTotalIOFChests;
this.fileHandler = new FileHandler(this, factoryRenames);

factoryCreationRecipes = new HashMap<>();
Expand All @@ -76,6 +86,7 @@ public FactoryModManager(FactoryMod plugin, Material factoryInteractionMaterial,
recipes = new HashMap<>();
compactLore = new HashSet<>();
forceInclude = new HashSet<>();
playerSettings = new FactoryModPlayerSettings(plugin);

// Normal furnace, craftingtable, chest factories
possibleCenterBlocks.add(Material.CRAFTING_TABLE);
Expand Down Expand Up @@ -149,6 +160,26 @@ public boolean isCitadelEnabled() {
return citadelEnabled;
}

public int getMaxInputChests() {
return maxInputChests;
}

public int getMaxOutputChests() {
return maxOutputChests;
}

public int getMaxFuelChests() {
return maxFuelChests;
}

/**
* @return The maximum total number of inputs, outputs, and fuel inputs a factory has. A chest with multiple IOF
* settings enabled is counted for each.
*/
public int getMaxTotalIOFChests() {
return maxTotalIOFChests;
}

/**
* @return Which material is used to interact with factories, stick by default
*/
Expand Down Expand Up @@ -239,6 +270,8 @@ public void attemptCreation(Block b, Player p) {
if (egg != null) {
Factory f = egg.hatch(fccs, p);
if (f != null) {
// Trigger lazy-initialize default crafting table IOSelector
((FurnCraftChestFactory)f).getTableIOSelector();
((Chest) (fccs.getChest().getState())).getInventory().clear();
addFactory(f);
p.sendMessage(ChatColor.GREEN + "Successfully created " + f.getName());
Expand Down Expand Up @@ -545,4 +578,8 @@ public boolean isForceInclude(String identifier) {
public Collection<IFactoryEgg> getAllFactoryEggs() {
return eggs.values();
}

public FactoryModPlayerSettings getPlayerSettings() {
return playerSettings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.github.igotyou.FactoryMod;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import vg.civcraft.mc.civmodcore.playersettings.PlayerSettingAPI;
import vg.civcraft.mc.civmodcore.playersettings.gui.MenuSection;
import vg.civcraft.mc.civmodcore.playersettings.impl.EnumSetting;

import java.util.UUID;

public class FactoryModPlayerSettings {

private final FactoryMod plugin;
EnumSetting<IoConfigDirectionMode> ioDirectionSetting;

public FactoryModPlayerSettings(FactoryMod plugin) {
this.plugin = plugin;
initSettings();
}

private void initSettings() {
MenuSection menu = PlayerSettingAPI.getMainMenu().createMenuSection(
"FactoryMod",
"FactoryMod settings",
new ItemStack(Material.FURNACE)
);

ioDirectionSetting = new EnumSetting<>(
plugin,
IoConfigDirectionMode.VISUAL_RELATIVE,
"Factory IOConfig Mode",
"ioconfig_visual_mode",
new ItemStack(Material.HOPPER),
"Change how the factory IO config appears",
true,
IoConfigDirectionMode.class
);
PlayerSettingAPI.registerSetting(ioDirectionSetting, menu);
}

public IoConfigDirectionMode getIoDirectionMode(UUID id) {
return ioDirectionSetting.getValue(id);
}

public enum IoConfigDirectionMode {

VISUAL_RELATIVE(
"Relative Directions",
new String[] {
"The furnace shows the",
"front of the factory."
}),
CARDINAL(
"Cardinal Directions",
new String[] {
"Cardinals (for those too",
"familiar with map mods.)"
});

public final String simpleDescription;
public final String[] fullDescription;

private IoConfigDirectionMode(String simpleDescription, String[] fullDescription) {
this.simpleDescription = simpleDescription;
this.fullDescription = fullDescription;
}
}

}
28 changes: 22 additions & 6 deletions src/main/java/com/github/igotyou/FactoryMod/factories/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.igotyou.FactoryMod.powerManager.IPowerManager;
import com.github.igotyou.FactoryMod.repairManager.IRepairManager;
import com.github.igotyou.FactoryMod.structures.MultiBlockStructure;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Furnace;
Expand Down Expand Up @@ -123,9 +124,13 @@ public void turnFurnaceOn(Block f) {
if (f.getType() != Material.FURNACE) {
return;
}
Furnace furnace = (Furnace) f.getState();
furnace.setBurnTime(Short.MAX_VALUE);
furnace.update();
Bukkit.getScheduler().runTask(FactoryMod.getInstance(), () -> {
if (this.isActive()) {
Furnace furnace = (Furnace) f.getState();
furnace.setBurnTime(Short.MAX_VALUE);
furnace.update();
}
});
}

public String getLogData() {
Expand All @@ -136,8 +141,19 @@ public void turnFurnaceOff(Block f) {
if (f.getType() != Material.FURNACE) {
return;
}
Furnace furnace = (Furnace) f.getState();
furnace.setBurnTime((short) 0);
furnace.update();
FactoryMod fmPlugin = FactoryMod.getInstance();
if (fmPlugin.isEnabled()) {
Bukkit.getScheduler().runTask(FactoryMod.getInstance(), () -> {
if (!this.isActive()) {
Furnace furnace = (Furnace) f.getState();
furnace.setBurnTime((short) 0);
furnace.update();
}
});
} else if (!this.isActive()) {
Furnace furnace = (Furnace) f.getState();
furnace.setBurnTime((short) 0);
furnace.update();
}
}
}
Loading