Run formatter

This commit is contained in:
Nicholas Ignoffo 2017-08-15 21:30:48 -07:00
parent 61c44a831b
commit 08258fd6ef
606 changed files with 13464 additions and 22975 deletions

View file

@ -1,16 +1,15 @@
package WayofTime.bloodmagic.meteor;
import java.util.List;
import java.util.Random;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import WayofTime.bloodmagic.util.Utils;
public class Meteor
{
import java.util.List;
import java.util.Random;
public class Meteor {
private static final Random RAND = new Random();
private final ItemStack catalystStack;
@ -20,8 +19,7 @@ public class Meteor
private final int maxWeight;
public int version;
public Meteor(ItemStack catalystStack, List<MeteorComponent> components, float explosionStrength, int radius)
{
public Meteor(ItemStack catalystStack, List<MeteorComponent> components, float explosionStrength, int radius) {
this.catalystStack = catalystStack;
this.components = components;
this.explosionStrength = explosionStrength;
@ -33,31 +31,24 @@ public class Meteor
this.maxWeight = weight;
}
public void generateMeteor(World world, BlockPos pos, IBlockState fillerBlock, double radiusModifier, double explosionModifier, double fillerChance)
{
public void generateMeteor(World world, BlockPos pos, IBlockState fillerBlock, double radiusModifier, double explosionModifier, double fillerChance) {
world.newExplosion(null, pos.getX(), pos.getY(), pos.getZ(), (float) (explosionStrength * explosionModifier), true, true);
int radius = (int) Math.ceil(getRadius() * radiusModifier);
double floatingRadius = getRadius() * radiusModifier;
for (int i = -radius; i <= radius; i++)
{
for (int j = -radius; j <= radius; j++)
{
for (int k = -radius; k <= radius; k++)
{
if (i * i + j * j + k * k > (floatingRadius + 0.5) * (floatingRadius + 0.5))
{
for (int i = -radius; i <= radius; i++) {
for (int j = -radius; j <= radius; j++) {
for (int k = -radius; k <= radius; k++) {
if (i * i + j * j + k * k > (floatingRadius + 0.5) * (floatingRadius + 0.5)) {
continue;
}
BlockPos newPos = pos.add(i, j, k);
IBlockState state = world.getBlockState(newPos);
if (world.isAirBlock(newPos) || Utils.isBlockLiquid(state))
{
if (world.isAirBlock(newPos) || Utils.isBlockLiquid(state)) {
IBlockState placedState = getRandomOreFromComponents(fillerBlock, fillerChance);
if (placedState != null)
{
if (placedState != null) {
world.setBlockState(newPos, placedState);
}
}
@ -67,21 +58,16 @@ public class Meteor
}
//fillerChance is the chance that the filler block will NOT be placed
public IBlockState getRandomOreFromComponents(IBlockState fillerBlock, double fillerChance)
{
public IBlockState getRandomOreFromComponents(IBlockState fillerBlock, double fillerChance) {
int goal = RAND.nextInt(getMaxWeight());
for (MeteorComponent component : getComponents())
{
for (MeteorComponent component : getComponents()) {
goal -= component.getWeight();
if (goal < 0)
{
if (goal < 0) {
IBlockState state = component.getStateFromOre();
if (state != null)
{
if (state != null) {
return state;
} else
{
} else {
return RAND.nextDouble() > fillerChance ? fillerBlock : null;
}
}

View file

@ -1,7 +1,6 @@
package WayofTime.bloodmagic.meteor;
import java.util.List;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
@ -10,10 +9,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.oredict.OreDictionary;
import WayofTime.bloodmagic.util.Utils;
public class MeteorComponent
{
import java.util.List;
public class MeteorComponent {
public int weight;
public String oreName;
@ -22,33 +21,26 @@ public class MeteorComponent
this.oreName = oreName;
}
public IBlockState getStateFromOre()
{
if (oreName.contains(":"))
{
public IBlockState getStateFromOre() {
if (oreName.contains(":")) {
String[] stringList = oreName.split(":");
String domain = stringList[0];
String block = stringList[1];
int meta = 0;
if (stringList.length > 2 && Utils.isInteger(stringList[2]))
{
if (stringList.length > 2 && Utils.isInteger(stringList[2])) {
meta = Integer.parseInt(stringList[2]);
}
Block ore = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(domain, block));
if (ore != Blocks.AIR)
{
if (ore != Blocks.AIR) {
return ore.getStateFromMeta(meta);
}
}
List<ItemStack> list = OreDictionary.getOres(oreName);
if (list != null && !list.isEmpty())
{
for (ItemStack stack : list)
{
if (stack != null && stack.getItem() instanceof ItemBlock)
{
if (list != null && !list.isEmpty()) {
for (ItemStack stack : list) {
if (stack != null && stack.getItem() instanceof ItemBlock) {
Block block = ((ItemBlock) stack.getItem()).getBlock();
IBlockState state = block.getStateFromMeta(stack.getItemDamage());

View file

@ -17,20 +17,17 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
public class MeteorConfigHandler
{
public class MeteorConfigHandler {
private static final Map<String, Meteor> DEFAULT_METEORS = Maps.newHashMap();
private static File meteorDir;
public static void init(File meteorDirectory)
{
public static void init(File meteorDirectory) {
meteorDir = meteorDirectory;
handleMeteors(true);
}
public static void handleMeteors(boolean checkNewVersion)
{
public static void handleMeteors(boolean checkNewVersion) {
if (meteorDir == null) {
BloodMagic.instance.logger.error("Attempted to handle meteor config but the folder has not been initialized. Was this run too early?");
return;
@ -40,13 +37,10 @@ public class MeteorConfigHandler
MeteorRegistry.meteorMap.clear();
List<Pair<String, Meteor>> defaultMeteors = getDefaultMeteors();
try
{
try {
// Create defaults if the folder doesn't exist
if (!meteorDir.exists() && meteorDir.mkdir())
{
for (Pair<String, Meteor> meteor : defaultMeteors)
{
if (!meteorDir.exists() && meteorDir.mkdir()) {
for (Pair<String, Meteor> meteor : defaultMeteors) {
String json = Serializers.GSON.toJson(meteor.getRight());
FileWriter writer = new FileWriter(new File(meteorDir, meteor.getLeft() + ".json"));
writer.write(json);
@ -62,24 +56,20 @@ public class MeteorConfigHandler
List<Pair<String, Meteor>> meteors = Lists.newArrayList();
// Filter names so we can compare to defaults
for (File meteorFile : meteorFiles)
{
for (File meteorFile : meteorFiles) {
FileReader reader = new FileReader(meteorFile);
Meteor meteor = Serializers.GSON.fromJson(reader, Meteor.class);
meteors.add(Pair.of(FilenameUtils.removeExtension(meteorFile.getName()), meteor));
reader.close();
}
if (checkNewVersion && ConfigHandler.config.getBoolean("resyncOnVersionChange", "Meteors", true, "Should the default meteors be regenerated if the mod has updated them"))
{
if (checkNewVersion && ConfigHandler.config.getBoolean("resyncOnVersionChange", "Meteors", true, "Should the default meteors be regenerated if the mod has updated them")) {
Set<String> discoveredDefaults = Sets.newHashSet();
// Check existing defaults for new version
for (Pair<String, Meteor> meteor : meteors)
{
for (Pair<String, Meteor> meteor : meteors) {
Meteor defaultMeteor = DEFAULT_METEORS.get(meteor.getLeft());
if (defaultMeteor != null)
{
if (defaultMeteor != null) {
discoveredDefaults.add(meteor.getLeft());
if (defaultMeteor.version > meteor.getRight().version) {
writeMeteor(meteor.getLeft(), defaultMeteor);
@ -100,16 +90,14 @@ public class MeteorConfigHandler
// Finally, register all of our meteors
for (Pair<String, Meteor> meteor : meteors)
MeteorRegistry.registerMeteor(meteor.getRight().getCatalystStack(), meteor.getRight());
} catch (Exception e)
{
} catch (Exception e) {
e.printStackTrace();
}
ConfigHandler.config.save();
}
private static List<Pair<String, Meteor>> getDefaultMeteors()
{
private static List<Pair<String, Meteor>> getDefaultMeteors() {
List<Pair<String, Meteor>> holders = Lists.newArrayList();
// Iron

View file

@ -1,51 +1,43 @@
package WayofTime.bloodmagic.meteor;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import WayofTime.bloodmagic.api.ItemStackWrapper;
public class MeteorRegistry
{
public class MeteorRegistry {
public static Map<ItemStackWrapper, Meteor> meteorMap = new HashMap<ItemStackWrapper, Meteor>();
public static void registerMeteor(ItemStack stack, Meteor holder)
{
public static void registerMeteor(ItemStack stack, Meteor holder) {
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
if (wrapper != null)
{
if (wrapper != null) {
meteorMap.put(wrapper, holder);
}
}
public static void registerMeteor(ItemStack stack, List<MeteorComponent> componentList, float explosionStrength, int radius)
{
public static void registerMeteor(ItemStack stack, List<MeteorComponent> componentList, float explosionStrength, int radius) {
Meteor holder = new Meteor(stack, componentList, explosionStrength, radius);
registerMeteor(stack, holder);
}
public static boolean hasMeteorForItem(ItemStack stack)
{
public static boolean hasMeteorForItem(ItemStack stack) {
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
return wrapper != null && meteorMap.containsKey(wrapper);
}
public static Meteor getMeteorForItem(ItemStack stack)
{
public static Meteor getMeteorForItem(ItemStack stack) {
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
return wrapper != null ? meteorMap.get(wrapper) : null;
}
public static void generateMeteorForItem(ItemStack stack, World world, BlockPos pos, IBlockState fillerBlock, double radiusModifier, double explosionModifier, double fillerChance)
{
public static void generateMeteorForItem(ItemStack stack, World world, BlockPos pos, IBlockState fillerBlock, double radiusModifier, double explosionModifier, double fillerChance) {
Meteor holder = getMeteorForItem(stack);
if (holder != null)
{
if (holder != null) {
holder.generateMeteor(world, pos, fillerBlock, radiusModifier, explosionModifier, fillerChance);
}
}