mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-25 14:34:33 +00:00
Update Soil and add Soil Models
This commit is contained in:
1 parent
0caaa095a2
commit
2ed7e79478
126 files changed
+900
-224
No files matched your search
@@ -1,11 +1,14 @@
|
||||
package binnie.botany.gardening;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.botany.Botany;
|
||||
import binnie.botany.CreativeTabBotany;
|
||||
import binnie.botany.api.EnumAcidity;
|
||||
import binnie.botany.api.EnumMoisture;
|
||||
import binnie.botany.api.EnumSoilType;
|
||||
import binnie.botany.api.gardening.IBlockSoil;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -17,23 +20,53 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockSoil extends Block implements IBlockSoil {
|
||||
boolean weedKilled;
|
||||
// IIcon[] iconsTop;
|
||||
// IIcon[] iconsSide;
|
||||
// IIcon[] iconsNoWeed;
|
||||
EnumSoilType type;
|
||||
public class BlockSoil extends Block implements IBlockSoil, IItemModelRegister {
|
||||
|
||||
private final boolean weedKilled;
|
||||
private final EnumSoilType type;
|
||||
|
||||
public static final PropertyEnum<EnumMoisture> MOISTURE = PropertyEnum.create("moisture", EnumMoisture.class);
|
||||
public static final PropertyEnum<EnumAcidity> ACIDITY = PropertyEnum.create("acidity", EnumAcidity.class);
|
||||
public static final AxisAlignedBB SOIL_BLOCK_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.9375D, 1.0D);
|
||||
|
||||
public BlockSoil(EnumSoilType type, String blockName, boolean weedKilled) {
|
||||
super(Material.GROUND);
|
||||
this.weedKilled = weedKilled;
|
||||
this.setCreativeTab(CreativeTabBotany.instance);
|
||||
this.setRegistryName(blockName);
|
||||
this.setTickRandomly(true);
|
||||
this.setLightOpacity(255);
|
||||
this.setHardness(0.5f);
|
||||
this.setSoundType(SoundType.GROUND);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
|
||||
return SOIL_BLOCK_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) {
|
||||
return SOIL_BLOCK_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos) {
|
||||
return SOIL_BLOCK_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubBlocks(final Item par1, final CreativeTabs par2CreativeTabs, final List par3List) {
|
||||
@@ -41,6 +74,32 @@ public class BlockSoil extends Block implements IBlockSoil {
|
||||
par3List.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
int index = 0;
|
||||
for(EnumMoisture moisture : EnumMoisture.values()){
|
||||
for(EnumAcidity acidity : EnumAcidity.values()){
|
||||
String modelName = "";
|
||||
if(acidity != EnumAcidity.Neutral){
|
||||
modelName +=acidity.getName();
|
||||
}
|
||||
if(moisture != EnumMoisture.Normal){
|
||||
if(!modelName.isEmpty()){
|
||||
modelName += "_";
|
||||
}
|
||||
modelName +=moisture.getName();
|
||||
}
|
||||
if(modelName.isEmpty()){
|
||||
modelName = "normal";
|
||||
}
|
||||
manager.registerItemModel(item, index, type.getName() + (weedKilled ? "NoWeed" : "") + "/" + modelName);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
@@ -59,103 +118,49 @@ public class BlockSoil extends Block implements IBlockSoil {
|
||||
return getDefaultState().withProperty(MOISTURE, moisture).withProperty(ACIDITY, acidity);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public IIcon getIcon(final IBlockAccess world, final int x, final int y, final int z, final int side) {
|
||||
// return this.getIcon(side, world.getBlockMetadata(x, y, z));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public IIcon getIcon(final int side, int meta) {
|
||||
// meta = ((meta >= 9) ? 8 : meta);
|
||||
// final EnumMoisture moisture = EnumMoisture.values()[meta % 3];
|
||||
// final EnumAcidity acidity = EnumAcidity.values()[meta / 3];
|
||||
// return (side == 1) ? (this.weedKilled ? this.iconsNoWeed[meta] : this.iconsTop[meta]) : ((side == 0) ? Blocks.dirt.getIcon(side, 0) : this.iconsSide[meta]);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public void registerBlockIcons(final IIconRegister register) {
|
||||
// for (final EnumMoisture moisture : EnumMoisture.values()) {
|
||||
// for (final EnumAcidity pH : EnumAcidity.values()) {
|
||||
// this.iconsTop[moisture.ordinal() + pH.ordinal() * 3] = Botany.proxy.getIcon(register, "soil/" + this.getType().getID() + "." + pH.getID() + "." + moisture.getID() + ".0");
|
||||
// this.iconsSide[moisture.ordinal() + pH.ordinal() * 3] = Botany.proxy.getIcon(register, "soil/" + this.getType().getID() + "." + pH.getID() + "." + moisture.getID() + ".1");
|
||||
// this.iconsNoWeed[moisture.ordinal() + pH.ordinal() * 3] = Botany.proxy.getIcon(register, "soil/" + this.getType().getID() + "." + pH.getID() + "." + moisture.getID() + ".2");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public EnumSoilType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public BlockSoil(final EnumSoilType type, final String blockName, final boolean weedKilled) {
|
||||
super(Material.GROUND);
|
||||
this.weedKilled = false;
|
||||
// this.iconsTop = new IIcon[9];
|
||||
// this.iconsSide = new IIcon[9];
|
||||
// this.iconsNoWeed = new IIcon[9];
|
||||
this.weedKilled = weedKilled;
|
||||
this.setCreativeTab(CreativeTabBotany.instance);
|
||||
this.setRegistryName(blockName);
|
||||
this.setTickRandomly(true);
|
||||
//this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.9375f, 1.0f);
|
||||
this.setLightOpacity(255);
|
||||
this.setHardness(0.5f);
|
||||
this.setSoundType(SoundType.GROUND);
|
||||
this.type = type;
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public int damageDropped(final int p_149692_1_) {
|
||||
// return p_149692_1_;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void updateTick(final World world, final int x, final int y, final int z, final Random random) {
|
||||
// final int meta = world.getBlockMetadata(x, y, z);
|
||||
// EnumMoisture moisture = EnumMoisture.values()[meta % 3];
|
||||
// final EnumAcidity acidity = EnumAcidity.values()[meta / 3];
|
||||
// final EnumMoisture desiredMoisture = Gardening.getNaturalMoisture(world, x, y, z);
|
||||
// if (desiredMoisture.ordinal() > moisture.ordinal()) {
|
||||
// moisture = ((moisture == EnumMoisture.Dry) ? EnumMoisture.Normal : EnumMoisture.Damp);
|
||||
// }
|
||||
// if (desiredMoisture.ordinal() < moisture.ordinal()) {
|
||||
// moisture = ((moisture == EnumMoisture.Damp) ? EnumMoisture.Normal : EnumMoisture.Dry);
|
||||
// }
|
||||
// final int meta2 = getMeta(acidity, moisture);
|
||||
// if (meta != meta2) {
|
||||
// world.setBlockMetadataWithNotify(x, y, z, meta2, 2);
|
||||
// }
|
||||
// if (!this.weedKilled && random.nextInt(5 - this.getType(world, x, y, z).ordinal()) == 0 && world.getBlock(x, y + 1, z) == Blocks.air) {
|
||||
// world.setBlock(x, y + 1, z, Botany.plant, BlockPlant.Type.Weeds.ordinal(), 2);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public AxisAlignedBB getCollisionBoundingBoxFromPool(final World p_149668_1_, final int p_149668_2_, final int p_149668_3_, final int p_149668_4_) {
|
||||
// return AxisAlignedBB.getBoundingBox(p_149668_2_ + 0, p_149668_3_ + 0, p_149668_4_ + 0, p_149668_2_ + 1, p_149668_3_ + 1, p_149668_4_ + 1);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isOpaqueCube() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean renderAsNormalBlock() {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
int meta = getMetaFromState(state);
|
||||
EnumMoisture moisture = EnumMoisture.values()[meta % 3];
|
||||
EnumAcidity acidity = EnumAcidity.values()[meta / 3];
|
||||
EnumMoisture desiredMoisture = Gardening.getNaturalMoisture(world, pos);
|
||||
if (desiredMoisture.ordinal() > moisture.ordinal()) {
|
||||
moisture = ((moisture == EnumMoisture.Dry) ? EnumMoisture.Normal : EnumMoisture.Damp);
|
||||
}
|
||||
if (desiredMoisture.ordinal() < moisture.ordinal()) {
|
||||
moisture = ((moisture == EnumMoisture.Damp) ? EnumMoisture.Normal : EnumMoisture.Dry);
|
||||
}
|
||||
int meta2 = getMeta(acidity, moisture);
|
||||
if (meta != meta2) {
|
||||
world.setBlockState(pos, getStateFromMeta(meta2), 2);
|
||||
}
|
||||
if (!this.weedKilled && rand.nextInt(5 - getType(world, pos).ordinal()) == 0 && world.getBlockState(pos.up()).getBlock() == Blocks.AIR) {
|
||||
world.setBlockState(pos.up(), Botany.plant.getStateFromMeta(BlockPlant.Type.Weeds.ordinal()), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAcidity getPH(final World world, final BlockPos pos) {
|
||||
return world.getBlockState(pos).getValue(ACIDITY); //EnumAcidity.values()[world.getBlockMetadata(x, y, z) / 3];
|
||||
return world.getBlockState(pos).getValue(ACIDITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumMoisture getMoisture(final World world, final BlockPos pos) {
|
||||
return world.getBlockState(pos).getValue(MOISTURE); //EnumMoisture.values()[world.getBlockMetadata(x, y, z) % 3];
|
||||
return world.getBlockState(pos).getValue(MOISTURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,14 +190,14 @@ public class BlockSoil extends Block implements IBlockSoil {
|
||||
|
||||
@Override
|
||||
public boolean setPH(final World world, final BlockPos pos, final EnumAcidity pH) {
|
||||
//final int meta = getMeta(pH, this.getMoisture(world, pos));
|
||||
return world.setBlockState(pos, world.getBlockState(pos).withProperty(ACIDITY, pH));//world.setBlockMetadataWithNotify(x, y, z, meta, 2);
|
||||
final int meta = getMeta(pH, this.getMoisture(world, pos));
|
||||
return world.setBlockState(pos, world.getBlockState(pos).withProperty(ACIDITY, pH));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMoisture(final World world, final BlockPos pos, final EnumMoisture moisture) {
|
||||
//final int meta = getMeta(this.getPH(world, x, y, z), moisture);
|
||||
return world.setBlockState(pos, world.getBlockState(pos).withProperty(MOISTURE, moisture));//return world.setBlockMetadataWithNotify(x, y, z, meta, 2);
|
||||
final int meta = getMeta(this.getPH(world, pos), moisture);
|
||||
return world.setBlockState(pos, world.getBlockState(pos).withProperty(MOISTURE, moisture));
|
||||
}
|
||||
|
||||
public static int getMeta(final EnumAcidity acid, final EnumMoisture moisture) {
|
||||
@@ -207,28 +212,32 @@ public class BlockSoil extends Block implements IBlockSoil {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPH(final ItemStack stack) {
|
||||
return Binnie.Language.localise(EnumAcidity.values()[stack.getItemDamage() / 3]);
|
||||
public static String getPH(ItemStack stack, boolean withColor) {
|
||||
return EnumAcidity.values()[stack.getItemDamage() / 3].getTranslated(withColor);
|
||||
}
|
||||
|
||||
public static String getMoisture(final ItemStack stack) {
|
||||
return Binnie.Language.localise(EnumMoisture.values()[stack.getItemDamage() % 3]);
|
||||
public static String getMoisture(ItemStack stack, boolean withColor) {
|
||||
return EnumMoisture.values()[stack.getItemDamage() % 3].getTranslated(withColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable) {
|
||||
IBlockState plant = plantable.getPlant(world, pos.up());
|
||||
if (plant.getBlock() == Botany.flower) {
|
||||
return true;
|
||||
}
|
||||
if (plant.getBlock() == Botany.plant) {
|
||||
return !this.weedKilled || !BlockPlant.isWeed(world, pos);
|
||||
}
|
||||
return world instanceof World && Blocks.DIRT.canSustainPlant(state, world, pos, direction, plantable);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean canSustainPlant(final IBlockAccess world, final BlockPos pos, final EnumFacing direction, final IPlantable plantable) {
|
||||
// final Block plant = plantable.getPlant(world, x, y + 1, z);
|
||||
// if (plant == Botany.flower) {
|
||||
// return true;
|
||||
// }
|
||||
// if (plant == Botany.plant) {
|
||||
// return !this.weedKilled || !BlockPlant.isWeed(world, x, y, z);
|
||||
// }
|
||||
// return world instanceof World && Blocks.dirt.canSustainPlant(world, x, y, z, direction, plantable);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean resistsWeeds(final World world, final BlockPos pos) {
|
||||
return this.weedKilled;
|
||||
}
|
||||
|
||||
public boolean isWeedKilled() {
|
||||
return weedKilled;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user