changed things a lot

This commit is contained in:
2016-05-13 15:13:55 +02:00
parent 25f1261dc6
commit 4ed981fcb1
33 changed files with 662 additions and 659 deletions

View File

@@ -0,0 +1,23 @@
package com.sosnitzka.ztic_addon.util;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.IFuelHandler;
import org.apache.commons.lang3.RandomUtils;
import static com.sosnitzka.ztic_addon.Items.fuel_brick;
import static com.sosnitzka.ztic_addon.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, 64))) * 200;
}
return 0;
}
}

View File

@@ -0,0 +1,41 @@
package com.sosnitzka.ztic_addon.util;
import com.sosnitzka.ztic_addon.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));
}
}
}

View File

@@ -0,0 +1,84 @@
package com.sosnitzka.ztic_addon.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;
}
}

View File

@@ -0,0 +1,54 @@
package com.sosnitzka.ztic_addon.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 void registerBlockWithItem(Block block) {
GameRegistry.register(block);
GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
}
public static void registerTinkerFluid(String oreDictSuffix, Fluid fluid, boolean toolForge) {
registerFluid(fluid);
NBTTagCompound tag = new NBTTagCompound();
tag.setString("fluid", fluid.getName());
tag.setString("ore", oreDictSuffix);
tag.setBoolean("toolforge", toolForge);
FMLInterModComms.sendMessage("tconstruct", "integrateSmeltery", tag);
}
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);
}
}