mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-18 19:39:37 +00:00
Update forestry version
This commit is contained in:
1 parent
04706d12c8
commit
7a8dfc3012
4 files changed
+267
-31
No files matched your search
@@ -0,0 +1,204 @@
|
||||
package binnie.extratrees.block;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
import forestry.api.arboriculture.IFruitProvider;
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.arboriculture.ITreeGenome;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.arboriculture.blocks.BlockAbstractLeaves;
|
||||
|
||||
import binnie.Constants;
|
||||
import binnie.extratrees.block.property.PropertyETType;
|
||||
import binnie.extratrees.genetics.ETTreeDefinition;
|
||||
|
||||
/**
|
||||
* Genetic leaves with no tile entity, used for worldgen trees.
|
||||
* Similar to decorative leaves, but these will drop saplings and can be used for pollination.
|
||||
*/
|
||||
public abstract class BlockETDefaultLeaves extends BlockAbstractLeaves {
|
||||
private static final int VARIANTS_PER_BLOCK = 4;
|
||||
|
||||
public static List<BlockETDefaultLeaves> create() {
|
||||
List<BlockETDefaultLeaves> blocks = new ArrayList<>();
|
||||
final int blockCount = PropertyETType.getBlockCount(VARIANTS_PER_BLOCK);
|
||||
for (int blockNumber = 0; blockNumber < blockCount; blockNumber++) {
|
||||
final PropertyETType variant = PropertyETType.create("variant", blockNumber, VARIANTS_PER_BLOCK);
|
||||
BlockETDefaultLeaves block = new BlockETDefaultLeaves(blockNumber) {
|
||||
@Override
|
||||
public PropertyETType getVariant() {
|
||||
return variant;
|
||||
}
|
||||
};
|
||||
blocks.add(block);
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private final int blockNumber;
|
||||
|
||||
public BlockETDefaultLeaves(int blockNumber) {
|
||||
this.blockNumber = blockNumber;
|
||||
PropertyETType variant = getVariant();
|
||||
setDefaultState(this.blockState.getBaseState()
|
||||
.withProperty(variant, variant.getFirstType())
|
||||
.withProperty(CHECK_DECAY, false)
|
||||
.withProperty(DECAYABLE, true));
|
||||
String name = "leaves.default." + blockNumber;
|
||||
setUnlocalizedName(name);
|
||||
setRegistryName(new ResourceLocation(Constants.EXTRA_TREES_MOD_ID, name));
|
||||
}
|
||||
|
||||
public int getBlockNumber() {
|
||||
return blockNumber;
|
||||
}
|
||||
|
||||
protected abstract PropertyETType getVariant();
|
||||
|
||||
@Nullable
|
||||
public ETTreeDefinition getTreeDefinition(IBlockState blockState) {
|
||||
if (blockState.getBlock() == this) {
|
||||
return blockState.getValue(getVariant());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
ETTreeDefinition treeDefinition = getTreeDefinition(state);
|
||||
if (treeDefinition == null) {
|
||||
return 0;
|
||||
}
|
||||
return treeDefinition.getMetadata() - blockNumber * VARIANTS_PER_BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState()
|
||||
.withProperty(getVariant(), getTreeType(meta))
|
||||
.withProperty(DECAYABLE, (meta & 4) == 0)
|
||||
.withProperty(CHECK_DECAY, (meta & 8) > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
int i = damageDropped(state);
|
||||
|
||||
if (!state.getValue(DECAYABLE)) {
|
||||
i |= 4;
|
||||
}
|
||||
|
||||
if (state.getValue(CHECK_DECAY)) {
|
||||
i |= 8;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, getVariant(), CHECK_DECAY, DECAYABLE);
|
||||
}
|
||||
|
||||
public ETTreeDefinition getTreeType(int meta) {
|
||||
int variantCount = getVariant().getAllowedValues().size();
|
||||
int variantMeta = (meta % variantCount) + blockNumber * VARIANTS_PER_BLOCK;
|
||||
return ETTreeDefinition.byMetadata(variantMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NonNullList<ItemStack> getLeafDrop(World world, @Nullable GameProfile playerProfile, BlockPos pos, float saplingModifier, int fortune) {
|
||||
NonNullList<ItemStack> prod = NonNullList.create();
|
||||
|
||||
ITree tree = getTree(world, pos);
|
||||
if (tree == null) {
|
||||
return prod;
|
||||
}
|
||||
|
||||
// Add saplings
|
||||
List<ITree> saplings = tree.getSaplings(world, playerProfile, pos, saplingModifier);
|
||||
for (ITree sapling : saplings) {
|
||||
if (sapling != null) {
|
||||
prod.add(TreeManager.treeRoot.getMemberStack(sapling, EnumGermlingType.SAPLING));
|
||||
}
|
||||
}
|
||||
|
||||
// Add fruits
|
||||
ITreeGenome genome = tree.getGenome();
|
||||
IFruitProvider fruitProvider = genome.getFruitProvider();
|
||||
if (fruitProvider.isFruitLeaf(genome, world, pos)) {
|
||||
NonNullList<ItemStack> produceStacks = tree.produceStacks(world, pos, Integer.MAX_VALUE);
|
||||
prod.addAll(produceStacks);
|
||||
}
|
||||
|
||||
return prod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
|
||||
ETTreeDefinition type = getTreeType(meta);
|
||||
return getDefaultState().withProperty(getVariant(), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
for (IBlockState state : blockState.getValidStates()) {
|
||||
int meta = getMetaFromState(state);
|
||||
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation("forestry:leaves.default." + blockNumber, "inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ITree getTree(IBlockAccess world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
ETTreeDefinition treeDefinition = getTreeDefinition(blockState);
|
||||
if (treeDefinition != null) {
|
||||
return treeDefinition.getIndividual();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex) {
|
||||
ETTreeDefinition treeDefinition = getTreeDefinition(state);
|
||||
if (treeDefinition == null) {
|
||||
treeDefinition = ETTreeDefinition.OrchardApple;
|
||||
}
|
||||
ITreeGenome genome = treeDefinition.getGenome();
|
||||
|
||||
if (tintIndex == 0) {
|
||||
return genome.getPrimary().getLeafSpriteProvider().getColor(false);
|
||||
} else {
|
||||
IFruitProvider fruitProvider = genome.getFruitProvider();
|
||||
return fruitProvider.getDecorativeColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,41 @@
|
||||
package binnie.extratrees.block;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import forestry.api.arboriculture.EnumVanillaWoodType;
|
||||
import forestry.api.arboriculture.IWoodAccess;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.arboriculture.PluginArboriculture;
|
||||
import forestry.arboriculture.WoodAccess;
|
||||
import forestry.arboriculture.blocks.BlockForestryFenceGate;
|
||||
import forestry.arboriculture.blocks.BlockForestryStairs;
|
||||
import forestry.arboriculture.items.ItemBlockLeaves;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
|
||||
import binnie.Constants;
|
||||
import binnie.core.IInitializable;
|
||||
import binnie.core.Mods;
|
||||
@@ -12,6 +48,7 @@ import binnie.extratrees.block.decor.FenceType;
|
||||
import binnie.extratrees.block.decor.MultiFenceRecipeEmbedded;
|
||||
import binnie.extratrees.block.decor.MultiFenceRecipeSize;
|
||||
import binnie.extratrees.block.decor.MultiFenceRecipeSolid;
|
||||
import binnie.extratrees.block.property.PropertyETType;
|
||||
import binnie.extratrees.block.wood.BlockETFence;
|
||||
import binnie.extratrees.block.wood.BlockETLog;
|
||||
import binnie.extratrees.block.wood.BlockETPlank;
|
||||
@@ -21,34 +58,6 @@ import binnie.extratrees.block.wood.ItemBlockETWood;
|
||||
import binnie.extratrees.block.wood.ItemETSlab;
|
||||
import binnie.extratrees.genetics.ETTreeDefinition;
|
||||
import binnie.extratrees.item.ExtraTreeLiquid;
|
||||
import forestry.api.arboriculture.EnumVanillaWoodType;
|
||||
import forestry.api.arboriculture.IWoodAccess;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.arboriculture.WoodAccess;
|
||||
import forestry.arboriculture.blocks.BlockForestryFenceGate;
|
||||
import forestry.arboriculture.blocks.BlockForestryStairs;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModuleBlocks implements IInitializable {
|
||||
//public static int hedgeRenderID;
|
||||
@@ -69,6 +78,7 @@ public class ModuleBlocks implements IInitializable {
|
||||
public List<BlockForestryFenceGate<EnumETLog>> fenceGatesFireproof;
|
||||
public List<BlockETDecorativeLeaves> leavesDecorative;
|
||||
public Map<String, ItemStack> speciesToLeavesDecorative;
|
||||
public List<BlockETDefaultLeaves> leavesDefault;
|
||||
public Block blockDoor;
|
||||
public BlockMultiFence blockMultiFence;
|
||||
public BlockHedge blockHedge;
|
||||
@@ -241,6 +251,22 @@ public class ModuleBlocks implements IInitializable {
|
||||
ItemStack coalOutput = new ItemStack(Items.COAL, 1, 1);
|
||||
RecipeUtil.addSmelting(logInput, coalOutput, 0.15F);
|
||||
}
|
||||
|
||||
leavesDefault = BlockETDefaultLeaves.create();
|
||||
Map speciesToLeavesDefault = PluginArboriculture.getBlocks().speciesToLeavesDefault;
|
||||
for (BlockETDefaultLeaves leaves : leavesDefault) {
|
||||
ExtraTrees.proxy.registerBlock(leaves, new ItemBlockLeaves(leaves));
|
||||
registerOreDictWildcard(OreDictUtil.TREE_LEAVES, leaves);
|
||||
|
||||
PropertyETType treeType = leaves.getVariant();
|
||||
for (ETTreeDefinition treeDefinition : treeType.getAllowedValues()) {
|
||||
Preconditions.checkNotNull(treeDefinition);
|
||||
String speciesUid = treeDefinition.getUID();
|
||||
IBlockState blockState = leaves.getDefaultState().withProperty(treeType, treeDefinition);
|
||||
speciesToLeavesDefault.put(speciesUid, blockState);
|
||||
}
|
||||
}
|
||||
|
||||
//ModuleBlocks.hedgeRenderID = BinnieCore.proxy.getUniqueRenderID();
|
||||
leavesDecorative = BlockETDecorativeLeaves.create();
|
||||
speciesToLeavesDecorative = new HashMap<>();
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package binnie.extratrees.block.property;
|
||||
|
||||
import binnie.extratrees.genetics.ETTreeDefinition;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
|
||||
import binnie.extratrees.genetics.ETTreeDefinition;
|
||||
|
||||
public class PropertyETType extends PropertyEnum<ETTreeDefinition> {
|
||||
protected PropertyETType(String name, Class<ETTreeDefinition> valueClass, Collection<ETTreeDefinition> allowedValues) {
|
||||
super(name, valueClass, allowedValues);
|
||||
@@ -21,4 +23,8 @@ public class PropertyETType extends PropertyEnum<ETTreeDefinition> {
|
||||
Collection<ETTreeDefinition> allowedValues = Collections2.filter(Lists.newArrayList(ETTreeDefinition.class.getEnumConstants()), filter);
|
||||
return new PropertyETType(name, ETTreeDefinition.class, allowedValues);
|
||||
}
|
||||
|
||||
public ETTreeDefinition getFirstType() {
|
||||
return getAllowedValues().iterator().next();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user