diff options
Diffstat (limited to 'src/main/java/com/sosnitzka/taiga/util')
5 files changed, 324 insertions, 0 deletions
diff --git a/src/main/java/com/sosnitzka/taiga/util/EntityAIPermanentPanic.java b/src/main/java/com/sosnitzka/taiga/util/EntityAIPermanentPanic.java new file mode 100644 index 0000000..4b4e96b --- /dev/null +++ b/src/main/java/com/sosnitzka/taiga/util/EntityAIPermanentPanic.java @@ -0,0 +1,99 @@ +package com.sosnitzka.taiga.util; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCreature; +import net.minecraft.entity.ai.EntityAIBase; +import net.minecraft.entity.ai.RandomPositionGenerator; +import net.minecraft.init.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class EntityAIPermanentPanic extends EntityAIBase { + private EntityCreature theEntityCreature; + protected double speed; + private double randPosX; + private double randPosY; + private double randPosZ; + + public EntityAIPermanentPanic(EntityCreature creature, double speedIn) { + this.theEntityCreature = creature; + this.speed = speedIn; + } + + /** + * Returns whether the EntityAIBase should begin execution. + */ + public boolean shouldExecute() { + + Vec3d vec3d = RandomPositionGenerator.findRandomTarget(this.theEntityCreature, 5, 4); + + if (vec3d == null) { + return false; + } else { + this.randPosX = vec3d.xCoord; + this.randPosY = vec3d.yCoord; + this.randPosZ = vec3d.zCoord; + + if (this.theEntityCreature.isBurning()) { + BlockPos blockpos = this.getRandPos(this.theEntityCreature.worldObj, this.theEntityCreature, 5, 4); + + if (blockpos != null) { + this.randPosX = (double) blockpos.getX(); + this.randPosY = (double) blockpos.getY(); + this.randPosZ = (double) blockpos.getZ(); + } + } + + return true; + } + + } + + /** + * Execute a one shot task or start executing a continuous task + */ + public void startExecuting() { + this.theEntityCreature.getNavigator().tryMoveToXYZ(this.randPosX, this.randPosY, this.randPosZ, this.speed); + } + + /** + * Returns whether an in-progress EntityAIBase should continue executing + */ + public boolean continueExecuting() { + return !this.theEntityCreature.getNavigator().noPath(); + } + + private BlockPos getRandPos(World worldIn, Entity entityIn, int horizontalRange, int verticalRange) { + BlockPos blockpos = new BlockPos(entityIn); + BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); + int i = blockpos.getX(); + int j = blockpos.getY(); + int k = blockpos.getZ(); + float f = (float) (horizontalRange * horizontalRange * verticalRange * 2); + BlockPos blockpos1 = null; + + for (int l = i - horizontalRange; l <= i + horizontalRange; ++l) { + for (int i1 = j - verticalRange; i1 <= j + verticalRange; ++i1) { + for (int j1 = k - horizontalRange; j1 <= k + horizontalRange; ++j1) { + blockpos$mutableblockpos.setPos(l, i1, j1); + IBlockState iblockstate = worldIn.getBlockState(blockpos$mutableblockpos); + Block block = iblockstate.getBlock(); + + if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) { + float f1 = (float) ((l - i) * (l - i) + (i1 - j) * (i1 - j) + (j1 - k) * (j1 - k)); + + if (f1 < f) { + f = f1; + blockpos1 = new BlockPos(blockpos$mutableblockpos); + } + } + } + } + } + + return blockpos1; + } +}
\ No newline at end of file diff --git a/src/main/java/com/sosnitzka/taiga/util/FuelHandler.java b/src/main/java/com/sosnitzka/taiga/util/FuelHandler.java new file mode 100644 index 0000000..ee655e5 --- /dev/null +++ b/src/main/java/com/sosnitzka/taiga/util/FuelHandler.java @@ -0,0 +1,27 @@ +package com.sosnitzka.taiga.util; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.IFuelHandler; +import org.apache.commons.lang3.RandomUtils; + +import static com.sosnitzka.taiga.Items.fuel_brick; +import static com.sosnitzka.taiga.Items.glimmercoal; +import static com.sosnitzka.taiga.Items.lignite; + +public class FuelHandler implements IFuelHandler { + + @Override + public int getBurnTime(ItemStack fuel) { + if (fuel.getItem().equals(lignite)) { + return 200 * 2; + } + if (fuel.getItem().equals(fuel_brick)) { + return RandomUtils.nextInt(1, RandomUtils.nextInt(1, RandomUtils.nextInt(1, 32))) * 100; + } + if (fuel.getItem().equals(glimmercoal)) { + return RandomUtils.nextInt(1, RandomUtils.nextInt(1, RandomUtils.nextInt(16, 64))) * 200; + } + return 0; + } + +} diff --git a/src/main/java/com/sosnitzka/taiga/util/Generator.java b/src/main/java/com/sosnitzka/taiga/util/Generator.java new file mode 100644 index 0000000..e7aed53 --- /dev/null +++ b/src/main/java/com/sosnitzka/taiga/util/Generator.java @@ -0,0 +1,41 @@ +package com.sosnitzka.taiga.util; + +import com.sosnitzka.taiga.world.ZWorldGenMinable; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import java.util.Random; + +public class Generator { + + public static void generateOre(IBlockState state, Random random, int x, int z, World world, int chance, int minY, int maxY, int minSize, int maxSize) { + generateOre(state, Blocks.STONE.getDefaultState(), null, null, random, x, z, world, chance, minY, maxY, minSize, maxSize); + } + + public static void generateNetherOre(IBlockState state, Random random, int x, int z, World world, int chance, int minY, int maxY, int minSize, int maxSize) { + generateOre(state, Blocks.NETHERRACK.getDefaultState(), null, null, random, x, z, world, chance, minY, maxY, minSize, maxSize); + } + + public static void generateEndOre(IBlockState state, Random random, int x, int z, World world, int chance, int minY, int maxY, int minSize, int maxSize) { + generateOre(state, Blocks.END_STONE.getDefaultState(), null, null, random, x, z, world, chance, minY, maxY, minSize, maxSize); + } + + public static void generateOre(IBlockState state, IBlockState replace, Random random, int chunkX, int chunkZ, World world, int chance, int minY, int maxY, int minSize, int maxSize) { + generateOre(state, replace, null, null, random, chunkX, chunkZ, world, chance, minY, maxY, minSize, maxSize); + } + + public static void generateOre(IBlockState state, IBlockState replace, IProperty property, Comparable comparable, Random random, int chunkX, int chunkZ, World world, int chance, int minY, int maxY, int minSize, int maxSize) { + int size = minSize + random.nextInt(maxSize - minSize); + int height = maxY - minY; + + for (int i = 0; i < chance; i++) { + int posX = chunkX + random.nextInt(16); + int posY = random.nextInt(height) + minY; + int posZ = chunkZ + random.nextInt(16); + new ZWorldGenMinable(state, size, StateMatcher.forState(replace, property, comparable)).generate(world, random, new BlockPos(posX, posY, posZ)); + } + } +} diff --git a/src/main/java/com/sosnitzka/taiga/util/StateMatcher.java b/src/main/java/com/sosnitzka/taiga/util/StateMatcher.java new file mode 100644 index 0000000..a5e9c17 --- /dev/null +++ b/src/main/java/com/sosnitzka/taiga/util/StateMatcher.java @@ -0,0 +1,84 @@ +package com.sosnitzka.taiga.util; + +import com.google.common.base.Predicate; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + + +public class StateMatcher implements Predicate<IBlockState> { + private final IBlockState state; + private final IProperty property; + private final Comparable value; + + private StateMatcher(IBlockState state, IProperty property, Comparable value) { + this.state = state; + this.property = property; + this.value = value; + } + + public static StateMatcher forState(IBlockState state, IProperty property, Comparable value) { + return new StateMatcher(state, property, value); + } + + public boolean apply(IBlockState state, BlockPos pos, World world) { + if (state != null) { + if (property != null && value != null) { + if (state.getBlock() == this.state.getBlock()) + if (checkLayerForBlocks(3, 3, -1, world, pos) || + checkLayerForBlocks(3, 3, 0, world, pos) || + checkLayerForBlocks(3, 3, 1, world, pos)) + return true; + + } else + return state.getBlock() == this.state.getBlock(); + } + return false; + } + + @Override + public boolean apply(IBlockState input) { + if (state != null) { + if (property != null && value != null) { + return state.getBlock() == this.state.getBlock() && state.getValue(property) == value; + } else + return state.getBlock() == this.state.getBlock(); + } + return false; + } + + private boolean checkLayerForBlocks(int X, int Z, int Y, World world, BlockPos origin) { + int x = 0, z = 0, dx = 0, dz = -1; + int t = Math.max(X, Z); + int maxI = t * t; + + for (int i = 0; i < maxI; i++) { + if ((-X / 2 <= x) && (x <= X / 2) && (-Z / 2 <= z) && (z <= Z / 2)) { + BlockPos blockPos = new BlockPos(origin.getX() + x, origin.getY() + Y, origin.getZ() + z); + if (blockPos == origin) + continue; + + if (i % 2 == 0) + continue; + + IBlockState bState = world.getBlockState(blockPos); + if (bState.getBlock() == this.state.getBlock() && bState.getValue(property) == value) { + // Check if a replacable block is near origin block - show pos in console + // System.out.println(String.format("Found block with desired state! (%s), Block: %s, try #%s, y=%s", i, Y)); + return true; + } + } + + if ((x == z) || ((x < 0) && (x == -z)) || ((x > 0) && (x == 1 - z))) { + t = dx; + dx = -dz; + dz = t; + } + x += dx; + z += dz; + } + + return false; + } +} diff --git a/src/main/java/com/sosnitzka/taiga/util/Utils.java b/src/main/java/com/sosnitzka/taiga/util/Utils.java new file mode 100644 index 0000000..184b935 --- /dev/null +++ b/src/main/java/com/sosnitzka/taiga/util/Utils.java @@ -0,0 +1,73 @@ +package com.sosnitzka.taiga.util; + + +import net.minecraft.block.Block; +import net.minecraft.item.ItemBlock; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fml.common.event.FMLInterModComms; +import net.minecraftforge.fml.common.registry.GameRegistry; + +public class Utils { + public static String PREFIX_INGOT = "ingot"; + public static String PREFIX_NUGGET = "nugget"; + public static String PREFIX_ORE = "ore"; + public static String PREFIX_BLOCK = "block"; + + + public static void registerBlockWithItem(Block block) { + GameRegistry.register(block); + GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName())); + } + + public static void registerFluid(Fluid fluid) { + FluidRegistry.registerFluid(fluid); + FluidRegistry.addBucketForFluid(fluid); + } + + public static void registerTinkerAlloys(Fluid alloy, int out, Fluid first, int inOne, Fluid second, int inTwo) { + NBTTagList tagList = new NBTTagList(); + NBTTagCompound fluid = new NBTTagCompound(); + fluid.setString("FluidName", alloy.getName()); + fluid.setInteger("Amount", out); + tagList.appendTag(fluid); + fluid = new NBTTagCompound(); + fluid.setString("FluidName", first.getName()); + fluid.setInteger("Amount", inOne); + tagList.appendTag(fluid); + fluid = new NBTTagCompound(); + fluid.setString("FluidName", second.getName()); + fluid.setInteger("Amount", inTwo); + tagList.appendTag(fluid); + + NBTTagCompound message = new NBTTagCompound(); + message.setTag("alloy", tagList); + FMLInterModComms.sendMessage("tconstruct", "alloy", message); + } + + public static void registerTinkerAlloys(Fluid alloy, int out, Fluid first, int inOne, Fluid second, int inTwo, Fluid third, int inThree) { + NBTTagList tagList = new NBTTagList(); + NBTTagCompound fluid = new NBTTagCompound(); + fluid.setString("FluidName", alloy.getName()); + fluid.setInteger("Amount", out); + tagList.appendTag(fluid); + fluid = new NBTTagCompound(); + fluid.setString("FluidName", first.getName()); + fluid.setInteger("Amount", inOne); + tagList.appendTag(fluid); + fluid = new NBTTagCompound(); + fluid.setString("FluidName", second.getName()); + fluid.setInteger("Amount", inTwo); + tagList.appendTag(fluid); + fluid = new NBTTagCompound(); + fluid.setString("FluidName", third.getName()); + fluid.setInteger("Amount", inThree); + tagList.appendTag(fluid); + + NBTTagCompound message = new NBTTagCompound(); + message.setTag("alloy", tagList); + FMLInterModComms.sendMessage("tconstruct", "alloy", message); + } +} |
