Skip to content

Commit

Permalink
Reflectors are now detected by the Solar Cooker #8
Browse files Browse the repository at this point in the history
  • Loading branch information
cech12 committed Jan 20, 2021
1 parent 2335bd5 commit 56fcee2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/java/cech12/solarcooker/config/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ServerConfig {
public static final ForgeConfigSpec.BooleanValue VANILLA_RECIPES_ENABLED;
public static final ForgeConfigSpec.ConfigValue<String> 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<String> RECIPE_BLACKLIST;

static {
Expand All @@ -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", "");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<? extends AbstractCookingRecipe> specificRecipeType;
private final Object2IntOpenHashMap<ResourceLocation> usedRecipes = new Object2IntOpenHashMap<>();
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 56fcee2

Please sign in to comment.