Skip to content

Commit

Permalink
Added apple trees
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Jan 25, 2019
1 parent 35851d3 commit cc710b9
Show file tree
Hide file tree
Showing 23 changed files with 626 additions and 24 deletions.
45 changes: 44 additions & 1 deletion src/main/java/com/minelittlepony/unicopia/UBlocks.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package com.minelittlepony.unicopia;

import com.minelittlepony.unicopia.block.BlockAlfalfa;
import com.minelittlepony.unicopia.block.BlockFruitLeaves;
import com.minelittlepony.unicopia.block.BlockCloud;
import com.minelittlepony.unicopia.block.BlockCloudAnvil;
import com.minelittlepony.unicopia.block.BlockCloudSlab;
import com.minelittlepony.unicopia.block.BlockCloudStairs;
import com.minelittlepony.unicopia.block.BlockSugar;
import com.minelittlepony.unicopia.block.BlockTomatoPlant;
import com.minelittlepony.unicopia.block.IColourful;
import com.minelittlepony.unicopia.block.USapling;
import com.minelittlepony.unicopia.block.BlockCloudDoor;
import com.minelittlepony.unicopia.block.BlockCloudFarm;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.ColorizerFoliage;
import net.minecraft.world.biome.BiomeColorHelper;
import net.minecraft.world.gen.feature.WorldGenTrees;
import net.minecraftforge.registries.IForgeRegistry;

public class UBlocks {
Expand All @@ -33,10 +45,41 @@ public class UBlocks {

public static final Block sugar_block = new BlockSugar(Unicopia.MODID, "sugar_block");

public static final USapling apple_tree = new USapling(Unicopia.MODID, "apple_sapling")
.setTreeGen((w, s, m) -> new WorldGenTrees(true, 5, Blocks.LOG.getDefaultState(), UBlocks.apple_leaves.getDefaultState(), false));
public static final Block apple_leaves = new BlockFruitLeaves(Unicopia.MODID, "apple_leaves", apple_tree)
.setBaseGrowthChance(1200)
.setTint(0xFFEE81)
.setHarvestFruit(w -> UItems.apple.getRandomApple(w.rand, null))
.setUnharvestFruit(w -> new ItemStack(UItems.rotten_apple));

static void registerBlocks(IForgeRegistry<Block> registry) {
registry.registerAll(cloud, cloud_stairs, double_cloud_slab, cloud_slab, mist_door, anvil, cloud_farmland,
sugar_block,
alfalfa,
tomato_plant);
tomato_plant,
apple_tree, apple_leaves);
}

static void registerColors(ItemColors items, BlockColors blocks) {
items.registerItemColorHandler((stack, tint) -> {
@SuppressWarnings("deprecation")
IBlockState state = ((ItemBlock)stack.getItem()).getBlock().getStateFromMeta(stack.getMetadata());

return blocks.colorMultiplier(state, null, null, tint);
}, apple_leaves);
blocks.registerBlockColorHandler((state, world, pos, tint) -> {
Block block = state.getBlock();

if (block instanceof IColourful) {
return ((IColourful)block).getCustomTint(state, tint);
}

if (world != null && pos != null) {
return BiomeColorHelper.getFoliageColorAtPos(world, pos);
}

return ColorizerFoliage.getFoliageColorBasic();
}, apple_leaves);
}
}
31 changes: 16 additions & 15 deletions src/main/java/com/minelittlepony/unicopia/UItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.minelittlepony.unicopia.item.ItemCereal;
import com.minelittlepony.unicopia.item.ItemCloud;
import com.minelittlepony.unicopia.item.ItemCurse;
import com.minelittlepony.unicopia.item.ItemFruitLeaves;
import com.minelittlepony.unicopia.item.ItemOfHolding;
import com.minelittlepony.unicopia.item.ItemRottenApple;
import com.minelittlepony.unicopia.item.ItemSpell;
Expand All @@ -14,6 +15,7 @@
import com.minelittlepony.unicopia.item.ItemZapApple;
import com.minelittlepony.unicopia.item.UItemBlock;
import com.minelittlepony.unicopia.item.UItemMultiTexture;
import com.minelittlepony.unicopia.item.UItemDecoration;
import com.minelittlepony.unicopia.item.UItemSlab;
import com.minelittlepony.unicopia.spell.SpellRegistry;

Expand All @@ -25,7 +27,6 @@
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeedFood;
Expand Down Expand Up @@ -53,7 +54,6 @@ public class UItems {
.setSubTypes("zap_apple", "red", "green", "sweet", "sour");

public static final ItemApple rotten_apple = new ItemRottenApple(Unicopia.MODID, "rotten_apple");

public static final ItemApple cooked_zap_apple = new ItemApple(Unicopia.MODID, "cooked_zap_apple");

public static final Item cloud_matter = new Item()
Expand All @@ -73,25 +73,18 @@ public class UItems {
}, INTERACT_WITH_CLOUDS)
.setRegistryName(Unicopia.MODID, "cloud_block");

public static final Item cloud_stairs = new UItemBlock(UBlocks.cloud_stairs, INTERACT_WITH_CLOUDS)
.setTranslationKey("cloud_stairs")
.setRegistryName(Unicopia.MODID, "cloud_stairs");
public static final Item cloud_stairs = new UItemBlock(UBlocks.cloud_stairs, Unicopia.MODID, "cloud_stairs", INTERACT_WITH_CLOUDS);

public static final Item cloud_farmland = new UItemBlock(UBlocks.cloud_farmland, INTERACT_WITH_CLOUDS)
.setTranslationKey("cloud_farmland")
.setRegistryName(Unicopia.MODID, "cloud_farmland");
public static final Item cloud_farmland = new UItemBlock(UBlocks.cloud_farmland, Unicopia.MODID, "cloud_farmland", INTERACT_WITH_CLOUDS);

public static final Item anvil = new UItemBlock(UBlocks.anvil, INTERACT_WITH_CLOUDS)
.setTranslationKey("cloud_anvil")
.setRegistryName(Unicopia.MODID, "anvil");
public static final Item anvil = new UItemBlock(UBlocks.anvil, Unicopia.MODID, "anvil", INTERACT_WITH_CLOUDS)
.setTranslationKey("cloud_anvil");

public static final Item mist_door = new ItemDoor(UBlocks.mist_door)
.setTranslationKey("mist_door")
.setRegistryName(Unicopia.MODID, "mist_door");

public static final Item sugar_block = new ItemBlock(UBlocks.sugar_block)
.setTranslationKey("sugar_block")
.setRegistryName(Unicopia.MODID, "sugar_block");
public static final Item sugar_block = new UItemDecoration(UBlocks.sugar_block, Unicopia.MODID, "sugar_block");

public static final Item cloud_slab = new UItemSlab(UBlocks.cloud_slab, UBlocks.cloud_slab, UBlocks.double_cloud_slab, INTERACT_WITH_CLOUDS)
.setTranslationKey("cloud_slab")
Expand Down Expand Up @@ -122,6 +115,10 @@ public class UItems {
public static final ItemTomato cloudsdale_tomato = new ItemTomato(Unicopia.MODID, "cloudsdale_tomato", 16, 4);
public static final ItemTomatoSeeds tomato_seeds = new ItemTomatoSeeds(Unicopia.MODID, "tomato_seeds");

public static final Item apple_seeds = new UItemDecoration(UBlocks.apple_tree, Unicopia.MODID, "apple_seeds");

public static final Item apple_leaves = new ItemFruitLeaves(UBlocks.apple_leaves, Unicopia.MODID, "apple_leaves");

static void registerItems(IForgeRegistry<Item> registry) {
RegistryLockSpinner.unlock(Item.REGISTRY);

Expand All @@ -140,7 +137,9 @@ static void registerItems(IForgeRegistry<Item> registry) {
cereal, sugar_cereal, sugar_block,
rotten_apple, zap_apple, cooked_zap_apple,

cloudsdale_tomato, tomato_seeds, tomato);
cloudsdale_tomato, tomato_seeds, tomato,

apple_seeds, apple_leaves);

if (UClient.isClientSide()) {
registerAllVariants(apple, apple.getVariants());
Expand Down Expand Up @@ -168,6 +167,8 @@ static void registerItems(IForgeRegistry<Item> registry) {
registerAllVariants(tomato, "tomato", "rotten_tomato");
registerAllVariants(cloudsdale_tomato, "cloudsdale_tomato", "rotten_cloudsdale_tomato");
registerAllVariants(tomato_seeds, "tomato_seeds");
registerAllVariants(apple_seeds, "apple_seeds");
registerAllVariants(apple_leaves, "apple_leaves");

BuildInTexturesBakery.getBuiltInTextures().add(new ResourceLocation("unicopia", "items/empty_slot_gem"));
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/minelittlepony/unicopia/Unicopia.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public static void registerItemsStatic(RegistryEvent.Register<Item> event) {
@SubscribeEvent
public static void registerItemColoursStatic(ColorHandlerEvent.Item event) {
UItems.registerColors(event.getItemColors());
UBlocks.registerColors(event.getItemColors(), event.getBlockColors());
}

@SubscribeEvent
Expand Down
Loading

0 comments on commit cc710b9

Please sign in to comment.