mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Get rid of some triple nested for loops
This commit is contained in:
8 files changed
+95
-127
No files matched your search
@@ -39,51 +39,45 @@ public class SubTileExoflame extends SubTileFunctional {
|
||||
|
||||
boolean did = false;
|
||||
|
||||
fireFurnaces : {
|
||||
for(int i = -RANGE; i < RANGE + 1; i++)
|
||||
for(int j = -RANGE_Y; j < RANGE_Y + 1; j++)
|
||||
for(int k = -RANGE; k < RANGE + 1; k++) {
|
||||
BlockPos pos = supertile.getPos().add(i, j, k);
|
||||
|
||||
TileEntity tile = supertile.getWorld().getTileEntity(pos);
|
||||
Block block = supertile.getWorld().getBlockState(pos).getBlock();
|
||||
if(tile != null) {
|
||||
if(tile instanceof TileEntityFurnace && (block == Blocks.FURNACE || block == Blocks.LIT_FURNACE)) {
|
||||
TileEntityFurnace furnace = (TileEntityFurnace) tile;
|
||||
boolean canSmelt = canFurnaceSmelt(furnace);
|
||||
if(canSmelt && mana > 2) {
|
||||
if(furnace.getField(0) < 2) { // Field 0 -> Burn time
|
||||
if(furnace.getField(0) == 0)
|
||||
BlockFurnace.setState(true, supertile.getWorld(), pos);
|
||||
furnace.setField(0, 200);
|
||||
mana = Math.max(0, mana - COST);
|
||||
}
|
||||
if(ticksExisted % 2 == 0)
|
||||
furnace.setField(2, Math.min(199, furnace.getField(2) + 1)); // Field 2 -> cook time
|
||||
|
||||
did = true;
|
||||
|
||||
if(mana <= 0)
|
||||
break fireFurnaces;
|
||||
}
|
||||
} else if(tile instanceof IExoflameHeatable) {
|
||||
IExoflameHeatable heatable = (IExoflameHeatable) tile;
|
||||
|
||||
if(heatable.canSmelt() && mana > 2) {
|
||||
if(heatable.getBurnTime() == 0) {
|
||||
heatable.boostBurnTime();
|
||||
mana = Math.max(0, mana - COST);
|
||||
}
|
||||
|
||||
if(ticksExisted % 2 == 0)
|
||||
heatable.boostCookTime();
|
||||
|
||||
if(mana <= 0)
|
||||
break fireFurnaces;
|
||||
}
|
||||
}
|
||||
for(BlockPos pos : BlockPos.getAllInBox(getPos().add(-RANGE, -RANGE_Y, -RANGE), getPos().add(RANGE, RANGE_Y, RANGE))) {
|
||||
TileEntity tile = supertile.getWorld().getTileEntity(pos);
|
||||
Block block = supertile.getWorld().getBlockState(pos).getBlock();
|
||||
if(tile != null) {
|
||||
if(tile instanceof TileEntityFurnace && (block == Blocks.FURNACE || block == Blocks.LIT_FURNACE)) {
|
||||
TileEntityFurnace furnace = (TileEntityFurnace) tile;
|
||||
boolean canSmelt = canFurnaceSmelt(furnace);
|
||||
if(canSmelt && mana > 2) {
|
||||
if(furnace.getField(0) < 2) { // Field 0 -> Burn time
|
||||
if(furnace.getField(0) == 0)
|
||||
BlockFurnace.setState(true, supertile.getWorld(), pos);
|
||||
furnace.setField(0, 200);
|
||||
mana = Math.max(0, mana - COST);
|
||||
}
|
||||
if(ticksExisted % 2 == 0)
|
||||
furnace.setField(2, Math.min(199, furnace.getField(2) + 1)); // Field 2 -> cook time
|
||||
|
||||
did = true;
|
||||
|
||||
if(mana <= 0)
|
||||
break;
|
||||
}
|
||||
} else if(tile instanceof IExoflameHeatable) {
|
||||
IExoflameHeatable heatable = (IExoflameHeatable) tile;
|
||||
|
||||
if(heatable.canSmelt() && mana > 2) {
|
||||
if(heatable.getBurnTime() == 0) {
|
||||
heatable.boostBurnTime();
|
||||
mana = Math.max(0, mana - COST);
|
||||
}
|
||||
|
||||
if(ticksExisted % 2 == 0)
|
||||
heatable.boostCookTime();
|
||||
|
||||
if(mana <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(did)
|
||||
|
||||
+5
-8
@@ -96,14 +96,11 @@ public class SubTileMarimorphosis extends SubTileFunctional {
|
||||
int range = getRange();
|
||||
int rangeY = getRangeY();
|
||||
|
||||
for(int i = -range; i < range + 1; i++)
|
||||
for(int j = -rangeY; j < rangeY; j++)
|
||||
for(int k = -range; k < range + 1; k++) {
|
||||
BlockPos pos = supertile.getPos().add(i, j, k);
|
||||
IBlockState state = supertile.getWorld().getBlockState(pos);
|
||||
if(state.getBlock().isReplaceableOreGen(state, supertile.getWorld(), pos, BlockStateMatcher.forBlock(Blocks.STONE)))
|
||||
possibleCoords.add(pos);
|
||||
}
|
||||
for(BlockPos pos : BlockPos.getAllInBox(getPos().add(-range, -rangeY, -range), getPos().add(range, rangeY, range))) {
|
||||
IBlockState state = supertile.getWorld().getBlockState(pos);
|
||||
if(state.getBlock().isReplaceableOreGen(state, supertile.getWorld(), pos, BlockStateMatcher.forBlock(Blocks.STONE)))
|
||||
possibleCoords.add(pos);
|
||||
}
|
||||
|
||||
if(possibleCoords.isEmpty())
|
||||
return null;
|
||||
|
||||
@@ -103,14 +103,11 @@ public class SubTileOrechid extends SubTileFunctional {
|
||||
List<BlockPos> possibleCoords = new ArrayList<>();
|
||||
|
||||
Block source = getSourceBlock();
|
||||
for(int i = -RANGE; i < RANGE + 1; i++)
|
||||
for(int j = -RANGE_Y; j < RANGE_Y; j++)
|
||||
for(int k = -RANGE; k < RANGE + 1; k++) {
|
||||
BlockPos pos = supertile.getPos().add(i, j, k);
|
||||
IBlockState state = supertile.getWorld().getBlockState(pos);
|
||||
if(state.getBlock().isReplaceableOreGen(state, supertile.getWorld(), pos, BlockStateMatcher.forBlock(source)))
|
||||
possibleCoords.add(pos);
|
||||
}
|
||||
for(BlockPos pos : BlockPos.getAllInBox(getPos().add(-RANGE, -RANGE_Y, -RANGE), getPos().add(RANGE, RANGE_Y, RANGE))) {
|
||||
IBlockState state = supertile.getWorld().getBlockState(pos);
|
||||
if(state.getBlock().isReplaceableOreGen(state, supertile.getWorld(), pos, BlockStateMatcher.forBlock(source)))
|
||||
possibleCoords.add(pos);
|
||||
}
|
||||
|
||||
if(possibleCoords.isEmpty())
|
||||
return null;
|
||||
|
||||
+9
-10
@@ -93,16 +93,15 @@ public class SubTileRannuncarpus extends SubTileFunctional {
|
||||
Item stackItem = stack.getItem();
|
||||
if(stackItem instanceof ItemBlock || stackItem instanceof ItemBlockSpecial || stackItem instanceof ItemRedstone || stackItem instanceof IFlowerPlaceable) {
|
||||
if(!scanned) {
|
||||
for(int i = -rangePlace; i < rangePlace + 1; i++)
|
||||
for(int j = -rangePlaceY; j < rangePlaceY + 1; j++)
|
||||
for(int l = -rangePlace; l < rangePlace + 1; l++) {
|
||||
BlockPos pos_ = pos.add(i, j, l);
|
||||
IBlockState stateAbove = supertile.getWorld().getBlockState(pos_.up());
|
||||
Block blockAbove = stateAbove.getBlock();
|
||||
|
||||
if(filter == supertile.getWorld().getBlockState(pos_) && (blockAbove.isAir(stateAbove, supertile.getWorld(), pos_.up()) || blockAbove.isReplaceable(supertile.getWorld(), pos_.up())))
|
||||
validPositions.add(pos_.up());
|
||||
}
|
||||
for(BlockPos pos_ : BlockPos.getAllInBox(pos.add(-rangePlace, -rangePlaceY, -rangePlace), pos.add(rangePlace, rangePlaceY, rangePlace))) {
|
||||
IBlockState stateAbove = supertile.getWorld().getBlockState(pos_.up());
|
||||
Block blockAbove = stateAbove.getBlock();
|
||||
BlockPos up = pos_.up();
|
||||
if(filter == supertile.getWorld().getBlockState(pos_)
|
||||
&& (blockAbove.isAir(stateAbove, supertile.getWorld(), up)
|
||||
|| blockAbove.isReplaceable(supertile.getWorld(), up)))
|
||||
validPositions.add(up);
|
||||
}
|
||||
|
||||
scanned = true;
|
||||
}
|
||||
|
||||
@@ -58,26 +58,22 @@ public class SubTileMunchdew extends SubTileGenerating {
|
||||
List<BlockPos> coords = new ArrayList<>();
|
||||
BlockPos pos = supertile.getPos();
|
||||
|
||||
for(int i = -RANGE; i < RANGE + 1; i++)
|
||||
for(int j = 0; j < RANGE_Y; j++)
|
||||
for(int k = -RANGE; k < RANGE + 1; k++) {
|
||||
BlockPos pos_ = pos.add(i, j, k);
|
||||
if(supertile.getWorld().getBlockState(pos_).getMaterial() == Material.LEAVES) {
|
||||
boolean exposed = false;
|
||||
for(EnumFacing dir : EnumFacing.VALUES) {
|
||||
IBlockState offState = supertile.getWorld().getBlockState(pos_.offset(dir));
|
||||
if(offState.getBlock().isAir(offState, supertile.getWorld(), pos_.offset(dir))) {
|
||||
exposed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(exposed)
|
||||
coords.add(pos_);
|
||||
for(BlockPos pos_ : BlockPos.getAllInBox(pos.add(-RANGE, -RANGE_Y, -RANGE), pos.add(RANGE, RANGE_Y, RANGE))) {
|
||||
if(supertile.getWorld().getBlockState(pos_).getMaterial() == Material.LEAVES) {
|
||||
boolean exposed = false;
|
||||
for(EnumFacing dir : EnumFacing.VALUES) {
|
||||
IBlockState offState = supertile.getWorld().getBlockState(pos_.offset(dir));
|
||||
if(offState.getBlock().isAir(offState, supertile.getWorld(), pos_.offset(dir))) {
|
||||
exposed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(exposed)
|
||||
coords.add(pos_);
|
||||
}
|
||||
}
|
||||
|
||||
if(coords.isEmpty())
|
||||
break eatLeaves;
|
||||
|
||||
|
||||
@@ -112,24 +112,24 @@ public class ItemGrassHorn extends ItemMod {
|
||||
int rangeY = 3 + stackDmg * 4;
|
||||
List<BlockPos> coords = new ArrayList<>();
|
||||
|
||||
for(int i = -range; i < range + 1; i++)
|
||||
for(int j = -range; j < range + 1; j++)
|
||||
for(int k = -rangeY; k < rangeY + 1; k++) {
|
||||
BlockPos pos = srcPos.add(i, k, j);
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if(block instanceof IHornHarvestable ? ((IHornHarvestable) block).canHornHarvest(world, pos, stack, type) : stackDmg == 0 && block instanceof BlockBush && !(block instanceof ISpecialFlower) || stackDmg == 1 && block.isLeaves(world.getBlockState(pos), world, pos) || stackDmg == 2 && block == Blocks.SNOW_LAYER)
|
||||
coords.add(pos);
|
||||
}
|
||||
for(BlockPos pos : BlockPos.getAllInBox(srcPos.add(-range, -rangeY, -range), srcPos.add(range, rangeY, range))) {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if(block instanceof IHornHarvestable
|
||||
? ((IHornHarvestable) block).canHornHarvest(world, pos, stack, type)
|
||||
: stackDmg == 0 && block instanceof BlockBush && !(block instanceof ISpecialFlower)
|
||||
|| stackDmg == 1 && block.isLeaves(world.getBlockState(pos), world, pos)
|
||||
|| stackDmg == 2 && block == Blocks.SNOW_LAYER)
|
||||
coords.add(pos);
|
||||
}
|
||||
|
||||
Collections.shuffle(coords, rand);
|
||||
|
||||
int count = Math.min(coords.size(), 32 + stackDmg * 16);
|
||||
for(int i = 0; i < count; i++) {
|
||||
BlockPos currCoords = coords.get(i);
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
IBlockState state = world.getBlockState(currCoords);
|
||||
Block block = state.getBlock();
|
||||
items.addAll(block.getDrops(world, currCoords, state, 0));
|
||||
List<ItemStack> items = block.getDrops(world, currCoords, state, 0);
|
||||
|
||||
if(block instanceof IHornHarvestable && ((IHornHarvestable) block).hasSpecialHornHarvest(world, currCoords, stack, type))
|
||||
((IHornHarvestable) block).harvestByHorn(world, currCoords, stack, type);
|
||||
|
||||
@@ -279,21 +279,10 @@ public class ItemGrassSeeds extends ItemMod implements IFloatingFlowerVariant {
|
||||
* should be removed.
|
||||
*/
|
||||
public boolean tick() {
|
||||
++ticksExisted;
|
||||
|
||||
// Go through all blocks in the specified RANGE, and then
|
||||
// try and spread around that block if it is our target block already
|
||||
for(int i = -RANGE; i <= RANGE; i++) {
|
||||
for(int j = -RANGE; j <= RANGE; j++) {
|
||||
BlockPos pos = startCoords.add(i, 0, j);
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
||||
if(state == stateToSet) {
|
||||
// Only make changes every 20 ticks
|
||||
if(ticksExisted % 20 != 0) continue;
|
||||
|
||||
if(++ticksExisted % 20 == 0) {
|
||||
for(BlockPos pos : BlockPos.getAllInBox(startCoords.add(-RANGE, 0, -RANGE), startCoords.add(RANGE, 0, RANGE))) {
|
||||
if(world.getBlockState(pos) == stateToSet)
|
||||
tickBlock(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,24 +66,20 @@ public class ItemDiviningRod extends ItemMod implements IManaUsingItem, IAvatarW
|
||||
|
||||
public void doHighlight(World world, BlockPos pos, int range, long seedxor) {
|
||||
Botania.proxy.setWispFXDepthTest(false);
|
||||
for(int i = -range; i < range + 1; i++)
|
||||
for(int j = -range; j < range + 1; j++)
|
||||
for(int k = -range; k < range + 1; k++) {
|
||||
BlockPos pos_ = pos.add(i, j, k);
|
||||
IBlockState state = world.getBlockState(pos_);
|
||||
if (Item.getItemFromBlock(state.getBlock()) == null) {
|
||||
continue;
|
||||
}
|
||||
ItemStack orestack = new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state));
|
||||
for(int id : OreDictionary.getOreIDs(orestack)) {
|
||||
String s = OreDictionary.getOreName(id);
|
||||
if(s.matches("^ore[A-Z].+")) {
|
||||
Random rand = new Random(s.hashCode() ^ seedxor);
|
||||
Botania.proxy.wispFX(world, pos_.getX() + world.rand.nextFloat(), pos_.getY() + world.rand.nextFloat(), pos_.getZ() + world.rand.nextFloat(), rand.nextFloat(), rand.nextFloat(), rand.nextFloat(), 0.25F, 0F, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(BlockPos pos_ : BlockPos.getAllInBox(pos.add(-range, -range, -range), pos.add(range, range, range))) {
|
||||
IBlockState state = world.getBlockState(pos_);
|
||||
if(Item.getItemFromBlock(state.getBlock()) == null)
|
||||
continue;
|
||||
ItemStack orestack = new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state));
|
||||
for(int id : OreDictionary.getOreIDs(orestack)) {
|
||||
String s = OreDictionary.getOreName(id);
|
||||
if(s.matches("^ore[A-Z].+")) {
|
||||
Random rand = new Random(s.hashCode() ^ seedxor);
|
||||
Botania.proxy.wispFX(world, pos_.getX() + world.rand.nextFloat(), pos_.getY() + world.rand.nextFloat(), pos_.getZ() + world.rand.nextFloat(), rand.nextFloat(), rand.nextFloat(), rand.nextFloat(), 0.25F, 0F, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Botania.proxy.setWispFXDepthTest(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user