mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-23 21:49:49 +00:00
Adding flower blockstate and blockstatemapper
This commit is contained in:
1 parent
5a64454906
commit
2a23e60cdb
60 files changed
+405
-201
No files matched your search
@@ -12,16 +12,20 @@ import binnie.botany.api.IFlower;
|
||||
import binnie.botany.api.IFlowerType;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.botany.gardening.Gardening;
|
||||
import binnie.botany.genetics.EnumFlowerType;
|
||||
import binnie.botany.genetics.FlowerDefinition;
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.util.TileUtil;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.core.blocks.IColoredBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -36,14 +40,17 @@ 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.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class BlockFlower extends BlockContainer implements IColoredBlock, IItemModelRegister {
|
||||
public class BlockFlower extends BlockContainer implements IColoredBlock, IItemModelRegister, IStateMapperRegister {
|
||||
|
||||
public static final AxisAlignedBB FLOWER_BLOCK_AABB = new AxisAlignedBB(0.3D, 0.0D, 0.3D, 0.7D, 0.6D, 0.7D);
|
||||
/* PROPERTYS */
|
||||
public static final PropertyFlower FLOWER = new PropertyFlower("flower", IFlowerType.class);
|
||||
public static final PropertyInteger SECTION = PropertyInteger.create("section", 0, EnumFlowerType.highestSection - 1);
|
||||
public static final PropertyBool FLOWERED = PropertyBool.create("flowered");
|
||||
|
||||
public BlockFlower() {
|
||||
super(Material.PLANTS);
|
||||
@@ -67,6 +74,12 @@ public class BlockFlower extends BlockContainer implements IColoredBlock, IItemM
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerStateMapper() {
|
||||
ModelLoader.setCustomStateMapper(this, new StateMapperFlower());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) {
|
||||
@@ -116,13 +129,13 @@ public class BlockFlower extends BlockContainer implements IColoredBlock, IItemM
|
||||
public int colorMultiplier(IBlockState state, IBlockAccess world, BlockPos pos, int tintIndex) {
|
||||
final TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileEntityFlower) {
|
||||
final TileEntityFlower f = (TileEntityFlower) tile;
|
||||
TileEntityFlower flower = (TileEntityFlower) tile;
|
||||
if(tintIndex == 0){
|
||||
return f.getStemColour();
|
||||
return flower.getStemColour();
|
||||
}else if(tintIndex == 1){
|
||||
return f.getPrimaryColour();
|
||||
return flower.getPrimaryColour();
|
||||
}else{
|
||||
return f.getSecondaryColour();
|
||||
return flower.getSecondaryColour();
|
||||
}
|
||||
}
|
||||
return 16777215;
|
||||
@@ -152,26 +165,30 @@ public class BlockFlower extends BlockContainer implements IColoredBlock, IItemM
|
||||
return EnumBlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public EnumOffsetType getOffsetType() {
|
||||
return EnumOffsetType.XZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
TileEntityFlower flower = TileUtil.getTile(world, pos, TileEntityFlower.class);
|
||||
if(flower != null && flower.getFlower() != null){
|
||||
state = state.withProperty(FLOWER, flower.getFlower().getGenome().getPrimary().getType());
|
||||
if(flower != null && flower.getType() != null){
|
||||
state = state.withProperty(FLOWER, flower.getType());
|
||||
state = state.withProperty(FLOWERED, flower.isFlowered());
|
||||
state = state.withProperty(SECTION, flower.getRenderSection());
|
||||
}else{
|
||||
state = state.withProperty(FLOWER, FlowerDefinition.Dandelion.getSpecies().getType());
|
||||
state = state.withProperty(FLOWERED, false);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, FLOWER);
|
||||
return new BlockStateContainer(this, FLOWER, FLOWERED, SECTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,6 @@ import binnie.botany.genetics.Flower;
|
||||
import binnie.core.BinnieCore;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.core.config.Config;
|
||||
@@ -96,13 +95,13 @@ public class ItemBotany extends Item implements IColoredItem, IItemModelRegister
|
||||
String primaryColor = genome.getPrimaryColor().getColourName();
|
||||
String secondaryColor = genome.getSecondaryColor().getColourName();
|
||||
String stemColor = genome.getStemColor().getColourName();
|
||||
String colourInfo;
|
||||
String colorInfo;
|
||||
if(!primaryColor.equals(secondaryColor)){
|
||||
colourInfo = Binnie.Language.localise("botany.grammar.flower.secondary");
|
||||
colorInfo = Binnie.Language.localise("botany.grammar.flower.secondary");
|
||||
}else{
|
||||
colourInfo = Binnie.Language.localise("botany.grammar.flower");
|
||||
colorInfo = Binnie.Language.localise("botany.grammar.flower");
|
||||
}
|
||||
list.add(TextFormatting.YELLOW + colourInfo.replaceAll("%PRIMARY", primaryColor).replaceAll("%SECONDARY", secondaryColor).replaceAll("%STEM", stemColor));
|
||||
list.add(TextFormatting.YELLOW + colorInfo.replaceAll("%PRIMARY", primaryColor).replaceAll("%SECONDARY", secondaryColor).replaceAll("%STEM", stemColor));
|
||||
|
||||
if (individual.isAnalyzed()) {
|
||||
if (BinnieCore.proxy.isShiftDown()) {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package binnie.botany.flower;
|
||||
|
||||
import java.util.Map;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import binnie.Constants;
|
||||
import binnie.botany.api.IFlowerType;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class StateMapperFlower extends StateMapperBase {
|
||||
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
|
||||
final Map<IProperty<?>, Comparable<?>> properties = Maps.newLinkedHashMap(state.getProperties());
|
||||
IFlowerType flowerType = (IFlowerType) state.getValue(BlockFlower.FLOWER);
|
||||
if (flowerType.getSections() < 2) {
|
||||
properties.remove(BlockFlower.SECTION);
|
||||
}else if(flowerType.getSections() <= state.getValue(BlockFlower.SECTION)){
|
||||
properties.put(BlockFlower.SECTION, flowerType.getSections()-1);
|
||||
}
|
||||
|
||||
return new ModelResourceLocation(Constants.BOTANY_MOD_ID + ":flower", getPropertyString(properties));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -537,6 +537,7 @@ public class TileEntityFlower extends TileEntity implements IPollinatable, IButt
|
||||
this.renderInfo = render;
|
||||
this.section = this.renderInfo.section;
|
||||
worldObj.markBlockRangeForRenderUpdate(pos, pos);
|
||||
worldObj.markChunkDirty(pos, this);
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
|
||||
@@ -60,6 +60,8 @@ public enum EnumFlowerType implements IFlowerType<EnumFlowerType> {
|
||||
Delphinium(2),
|
||||
Hollyhock(2);
|
||||
|
||||
public static int highestSection = 2;
|
||||
|
||||
int sections;
|
||||
ModelResourceLocation[] flowered;
|
||||
ModelResourceLocation[] unflowered;
|
||||
@@ -119,8 +121,4 @@ public enum EnumFlowerType implements IFlowerType<EnumFlowerType> {
|
||||
public String getName() {
|
||||
return name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
// public IIcon getBlank() {
|
||||
// return this.blank;
|
||||
// }
|
||||
}
|
||||
@@ -89,13 +89,13 @@ public class Flower extends Individual implements IFlower {
|
||||
final IAlleleFlowerSpecies primary = this.genome.getPrimary();
|
||||
final IAlleleFlowerSpecies secondary = this.genome.getSecondary();
|
||||
if (!this.isPureBred(EnumFlowerChromosome.SPECIES)) {
|
||||
list.add("§9" + primary.getName() + "-" + secondary.getName() + " Hybrid");
|
||||
list.add("§9" + primary.getName() + "-" + secondary.getName() + " Hybrid");
|
||||
}
|
||||
list.add("§6Age: " + this.getAge());
|
||||
list.add("§6T: " + this.getGenome().getPrimary().getTemperature() + " / " + this.getGenome().getToleranceTemperature());
|
||||
list.add("§6M: " + this.getGenome().getPrimary().getMoisture() + " / " + this.getGenome().getToleranceMoisture());
|
||||
list.add("§6pH: " + this.getGenome().getPrimary().getHumidity() + " / " + this.getGenome().getTolerancePH());
|
||||
list.add("§6Fert: " + this.getGenome().getFertility() + "x");
|
||||
list.add("§6Age: " + this.getAge());
|
||||
list.add("§6T: " + this.getGenome().getPrimary().getTemperature() + " / " + this.getGenome().getToleranceTemperature());
|
||||
list.add("§6M: " + this.getGenome().getPrimary().getMoisture() + " / " + this.getGenome().getToleranceMoisture());
|
||||
list.add("§6pH: " + this.getGenome().getPrimary().getHumidity() + " / " + this.getGenome().getTolerancePH());
|
||||
list.add("§6Fert: " + this.getGenome().getFertility() + "x");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -944,7 +944,6 @@ public enum FlowerDefinition implements IFlowerDefinition {
|
||||
flowerRood.addConversion(new ItemStack(Blocks.RED_FLOWER, 1, 4), Tulip.addVariant(EnumFlowerColor.Crimson));
|
||||
flowerRood.addConversion(new ItemStack(Blocks.RED_FLOWER, 1, 5), Tulip.addVariant(EnumFlowerColor.DarkOrange));
|
||||
}
|
||||
|
||||
public static FlowerDefinition[] VALUES = values();
|
||||
|
||||
private final IAlleleFlowerSpecies species;
|
||||
@@ -1049,6 +1048,12 @@ public enum FlowerDefinition implements IFlowerDefinition {
|
||||
|
||||
public static void preInitFlowers(){
|
||||
MinecraftForge.EVENT_BUS.post(new AlleleSpeciesRegisterEvent(FlowerManager.flowerRoot));
|
||||
for(FlowerDefinition def : values()){
|
||||
IFlowerType type = def.species.getType();
|
||||
if(EnumFlowerType.highestSection < type.getSections()){
|
||||
EnumFlowerType.highestSection = type.getSections();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void initFlowers() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import forestry.core.genetics.alleles.EnumAllele;
|
||||
public class FlowerTemplates {
|
||||
public static IAllele[] getDefaultTemplate() {
|
||||
final IAllele[] alleles = new IAllele[EnumFlowerChromosome.values().length];
|
||||
AlleleHelper.instance.set(alleles, EnumFlowerChromosome.SPECIES, FlowerDefinition.Poppy.getSpecies());
|
||||
AlleleHelper.instance.set(alleles, EnumFlowerChromosome.SPECIES, FlowerDefinition.Dandelion.getSpecies());
|
||||
AlleleHelper.instance.set(alleles, EnumFlowerChromosome.PRIMARY, EnumFlowerColor.Red);
|
||||
AlleleHelper.instance.set(alleles, EnumFlowerChromosome.SECONDARY, EnumFlowerColor.Red);
|
||||
AlleleHelper.instance.set(alleles, EnumFlowerChromosome.FERTILITY, EnumAllele.Fertility.NORMAL);
|
||||
|
||||
@@ -32,10 +32,10 @@ public class ModuleGenetics implements IInitializable {
|
||||
FlowerDefinition.preInitFlowers();
|
||||
|
||||
Botany.flower = new BlockFlower();
|
||||
GameRegistry.register(Botany.flower);
|
||||
Botany.proxy.registerBlock(Botany.flower);
|
||||
BinnieCore.proxy.registerTileEntity(TileEntityFlower.class, "botany.tile.flower", null);
|
||||
//Need we this ?
|
||||
GameRegistry.register(new ItemBlock(Botany.flower).setRegistryName(Botany.flower.getRegistryName()));
|
||||
Botany.proxy.registerItem(new ItemBlock(Botany.flower).setRegistryName(Botany.flower.getRegistryName()));
|
||||
|
||||
Botany.flowerItem = new ItemBotany("itemFlower", EnumFlowerStage.FLOWER, "");
|
||||
Botany.pollen = new ItemBotany("pollen", EnumFlowerStage.POLLEN, "Pollen");
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package binnie.botany.items;
|
||||
|
||||
import binnie.botany.Botany;
|
||||
import binnie.core.item.IItemMisc;
|
||||
import binnie.core.item.IItemMiscProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public enum BotanyItems implements IItemMisc {
|
||||
public enum BotanyItems implements IItemMiscProvider {
|
||||
AshPowder("Ash Powder", "powderAsh"),
|
||||
PulpPowder("Wood Pulp Powder", "powderPulp"),
|
||||
MulchPowder("Mulch Powder", "powderMulch"),
|
||||
@@ -16,26 +16,30 @@ public enum BotanyItems implements IItemMisc {
|
||||
Mortar("Mortar", "mortar"),
|
||||
Weedkiller("Weedkiller", "weedkiller");
|
||||
|
||||
// IIcon icon;
|
||||
String name;
|
||||
String iconPath;
|
||||
String modelPath;
|
||||
|
||||
BotanyItems(final String name, final String iconPath) {
|
||||
BotanyItems(String name, String modelPath) {
|
||||
this.name = name;
|
||||
this.iconPath = iconPath;
|
||||
this.modelPath = modelPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(final List par3List) {
|
||||
public void addInformation(List tooltip) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(final ItemStack stack) {
|
||||
public String getName(ItemStack stack) {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelPath() {
|
||||
return modelPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack get(final int size) {
|
||||
public ItemStack get(int size) {
|
||||
return new ItemStack(Botany.misc, size, this.ordinal());
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
//TODO Remove this after test the PacketFlowerUpdate
|
||||
public class MessageFlowerUpdate extends MessageCoordinates {
|
||||
public TileEntityFlower.RenderInfo render;
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class PacketFlowerUpdate extends SPacketUpdateTileEntity {
|
||||
|
||||
|
||||
public TileEntityFlower.RenderInfo render;
|
||||
|
||||
public PacketFlowerUpdate(BlockPos blockPos, int metadata, NBTTagCompound compound, final TileEntityFlower.RenderInfo render) {
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package binnie.botany.proxy;
|
||||
|
||||
import binnie.botany.Botany;
|
||||
import binnie.core.proxy.BinnieModProxy;
|
||||
|
||||
public class Proxy extends BinnieModProxy implements IBotanyProxy {
|
||||
public Proxy() {
|
||||
super(Botany.instance);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user