Add biome essence and biome block

This commit is contained in:
Cheeserolls 2015-05-03 23:40:18 +01:00
parent fd81cb9029
commit c32a624f92
13 changed files with 145 additions and 55 deletions

View File

@ -69,4 +69,10 @@ public class BOPBiome extends BiomeGenBase implements IExtendedBiome
{
this.weightMap.clear();
}
// whether or not a biome essence item corresponding to this biome should be able to drop from biome blocks
public boolean hasBiomeEssence()
{
return true;
}
}

View File

@ -24,6 +24,7 @@ public class BOPBlocks
public static Block hive;
public static Block mushroom;
public static Block stone;
public static Block biome_block;
public static Block log_0;
public static Block log_1;

View File

@ -97,6 +97,7 @@ public class BOPItems
public static Item amethyst_scythe;
public static Item biome_finder;
public static Item biome_essence;
public static Item enderporter;
public static Item jar_empty;
public static Item jar_filled;

View File

@ -5,11 +5,15 @@
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
/*
package biomesoplenty.common.block;
import biomesoplenty.api.biome.BOPBiomes;
import biomesoplenty.api.block.BOPBlock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import biomesoplenty.api.biome.BOPBiome;
import biomesoplenty.api.item.BOPItems;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@ -17,42 +21,83 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
public class BlockBiomeBlock extends BOPBlock
{
public class BlockBiomeBlock extends BlockBOPGeneric
{
public BlockBiomeBlock() {
super(Material.glass);
this.setHardness(0.6F);
this.setStepSound(Block.soundTypeGlass);
}
// TODO: don't understand this method at all.
@Override
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
// list of biomes which have an associated essence (possible drops when this block is broken)
private static List<BiomeGenBase> biomesWithEssence;
// generate the list of biomes which have an associated essence
public List<BiomeGenBase> getBiomesWithEssence()
{
if (!worldIn.isRemote && !worldIn.restoringBlockSnapshots) // do not drop items while restoring blockstates, prevents item dupe
if (biomesWithEssence != null) {return biomesWithEssence;}
biomesWithEssence = new ArrayList<BiomeGenBase>();
List<BiomeGenBase> vanillaBiomesToExclude = Arrays.asList(
new BiomeGenBase[] {
BiomeGenBase.sky,
BiomeGenBase.hell,
BiomeGenBase.beach,
BiomeGenBase.coldBeach,
BiomeGenBase.stoneBeach,
BiomeGenBase.ocean,
BiomeGenBase.frozenOcean,
BiomeGenBase.deepOcean,
BiomeGenBase.river,
BiomeGenBase.frozenRiver
}
);
for (BiomeGenBase biome : BiomeGenBase.getBiomeGenArray())
{
for (BiomeGenBase biome : BiomeGenBase.getBiomeGenArray())
if (biome == null) {continue;}
if (biome instanceof BOPBiome)
{
if (biome == null) {continue;}
// TODO: add the other biomes
// TODO: add areBiomesEqual function for comparing these
if ( biome.biomeID == BOPBiomes.alps.biomeID )
{
if (worldIn.rand.nextInt(75) == 0)
{
ItemStack biome_essence = new ItemStack(BOPItems.biome_essence);
biome_essence.setTagCompound(new NBTTagCompound());
biome_essence.getTagCompound().setInteger("biomeID", biome.biomeID);
spawnAsEntity(worldIn, pos, biome_essence);
}
}
if (((BOPBiome)biome).hasBiomeEssence()) {biomesWithEssence.add(biome);}
}
else
{
if (!vanillaBiomesToExclude.contains(biome)) {biomesWithEssence.add(biome);}
}
}
}
return biomesWithEssence;
}
}
*/
// drops biome essence items for random biomes
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
List<ItemStack> ret = new ArrayList<ItemStack>();
Random rand = world instanceof World ? ((World)world).rand : RANDOM;
List<BiomeGenBase> biomes = this.getBiomesWithEssence();
int numToDrop = rand.nextInt(fortune + 2) + 1;
int numChoices = biomes.size();
BiomeGenBase biome;
for (int i = 0; i < numToDrop; i++)
{
biome = biomes.get(rand.nextInt(numChoices));
ItemStack biome_essence = new ItemStack(BOPItems.biome_essence);
biome_essence.setTagCompound(new NBTTagCompound());
biome_essence.getTagCompound().setInteger("biomeID", biome.biomeID);
ret.add(biome_essence);
}
return ret;
}
}

View File

@ -66,6 +66,7 @@ public class ModBlocks
stone_formations = registerBlock( new BlockStoneFormations(), "stone_formations" );
fruit_block = registerBlock( new BlockFruit(), "fruit_block" /*, creativeTab(null) */); // TODO: once the mechanism for farming fruit is established: remove creative tab
crystal = registerBlock( new BlockCrystal(), "crystal" );
biome_block = registerBlock( new BlockBiomeBlock(), "biome_block" );
// generics
ash_stone = registerBlock( new BlockBOPGeneric(), "ash_stone" );

View File

@ -174,6 +174,7 @@ public class ModItems
biome_finder = registerItem(new ItemBiomeFinder(), "biome_finder");
biome_essence = registerItem(new ItemBiomeEssence(), "biome_essence");
enderporter = registerItem(new ItemEnderporter(), "enderporter");
jar_empty = registerItem(new ItemJarEmpty(), "jar_empty");
jar_filled = registerItem(new ItemJarFilled(), "jar_filled");

View File

@ -17,7 +17,6 @@ import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
// TODO: This is probably all kinds of wrong
public class ItemBiomeEssence extends Item
{
public ItemBiomeEssence() {}
@ -28,49 +27,46 @@ public class ItemBiomeEssence extends Item
return true;
}
// TODO: wtf?
// TODO: really? this looks well dodgy.
@Override
public ItemStack getContainerItem(ItemStack itemStack)
{
return itemStack;
}
}
public BiomeGenBase getBiome(ItemStack itemStack)
{
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("biomeID"))
{
int biomeId = itemStack.getTagCompound().getInteger("biomeID");
try
{
return BiomeGenBase.getBiomeGenArray()[biomeId];
}
catch (Exception e)
{
return null;
}
}
return null;
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List infoList, boolean advancedItemTooltips)
{
if (itemStack.hasTagCompound())
BiomeGenBase biome = this.getBiome(itemStack);
if (biome != null)
{
if (itemStack.getTagCompound().hasKey("biomeID"))
{
BiomeGenBase biome = BiomeGenBase.getBiomeGenArray()[itemStack.getTagCompound().getInteger("biomeID")];
if (biome != null)
{
infoList.add(biome.biomeName);
}
}
infoList.add(biome.biomeName);
}
}
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack itemStack, int par2)
public int getColorFromItemStack(ItemStack itemStack, int tintIndex)
{
if (itemStack.hasTagCompound())
{
if (itemStack.getTagCompound().hasKey("biomeID"))
{
BiomeGenBase biome = BiomeGenBase.getBiomeGenArray()[itemStack.getTagCompound().getInteger("biomeID")];
if (biome != null)
{
return biome.color;
}
}
}
return 16777215;
BiomeGenBase biome = this.getBiome(itemStack);
return biome == null ? 0xFFFFFF : biome.color;
}
@Override

View File

@ -0,0 +1,5 @@
{
"variants": {
"normal": { "model": "biomesoplenty:biome_block" }
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "biomesoplenty:blocks/biome_block"
}
}

View File

@ -0,0 +1,10 @@
{
"parent": "biomesoplenty:block/biome_block",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}

View File

@ -0,0 +1,18 @@
{
"parent": "builtin/generated",
"textures": {
"layer0": "biomesoplenty:items/biome_essence"
},
"display": {
"thirdperson": {
"rotation": [ -90, 0, 0 ],
"translation": [ 0, 1, -3 ],
"scale": [ 0.55, 0.55, 0.55 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B