Skip to content

Commit

Permalink
rework particles to use the state, implement auto watering climate st…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
eerussianguy committed Jun 27, 2021
1 parent cda33fe commit 6282f9b
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public static void registerModels(ModelRegistryEvent event)
ModelLoader.setCustomModelResourceLocation(ib, 0, new ModelResourceLocation(ib.getRegistryName().toString(), "normal"));
for (BlockFruitTreeLeaves leaves : BlocksFL.getAllFruitLeaves())
ModelLoader.setCustomStateMapper(leaves, new StateMap.Builder().ignore(BlockFruitTreeLeaves.DECAYABLE).ignore(BlockFruitTreeLeaves.HARVESTABLE).build());
ModelLoader.setCustomStateMapper(BlocksFL.SPOUT, new StateMap.Builder().ignore(StatePropertiesFL.WATERED).ignore(StatePropertiesFL.NEEDS_SOURCE).build());
ModelLoader.setCustomStateMapper(BlocksFL.SPRINKLER, new StateMap.Builder().ignore(StatePropertiesFL.WATERED).ignore(StatePropertiesFL.NEEDS_SOURCE).build());

ModelLoader.setCustomModelResourceLocation(ItemsFL.CHEESECLOTH, 0, new ModelResourceLocation(ItemsFL.CHEESECLOTH.getRegistryName(), "inventory"));
ModelLoader.setCustomModelResourceLocation(ItemsFL.CRACKED_COCONUT, 0, new ModelResourceLocation(ItemsFL.CRACKED_COCONUT.getRegistryName(), "inventory"));
ModelLoader.setCustomModelResourceLocation(ItemsFL.ITEM_CINNAMON_SAPLING, 0, new ModelResourceLocation(ItemsFL.ITEM_CINNAMON_SAPLING.getRegistryName().toString()));
Expand Down
81 changes: 61 additions & 20 deletions src/main/java/com/eerussianguy/firmalife/blocks/BlockSpout.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
Expand All @@ -21,16 +23,19 @@

import com.eerussianguy.firmalife.init.StatePropertiesFL;
import com.eerussianguy.firmalife.particle.ParticlesFL;
import com.eerussianguy.firmalife.util.GreenhouseHelpers;
import com.eerussianguy.firmalife.util.HelpersFL;
import com.eerussianguy.firmalife.util.IWaterable;
import net.dries007.tfc.objects.fluids.FluidsTFC;
import net.dries007.tfc.util.Helpers;

import static com.eerussianguy.firmalife.init.StatePropertiesFL.NEEDS_SOURCE;
import static com.eerussianguy.firmalife.init.StatePropertiesFL.WATERED;

@ParametersAreNonnullByDefault
public class BlockSpout extends BlockNonCube
public class BlockSpout extends BlockNonCube implements GreenhouseHelpers.IGreenhouseReceiverBlock
{
private static final AxisAlignedBB SHAPE = new AxisAlignedBB(5.0D / 16, 7.0D / 16, 5.0D / 16, 11.0D / 16, 16.0D / 16, 11.0D / 16);

private final boolean range;

public BlockSpout(boolean range)
Expand All @@ -40,6 +45,7 @@ public BlockSpout(boolean range)
setResistance(3.0f);
setSoundType(SoundType.METAL);
setTickRandomly(true);
setDefaultState(this.blockState.getBaseState().withProperty(WATERED, false).withProperty(NEEDS_SOURCE, true));
this.range = range;
}

Expand All @@ -54,34 +60,44 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc
@Override
public void randomTick(World world, BlockPos pos, IBlockState state, Random random)
{
if (!world.isRemote && doWater(world, pos, true))
if (!world.isRemote)
{
if (range)
boolean water = doWater(world, pos, state);
world.setBlockState(pos, state.withProperty(WATERED, water));
if (water)
{
for (int x = -2; x <= 2; x++)
if (range)
{
for (int y = -1; y > -6; y--)
for (int x = -2; x <= 2; x++)
{
for (int z = -2; z <= 2; z++)
for (int y = -1; y > -6; y--)
{
BlockPos checkPos = pos.add(x, y, z);
waterPosition(world, checkPos);
for (int z = -2; z <= 2; z++)
{
BlockPos checkPos = pos.add(x, y, z);
waterPosition(world, checkPos);
}
}
}
}
}
else
{
for (int i = -1; i > -6; i--)
else
{
BlockPos checkPos = pos.add(0, i, 0);
if (waterPosition(world, checkPos)) return;
for (int i = -1; i > -6; i--)
{
BlockPos checkPos = pos.add(0, i, 0);
if (waterPosition(world, checkPos)) return;
}
}
}

}
}

@Override
public IBlockState getStateFor(IBlockState state, boolean approvalStatus, int tier)
{
return state.withProperty(NEEDS_SOURCE, !(approvalStatus && tier > 4));
}

private boolean waterPosition(World world, BlockPos checkPos)
{
TileEntity te = Helpers.getTE(world, checkPos, TileEntity.class);
Expand All @@ -99,11 +115,11 @@ private boolean waterPosition(World world, BlockPos checkPos)
@Override
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand)
{
if (doWater(world, pos, false))
if (state.getValue(WATERED))
{
if (range)
{
double speed = 0.05D * (Math.sin(world.getWorldTime()) * 2.0D - 1.0D);
double speed = MathHelper.nextDouble(rand, -0.1D, 0.1D);
for (int i = 0; i < 5; i++)
{
ParticlesFL.SPRINKLE.spawn(world, pos.getX() + 0.5D, pos.getY() + 0.25D, pos.getZ() + 0.5D, speed * HelpersFL.nextSign(rand), 0.0D, speed * HelpersFL.nextSign(rand), 130);
Expand All @@ -116,15 +132,40 @@ public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Rand
}
}

private boolean doWater(World world, BlockPos pos, boolean execute)
@Override
@Nonnull
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, WATERED, NEEDS_SOURCE);
}

@Override
@SuppressWarnings("deprecation")
@Nonnull
public IBlockState getStateFromMeta(int meta)
{
return getDefaultState().withProperty(WATERED, meta % 2 == 1).withProperty(NEEDS_SOURCE, meta > 1);
}

@Override
public int getMetaFromState(IBlockState state)
{
return (state.getValue(WATERED) ? 1 : 0) + (state.getValue(NEEDS_SOURCE) ? 2 : 0);
}

private boolean doWater(World world, BlockPos pos, IBlockState state)
{
if (!state.getValue(NEEDS_SOURCE))
{
return true;
}
TileEntity te = world.getTileEntity(pos.up());
if (te != null)
{
IFluidHandler cap = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN);
if (cap != null)
{
return cap.drain(new FluidStack(FluidsTFC.FRESH_WATER.get(), 1), execute) != null;
return cap.drain(new FluidStack(FluidsTFC.FRESH_WATER.get(), 1), true) != null;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.eerussianguy.firmalife.blocks.BlockQuadPlanter;
import com.eerussianguy.firmalife.recipe.PlanterRecipe;
import com.eerussianguy.firmalife.te.TEPlanter;
import com.eerussianguy.firmalife.util.IGreenhouseReceiver;
import net.dries007.tfc.compat.waila.interfaces.IWailaBlock;

public class PlanterProvider implements IWailaBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class StatePropertiesFL
public static final PropertyBool GROWN = PropertyBool.create("grown");
public static final PropertyBool CAN_GROW = PropertyBool.create("can_grow");
public static final PropertyBool WET = PropertyBool.create("wet");
public static final PropertyBool WATERED = PropertyBool.create("watered");
public static final PropertyBool NEEDS_SOURCE = PropertyBool.create("needs_source");
public static final PropertyBool CONNECTED = PropertyBool.create("connected");
public static final PropertyBool TOP = PropertyBool.create("top");
public static final PropertyBool GLASS = PropertyBool.create("glass");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public class BlocksFL
public static final BlockBeeNest BEE_NEST = Helpers.getNull();
@GameRegistry.ObjectHolder("spout")
public static final BlockSpout SPOUT = Helpers.getNull();
@GameRegistry.ObjectHolder("sprinkler")
public static final BlockSpout SPRINKLER = Helpers.getNull();

private static ImmutableList<ItemBlock> allIBs;
private static ImmutableList<Block> allNormalIBs = Helpers.getNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import net.minecraft.nbt.NBTTagCompound;

import com.eerussianguy.firmalife.util.IGreenhouseReceiver;
import com.eerussianguy.firmalife.util.GreenhouseHelpers;
import net.dries007.tfc.objects.te.TETickCounter;

public class TEHangingPlanter extends TETickCounter implements IGreenhouseReceiver
public class TEHangingPlanter extends TETickCounter implements GreenhouseHelpers.IGreenhouseReceiver
{
private boolean isClimateValid;

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/eerussianguy/firmalife/te/TEPlanter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.eerussianguy.firmalife.init.StatePropertiesFL;
import com.eerussianguy.firmalife.recipe.PlanterRecipe;
import com.eerussianguy.firmalife.util.GreenhouseHelpers;
import com.eerussianguy.firmalife.util.IGreenhouseReceiver;
import com.eerussianguy.firmalife.util.IWaterable;
import net.dries007.tfc.ConfigTFC;
import net.dries007.tfc.Constants;
Expand All @@ -25,7 +24,7 @@
/**
* Evil combination of TEInventory and TECropBase because I can't code
*/
public class TEPlanter extends TEInventory implements ITickable, ICalendarTickable, IWaterable, IGreenhouseReceiver
public class TEPlanter extends TEInventory implements ITickable, ICalendarTickable, IWaterable, GreenhouseHelpers.IGreenhouseReceiver
{
protected int[] stages;
private long lastUpdateTick;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eerussianguy.firmalife.util;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
Expand Down Expand Up @@ -290,6 +291,15 @@ public static void setApproval(World world, BlockPos pos, IBlockState state, Enu
{
((IGreenhouseReceiver) teFound).setValidity(approvalStatus, approvalStatus ? tier : 0);
}
else
{
IBlockState checkState = world.getBlockState(checkPos);
Block checkBlock = checkState.getBlock();
if (checkState.getBlock() instanceof IGreenhouseReceiverBlock)
{
world.setBlockState(checkPos, ((IGreenhouseReceiverBlock) checkBlock).getStateFor(checkState, approvalStatus, tier));
}
}
}
}
}
Expand Down Expand Up @@ -317,4 +327,14 @@ private static boolean packet(World world, BlockPos pos, boolean valid, boolean
}
return valid;
}

public interface IGreenhouseReceiver
{
void setValidity(boolean approvalStatus, int tier);
}

public interface IGreenhouseReceiverBlock
{
IBlockState getStateFor(IBlockState state, boolean approvalStatus, int tier);
}
}

This file was deleted.

0 comments on commit 6282f9b

Please sign in to comment.