Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mdf25.moglass.block;
- import org.lwjgl.input.Keyboard;
- import com.mdf25.moglass.core;
- import com.mdf25.moglass.refStrings;
- import com.mdf25.moglass.gui.tintControllerGUIScreen;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.IIcon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- public class TintedGlassController extends VariableTintedGlass {
- protected TintedGlassController(Material material) {
- super(material, 0);
- this.setBlockName("tintedGlassController");
- this.setHardness(6.0F);
- this.setStepSound(soundTypeMetal);
- this.setResistance(10.0F);
- this.useNeighborBrightness = true;
- this.setBlockTextureName(refStrings.MODID + ":tintedGlassController");
- this.setCreativeTab(CreativeTabs.tabDecorations);
- }
- public int minX;
- public int maxX;
- public int minY;
- public int maxY;
- public int minZ;
- public int maxZ;
- @Override
- public void onBlockPlacedBy(World world, int y, int z, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) {
- int l = determineOrientation(world, y, z, par4, par5EntityLivingBase);
- if(l == 5){
- l = 1;
- }
- l = l - 1;
- world.setBlockMetadataWithNotify(y, z, par4, l, 2);
- }
- @Override
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
- if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
- System.out.println("SHIFT_RCLICK detected");
- CheckBlocks(world, player, x, y, z, "variableTintedGlass", 0);
- }
- else if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)){
- System.out.println("CTRL_RCLICK detected");
- CheckBlocks(world, player, x, y, z, "variableTintedGlass", 1);
- }
- return false;
- }
- @Override
- public boolean CheckBlocks(World world, EntityPlayer player, int x, int y, int z, String name, int flag){
- System.out.println("checkBlocks started");
- boolean emptyhanded;
- if (!world.isRemote){
- System.out.println("World was not remote. Continuing");
- if(player!=null && player.worldObj!=null && player.worldObj.getBlock(x,y,z)!=null){
- if(player.getHeldItem()!= null && player.getHeldItem().getItem()!= null){
- emptyhanded = false;
- System.out.println("Player has an item in hand.");
- }
- else{
- emptyhanded = true;
- System.out.println("Player has an empty hand.");
- }
- if(emptyhanded == false){
- System.out.println("Terminated");
- return false;
- }
- }
- else{
- return false;
- }
- }
- System.out.println("Still here! Looking for " + player.worldObj.getBlock(x, y, z).getUnlocalizedName());
- Block block = player.worldObj.getBlock(x, y, z);
- if(block == BlockInit.tintedGlassController){
- System.out.println("Tinted Glass Controller was clicked on");
- if(getRegion(world, x, y, z, 16, BlockInit.tintedGlassBeacon, Blocks.air) == true){
- changeBlocksInArea(player, world, minX, maxX, minY, maxY, minZ, maxZ, "variableTintedGlass", flag);
- return true;
- }
- }
- return false;
- }
- //New Methods
- public static int determineOrientation(World world, int x, int y, int z, EntityLivingBase entity) {
- int l = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
- }
- public static int getOrientation(int orient) {
- return orient & 7;
- }
- public static boolean isExtended(int orient) {
- return (orient & 8) != 0;
- }
- public boolean getRegion(World world, int x, int y, int z, int range, Block boundingBlock, Block duffBlock){
- System.out.println("getRegion started");
- int xCounterMin = 0;
- int xCounterMax = 0;
- int yCounterMin = 0;
- int yCounterMax = 0;
- int zCounterMin = 0;
- int zCounterMax = 0;
- Block blockMinX;
- Block blockMinY;
- Block blockMinZ;
- Block blockMaxX;
- Block blockMaxY;
- Block blockMaxZ;
- int aCounter = 0;
- if(range<=1){
- System.out.println("getRegion terminated - range must be > 1!");
- return false;
- }
- if(boundingBlock == duffBlock){
- System.out.println("getRegion terminated - duffBlock and boundingBlock can't be the same!");
- return false;
- }
- int maxRangeXZ = 30000000 - range;
- int minRangeXZ = -1*maxRangeXZ;
- if(x > minRangeXZ && x < maxRangeXZ && z > minRangeXZ && z < maxRangeXZ){
- System.out.println("Checks Passed.");
- for(int i = 1; i < range; i++){
- System.out.println("Loop " + i);
- if(aCounter == 6){
- System.out.println("Correct blocks found! Region is the following:");
- return true;
- }
- if(xCounterMin == 0){
- blockMinX = world.getBlock(x+i, y, z);
- }
- else{
- blockMinX = duffBlock;
- }
- if(yCounterMin == 0){
- blockMinY = world.getBlock(x-i, y, z);
- }
- else{
- blockMinY = duffBlock;
- }
- if(zCounterMin == 0){
- blockMinZ = world.getBlock(x, y+i, z);
- }
- else{
- blockMinZ = duffBlock;
- }
- if(xCounterMax == 0){
- blockMaxX = world.getBlock(x, y-i, z);
- }
- else{
- blockMaxX = duffBlock;
- }
- if(yCounterMax == 0){
- blockMaxY = world.getBlock(x, y, z+i);
- }
- else{
- blockMaxY = duffBlock;
- }
- if(zCounterMax == 0){
- blockMaxZ = world.getBlock(x, y, z-i);
- }
- else{
- blockMaxZ = duffBlock;
- }
- if(blockMinX != null && blockMaxX != null
- && blockMinY != null && blockMaxY != null
- && blockMinZ != null && blockMaxZ != null){
- if(blockMinX.equals(boundingBlock)){
- xCounterMin = 1;
- aCounter = aCounter + 1;
- minX = x - i;
- System.out.println("xCounterMin = " + xCounterMin);
- }
- if(blockMaxX.equals(boundingBlock)){
- xCounterMax = 1;
- aCounter = aCounter + 1;
- maxX = x + i;
- System.out.println("xCounterMax = " + xCounterMax);
- }
- if(blockMinY.equals(boundingBlock)){
- yCounterMin = 1;
- aCounter = aCounter + 1;
- minY = y - i;
- System.out.println("yCounterMin = " + yCounterMin);
- }
- if(blockMaxY.equals(boundingBlock)){
- yCounterMax = 1;
- aCounter = aCounter + 1;
- minY = y + i;
- System.out.println("yCounterMax = " + yCounterMax);
- }
- if(blockMinZ.equals(boundingBlock)){
- zCounterMin = 1;
- aCounter = aCounter + 1;
- minZ = z - i;
- System.out.println("zCounterMin = " + zCounterMin);
- }
- if(blockMaxZ.equals(boundingBlock)){
- zCounterMax = 1;
- aCounter = aCounter + 1;
- maxZ = x - i;
- System.out.println("zCounterMax = " + zCounterMax);
- }
- }
- System.out.println("aCounter is now: " + aCounter);
- }
- }
- return false;
- }
- //This is the bit I am having issues with:
- public boolean changeBlocksInArea(EntityPlayer player, World world, int lowX, int highX, int lowY, int highY, int lowZ, int highZ, String blockName, int flag){
- System.out.println("changeBlocksInArea started");
- System.out.println("Min X: " + lowX + " MaxX: " + highX);
- System.out.println("Min Y: " + lowY + " MaxY: " + highY);
- System.out.println("Min Z: " + lowZ + " MaxZ: " + highZ);
- //The above system outs all print the correct values.
- for(int a = lowX; a<=highX; a++){
- System.out.println("a is working"); //This works fine and shows the string
- for(int b = lowY; b<=highY; b++){
- System.out.println("b is working"); //Loop does not print this out or execute any of the code inside
- for(int c = lowZ; c<=highZ; c++){
- System.out.println("Loop(a,b,c): (" + a + "," + b + "," + c + ")");
- Block scanBlock = world.getBlock(a, b, c);
- if(scanBlock != null && scanBlock.getUnlocalizedName() != null){
- String scanBlockName = scanBlock.getUnlocalizedName().substring(5);
- if(scanBlockName.contains(blockName)){
- System.out.println("Got the block we wanted");
- if(flag == 0){
- metaChange(player, world, a, b, c, scanBlock, 0);
- }
- if(flag == 1){
- metaChange(player, world, a, b, c, scanBlock, 1);
- }
- }
- }
- if(a == highX && b == highY && c == highZ){
- return true;
- }
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement