Add cherries
This commit is contained in:
parent
574b1dd2a0
commit
4b464a39f9
3 changed files with 58 additions and 3 deletions
|
@ -1,5 +1,9 @@
|
||||||
package net.universe_factory.minecraft.test;
|
package net.universe_factory.minecraft.test;
|
||||||
|
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemFood;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.terraingen.BiomeEvent.CreateDecorator;
|
import net.minecraftforge.event.terraingen.BiomeEvent.CreateDecorator;
|
||||||
import net.universe_factory.minecraft.test.generic.GenericWood;
|
import net.universe_factory.minecraft.test.generic.GenericWood;
|
||||||
|
@ -8,6 +12,7 @@ import cpw.mods.fml.common.Mod.EventHandler;
|
||||||
import cpw.mods.fml.common.Mod.Instance;
|
import cpw.mods.fml.common.Mod.Instance;
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
@Mod(modid = Test.MODID, version = Test.VERSION)
|
@Mod(modid = Test.MODID, version = Test.VERSION)
|
||||||
public class Test {
|
public class Test {
|
||||||
|
@ -17,7 +22,8 @@ public class Test {
|
||||||
@Instance(value = MODID)
|
@Instance(value = MODID)
|
||||||
public static Test instance;
|
public static Test instance;
|
||||||
|
|
||||||
public static final GenericWood cherry = new GenericWood(new GenericWood.Info() {
|
public static final Item cherries = new ItemFood(2, 0.2f, false).setTextureName(MODID + ":cherries").setUnlocalizedName("cherries");
|
||||||
|
public static final GenericWood cherryTree = new GenericWood(new GenericWood.Info() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Cherry";
|
return "Cherry";
|
||||||
|
@ -27,19 +33,38 @@ public class Test {
|
||||||
public int getMinTreeHeight() {
|
public int getMinTreeHeight() {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getDrop(World world, int x, int y, int z, int meta, int fortune) {
|
||||||
|
int chance = 30;
|
||||||
|
|
||||||
|
if (fortune > 0) {
|
||||||
|
chance -= 2 << fortune;
|
||||||
|
|
||||||
|
if (chance < 5)
|
||||||
|
chance = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world.rand.nextInt(chance) == 0)
|
||||||
|
return new ItemStack(cherries, 1);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preInit(FMLInitializationEvent event) {
|
public void preInit(FMLInitializationEvent event) {
|
||||||
MinecraftForge.TERRAIN_GEN_BUS.register(new TerrainGenHandler());
|
MinecraftForge.TERRAIN_GEN_BUS.register(new TerrainGenHandler());
|
||||||
|
|
||||||
cherry.register();
|
GameRegistry.registerItem(cherries, "cherries");
|
||||||
|
|
||||||
|
cherryTree.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TerrainGenHandler {
|
public class TerrainGenHandler {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void handleCreateDecorator(CreateDecorator event) {
|
public void handleCreateDecorator(CreateDecorator event) {
|
||||||
event.newBiomeDecorator = new TestBiomeDecorator(cherry);
|
event.newBiomeDecorator = new TestBiomeDecorator(cherryTree);
|
||||||
|
|
||||||
event.newBiomeDecorator.bigMushroomsPerChunk = event.originalBiomeDecorator.bigMushroomsPerChunk;
|
event.newBiomeDecorator.bigMushroomsPerChunk = event.originalBiomeDecorator.bigMushroomsPerChunk;
|
||||||
event.newBiomeDecorator.cactiPerChunk = event.originalBiomeDecorator.cactiPerChunk;
|
event.newBiomeDecorator.cactiPerChunk = event.originalBiomeDecorator.cactiPerChunk;
|
||||||
|
|
|
@ -206,6 +206,30 @@ public class GenericWood {
|
||||||
// / 9 & 255;
|
// / 9 & 255;
|
||||||
return 0xffffff;
|
return 0xffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dropBlockAsItemWithChance(World world, int x, int y, int z, int meta, float p, int fortune) {
|
||||||
|
if (!world.isRemote) {
|
||||||
|
int j1 = this.func_150123_b(meta);
|
||||||
|
|
||||||
|
if (fortune > 0) {
|
||||||
|
j1 -= 2 << fortune;
|
||||||
|
|
||||||
|
if (j1 < 10) {
|
||||||
|
j1 = 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world.rand.nextInt(j1) == 0) {
|
||||||
|
Item item = this.getItemDropped(meta, world.rand, fortune);
|
||||||
|
this.dropBlockAsItem(world, x, y, z, new ItemStack(item, 1, this.damageDropped(meta)));
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack drop = info.getDrop(world, x, y, z, meta, fortune);
|
||||||
|
if (drop != null)
|
||||||
|
this.dropBlockAsItem(world, x, y, z, drop);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Sapling extends BlockSapling {
|
private class Sapling extends BlockSapling {
|
||||||
|
@ -317,5 +341,9 @@ public class GenericWood {
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
public abstract int getMinTreeHeight();
|
public abstract int getMinTreeHeight();
|
||||||
|
|
||||||
|
public ItemStack getDrop(World world, int x, int y, int z, int meta, int fortune) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
item.cherries.name=Cherries
|
||||||
|
|
||||||
tile.woodCherry.name=Cherry Tree Wood Planks
|
tile.woodCherry.name=Cherry Tree Wood Planks
|
||||||
tile.logCherry.name=Cherry Tree Wood
|
tile.logCherry.name=Cherry Tree Wood
|
||||||
tile.leavesCherry.name=Cherry Tree Leaves
|
tile.leavesCherry.name=Cherry Tree Leaves
|
||||||
|
|
Reference in a new issue