Local variables do not working with some types of blocks

Published by laugexd on
Status
Fixed
Issue description

Loops and local variables don't work well together and give me a "local variables referenced from an inner class must be final or effectively final" when used inside of the loop. Oddly enough when recompiling if this error happens in multiple mod elements it will only show the error being in the first of those elements in the list.

Error Log:

This mapping 'snapshot_20171003' was designed for MC 1.12! Use at your own peril.This mapping 'snapshot_20171003' was designed for MC 1.12! Use at your own peril.

#################################################
         ForgeGradle 2.3-SNAPSHOT-ee3e3df        
  https://github.com/MinecraftForge/ForgeGradle  
#################################################
                 Powered by MCP                  
             http://modcoderpack.com             
     by: Searge, ProfMobius, R4wk, ZeuX          
     Fesh0r, IngisKahn, bspkrs, LexManos         
#################################################
:clean
:deobfCompileDummyTask
:deobfProvidedDummyTask
:sourceApiJava
:compileApiJava UP-TO-DATE
:processApiResources UP-TO-DATE
:apiClasses UP-TO-DATE
:sourceMainJava
:compileJavaF:\mcreator\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_aGNormalGen.java:90: error: local variables referenced from an inner class must be final or effectively final
									ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
									                                                                       ^
F:\mcreator\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_aGNormalGen.java:101: error: local variables referenced from an inner class must be final or effectively final
									ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
									                                                                       ^
F:\mcreator\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_aGNormalGen.java:112: error: local variables referenced from an inner class must be final or effectively final
									ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
									                                                                       ^
F:\mcreator\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_aGNormalGen.java:125: error: local variables referenced from an inner class must be final or effectively final
										ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
										                                                                       ^
F:\mcreator\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_aGNormalGen.java:137: error: local variables referenced from an inner class must be final or effectively final
											ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
											                                                                       ^
F:\mcreator\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_aGNormalGen.java:175: error: local variables referenced from an inner class must be final or effectively final
															ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
															                                                                       ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 16.429 secs

Procedure:

package mod.mcreator;

import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.tileentity.TileEntityLockableLoot;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Items;

import java.util.Random;
import java.util.HashMap;

public class mcreator_aGNormalGen {

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
		if (dependencies.get("x") == null) {
			System.err.println("Failed to load dependency x for procedure aGNormalGen!");
			return;
		}
		if (dependencies.get("y") == null) {
			System.err.println("Failed to load dependency y for procedure aGNormalGen!");
			return;
		}
		if (dependencies.get("z") == null) {
			System.err.println("Failed to load dependency z for procedure aGNormalGen!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure aGNormalGen!");
			return;
		}
		int x = (int) dependencies.get("x");
		int y = (int) dependencies.get("y");
		int z = (int) dependencies.get("z");
		World world = (World) dependencies.get("world");
		double Test = 0;
		double Remainder = 0;
		double SecondLoop = 0;
		double SlotsToFill = 0;
		boolean NotDone = false;
		if ((mcreator_arrowChest.block.getDefaultState().getBlock() == (world.getBlockState(new BlockPos((int) x, (int) (y + 1), (int) z)))
				.getBlock())) {
			if ((0 < (world.isBlockIndirectlyGettingPowered(new BlockPos((int) x, (int) y, (int) z))))) {
				if (((new ItemStack(Items.STICK, (int) (1)).getItem() == new ItemStack((new Object() {

					public Item getItem() {
						TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) y, (int) z));
						if (inv != null && (inv instanceof TileEntityLockableLoot)) {
							ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (0));
							if (stack != null)
								return stack.getItem();
						}
						return null;
					}
				}.getItem()), (int) (1)).getItem()) && ((new ItemStack(Items.FEATHER, (int) (1)).getItem() == new ItemStack((new Object() {

					public Item getItem() {
						TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) y, (int) z));
						if (inv != null && (inv instanceof TileEntityLockableLoot)) {
							ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (1));
							if (stack != null)
								return stack.getItem();
						}
						return null;
					}
				}.getItem()), (int) (1)).getItem()) && (new ItemStack(Items.FLINT, (int) (1)).getItem() == new ItemStack((new Object() {

					public Item getItem() {
						TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) y, (int) z));
						if (inv != null && (inv instanceof TileEntityLockableLoot)) {
							ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (2));
							if (stack != null)
								return stack.getItem();
						}
						return null;
					}
				}.getItem()), (int) (1)).getItem())))) {
					Remainder = ((double) 16);
					for (int index0 = 0; index0 < (int) (18); index0++) {
						if ((((new ItemStack(Items.ARROW, (int) (1)).getItem() == new ItemStack((new Object() {

							public Item getItem() {
								TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) (y + 1), (int) z));
								if (inv != null && (inv instanceof TileEntityLockableLoot)) {
									ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
									if (stack != null)
										return stack.getItem();
								}
								return null;
							}
						}.getItem()), (int) (1)).getItem()) && (64 > (new Object() {

							public int getAmount() {
								TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) (y + 1), (int) z));
								if (inv != null && (inv instanceof TileEntityLockableLoot)) {
									ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
									if (stack != null)
										return stack.getCount();
								}
								return 0;
							}
						}.getAmount()))) || (0 == (new Object() {

							public int getAmount() {
								TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) (y + 1), (int) z));
								if (inv != null && (inv instanceof TileEntityLockableLoot)) {
									ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
									if (stack != null)
										return stack.getCount();
								}
								return 0;
							}
						}.getAmount())))) {
							SlotsToFill = ((double) (64 - Remainder));
							if ((SlotsToFill < (new Object() {

								public int getAmount() {
									TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) (y + 1), (int) z));
									if (inv != null && (inv instanceof TileEntityLockableLoot)) {
										ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
										if (stack != null)
											return stack.getCount();
									}
									return 0;
								}
							}.getAmount()))) {
								Remainder = ((double) (Remainder - (64 - (new Object() {

									public int getAmount() {
										TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) (y + 1), (int) z));
										if (inv != null && (inv instanceof TileEntityLockableLoot)) {
											ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
											if (stack != null)
												return stack.getCount();
										}
										return 0;
									}
								}.getAmount()))));
								{
									TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) (y + 1), (int) z));
									if (inv != null && (inv instanceof TileEntityLockableLoot))
										((TileEntityLockableLoot) inv).setInventorySlotContents((int) (Test), new ItemStack(Items.ARROW, (int) (64)));
								}
								Test = ((double) (Test + 1));
							} else {
								{
									TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) y, (int) z));
									if (inv != null && (inv instanceof TileEntityLockableLoot))
										((TileEntityLockableLoot) inv).decrStackSize((int) (0), (int) (1));
								}
								{
									TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) y, (int) z));
									if (inv != null && (inv instanceof TileEntityLockableLoot))
										((TileEntityLockableLoot) inv).decrStackSize((int) (1), (int) (1));
								}
								{
									TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) y, (int) z));
									if (inv != null && (inv instanceof TileEntityLockableLoot))
										((TileEntityLockableLoot) inv).decrStackSize((int) (2), (int) (1));
								}
								{
									TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) (y + 1), (int) z));
									if (inv != null && (inv instanceof TileEntityLockableLoot))
										((TileEntityLockableLoot) inv).setInventorySlotContents((int) (Test), new ItemStack(Items.ARROW,
												(int) (((new Object() {

													public int getAmount() {
														TileEntity inv = world.getTileEntity(new BlockPos((int) x, (int) (y + 1), (int) z));
														if (inv != null && (inv instanceof TileEntityLockableLoot)) {
															ItemStack stack = ((TileEntityLockableLoot) inv).getStackInSlot((int) (Test));
															if (stack != null)
																return stack.getCount();
														}
														return 0;
													}
												}.getAmount()) + Remainder))));
								}
								break;
							}
						} else {
							Test = ((double) (Test + 1));
						}
					}
				}
			}
		}
	}

	public static Object instance;

	public void load(FMLInitializationEvent event) {
	}

	public void generateNether(World world, Random random, int chunkX, int chunkZ) {
	}

	public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
	}

	public void serverLoad(FMLServerStartingEvent event) {
	}

	public void preInit(FMLPreInitializationEvent event) {
	}

	public void registerRenderers() {
	}

	public int addFuel(ItemStack fuel) {
		return 0;
	}
}

Issue comments

I can confirm this is a bug. The loop is not a problem but implementation of Java code for some of the blocks. We will fix this in next updates.