From d6d75d7e40228a12cc4b200af94a42580862834e Mon Sep 17 00:00:00 2001 From: Cheeserolls Date: Mon, 6 Apr 2015 19:29:24 +0100 Subject: [PATCH] Further simplify code for blocks with pages of variants. Remove test blocks --- .../biomesoplenty/api/block/BOPTreeEnums.java | 53 ++++++++ .../biomesoplenty/api/block/BOPWoodEnums.java | 57 +++++++++ .../common/block/BlockBOPHalfWoodSlab.java | 59 +++------ .../common/block/BlockBOPLeaves.java | 56 +++------ .../common/block/BlockBOPLog.java | 55 +++------ .../common/block/BlockBOPPlanks.java | 60 +++------ .../common/block/BlockBOPSapling.java | 59 +++------ .../common/block/BlockCheese.java | 116 ------------------ .../common/block/BlockCheese0.java | 17 --- .../common/block/BlockCheese1.java | 17 --- 10 files changed, 182 insertions(+), 367 deletions(-) delete mode 100644 src/main/java/biomesoplenty/common/block/BlockCheese.java delete mode 100644 src/main/java/biomesoplenty/common/block/BlockCheese0.java delete mode 100644 src/main/java/biomesoplenty/common/block/BlockCheese1.java diff --git a/src/main/java/biomesoplenty/api/block/BOPTreeEnums.java b/src/main/java/biomesoplenty/api/block/BOPTreeEnums.java index 4b00b2988..4b62f35e5 100644 --- a/src/main/java/biomesoplenty/api/block/BOPTreeEnums.java +++ b/src/main/java/biomesoplenty/api/block/BOPTreeEnums.java @@ -8,6 +8,12 @@ package biomesoplenty.api.block; +import java.util.HashMap; +import java.util.Map; + +import com.google.common.base.Predicate; + +import net.minecraft.block.properties.PropertyEnum; import net.minecraft.util.IStringSerializable; public class BOPTreeEnums @@ -28,4 +34,51 @@ public class BOPTreeEnums } } + public static enum TreesFilterType { + ALL, SAPLINGS; + public Predicate getPredicate(final int pageNum, final int numPerPage) + { + final TreesFilterType filterType = this; + return new Predicate() + { + @Override + public boolean apply(AllTrees tree) + { + if (filterType == SAPLINGS && (tree == AllTrees.YELLOW_BIG_FLOWER || tree == AllTrees.RED_BIG_FLOWER) ) + { + return false; + } + return (tree.ordinal() >= (numPerPage * pageNum)) && (tree.ordinal() < (numPerPage * (pageNum+1))); + } + }; + } + } + + private static Map propCache = new HashMap(); + + public static PropertyEnum getVariantProperty(int pageNum, int numPerPage) + { + return getVariantProperty(pageNum, numPerPage, TreesFilterType.ALL); + } + + public static PropertyEnum getVariantProperty(int pageNum, int numPerPage, TreesFilterType filterType) + { + // check length and make sure things are in bounds + int len = AllTrees.values().length; + int numPages = (int) Math.ceil( (double)len / numPerPage); + pageNum = Math.max(0, Math.min(pageNum, numPages - 1)); + + // look up the array of properties for pages of size numPerPage and the given filter - if it doesn't exist yet, create it + Integer index = new Integer(numPerPage * TreesFilterType.values().length + filterType.ordinal() ); + if (!propCache.containsKey(index)) {propCache.put(index, new PropertyEnum[numPages]);} + + // look up the property for page pageNum - if it doesn't exist yet, create it + PropertyEnum[] propArr = propCache.get(index); + if (propArr[pageNum] == null) + { + propArr[pageNum] = PropertyEnum.create("variant", AllTrees.class, filterType.getPredicate(pageNum, numPerPage)); + } + return propArr[pageNum]; + } + } \ No newline at end of file diff --git a/src/main/java/biomesoplenty/api/block/BOPWoodEnums.java b/src/main/java/biomesoplenty/api/block/BOPWoodEnums.java index eb3bf9f66..358fdaa19 100644 --- a/src/main/java/biomesoplenty/api/block/BOPWoodEnums.java +++ b/src/main/java/biomesoplenty/api/block/BOPWoodEnums.java @@ -8,6 +8,12 @@ package biomesoplenty.api.block; +import java.util.HashMap; +import java.util.Map; + +import com.google.common.base.Predicate; + +import net.minecraft.block.properties.PropertyEnum; import net.minecraft.util.IStringSerializable; public class BOPWoodEnums @@ -26,5 +32,56 @@ public class BOPWoodEnums return this.getName(); } } + + + public static enum WoodsFilterType { + ALL, WITH_PLANKS; + public Predicate getPredicate(final int pageNum, final int numPerPage) + { + final WoodsFilterType filterType = this; + return new Predicate() + { + @Override + public boolean apply(AllWoods wood) + { + if (filterType == WITH_PLANKS && (wood == AllWoods.GIANT_FLOWER || wood == AllWoods.DEAD) ) + { + return false; + } + return (wood.ordinal() >= (numPerPage * pageNum)) && (wood.ordinal() < (numPerPage * (pageNum+1))); + } + }; + } + } + + private static Map propCache = new HashMap(); + + public static PropertyEnum getVariantProperty(int pageNum, int numPerPage) + { + return getVariantProperty(pageNum, numPerPage, WoodsFilterType.ALL); + } + + public static PropertyEnum getVariantProperty(int pageNum, int numPerPage, WoodsFilterType filterType) + { + // check length and make sure things are in bounds + int len = AllWoods.values().length; + int numPages = (int) Math.ceil( (double)len / numPerPage); + pageNum = Math.max(0, Math.min(pageNum, numPages - 1)); + + // look up the array of properties for pages of size numPerPage and the given filter - if it doesn't exist yet, create it + Integer index = new Integer(numPerPage * WoodsFilterType.values().length + filterType.ordinal() ); + if (!propCache.containsKey(index)) {propCache.put(index, new PropertyEnum[numPages]);} + + // look up the property for page pageNum - if it doesn't exist yet, create it + PropertyEnum[] propArr = propCache.get(index); + if (propArr[pageNum] == null) + { + propArr[pageNum] = PropertyEnum.create("variant", AllWoods.class, filterType.getPredicate(pageNum, numPerPage)); + } + return propArr[pageNum]; + } + + + } \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPHalfWoodSlab.java b/src/main/java/biomesoplenty/common/block/BlockBOPHalfWoodSlab.java index d671aabd5..075c5e19a 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPHalfWoodSlab.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPHalfWoodSlab.java @@ -2,9 +2,9 @@ package biomesoplenty.common.block; import java.util.List; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; +import biomesoplenty.api.block.BOPWoodEnums; import biomesoplenty.api.block.BOPWoodEnums.AllWoods; import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.util.block.BlockStateUtils; @@ -26,62 +26,33 @@ public abstract class BlockBOPHalfWoodSlab extends BlockSlab implements IBOPBloc { - // store the variant properties for each page in this array - private static PropertyEnum[] variantProperties; - // number of variants per page - HALF requires 1 meta bit, so we have 3 left for the VARIANT, which means we can have eight woods per instance - public static final int variantsPerPage = 8; - // fetch a particular page's variant property - // the first time this is called, it also sets up the array of variant properties - protected static PropertyEnum getVariantProperty(int pageNum) - { - int len = AllWoods.values().length; - int numPages = (int) Math.ceil( (double)len / variantsPerPage); - if (variantProperties == null) - { - variantProperties = new PropertyEnum[numPages]; - } - pageNum = Math.max(0, Math.min(pageNum, numPages - 1)); - if (variantProperties[pageNum] == null) - { - variantProperties[pageNum] = PropertyEnum.create("variant", AllWoods.class, getVariantEnumFilter(pageNum)); - } - return variantProperties[pageNum]; - } - // define the filter function used to reduce the set of enum values to the subset for the given page - protected static Predicate getVariantEnumFilter(final int pageNum) - { - return new Predicate() - { - @Override - public boolean apply(AllWoods wood) - { - switch (wood) - { - case GIANT_FLOWER: case DEAD: - return false; - default: - return (wood.ordinal() >= (variantsPerPage * pageNum)) && (wood.ordinal() < (variantsPerPage * (pageNum+1))); - } - } - }; - } + // setup paged variant property + + // STAGE require one bit, so we have 3 bits left for the VARIANT which means we can have eight per instance + public static final int VARIANTS_PER_PAGE = 8; // child classes must implement to define their page number abstract public int getPageNum(); + // fetch the variant property for a given page + public static PropertyEnum getVariantProperty(int pageNum) + { + return BOPWoodEnums.getVariantProperty(pageNum, VARIANTS_PER_PAGE, BOPWoodEnums.WoodsFilterType.WITH_PLANKS); + } // fetch the current instance's variant property public PropertyEnum getMyVariantProperty() { - return getVariantProperty(this.getPageNum()); + return getVariantProperty(getPageNum()); } + // get the meta bits from the variant public int metaFromVariant(AllWoods wood) { - return wood.ordinal() % variantsPerPage; + return wood.ordinal() % VARIANTS_PER_PAGE; } + // get the variant from meta bits (safely) public AllWoods variantFromMeta(int meta) { - int i = Math.max(0, Math.min(meta + (this.getPageNum() * variantsPerPage), AllWoods.values().length)); // clamp to + int i = Math.max(0, Math.min(meta + (this.getPageNum() * VARIANTS_PER_PAGE), AllWoods.values().length)); return AllWoods.values()[i]; } - // add properties (note we inherit HALF property from parent BlockSlab) diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java b/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java index 6013ec705..9b807604d 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java @@ -11,9 +11,8 @@ package biomesoplenty.common.block; import java.util.List; import java.util.Random; -import com.google.common.base.Predicate; - import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.api.block.BOPTreeEnums; import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.api.block.BOPTreeEnums.AllTrees; import biomesoplenty.common.item.ItemBOPBlock; @@ -41,60 +40,33 @@ import net.minecraftforge.fml.relauncher.SideOnly; public abstract class BlockBOPLeaves extends BlockLeaves implements IBOPBlock { + // setup paged variant property - // store the variant properties for each page in this array - private static PropertyEnum[] variantProperties; // CHECK_DECAY and DECAYABLE require one bit each, so we have 2 bits left for the VARIANT which means we can have four per instance - public static final int variantsPerPage = 4; - // fetch a particular page's variant property - // the first time this is called, it also sets up the array of variant properties - protected static PropertyEnum getVariantProperty(int pageNum) - { - int len = AllTrees.values().length; - int numPages = (int) Math.ceil( (double)len / variantsPerPage); - if (variantProperties == null) - { - variantProperties = new PropertyEnum[numPages]; - } - pageNum = Math.max(0, Math.min(pageNum, numPages - 1)); - if (variantProperties[pageNum] == null) - { - variantProperties[pageNum] = PropertyEnum.create("variant", AllTrees.class, getVariantEnumFilter(pageNum)); - } - return variantProperties[pageNum]; - } - // define the filter function used to reduce the set of enum values to the subset for the given page - protected static Predicate getVariantEnumFilter(final int pageNum) - { - return new Predicate() - { - @Override - public boolean apply(AllTrees tree) - { - return (tree.ordinal() >= (variantsPerPage * pageNum)) && (tree.ordinal() < (variantsPerPage * (pageNum+1))); - } - }; - } + public static final int VARIANTS_PER_PAGE = 4; // child classes must implement to define their page number abstract public int getPageNum(); + // fetch the variant property for a given page + public static PropertyEnum getVariantProperty(int pageNum) + { + return BOPTreeEnums.getVariantProperty(pageNum, VARIANTS_PER_PAGE); + } // fetch the current instance's variant property public PropertyEnum getMyVariantProperty() { - return getVariantProperty(this.getPageNum()); + return getVariantProperty(getPageNum()); } + // get the meta bits from the variant public int metaFromVariant(AllTrees tree) { - return tree.ordinal() % variantsPerPage; + return tree.ordinal() % VARIANTS_PER_PAGE; } + // get the variant from meta bits (safely) public AllTrees variantFromMeta(int meta) { - int i = Math.max(0, Math.min(meta + (this.getPageNum() * variantsPerPage), AllTrees.values().length)); // clamp to + int i = Math.max(0, Math.min(meta + (this.getPageNum() * VARIANTS_PER_PAGE), AllTrees.values().length)); return AllTrees.values()[i]; - } - - - - + } // add properties - note CHECK_DECAY and DECAYABLE are both inherited from BlockLeaves @Override diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPLog.java b/src/main/java/biomesoplenty/common/block/BlockBOPLog.java index 05fc36d11..b019a0e39 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPLog.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPLog.java @@ -8,9 +8,8 @@ package biomesoplenty.common.block; -import com.google.common.base.Predicate; - import biomesoplenty.api.block.BOPWoodEnums.AllWoods; +import biomesoplenty.api.block.BOPWoodEnums; import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.item.ItemBOPBlock; import net.minecraft.block.BlockLog; @@ -23,57 +22,33 @@ import net.minecraft.item.ItemBlock; public abstract class BlockBOPLog extends BlockLog implements IBOPBlock { + // setup paged variant property - // store the variant properties for each page in this array - private static PropertyEnum[] variantProperties; - // number of variants per page - public static final int variantsPerPage = 4; - // fetch a particular page's variant property - // the first time this is called, it also sets up the array of variant properties - protected static PropertyEnum getVariantProperty(int pageNum) - { - int len = AllWoods.values().length; - int numPages = (int) Math.ceil( (double)len / variantsPerPage); - if (variantProperties == null) - { - variantProperties = new PropertyEnum[numPages]; - } - pageNum = Math.max(0, Math.min(pageNum, numPages - 1)); - if (variantProperties[pageNum] == null) - { - variantProperties[pageNum] = PropertyEnum.create("variant", AllWoods.class, getVariantEnumFilter(pageNum)); - } - return variantProperties[pageNum]; - } - // define the filter function used to reduce the set of enum values to the subset for the given page - protected static Predicate getVariantEnumFilter(final int pageNum) - { - return new Predicate() - { - @Override - public boolean apply(AllWoods wood) - { - return (wood.ordinal() >= (variantsPerPage * pageNum)) && (wood.ordinal() < (variantsPerPage * (pageNum+1))); - } - }; - } + // STAGE require one bit, so we have 3 bits left for the VARIANT which means we can have eight per instance + public static final int VARIANTS_PER_PAGE = 4; // child classes must implement to define their page number abstract public int getPageNum(); + // fetch the variant property for a given page + public static PropertyEnum getVariantProperty(int pageNum) + { + return BOPWoodEnums.getVariantProperty(pageNum, VARIANTS_PER_PAGE); + } // fetch the current instance's variant property public PropertyEnum getMyVariantProperty() { - return getVariantProperty(this.getPageNum()); + return getVariantProperty(getPageNum()); } + // get the meta bits from the variant public int metaFromVariant(AllWoods wood) { - return wood.ordinal() % variantsPerPage; + return wood.ordinal() % VARIANTS_PER_PAGE; } + // get the variant from meta bits (safely) public AllWoods variantFromMeta(int meta) { - int i = Math.max(0, Math.min(meta + (this.getPageNum() * variantsPerPage), AllWoods.values().length)); // clamp to + int i = Math.max(0, Math.min(meta + (this.getPageNum() * VARIANTS_PER_PAGE), AllWoods.values().length)); return AllWoods.values()[i]; - } - + } @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { LOG_AXIS, getMyVariantProperty() });} diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPPlanks.java b/src/main/java/biomesoplenty/common/block/BlockBOPPlanks.java index 1cc4e766e..dbff46bb5 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPPlanks.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPPlanks.java @@ -8,8 +8,6 @@ package biomesoplenty.common.block; -import com.google.common.base.Predicate; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; @@ -17,6 +15,7 @@ import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemBlock; +import biomesoplenty.api.block.BOPWoodEnums; import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.api.block.BOPWoodEnums.AllWoods; import biomesoplenty.common.item.ItemBOPBlock; @@ -24,64 +23,33 @@ import biomesoplenty.common.item.ItemBOPBlock; public abstract class BlockBOPPlanks extends Block implements IBOPBlock { + // setup paged variant property - // store the variant properties for each page in this array - private static PropertyEnum[] variantProperties; - // number of variants per page - all 4 meta bits are available so we can have 16 - public static final int variantsPerPage = 16; - // fetch a particular page's variant property - // the first time this is called, it also sets up the array of variant properties - protected static PropertyEnum getVariantProperty(int pageNum) - { - int len = AllWoods.values().length; - int numPages = (int) Math.ceil( (double)len / variantsPerPage); - if (variantProperties == null) - { - variantProperties = new PropertyEnum[numPages]; - } - pageNum = Math.max(0, Math.min(pageNum, numPages - 1)); - if (variantProperties[pageNum] == null) - { - variantProperties[pageNum] = PropertyEnum.create("variant", AllWoods.class, getVariantEnumFilter(pageNum)); - } - return variantProperties[pageNum]; - } - // define the filter function used to reduce the set of enum values to the subset for the given page - protected static Predicate getVariantEnumFilter(final int pageNum) - { - return new Predicate() - { - @Override - public boolean apply(AllWoods wood) - { - switch (wood) - { - case GIANT_FLOWER: case DEAD: - return false; - default: - return (wood.ordinal() >= (variantsPerPage * pageNum)) && (wood.ordinal() < (variantsPerPage * (pageNum+1))); - } - } - }; - } + // STAGE require one bit, so we have 3 bits left for the VARIANT which means we can have eight per instance + public static final int VARIANTS_PER_PAGE = 16; // child classes must implement to define their page number abstract public int getPageNum(); + // fetch the variant property for a given page + public static PropertyEnum getVariantProperty(int pageNum) + { + return BOPWoodEnums.getVariantProperty(pageNum, VARIANTS_PER_PAGE, BOPWoodEnums.WoodsFilterType.WITH_PLANKS); + } // fetch the current instance's variant property public PropertyEnum getMyVariantProperty() { - return getVariantProperty(this.getPageNum()); + return getVariantProperty(getPageNum()); } + // get the meta bits from the variant public int metaFromVariant(AllWoods wood) { - return wood.ordinal() % variantsPerPage; + return wood.ordinal() % VARIANTS_PER_PAGE; } + // get the variant from meta bits (safely) public AllWoods variantFromMeta(int meta) { - int i = Math.max(0, Math.min(meta + (this.getPageNum() * variantsPerPage), AllWoods.values().length)); // clamp to + int i = Math.max(0, Math.min(meta + (this.getPageNum() * VARIANTS_PER_PAGE), AllWoods.values().length)); return AllWoods.values()[i]; } - - // add properties (note we inherit LOG_AXIS property from parent BlockLog) @Override diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPSapling.java b/src/main/java/biomesoplenty/common/block/BlockBOPSapling.java index dd0ee6a00..44259d1b1 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPSapling.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPSapling.java @@ -10,9 +10,8 @@ package biomesoplenty.common.block; import java.util.Random; -import com.google.common.base.Predicate; - import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.api.block.BOPTreeEnums; import biomesoplenty.api.block.BOPTreeEnums.AllTrees; import net.minecraft.block.Block; import net.minecraft.block.IGrowable; @@ -30,66 +29,36 @@ import net.minecraft.world.gen.feature.WorldGenerator; public abstract class BlockBOPSapling extends BlockDecoration implements IGrowable { + + // setup paged variant property - // store the variant properties for each page in this array - private static PropertyEnum[] variantProperties; // STAGE require one bit, so we have 3 bits left for the VARIANT which means we can have eight per instance - public static final int variantsPerPage = 8; - // fetch a particular page's variant property - // the first time this is called, it also sets up the array of variant properties - protected static PropertyEnum getVariantProperty(int pageNum) - { - int len = AllTrees.values().length; - int numPages = (int) Math.ceil( (double)len / variantsPerPage); - if (variantProperties == null) - { - variantProperties = new PropertyEnum[numPages]; - } - pageNum = Math.max(0, Math.min(pageNum, numPages - 1)); - if (variantProperties[pageNum] == null) - { - variantProperties[pageNum] = PropertyEnum.create("variant", AllTrees.class, getVariantEnumFilter(pageNum)); - } - return variantProperties[pageNum]; - } - // define the filter function used to reduce the set of enum values to the subset for the given page - protected static Predicate getVariantEnumFilter(final int pageNum) - { - return new Predicate() - { - @Override - public boolean apply(AllTrees tree) - { - switch (tree) - { - case RED_BIG_FLOWER: case YELLOW_BIG_FLOWER: - return false; - default: - return (tree.ordinal() >= (variantsPerPage * pageNum)) && (tree.ordinal() < (variantsPerPage * (pageNum+1))); - } - } - }; - } + public static final int VARIANTS_PER_PAGE = 8; // child classes must implement to define their page number abstract public int getPageNum(); + // fetch the variant property for a given page + public static PropertyEnum getVariantProperty(int pageNum) + { + return BOPTreeEnums.getVariantProperty(pageNum, VARIANTS_PER_PAGE, BOPTreeEnums.TreesFilterType.SAPLINGS); + } // fetch the current instance's variant property public PropertyEnum getMyVariantProperty() { - return getVariantProperty(this.getPageNum()); + return getVariantProperty(getPageNum()); } + // get the meta bits from the variant public int metaFromVariant(AllTrees tree) { - return tree.ordinal() % variantsPerPage; + return tree.ordinal() % VARIANTS_PER_PAGE; } + // get the variant from meta bits (safely) public AllTrees variantFromMeta(int meta) { - int i = Math.max(0, Math.min(meta + (this.getPageNum() * variantsPerPage), AllTrees.values().length)); // clamp to + int i = Math.max(0, Math.min(meta + (this.getPageNum() * VARIANTS_PER_PAGE), AllTrees.values().length)); return AllTrees.values()[i]; } - - // add properties public static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, 1); @Override diff --git a/src/main/java/biomesoplenty/common/block/BlockCheese.java b/src/main/java/biomesoplenty/common/block/BlockCheese.java deleted file mode 100644 index f0cf4c760..000000000 --- a/src/main/java/biomesoplenty/common/block/BlockCheese.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright 2014, the Biomes O' Plenty Team - * - * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. - * - * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. - ******************************************************************************/ - -package biomesoplenty.common.block; - -import com.google.common.base.Predicate; - -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; -import net.minecraft.block.properties.PropertyEnum; -import net.minecraft.block.state.BlockState; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.IStringSerializable; - -public abstract class BlockCheese extends Block -{ - - public enum AllCheeses implements IStringSerializable - { - CHEDDAR, EDAM, MOZARELLA, STILTON, PARMESAN, BRIE, LANCS, WENSLEYDALE, GRUYERE, COMTE; - @Override - public String getName() - { - return this.name().toLowerCase(); - } - @Override - public String toString() - { - return this.getName(); - } - } - - // store the variant properties for each page in this array - private static PropertyEnum[] variantProperties; - // number of variants per page - public static final int variantsPerPage = 4; - // fetch a particular page's variant property - // the first time this is called, it also sets up the array of variant properties - protected static PropertyEnum getVariantProperty(int pageNum) - { - int len = AllCheeses.values().length; - int numPages = (int) Math.ceil( (double)len / variantsPerPage); - if (variantProperties == null) - { - variantProperties = new PropertyEnum[numPages]; - } - pageNum = Math.max(0, Math.min(pageNum, numPages - 1)); - if (variantProperties[pageNum] == null) - { - variantProperties[pageNum] = PropertyEnum.create("variant", AllCheeses.class, getVariantEnumFilter(pageNum)); - } - return variantProperties[pageNum]; - } - // child classes must implement to define their page number - abstract public int getPageNum(); - // fetch the current instance's variant property - public PropertyEnum getMyVariantProperty() - { - return getVariantProperty(this.getPageNum()); - } - // define the filter function used to reduce the set of enum values to the subset for the given page - protected static Predicate getVariantEnumFilter(final int pageNum) - { - return new Predicate() - { - @Override - public boolean apply(AllCheeses cheese) - { - return (cheese.ordinal() >= (variantsPerPage * pageNum)) && (cheese.ordinal() < (variantsPerPage * (pageNum+1))); - } - }; - } - public int metaFromVariant(AllCheeses type) - { - return type.ordinal() % variantsPerPage; - } - public AllCheeses variantFromMeta(int meta) - { - int i = Math.max(0, Math.min(meta + (this.getPageNum() * variantsPerPage), AllCheeses.values().length)); // clamp to - return AllCheeses.values()[i]; - } - - - - - @Override - protected BlockState createBlockState() - { - return new BlockState(this, new IProperty[] { getMyVariantProperty() }); - } - - public BlockCheese() - { - super(Material.cake); - } - - // map from state to meta and vice verca - @Override - public IBlockState getStateFromMeta(int meta) - { - return this.getDefaultState().withProperty(getMyVariantProperty(), variantFromMeta(meta & 3)); // in addition to other properties - } - @Override - public int getMetaFromState(IBlockState state) - { - return metaFromVariant((AllCheeses) state.getValue(getMyVariantProperty())); // plus bits from other properties - } - - -} \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/block/BlockCheese0.java b/src/main/java/biomesoplenty/common/block/BlockCheese0.java deleted file mode 100644 index a4ac95b26..000000000 --- a/src/main/java/biomesoplenty/common/block/BlockCheese0.java +++ /dev/null @@ -1,17 +0,0 @@ -package biomesoplenty.common.block; - -import net.minecraft.block.properties.PropertyEnum; - -public class BlockCheese0 extends BlockCheese -{ - - public static final int PAGENUM = 0; - - // create a static reference to this block's variant property - // this is for convenience, and for consistency with other Block classes - public static final PropertyEnum VARIANT = BlockCheese.getVariantProperty(PAGENUM); - - @Override - public int getPageNum() {return PAGENUM;} - -} diff --git a/src/main/java/biomesoplenty/common/block/BlockCheese1.java b/src/main/java/biomesoplenty/common/block/BlockCheese1.java deleted file mode 100644 index b650eebe7..000000000 --- a/src/main/java/biomesoplenty/common/block/BlockCheese1.java +++ /dev/null @@ -1,17 +0,0 @@ -package biomesoplenty.common.block; - -import net.minecraft.block.properties.PropertyEnum; - -public class BlockCheese1 extends BlockCheese -{ - - public static final int PAGENUM = 1; - - // create a static reference to this block's variant property - // this is for convenience, and for consistency with other Block classes - public static final PropertyEnum VARIANT = BlockCheese.getVariantProperty(PAGENUM); - - @Override - public int getPageNum() {return PAGENUM;} - -}