2018-10-14 14:27:18 +02:00
|
|
|
package de.ellpeck.naturesaura;
|
|
|
|
|
2018-10-16 01:36:30 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2018-10-14 14:27:18 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2018-10-15 18:36:46 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2018-10-14 14:27:18 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public final class Helper {
|
|
|
|
|
|
|
|
public static List<TileEntity> getTileEntitiesInArea(World world, BlockPos pos, int radius) {
|
|
|
|
List<TileEntity> tiles = new ArrayList<>();
|
|
|
|
for (int x = (pos.getX() - radius) >> 4; x <= (pos.getX() + radius) >> 4; x++) {
|
|
|
|
for (int z = (pos.getZ() - radius) >> 4; z <= (pos.getZ() + radius) >> 4; z++) {
|
|
|
|
for (TileEntity tile : world.getChunk(x, z).getTileEntityMap().values()) {
|
|
|
|
if (tile.getPos().distanceSq(pos) <= radius * radius) {
|
|
|
|
tiles.add(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tiles;
|
|
|
|
}
|
|
|
|
|
2018-10-16 01:36:30 +02:00
|
|
|
public static boolean checkMultiblock(World world, BlockPos pos, BlockPos[] positions, IBlockState state, boolean blockOnly) {
|
|
|
|
for (BlockPos offset : positions) {
|
|
|
|
IBlockState current = world.getBlockState(pos.add(offset));
|
|
|
|
if (blockOnly ? current.getBlock() != state.getBlock() : current != state) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-15 18:36:46 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public static int blendColors(int c1, int c2, float ratio) {
|
|
|
|
int a = (int) ((c1 >> 24 & 0xFF) * ratio + (c2 >> 24 & 0xFF) * (1 - ratio));
|
|
|
|
int r = (int) ((c1 >> 16 & 0xFF) * ratio + (c2 >> 16 & 0xFF) * (1 - ratio));
|
|
|
|
int g = (int) ((c1 >> 8 & 0xFF) * ratio + (c2 >> 8 & 0xFF) * (1 - ratio));
|
|
|
|
int b = (int) ((c1 & 0xFF) * ratio + (c2 & 0xFF) * (1 - ratio));
|
|
|
|
return ((a & 255) << 24) | ((r & 255) << 16) | ((g & 255) << 8) | (b & 255);
|
|
|
|
}
|
2018-10-16 01:36:30 +02:00
|
|
|
|
|
|
|
public static boolean containsItem(List<ItemStack> list, ItemStack item) {
|
|
|
|
for (ItemStack stack : list) {
|
|
|
|
if (stack.isItemEqual(item)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean containsItem(ItemStack[] array, ItemStack item) {
|
|
|
|
for (ItemStack stack : array) {
|
|
|
|
if (stack.isItemEqual(item)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-14 14:27:18 +02:00
|
|
|
}
|