Skip to content

Commit

Permalink
terra growth system refactor shared and new configs added
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Apr 5, 2024
1 parent fc6f095 commit 25af3f6
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 141 deletions.
80 changes: 49 additions & 31 deletions examples/config/cyclic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@
# Allows the dimensional Transfer Nodes to cross dimensions (no chunk loading is done, you have to do that on your own); This affects blocks cyclic:wireless_energy, cyclic:wireless_item, cyclic:wireless_fluid, cyclic:wireless_transmitter; If you change it to false it will only work if the target is in the same dimension.
wireless_transfer_dimensional = true

#Ender shelf settings
[cyclic.blocks.ender_shelf]
#Controller Max distance to search (using manhattan distance)
#Range: 1 ~ 256
controller_distance = 64
#Each shelf has five rows. Set the number of books stored per row here
#Range: 1 ~ 64
books_per_row = 64

#Ender Anchor settings
[cyclic.blocks.eye_teleport]
#Maximum distance to activate
Expand All @@ -101,6 +92,45 @@
#Range: 1 ~ 20
frequency = 5

#Ender shelf settings
[cyclic.blocks.sound]
#Sound Recorder - how far out does it listen to record sounds
#Range: 1 ~ 64
radius = 8

#battery settings
[cyclic.blocks.battery]
#RF/t charging rate for the battery item slot
#Range: 1 ~ 6400000
charge = 8000

#fisher settings
[cyclic.blocks.fisher]
#Chance to Fish from nearby water. Smaller values is slower fish
#Range: 1.0E-5 ~ 0.999
chance = 0.1
#Radius to Fish from nearby water
#Range: 1 ~ 32
radius = 12

#Ender shelf settings
[cyclic.blocks.ender_shelf]
#Controller Max distance to search (using manhattan distance)
#Range: 1 ~ 256
controller_distance = 64
#Each shelf has five rows. Set the number of books stored per row here
#Range: 1 ~ 64
books_per_row = 64

#terra_preta settings
[cyclic.blocks.terra_preta]
#ticks between growth cycles
#Range: 1 ~ 10000
timer = 100
#growth height above the soil
#Range: 2 ~ 32
height = 8

#Uncrafter settings
[cyclic.blocks.uncrafter]
#False will mean you cannot uncraft damaged repairable items. When searching for a recipe, does it ignore all NBT values (such as enchantments, RepairCost, Damage, etc). For example, if false it will not uncraft damaged or enchanted items
Expand All @@ -113,12 +143,6 @@
#RECIPE IDS HERE. Block these recipe ids from being reversed, but do not block all recipes for this output item
ignore_recipes = ["botania:cobweb", "minecraft:magma_cream", "minecraft:beacon", "minecraft:stick_from_bamboo_item", "minecraft:netherite_ingot_from_netherite_block", "mysticalagriculture:essence*", "mysticalagriculture:farmland_till", "refinedstorage:coloring_recipes*", "forcecraft:transmutation*"]

#Ender shelf settings
[cyclic.blocks.sound]
#Sound Recorder - how far out does it listen to record sounds
#Range: 1 ~ 64
radius = 8

#Ender Trigger settings
[cyclic.blocks.eye_redstone]
#Maximum distance to activate
Expand All @@ -128,12 +152,6 @@
#Range: 1 ~ 20
frequency = 5

#battery settings
[cyclic.blocks.battery]
#RF/t charging rate for the battery item slot
#Range: 1 ~ 6400000
charge = 8000

#Sprinkler settings
[cyclic.blocks.sprinkler]
#Tick rate. 20 will fire one block per second
Expand All @@ -146,21 +164,21 @@
#Range: 0 ~ 1000
water = 5

#terra_glass settings
[cyclic.blocks.terra_glass]
#ticks between growth cycles
#Range: 1 ~ 10000
timer = 100
#growth height below the glass
#Range: 0 ~ 32
height = 8

#experience_pylon settings
[cyclic.blocks.experience_pylon]
#Radius to pickup xp orbs
#Range: 1 ~ 64
radius = 16

#fisher settings
[cyclic.blocks.fisher]
#Chance to Fish from nearby water. Smaller values is slower fish
#Range: 1.0E-5 ~ 0.999
chance = 0.1
#Radius to Fish from nearby water
#Range: 1 ~ 32
radius = 12

#soundproofing settings
[cyclic.blocks.soundproofing]
#Radius of sound proofing (distance from each block that it will listen)
Expand All @@ -172,7 +190,7 @@
#####################################################################################
[cyclic.logging]
#Unblock info logs; very spammy; can be useful for testing certain issues
info = false
info = true

#####################################################################################
#Fluid cost for various machines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos
public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
int age = state.get(AGE);
if (age < MAX_AGE && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, worldIn.rand.nextInt(5) == 0)) {
worldIn.setBlockState(pos, state.with(AGE, Integer.valueOf(age + 1)), 2);
this.grow(worldIn, random, pos, state);
ForgeHooks.onCropsGrowPost(worldIn, pos, state);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.lothrazar.cyclic.base.FluidTankBase;
import com.lothrazar.cyclic.base.TileEntityBase;
import com.lothrazar.cyclic.block.terrasoil.TileTerraPreta;
import com.lothrazar.cyclic.registry.TileRegistry;
import com.lothrazar.cyclic.util.GrowthUtil;
import com.lothrazar.cyclic.util.UtilFluid;
import com.lothrazar.cyclic.util.UtilParticle;
import com.lothrazar.cyclic.util.UtilShape;
Expand Down Expand Up @@ -56,14 +56,14 @@ public void tick() {
if (shapeIndex >= shape.size()) {
shapeIndex = 0;
}
if (world.isRemote && TileTerraPreta.isValidGrow(world, shape.get(shapeIndex))) {
if (world.isRemote && GrowthUtil.isValidGrow(world, shape.get(shapeIndex))) {
UtilParticle.spawnParticle(world, ParticleTypes.FALLING_WATER, shape.get(shapeIndex), 9);
}
if (TileTerraPreta.grow(world, shape.get(shapeIndex), 1)) {
if (GrowthUtil.tryGrow(world, shape.get(shapeIndex), 1)) {
//it worked so pay
tank.drain(WATERCOST.get(), FluidAction.EXECUTE);
//run it again since sprinkler costs fluid and therefore should double what the glass and soil do
TileTerraPreta.grow(world, shape.get(shapeIndex), 1);
GrowthUtil.tryGrow(world, shape.get(shapeIndex), 1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

import com.lothrazar.cyclic.base.BlockBase;
import com.lothrazar.cyclic.base.TileEntityBase;
import com.lothrazar.cyclic.block.terrasoil.TileTerraPreta;
import com.lothrazar.cyclic.registry.TileRegistry;
import com.lothrazar.cyclic.util.GrowthUtil;
import net.minecraft.block.BlockState;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeConfigSpec.IntValue;

public class TileTerraGlass extends TileEntityBase implements ITickableTileEntity {

private static final int TIMER_FULL = TileTerraPreta.TIMER_FULL / 2;
private static final int DISTANCE = TileTerraPreta.HEIGHT / 2;
public static IntValue TIMER_FULL;
public static IntValue HEIGHT;

public TileTerraGlass() {
super(TileRegistry.TERRAGLASS.get());
super(TileRegistry.TERRA_GLASS.get());
}

@Override
Expand All @@ -28,7 +29,7 @@ public void tick() {
if (timer > 0) {
return;
}
timer = TIMER_FULL;
timer = TIMER_FULL.get();
boolean lit = this.getBlockState().get(BlockBase.LIT);
boolean newLit = canBlockSeeSky(world, pos);
if (lit != newLit) {
Expand All @@ -38,18 +39,16 @@ public void tick() {
if (!newLit) {
return;
}
for (int h = 0; h < DISTANCE; h++) {
for (int h = 0; h < HEIGHT.get(); h++) {
BlockPos current = pos.down(h);
TileTerraPreta.grow(world, current, 0.25);
GrowthUtil.tryGrow(world, current, 0.25);
}
}

private boolean canBlockSeeSky(World world, BlockPos pos) {
if (world.canSeeSky(pos)) {
return true;
}
// world.isOutsideBuildHeight(pos)
// else {
for (BlockPos blockpos1 = pos.up(); blockpos1.getY() < 256; blockpos1 = blockpos1.up()) {
if (World.isYOutOfBounds(blockpos1.getY())) {
continue;
Expand All @@ -61,7 +60,6 @@ private boolean canBlockSeeSky(World world, BlockPos pos) {
}
}
return true;
// }
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

import com.lothrazar.cyclic.base.TileEntityBase;
import com.lothrazar.cyclic.registry.TileRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.IGrowable;
import net.minecraft.tags.BlockTags;
import com.lothrazar.cyclic.util.GrowthUtil;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ForgeConfigSpec.IntValue;

public class TileTerraPreta extends TileEntityBase implements ITickableTileEntity {

public static final int TIMER_FULL = 100;
public static final int HEIGHT = 16;
public static final double ODDS_DEFAULT = 0.5;
//see: [cyclic.blocks.terra_preta]
public static IntValue TIMER_FULL;
public static IntValue HEIGHT;

public TileTerraPreta() {
super(TileRegistry.terra_preta);
Expand All @@ -27,48 +25,13 @@ public void tick() {
if (timer > 0) {
return;
}
timer = TIMER_FULL;
for (int h = 0; h < HEIGHT; h++) {
timer = TIMER_FULL.get();
for (int h = 0; h < HEIGHT.get(); h++) {
BlockPos current = this.getPos().up(h);
grow(world, current, 0.5);
GrowthUtil.tryGrow(world, current, ODDS_DEFAULT);
}
}

@SuppressWarnings("deprecation")
public static boolean grow(World world, BlockPos current, double d) {
if (!isValidGrow(world, current)) {
return false;
}
BlockState bState = world.getBlockState(current);
Block block = bState.getBlock();
if (world instanceof ServerWorld) {
try {
ServerWorld sw = (ServerWorld) world;
if (d >= 1 || world.rand.nextDouble() < d) {
block.randomTick(bState, sw, current, world.rand);
block.randomTick(bState, sw, current, world.rand);
block.randomTick(bState, sw, current, world.rand);
}
}
catch (Exception e) {
return false;
}
}
return true;
}

public static boolean isValidGrow(World world, BlockPos current) {
BlockState bState = world.getBlockState(current);
if (bState.getBlock() instanceof IGrowable) {
IGrowable crop = ((IGrowable) bState.getBlock());
if (!crop.canGrow(world, current, bState, world.isRemote) || !crop.canUseBonemeal(world, world.rand, current, bState)) {
return false; //cant grow, or cant bonemeal. no
}
}
//check tags
return bState.isIn(BlockTags.CROPS) || bState.isIn(BlockTags.SAPLINGS);
}

@Override
public void setField(int field, int value) {}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/lothrazar/cyclic/config/ConfigRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.lothrazar.cyclic.block.solidifier.TileSolidifier;
import com.lothrazar.cyclic.block.soundrecord.BlockSoundRecorder;
import com.lothrazar.cyclic.block.sprinkler.TileSprinkler;
import com.lothrazar.cyclic.block.terraglass.TileTerraGlass;
import com.lothrazar.cyclic.block.terrasoil.TileTerraPreta;
import com.lothrazar.cyclic.block.uncrafter.TileUncraft;
import com.lothrazar.cyclic.block.user.TileUser;
import com.lothrazar.cyclic.enchant.EnchantAutoSmelt;
Expand Down Expand Up @@ -232,7 +234,7 @@ private static void initConfig() {
it -> it instanceof String);
EnchantBeheading.PERCENTDROP = CFG.comment("Initial level drop rate. So level I of enchant gives this % drop chance").defineInRange("beheadingDrop", 20, 1, 100);
EnchantBeheading.PERCENTPERLEVEL = CFG.comment("Enchant level increase drop rate. % = beheadingDrop + (level-1)*beheadingPerLevel").defineInRange("beheadingPerLevel", 25, 1, 100);
EnchantGrowth.RADIUSFACTOR = CFG.comment("Radius per level. size around player to perform growth logic").defineInRange("growthRadius", 2, 1, 16);
EnchantGrowth.RADIUSFACTOR = CFG.comment("Radius per level. size around player to perform growth logic").defineInRange("growthRadius", 6, 1, 16);
CFG.pop(); //enchantment
CFG.comment(WALL, " Worldgen settings ", WALL)
.push("worldgen");
Expand Down Expand Up @@ -410,6 +412,14 @@ private static void initConfig() {
TileSprinkler.WATERCOST = CFG.comment("Water consumption").defineInRange("water", 5, 0, 1000);
TileSprinkler.TIMER_FULL = CFG.comment("Tick rate. 20 will fire one block per second").defineInRange("ticks", 20, 1, 20);
CFG.pop(); // sprinkler
CFG.comment("terra_preta settings").push("terra_preta");
TileTerraPreta.TIMER_FULL = CFG.comment("ticks between growth cycles").defineInRange("timer", 100, 1, 10000);
TileTerraPreta.HEIGHT = CFG.comment("growth height above the soil").defineInRange("height", 8, 2, 32);
CFG.pop(); // terra_preta
CFG.comment("terra_glass settings").push("terra_glass");
TileTerraGlass.TIMER_FULL = CFG.comment("ticks between growth cycles").defineInRange("timer", 100, 1, 10000);
TileTerraGlass.HEIGHT = CFG.comment("growth height below the glass").defineInRange("height", 8, 0, 32);
CFG.pop(); // terra_preta
CFG.comment("Ender Anchor settings").push("eye_teleport");
TileEyeTp.RANGE = CFG.comment("Maximum distance to activate").defineInRange("range", 128, 2, 256);
TileEyeTp.HUNGER = CFG.comment("Hunger cost on teleport").defineInRange("hunger", 1, 0, 20);
Expand Down
Loading

0 comments on commit 25af3f6

Please sign in to comment.