Advertisement
Guest User

For Loop problem

a guest
Mar 12th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.64 KB | None | 0 0
  1. package com.mdf25.moglass.block;
  2.  
  3. import org.lwjgl.input.Keyboard;
  4.  
  5. import com.mdf25.moglass.core;
  6. import com.mdf25.moglass.refStrings;
  7. import com.mdf25.moglass.gui.tintControllerGUIScreen;
  8.  
  9. import cpw.mods.fml.relauncher.Side;
  10. import cpw.mods.fml.relauncher.SideOnly;
  11. import net.minecraft.block.Block;
  12. import net.minecraft.block.material.Material;
  13. import net.minecraft.client.Minecraft;
  14. import net.minecraft.client.renderer.texture.IIconRegister;
  15. import net.minecraft.creativetab.CreativeTabs;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.player.EntityPlayer;
  18. import net.minecraft.init.Blocks;
  19. import net.minecraft.item.ItemStack;
  20. import net.minecraft.util.IIcon;
  21. import net.minecraft.util.MathHelper;
  22. import net.minecraft.world.World;
  23.  
  24. public class TintedGlassController extends VariableTintedGlass {
  25.  
  26.     protected TintedGlassController(Material material) {
  27.         super(material, 0);
  28.         this.setBlockName("tintedGlassController");
  29.         this.setHardness(6.0F);
  30.         this.setStepSound(soundTypeMetal);
  31.         this.setResistance(10.0F);
  32.         this.useNeighborBrightness = true;
  33.         this.setBlockTextureName(refStrings.MODID + ":tintedGlassController");
  34.         this.setCreativeTab(CreativeTabs.tabDecorations);
  35.     }
  36.    
  37.     public int minX;
  38.     public int maxX;
  39.     public int minY;
  40.     public int maxY;
  41.     public int minZ;
  42.     public int maxZ;
  43.    
  44.     @Override
  45.     public void onBlockPlacedBy(World world, int y, int z, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) {
  46.         int l = determineOrientation(world, y, z, par4, par5EntityLivingBase);
  47.         if(l == 5){
  48.             l = 1;
  49.         }
  50.         l = l - 1;
  51.         world.setBlockMetadataWithNotify(y, z, par4, l, 2);
  52.     }
  53.    
  54.     @Override
  55.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
  56.         if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
  57.             System.out.println("SHIFT_RCLICK detected");
  58.             CheckBlocks(world, player, x, y, z, "variableTintedGlass", 0);
  59.         }
  60.         else if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)){
  61.             System.out.println("CTRL_RCLICK detected");
  62.             CheckBlocks(world, player, x, y, z, "variableTintedGlass", 1);
  63.         }
  64.         return false;
  65.     }
  66.    
  67.     @Override
  68.     public boolean CheckBlocks(World world, EntityPlayer player, int x, int y, int z, String name, int flag){
  69.         System.out.println("checkBlocks started");
  70.         boolean emptyhanded;
  71.         if (!world.isRemote){
  72.             System.out.println("World was not remote. Continuing");
  73.    
  74.             if(player!=null && player.worldObj!=null && player.worldObj.getBlock(x,y,z)!=null){
  75.                 if(player.getHeldItem()!= null && player.getHeldItem().getItem()!= null){
  76.                     emptyhanded = false;
  77.                     System.out.println("Player has an item in hand.");
  78.                 }
  79.                 else{
  80.                     emptyhanded = true;
  81.                     System.out.println("Player has an empty hand.");
  82.                 }
  83.                
  84.                 if(emptyhanded == false){
  85.                     System.out.println("Terminated");
  86.                     return false;
  87.                 }
  88.             }
  89.             else{
  90.                 return false;
  91.             }
  92.         }
  93.        
  94.         System.out.println("Still here! Looking for " + player.worldObj.getBlock(x, y, z).getUnlocalizedName());
  95.         Block block = player.worldObj.getBlock(x, y, z);
  96.         if(block == BlockInit.tintedGlassController){
  97.             System.out.println("Tinted Glass Controller was clicked on");
  98.             if(getRegion(world, x, y, z, 16, BlockInit.tintedGlassBeacon, Blocks.air) == true){
  99.                 changeBlocksInArea(player, world, minX, maxX, minY, maxY, minZ, maxZ, "variableTintedGlass", flag);
  100.                 return true;
  101.             }
  102.         }
  103.         return false;
  104.     }
  105.    
  106.     //New Methods
  107.     public static int determineOrientation(World world, int x, int y, int z, EntityLivingBase entity) {
  108.         int l = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  109.         return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
  110.     }
  111.  
  112.     public static int getOrientation(int orient) {
  113.         return orient & 7;
  114.     }
  115.  
  116.     public static boolean isExtended(int orient) {
  117.         return (orient & 8) != 0;
  118.     }
  119.    
  120.    
  121.    
  122.     public boolean getRegion(World world, int x, int y, int z, int range, Block boundingBlock, Block duffBlock){
  123.         System.out.println("getRegion started");
  124.        
  125.         int xCounterMin = 0;
  126.         int xCounterMax = 0;
  127.         int yCounterMin = 0;
  128.         int yCounterMax = 0;
  129.         int zCounterMin = 0;
  130.         int zCounterMax = 0;
  131.        
  132.         Block blockMinX;
  133.         Block blockMinY;
  134.         Block blockMinZ;
  135.         Block blockMaxX;
  136.         Block blockMaxY;
  137.         Block blockMaxZ;
  138.        
  139.         int aCounter = 0;
  140.        
  141.         if(range<=1){
  142.             System.out.println("getRegion terminated - range must be > 1!");
  143.             return false;
  144.         }
  145.        
  146.         if(boundingBlock == duffBlock){
  147.             System.out.println("getRegion terminated - duffBlock and boundingBlock can't be the same!");
  148.             return false;
  149.         }
  150.        
  151.         int maxRangeXZ = 30000000 - range;
  152.         int minRangeXZ = -1*maxRangeXZ;
  153.        
  154.         if(x > minRangeXZ && x < maxRangeXZ && z > minRangeXZ && z < maxRangeXZ){
  155.             System.out.println("Checks Passed.");
  156.             for(int i = 1; i < range; i++){
  157.                
  158.                 System.out.println("Loop " + i);
  159.                
  160.                 if(aCounter == 6){
  161.                     System.out.println("Correct blocks found! Region is the following:");
  162.                     return true;
  163.                 }
  164.                
  165.                 if(xCounterMin == 0){
  166.                     blockMinX = world.getBlock(x+i, y, z);
  167.                 }
  168.                 else{
  169.                     blockMinX = duffBlock;
  170.                 }
  171.                
  172.                 if(yCounterMin == 0){
  173.                     blockMinY = world.getBlock(x-i, y, z);
  174.                 }
  175.                 else{
  176.                     blockMinY = duffBlock;
  177.                 }
  178.                
  179.                 if(zCounterMin == 0){
  180.                     blockMinZ = world.getBlock(x, y+i, z);
  181.                 }
  182.                 else{
  183.                     blockMinZ = duffBlock;
  184.                 }
  185.                    
  186.                 if(xCounterMax == 0){
  187.                     blockMaxX = world.getBlock(x, y-i, z);
  188.                 }
  189.                 else{
  190.                     blockMaxX = duffBlock;
  191.                 }
  192.                
  193.                 if(yCounterMax == 0){
  194.                     blockMaxY = world.getBlock(x, y, z+i);
  195.                 }
  196.                 else{
  197.                     blockMaxY = duffBlock;
  198.                 }
  199.                
  200.                 if(zCounterMax == 0){
  201.                     blockMaxZ = world.getBlock(x, y, z-i);
  202.                 }
  203.                 else{
  204.                     blockMaxZ = duffBlock;
  205.                 }
  206.                
  207.                 if(blockMinX != null && blockMaxX != null
  208.                 && blockMinY != null && blockMaxY != null
  209.                 && blockMinZ != null && blockMaxZ != null){
  210.                    
  211.                     if(blockMinX.equals(boundingBlock)){
  212.                         xCounterMin = 1;
  213.                         aCounter    = aCounter + 1;
  214.                         minX = x - i;
  215.                         System.out.println("xCounterMin = " + xCounterMin);
  216.                     }
  217.                     if(blockMaxX.equals(boundingBlock)){
  218.                         xCounterMax = 1;
  219.                         aCounter = aCounter + 1;
  220.                         maxX = x + i;
  221.                         System.out.println("xCounterMax = " + xCounterMax);
  222.                     }
  223.                     if(blockMinY.equals(boundingBlock)){
  224.                         yCounterMin = 1;
  225.                         aCounter = aCounter + 1;
  226.                         minY = y - i;
  227.                         System.out.println("yCounterMin = " + yCounterMin);
  228.                     }
  229.                     if(blockMaxY.equals(boundingBlock)){
  230.                         yCounterMax = 1;
  231.                         aCounter    = aCounter + 1;
  232.                         minY = y + i;
  233.                         System.out.println("yCounterMax = " + yCounterMax);
  234.                     }
  235.                     if(blockMinZ.equals(boundingBlock)){
  236.                         zCounterMin = 1;
  237.                         aCounter = aCounter + 1;
  238.                         minZ = z - i;
  239.                         System.out.println("zCounterMin = " + zCounterMin);
  240.                     }
  241.                     if(blockMaxZ.equals(boundingBlock)){
  242.                         zCounterMax = 1;
  243.                         aCounter = aCounter + 1;
  244.                         maxZ = x - i;
  245.                         System.out.println("zCounterMax = " + zCounterMax);
  246.                     }
  247.                    
  248.                 }
  249.                 System.out.println("aCounter is now: " + aCounter);
  250.             }
  251.         }
  252.         return false;
  253.     }
  254.    
  255. //This is the bit I am having issues with:
  256.     public boolean changeBlocksInArea(EntityPlayer player, World world, int lowX, int highX, int lowY, int highY, int lowZ, int highZ, String blockName, int flag){
  257.         System.out.println("changeBlocksInArea started");
  258.         System.out.println("Min X: " + lowX + " MaxX: " + highX);
  259.         System.out.println("Min Y: " + lowY + " MaxY: " + highY);
  260.         System.out.println("Min Z: " + lowZ + " MaxZ: " + highZ);
  261.         //The above system outs all print the correct values.
  262.        
  263.         for(int a = lowX; a<=highX; a++){
  264.             System.out.println("a is working"); //This works fine and shows the string
  265.         for(int b = lowY; b<=highY; b++){
  266.             System.out.println("b is working"); //Loop does not print this out or execute any of the code inside
  267.         for(int c = lowZ; c<=highZ; c++){
  268.  
  269.             System.out.println("Loop(a,b,c): (" + a + "," + b + "," + c + ")");
  270.            
  271.             Block scanBlock = world.getBlock(a, b, c);
  272.             if(scanBlock != null && scanBlock.getUnlocalizedName() != null){
  273.                 String scanBlockName = scanBlock.getUnlocalizedName().substring(5);
  274.                 if(scanBlockName.contains(blockName)){
  275.                     System.out.println("Got the block we wanted");
  276.                     if(flag == 0){
  277.                         metaChange(player, world, a, b, c, scanBlock, 0);
  278.                     }
  279.                     if(flag == 1){
  280.                         metaChange(player, world, a, b, c, scanBlock, 1);
  281.                     }
  282.                 }
  283.             }
  284.             if(a == highX && b == highY && c == highZ){
  285.                 return true;
  286.             }
  287.         }
  288.         }
  289.         }
  290.         return false;
  291.     }
  292.        
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement