Skip to content

Commit

Permalink
implement bonsai fruit trees, optimize some code, scooping pumpkins n…
Browse files Browse the repository at this point in the history
…ow gives seeds, chunking pumpkins now gives 4, slightly nerfed pumpkin food stats
  • Loading branch information
eerussianguy committed Jul 2, 2021
1 parent 6282f9b commit 27e48d1
Show file tree
Hide file tree
Showing 37 changed files with 1,033 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.eerussianguy.firmalife.blocks.BlockBonsai;
import com.eerussianguy.firmalife.blocks.BlockFruitDoor;
import com.eerussianguy.firmalife.blocks.BlockFruitFenceGate;
import com.eerussianguy.firmalife.blocks.BlockStemCrop;
Expand Down Expand Up @@ -149,6 +150,10 @@ public static void registerColorHandlerItems(ColorHandlerEvent.Item event)
event.getBlockColors().colorMultiplier(((ItemBlock) stack.getItem()).getBlock().getStateFromMeta(stack.getMetadata()), null, null, tintIndex),
BlocksFL.getAllFruitLeaves().toArray(new BlockFruitTreeLeaves[0])
);
itemColors.registerItemColorHandler((stack, tintIndex) ->
event.getBlockColors().colorMultiplier(((ItemBlock) stack.getItem()).getBlock().getStateFromMeta(stack.getMetadata()), null, null, tintIndex),
BlocksFL.getAllBonsai().toArray(new BlockBonsai[0])
);

itemColors.registerItemColorHandler((stack, tintIndex) ->
event.getBlockColors().colorMultiplier(((ItemBlock) stack.getItem()).getBlock().getStateFromMeta(stack.getMetadata()), null, null, tintIndex),
Expand All @@ -163,6 +168,7 @@ public static void registerColorHandlerBlocks(ColorHandlerEvent.Block event)
IBlockColor foliageColor = GrassColorHandler::computeGrassColor;

blockColors.registerBlockColorHandler(foliageColor, BlocksFL.getAllFruitLeaves().toArray(new Block[0]));
blockColors.registerBlockColorHandler(foliageColor, BlocksFL.getAllBonsai().toArray(new Block[0]));

//use vanilla stem coloring for stemcrops
for (BlockStemCrop block : BlocksFL.getAllCropBlocks())
Expand Down
142 changes: 142 additions & 0 deletions src/main/java/com/eerussianguy/firmalife/blocks/BlockBonsai.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package com.eerussianguy.firmalife.blocks;

import java.util.Random;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import com.eerussianguy.firmalife.te.TEHangingPlanter;
import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.Constants;
import net.dries007.tfc.objects.te.TETickCounter;
import net.dries007.tfc.util.Helpers;
import net.dries007.tfc.util.calendar.ICalendar;

import static com.eerussianguy.firmalife.init.StatePropertiesFL.STAGE;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class BlockBonsai extends BlockNonCube
{
protected final Supplier<? extends Item> fruit;
protected final Supplier<? extends Item> seed;
protected final long period;
protected final int tier;

public BlockBonsai(Supplier<? extends Item> fruit, Supplier<? extends Item> seed, int period, int tier, Material material)
{
super(material);
setHardness(2.0f);
setResistance(3.0f);
setLightOpacity(0);
setTickRandomly(true);
this.seed = seed;
this.fruit = fruit;
this.period = period;
this.tier = tier;
setDefaultState(getBlockState().getBaseState().withProperty(STAGE, 0));
}

@Override
@SuppressWarnings("deprecation")
public IBlockState getStateFromMeta(int meta)
{
return getDefaultState().withProperty(STAGE, meta);
}

@Override
public int getMetaFromState(IBlockState state)
{
return state.getValue(STAGE);
}

@Override
public void randomTick(World world, BlockPos pos, IBlockState state, Random random)
{
if (!world.isRemote)
{
TEHangingPlanter te = Helpers.getTE(world, pos, TEHangingPlanter.class);
int stage = state.getValue(STAGE);
if (te != null && te.isClimateValid(tier) && te.getTicksSinceUpdate() >= (ICalendar.TICKS_IN_DAY * period) && stage < 2)
{
world.setBlockState(pos, state.withProperty(STAGE, stage + 1));
te.reduceCounter(ICalendar.TICKS_IN_DAY * period);
te.markForSync();
}
}
}

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
TEHangingPlanter te = Helpers.getTE(world, pos, TEHangingPlanter.class);
if (te == null) return false;
ItemStack held = player.getHeldItem(hand);
if (held.isEmpty() && state.getValue(STAGE) == 2)
{
BlockPos spawnPos = tier == 4 ? pos.up() : pos.down(); // who let me learn to code???
Helpers.spawnItemStack(world, spawnPos, new ItemStack(fruit.get(), tier == 4 ? 3 : 1));
if (Constants.RNG.nextInt(7) == 0)
Helpers.spawnItemStack(world, spawnPos, new ItemStack(seed.get()));
world.setBlockState(pos, state.withProperty(STAGE, 0));
te.resetCounter();
return true;
}
}
return false;
}

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
TETickCounter tile = Helpers.getTE(worldIn, pos, TETickCounter.class);
if (tile != null)
{
tile.resetCounter();
}
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}

@Override
@SuppressWarnings("deprecation")
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return BlockLargePlanter.HALF_BLOCK_SHAPE;
}

@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, STAGE);
}

@Override
public boolean hasTileEntity(IBlockState state)
{
return true;
}

@Override
@Nullable
public TileEntity createTileEntity(World world, IBlockState state)
{
return new TEHangingPlanter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class BlockCheesewheel extends Block implements IItemSize
public class BlockCheesewheel extends BlockNonCube implements IItemSize
{
public static final PropertyInteger WEDGES = StatePropertiesFL.WEDGES;
public static final PropertyEnum<AgingFL> AGE = StatePropertiesFL.AGE;
Expand Down Expand Up @@ -121,32 +121,11 @@ public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Bloc
}
}

@SuppressWarnings("deprecation")
@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}

@SuppressWarnings("deprecation")
@Override
public boolean isFullCube(IBlockState state)
{
return false;
}

private boolean canBlockStay(World worldIn, BlockPos pos)
{
return worldIn.getBlockState(pos.down()).getMaterial().isSolid();
}

@SideOnly(Side.CLIENT)
@Override
public BlockRenderLayer getRenderLayer()
{
return BlockRenderLayer.CUTOUT;
}

public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random)
{
TETickCounter te = Helpers.getTE(worldIn, pos, TETickCounter.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,43 @@
package com.eerussianguy.firmalife.blocks;

import java.util.Random;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import com.eerussianguy.firmalife.init.StatePropertiesFL;
import com.eerussianguy.firmalife.te.TEHangingPlanter;
import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.Constants;
import net.dries007.tfc.api.capability.size.IItemSize;
import net.dries007.tfc.api.capability.size.Size;
import net.dries007.tfc.api.capability.size.Weight;
import net.dries007.tfc.objects.te.TETickCounter;
import net.dries007.tfc.util.Helpers;
import net.dries007.tfc.util.calendar.ICalendar;

import static com.eerussianguy.firmalife.init.StatePropertiesFL.STAGE;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class BlockHangingPlanter extends BlockNonCube implements IItemSize
public class BlockHangingPlanter extends BlockBonsai
{
public static final PropertyEnum<EnumFacing.Axis> AXIS = StatePropertiesFL.XZ;
public static final PropertyInteger STAGE = StatePropertiesFL.STAGE;

private static final AxisAlignedBB SHAPE = new AxisAlignedBB(0.0D, 0.75D, 0.0D, 1.0D, 1.0D, 1.0D);

private final Supplier<? extends Item> fruit;
private final Supplier<? extends Item> seed;

public BlockHangingPlanter(Supplier<? extends Item> fruit, Supplier<? extends Item> seed)
public BlockHangingPlanter(Supplier<? extends Item> fruit, Supplier<? extends Item> seed, int period)
{
super(Material.IRON);
setHardness(2.0f);
setResistance(3.0f);
setLightOpacity(0);
setSoundType(SoundType.METAL);
setTickRandomly(true);
this.fruit = fruit;
this.seed = seed;
super(fruit, seed, period, 0, Material.IRON);
this.setDefaultState(this.getBlockState().getBaseState().withProperty(AXIS, EnumFacing.Axis.X).withProperty(STAGE, 0));
}

@Override
@SuppressWarnings("deprecation")
@Nonnull
public IBlockState getStateFromMeta(int meta)
{
Expand All @@ -85,26 +59,16 @@ public int getMetaFromState(IBlockState state)
}

@Override
@SuppressWarnings("deprecation")
@Nonnull
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
protected BlockStateContainer createBlockState()
{
return SHAPE;
return new BlockStateContainer(this, AXIS, STAGE);
}

@Override
public void randomTick(World world, BlockPos pos, IBlockState state, Random random)
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
if (!world.isRemote)
{
TEHangingPlanter te = Helpers.getTE(world, pos, TEHangingPlanter.class);
int stage = state.getValue(STAGE);
if (te != null && te.isClimateValid() && te.getTicksSinceUpdate() >= (ICalendar.TICKS_IN_DAY * 13) && stage < 2)
{
world.setBlockState(pos, state.withProperty(STAGE, stage + 1));
te.reduceCounter(ICalendar.TICKS_IN_DAY * 10);
}
}
return SHAPE;
}

@Override
Expand All @@ -122,28 +86,6 @@ public void neighborChanged(IBlockState state, World world, BlockPos pos, Block
}
}


@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
TEHangingPlanter te = Helpers.getTE(world, pos, TEHangingPlanter.class);
if (te == null) return false;
ItemStack held = player.getHeldItem(hand);
if (held.isEmpty() && state.getValue(STAGE) == 2)
{
Helpers.spawnItemStack(world, pos.down(), new ItemStack(fruit.get()));
if (Constants.RNG.nextInt(7) == 0)
Helpers.spawnItemStack(world, pos.down(), new ItemStack(seed.get()));
world.setBlockState(pos, state.withProperty(STAGE, 0));
te.resetCounter();
return true;
}
}
return false;
}

@Override
@SuppressWarnings("deprecation")
@Nonnull
Expand All @@ -165,49 +107,4 @@ else if (block instanceof BlockHangingPlanter)
}
return getDefaultState().withProperty(AXIS, facing.getAxis());
}

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
TETickCounter tile = Helpers.getTE(worldIn, pos, TETickCounter.class);
if (tile != null)
{
tile.resetCounter();
}
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}

@Override
@Nonnull
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, AXIS, STAGE);
}

@Override
public boolean hasTileEntity(IBlockState state)
{
return true;
}

@Override
@Nullable
public TileEntity createTileEntity(World world, IBlockState state)
{
return new TEHangingPlanter();
}

@Nonnull
@Override
public Size getSize(@Nonnull ItemStack stack)
{
return Size.NORMAL;
}

@Nonnull
@Override
public Weight getWeight(@Nonnull ItemStack stack)
{
return Weight.MEDIUM;
}
}
Loading

0 comments on commit 27e48d1

Please sign in to comment.