Commits

Anonymous committed 705463c

added more options and limited duplication of duplicator ingredient obsidian and fuel cobblestone, fixed fuel consumption bug when not duplicated

  • Participants
  • Parent commits 0aa9b1a

Comments (0)

Files changed (2)

src/info/daybreaker/minecraft/PhilosophersCircuitPistonListener.java

 		if (Utils.checkActivatingCondition(piston)) {
 			final Material sourceType = targetBlock.getType();
 
-			if (plugin.isChestDuplicatorEnabled && retractedLocation.getBlock().getType().equals(Material.CHEST)) {
+			if (plugin.config.getBoolean("chestDuplicator.enabled", false)
+					&& retractedLocation.getBlock().getType().equals(Material.CHEST)) {
 				// Copy the first item in the chest and decrement the amount of the original stack in the chest.
 				// If we do not decrement it, an infinite amount of item entities on the map may cause severe lag.
 				Chest chest = (Chest) retractedLocation.getBlock().getState();
 							stack.setAmount(amount - 1);
 					}
 				}
-			} else if (targetBlock.getType().equals(Material.FURNACE)) {
+			} else if (plugin.config.getBoolean("furnaceDuplicator.enabled", true)
+					&& targetBlock.getType().equals(Material.FURNACE)) {
 
 				final Furnace furnace = (Furnace) targetBlock.getState();
 				Inventory inventory = furnace.getInventory();
 				ItemStack fuelStack = inventory.getItem(indexOfFuel);
 				ItemStack resultStack = inventory.getItem(indexOfResult);
 
+				if (plugin.config.getBoolean("furnaceDuplicator.preventInfiniteLoop", true)
+						&& sourceStack.getType().equals(Material.COBBLESTONE)
+						&& sourceStack.getType().equals(Material.OBSIDIAN))
+					return;
+
 				if (fuelStack.getType().equals(Material.COBBLESTONE) && sourceStack.getAmount() > 0) {
 					int fuelAmount = fuelStack.getAmount();
+					int newAmount;
 					if (resultStack.getTypeId() == 0)
 						resultStack = new ItemStack(sourceStack.getType());
+					if (resultStack.getAmount() == resultStack.getMaxStackSize()) // already full
+						return;
 					resultStack.setData(sourceStack.getData());
 					resultStack.setDurability(sourceStack.getDurability());
-					resultStack.setAmount(resultStack.getAmount()
+					newAmount = resultStack.getAmount()
 							+ Math.min(Utils.countBlocksAbove(piston, Material.OBSIDIAN, 2),
-									resultStack.getMaxStackSize()));
-					if (fuelAmount == 1)
-						inventory.clear(indexOfFuel);
-					else
-						fuelStack.setAmount(fuelAmount - 1);
+									resultStack.getMaxStackSize());
+					resultStack.setAmount(newAmount);
+					if (resultStack.getAmount() == newAmount || resultStack.getAmount() == resultStack.getMaxStackSize())
+						if (fuelAmount == 1)
+							inventory.clear(indexOfFuel);
+						else
+							fuelStack.setAmount(fuelAmount - 1);
 					inventory.setItem(indexOfResult, resultStack);
 				}
 

src/info/daybreaker/minecraft/PhilosophersCircuitPlugin.java

 	protected Configuration config;
 	public final Logger log = Logger.getLogger("Minecraft");
 
-	public boolean isChestDuplicatorEnabled = false;
-
 	public void loadConfig() {
 		File file = new File(this.getDataFolder() + File.separator + "config.yml");
 		if (file.exists() && file.canRead()) {
 			}
 			config = new Configuration(file);
 			config.setProperty("chestDuplicator.enabled", false);
+			config.setProperty("furnaceDuplicator.enabled", true);
+			config.setProperty("furnaceDuplicator.preventInfiniteLoop", true);
 			config.save();
 		}
 	}
 
 	@Override
 	public void onEnable() {
+		loadConfig();
 		PluginManager pm = getServer().getPluginManager();
 		pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, pistonListener, Priority.Normal, this);
-		loadConfig();
-		isChestDuplicatorEnabled = config.getBoolean("chestDuplicator.enabled", false);
 		log.info("Philosopher's Circuit is enabled.");
 	}