diff --git a/src/main/java/cech12/solarcooker/config/ServerConfig.java b/src/main/java/cech12/solarcooker/config/ServerConfig.java index 600c90b..6dfb01a 100644 --- a/src/main/java/cech12/solarcooker/config/ServerConfig.java +++ b/src/main/java/cech12/solarcooker/config/ServerConfig.java @@ -15,6 +15,7 @@ public class ServerConfig { public static final ForgeConfigSpec.BooleanValue VANILLA_RECIPES_ENABLED; public static final ForgeConfigSpec.ConfigValue VANILLA_RECIPE_TYPE; public static final ForgeConfigSpec.DoubleValue COOK_TIME_FACTOR; + public static final ForgeConfigSpec.DoubleValue MAX_REFLECTOR_TIME_FACTOR; public static final ForgeConfigSpec.ConfigValue RECIPE_BLACKLIST; static { @@ -30,6 +31,9 @@ public class ServerConfig { COOK_TIME_FACTOR = builder .comment("Cook time factor of the solar cooker in relation to corresponding vanilla furnace. (i. e. 0.5 - half the time, 1.0 same time, 2.0 twice the time)") .defineInRange("cookTimeFactor", 4.0, 0.0, 100.0); + MAX_REFLECTOR_TIME_FACTOR = builder + .comment("Speed factor when all 4 reflectors are placed next to the solar cooker. (i. e. 0.5 - half the time, 1.0 same time)") + .defineInRange("maxReflectorSpeedFactor", 0.25, 0.0, 1.0); RECIPE_BLACKLIST = builder .comment("A comma separated list of all vanilla recipes that should not be used by the solar cooker. Example: \"baked_potato,baked_potato_from_smoking,othermod:other_baked_food\"") .define("recipeBlacklist", ""); diff --git a/src/main/java/cech12/solarcooker/tileentity/AbstractSolarCookerTileEntity.java b/src/main/java/cech12/solarcooker/tileentity/AbstractSolarCookerTileEntity.java index 4ed7aa1..26c92a4 100644 --- a/src/main/java/cech12/solarcooker/tileentity/AbstractSolarCookerTileEntity.java +++ b/src/main/java/cech12/solarcooker/tileentity/AbstractSolarCookerTileEntity.java @@ -1,5 +1,7 @@ package cech12.solarcooker.tileentity; +import cech12.solarcooker.block.AbstractSolarCookerBlock; +import cech12.solarcooker.block.ReflectorBlock; import cech12.solarcooker.block.SolarCookerBlock; import cech12.solarcooker.config.ServerConfig; import com.google.common.collect.Lists; @@ -30,6 +32,7 @@ import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvents; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; @@ -61,8 +64,10 @@ public abstract class AbstractSolarCookerTileEntity extends LockableTileEntity i protected float lidAngle; /** The angle of the lid last tick */ protected float prevLidAngle; - /** The number of players currently using this chest */ + /** The number of players currently using this cooker */ protected int numPlayersUsing; + /** The number of reflectors next to the cooker */ + protected int reflectorCount = 0; protected final IRecipeType specificRecipeType; private final Object2IntOpenHashMap usedRecipes = new Object2IntOpenHashMap<>(); @@ -295,10 +300,13 @@ protected int getRecipeCookTime() { AbstractCookingRecipe rec = getRecipe(); if (rec == null) { return 200; - } else if (this.specificRecipeType.getClass().isInstance(rec.getType())) { - return rec.getCookTime(); } - return (int) (rec.getCookTime() * ServerConfig.COOK_TIME_FACTOR.get()); + this.checkForReflectors(); + double reflectorFactor = (this.reflectorCount > 0) ? 1 - ((1 - ServerConfig.MAX_REFLECTOR_TIME_FACTOR.get()) / 4.0D) * this.reflectorCount : 1; + if (this.specificRecipeType.getClass().isInstance(rec.getType())) { + return (int) (rec.getCookTime() * reflectorFactor); + } + return (int) (rec.getCookTime() * (ServerConfig.COOK_TIME_FACTOR.get() * reflectorFactor)); } @SuppressWarnings("unchecked") @@ -327,6 +335,33 @@ protected AbstractCookingRecipe getRecipe() { } } + private void checkForReflectors() { + this.reflectorCount = 0; + if (this.world != null) { + BlockState state = this.world.getBlockState(this.pos); + if (state.getBlock() instanceof AbstractSolarCookerBlock) { + Direction facing = state.get(AbstractSolarCookerBlock.FACING); + this.reflectorCount += countReflectorsOnSide(facing.rotateY()); + this.reflectorCount += countReflectorsOnSide(facing.rotateYCCW()); + } + } + } + + private int countReflectorsOnSide(Direction direction) { + int count = 0; + if (this.world != null) { + BlockPos blockPos = this.pos.offset(direction); + for (BlockPos position : new BlockPos[] {blockPos, blockPos.up()}) { + BlockState state = this.world.getBlockState(position); + if (state.getBlock() instanceof ReflectorBlock + && state.get(ReflectorBlock.HORIZONTAL_FACING) == direction.getOpposite()) { + count++; + } + } + } + return count; + } + @Override @Nonnull public int[] getSlotsForFace(@Nonnull Direction side) {