Merge branch 'master-MC1.10.2' of https://github.com/ForestryMC/Binnie into master-MC1.10.2

This commit is contained in:
marcin212 committed 2016-10-24 21:35:41 +02:00
commit 9d5144ddea
36 files changed
+269 -102

No files matched your search

@@ -2,9 +2,14 @@ package binnie.botany.gardening;
import binnie.botany.Botany;
import binnie.botany.CreativeTabBotany;
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.BlockBush;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
@@ -20,23 +25,39 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class BlockPlant extends BlockBush {
public class BlockPlant extends BlockBush implements IItemModelRegister {
public static final PropertyEnum<Type> PLANT_TYPE = PropertyEnum.create("plant_type", Type.class);
// @Override
// @SideOnly(Side.CLIENT)
// public void registerBlockIcons(final IIconRegister p_149651_1_) {
// for (final Type t : Type.values()) {
// t.icon = Botany.proxy.getIcon(p_149651_1_, t.name().toLowerCase());
// }
// }
public BlockPlant() {
this.setRegistryName("plant");
this.setCreativeTab(CreativeTabBotany.instance);
this.setTickRandomly(true);
}
@Override
public void registerModel(Item item, IModelManager manager) {
int index = 0;
for (Type type : Type.values()) {
manager.registerItemModel(item, index, type.getName());
index++;
}
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, PLANT_TYPE);
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(PLANT_TYPE).ordinal();
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(PLANT_TYPE, Type.values()[meta]);
}
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
return new ArrayList<>();
@@ -46,23 +67,17 @@ public class BlockPlant extends BlockBush {
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
return super.canPlaceBlockAt(worldIn, pos) || Gardening.isSoil(worldIn.getBlockState(pos).getBlock());
}
// @Override
// @SideOnly(Side.CLIENT)
// public IIcon getIcon(final int side, final int meta) {
// return Type.values()[meta % Type.values().length].icon;
// }
// @Override
// public int damageDropped(final int p_149692_1_) {
// return p_149692_1_;
// }
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(final Item p_149666_1_, final CreativeTabs p_149666_2_, final List p_149666_3_) {
public void getSubBlocks(final Item p_149666_1_, final CreativeTabs p_149666_2_, final List subBlocks) {
for (final Type type : Type.values()) {
p_149666_3_.add(type.get());
subBlocks.add(type.get());
}
}
@@ -92,16 +107,16 @@ public class BlockPlant extends BlockBush {
}
final Block below = world.getBlockState(pos.down()).getBlock();
if (Gardening.isSoil(below)) {
// final IBlockSoil soil = (IBlockSoil) below;
// if (world.rand.nextInt(3) == 0) {
// if (type == Type.Weeds || type == Type.WeedsLong || type == Type.WeedsVeryLong) {
// if (!soil.degrade(world, pos.down(), EnumSoilType.LOAM)) {
// soil.degrade(world, pos.down(), EnumSoilType.SOIL);
// }
// } else if (type == Type.DecayingFlower && !soil.fertilise(world, pos.down(), EnumSoilType.LOAM)) {
// soil.fertilise(world, pos.down(), EnumSoilType.FLOWERBED);
// }
// }
final IBlockSoil soil = (IBlockSoil) below;
if (world.rand.nextInt(3) == 0) {
if (type == Type.Weeds || type == Type.WeedsLong || type == Type.WeedsVeryLong) {
if (!soil.degrade(world, pos.down(), EnumSoilType.LOAM)) {
soil.degrade(world, pos.down(), EnumSoilType.SOIL);
}
} else if (type == Type.DecayingFlower && !soil.fertilise(world, pos.down(), EnumSoilType.LOAM)) {
soil.fertilise(world, pos.down(), EnumSoilType.FLOWERBED);
}
}
}
}
@@ -117,15 +132,19 @@ public class BlockPlant extends BlockBush {
final Type type = world.getBlockState(pos).getValue(PLANT_TYPE);
return type == Type.Weeds || type == Type.WeedsLong || type == Type.WeedsVeryLong;
}
@Override
public EnumOffsetType getOffsetType() {
return EnumOffsetType.XZ;
}
public enum Type implements IStringSerializable {
Weeds("Weeds"),
WeedsLong("Long Weeds"),
WeedsVeryLong("Very Long Weeds"),
DeadFlower("Dead Flower"),
DecayingFlower("Decaying Flower");
Weeds("weeds"),
WeedsLong("weeds_long"),
WeedsVeryLong("weeds_very_long"),
DeadFlower("dead_flower"),
DecayingFlower("decaying_flower");
// public IIcon icon;
String name;
Type(final String name) {
@@ -142,7 +161,7 @@ public class BlockPlant extends BlockBush {
@Override
public String getName() {
return this.name;
return name;
}
}
}
@@ -22,6 +22,7 @@ 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.util.text.TextFormatting;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
@@ -212,12 +213,24 @@ public class BlockSoil extends Block implements IBlockSoil, IItemModelRegister {
}
}
public static String getPH(ItemStack stack, boolean withColor) {
return EnumAcidity.values()[stack.getItemDamage() / 3].getTranslated(withColor);
public static String getPH(ItemStack stack, boolean withColor, boolean byNeutralNone) {
EnumAcidity ph = EnumAcidity.values()[stack.getItemDamage() / 3];
if(byNeutralNone){
if(ph == EnumAcidity.Neutral){
return "";
}
}
return TextFormatting.GRAY + Binnie.Language.localise("botany.ph") + ": " + ph.getTranslated(withColor);
}
public static String getMoisture(ItemStack stack, boolean withColor) {
return EnumMoisture.values()[stack.getItemDamage() % 3].getTranslated(withColor);
public static String getMoisture(ItemStack stack, boolean withColor, boolean byNormalNone) {
EnumMoisture moisure = EnumMoisture.values()[stack.getItemDamage() % 3];
if(byNormalNone){
if(moisure == EnumMoisture.Normal){
return "";
}
}
return TextFormatting.GRAY + Binnie.Language.localise("botany.moisture") + ": " + moisure.getTranslated(withColor);
}
@Override
@@ -27,10 +27,10 @@ import java.util.LinkedHashMap;
import java.util.Map;
public class Gardening {
public static Map<ItemStack, Integer> fertiliserAcid = new LinkedHashMap<>();
public static Map<ItemStack, Integer> fertiliserAlkaline = new LinkedHashMap<>();
public static Map<ItemStack, Integer> fertiliserNutrient = new LinkedHashMap<>();
public static final Map<ItemStack, Integer> fertiliserAcid = new LinkedHashMap<>();
public static final Map<ItemStack, Integer> fertiliserAlkaline = new LinkedHashMap<>();
public static final Map<ItemStack, Integer> fertiliserNutrient = new LinkedHashMap<>();
public static boolean isSoil(final Block block) {
return block instanceof IBlockSoil;
}
@@ -90,7 +90,7 @@ public class Gardening {
return (float) (-3.0 * (R - 0.5) + 0.5 * (T - 0.699999988079071) * (T - 0.699999988079071) + 0.02f * (H - 64) - 0.15000000596046448);
}
public static void createSoil(final World world, final BlockPos pos, final EnumSoilType soil, final EnumMoisture moisture, final EnumAcidity acidity) {
public static void plantSoil(final World world, final BlockPos pos, final EnumSoilType soil, final EnumMoisture moisture, final EnumAcidity acidity) {
final int meta = moisture.ordinal() + acidity.ordinal() * 3;
world.setBlockState(pos, getSoilBlock(soil).getStateFromMeta(meta), 2);
}
@@ -254,5 +254,4 @@ public class Gardening {
}
return done;
}
}
@@ -1,11 +1,7 @@
package binnie.botany.gardening;
import binnie.Binnie;
import binnie.botany.api.EnumAcidity;
import binnie.botany.api.EnumMoisture;
import binnie.botany.api.EnumSoilType;
import forestry.core.utils.Translator;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
@@ -30,11 +26,11 @@ public class ItemSoil extends ItemBlock {
@SideOnly(Side.CLIENT)
public void addInformation(final ItemStack stack, final EntityPlayer playerIn, final List tooltip, final boolean advanced) {
String info = "";
info+=BlockSoil.getMoisture(stack, true);
info+=BlockSoil.getMoisture(stack, true, true);
if (info.length() > 0) {
info += ", ";
}
info+=BlockSoil.getPH(stack, true);
info+=BlockSoil.getPH(stack, true, true);
if (info.length() > 0) {
tooltip.add(info);
}
@@ -1,15 +1,36 @@
package binnie.botany.gardening;
import binnie.Constants;
import binnie.botany.Botany;
import binnie.botany.CreativeTabBotany;
import binnie.botany.api.EnumAcidity;
import binnie.botany.api.EnumMoisture;
import binnie.botany.api.EnumSoilType;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.IModelManager;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemTrowel extends Item {
protected Item.ToolMaterial theToolMaterial;
String locName;
public class ItemTrowel extends Item implements IItemModelRegister {
protected final ToolMaterial theToolMaterial;
protected final String locName;
public ItemTrowel(final Item.ToolMaterial p_i45343_1_, final String material) {
public ItemTrowel(ToolMaterial p_i45343_1_, final String material) {
this.theToolMaterial = p_i45343_1_;
this.maxStackSize = 1;
this.setMaxDamage(p_i45343_1_.getMaxUses());
@@ -18,34 +39,35 @@ public class ItemTrowel extends Item {
this.locName = "trowel" + material;
setRegistryName("trowel" + material);
}
// @Override
// @SideOnly(Side.CLIENT)
// public void registerIcons(final IIconRegister p_94581_1_) {
// this.itemIcon = Botany.proxy.getIcon(p_94581_1_, "tools/" + this.locName);
// }
//
// @Override
// public boolean onItemUse(final ItemStack stack, final EntityPlayer player, final World world, final int x, final int y, final int z, final int p_77648_7_, final float p_77648_8_, final float p_77648_9_, final float p_77648_10_) {
// if (!player.canPlayerEdit(x, y, z, p_77648_7_, stack)) {
// return false;
// }
// final Block block = world.getBlock(x, y, z);
// if (p_77648_7_ == 0 || (!world.getBlock(x, y + 1, z).isAir(world, x, y + 1, z) && world.getBlock(x, y + 1, z) != Botany.flower) || (block != Blocks.grass && block != Blocks.dirt)) {
// return false;
// }
// final Block block2 = Botany.soil;
// world.playSoundEffect(x + 0.5f, y + 0.5f, z + 0.5f, block2.stepSound.getStepResourcePath(), (block2.stepSound.getVolume() + 1.0f) / 2.0f, block2.stepSound.getPitch() * 0.8f);
// if (world.isRemote) {
// return true;
// }
// final EnumMoisture moisture = Gardening.getNaturalMoisture(world, x, y, z);
// final EnumAcidity acidity = Gardening.getNaturalPH(world, x, y, z);
// Gardening.createSoil(world, x, y, z, EnumSoilType.SOIL, moisture, acidity);
// stack.damageItem(1, player);
// return true;
// }
@SideOnly(Side.CLIENT)
@Override
public void registerModel(Item item, IModelManager manager) {
manager.registerItemModel(item, new ItemTrowelMeshDefinition());
ModelBakery.registerItemVariants(item, new ResourceLocation(Constants.BOTANY_MOD_ID + ":tools/"+ locName));
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!player.canPlayerEdit(pos, facing, stack)) {
return EnumActionResult.FAIL;
}
Block block = world.getBlockState(pos).getBlock();
if (facing == EnumFacing.DOWN || (!world.isAirBlock(pos.up()) && world.getBlockState(pos.up()).getBlock() != Botany.flower) || (block != Blocks.GRASS && block != Blocks.DIRT)) {
return EnumActionResult.PASS;
}
Block block2 = Botany.soil;
world.playSound(player, hitX + 0.5f, hitY + 0.5f, hitZ + 0.5f, block2.getSoundType().getStepSound(), SoundCategory.NEUTRAL, (block2.getSoundType().getVolume() + 1.0f) / 2.0f, block2.getSoundType().getPitch() * 0.8f);
if (world.isRemote) {
return EnumActionResult.SUCCESS;
}
EnumMoisture moisture = Gardening.getNaturalMoisture(world, pos);
EnumAcidity acidity = Gardening.getNaturalPH(world, pos);
Gardening.plantSoil(world, pos, EnumSoilType.SOIL, moisture, acidity);
stack.damageItem(1, player);
return EnumActionResult.SUCCESS;
}
@Override
@SideOnly(Side.CLIENT)
public boolean isFull3D() {
@@ -55,4 +77,12 @@ public class ItemTrowel extends Item {
public String getToolMaterialName() {
return this.theToolMaterial.toString();
}
@SideOnly(Side.CLIENT)
private class ItemTrowelMeshDefinition implements ItemMeshDefinition{
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(Constants.BOTANY_MOD_ID + ":tools/"+ locName, "inventory");
}
}
}
@@ -1,29 +1,25 @@
package binnie.botany.gardening;
import binnie.Binnie;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class ItemWeed extends ItemBlock {
public ItemWeed(final Block p_i45328_1_) {
super(p_i45328_1_);
public ItemWeed(Block block) {
super(block);
this.setHasSubtypes(true);
this.hasSubtypes = true;
}
@Override
public String getItemStackDisplayName(final ItemStack stack) {
return BlockPlant.Type.values()[stack.getItemDamage()].getName();
return Binnie.Language.localise("botany.plant." + BlockPlant.Type.values()[stack.getItemDamage()].getName());
}
@Override
public int getMetadata(final int p_77647_1_) {
return p_77647_1_;
public int getMetadata(int damage) {
return damage;
}
// @Override
// @SideOnly(Side.CLIENT)
// public IIcon getIconFromDamage(final int p_77617_1_) {
// return this.field_150939_a.getIcon(2, p_77617_1_);
// }
}
@@ -1,7 +1,6 @@
package binnie.core.mod.parser;
import binnie.core.AbstractMod;
import binnie.core.BinnieCore;
import net.minecraft.item.Item;
import java.lang.reflect.Field;
@@ -15,7 +14,7 @@ public class ItemParser extends FieldParser {
public void preInit(final Field field, final AbstractMod mod) throws IllegalArgumentException, IllegalAccessException {
final Item item = (Item) field.get(null);
if (item != null) {
BinnieCore.proxy.registerItem(item);
mod.getProxy().registerItem(item);
}
}
}
@@ -20,11 +20,13 @@ public class BinnieModProxy implements IBinnieModProxy {
this.mod = mod;
}
public Item registerItem(Item item){
@Override
public Item registerItem(Item item){
return GameRegistry.register(item);
}
public Block registerBlock(Block block){
@Override
public Block registerBlock(Block block){
return GameRegistry.register(block);
}
@@ -1,6 +1,12 @@
package binnie.core.proxy;
import binnie.core.IInitializable;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
public interface IProxyCore extends IInitializable {
Item registerItem(Item item);
Block registerBlock(Block block);
}