Skip to content

Commit

Permalink
Fix part of #1875: make the sensor work on any block with an age
Browse files Browse the repository at this point in the history
  • Loading branch information
josephcsible committed Nov 23, 2018
1 parent 1b476ea commit f359c8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
7.59:
- Joseph fixed the storage scanner double-counting the contents of double chests.
- Joseph made the sensor able to measure the growth of any block with an integer property named "age".

7.58:
- This release requires that you also upgrade all other mods that add screen modules (RFTools Control, RFTools Dimensions, Deep Resonance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.BlockNetherWart;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCreature;
Expand Down Expand Up @@ -47,6 +46,7 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

Expand Down Expand Up @@ -317,20 +317,16 @@ private Boolean checkGrowthLevelRow(BlockPos newpos, EnumFacing dir, int blockCo

private boolean checkGrowthLevel(BlockPos newpos) {
IBlockState state = getWorld().getBlockState(newpos);
Block block = state.getBlock();
int pct;
if (block instanceof BlockCrops) {
BlockCrops crops = (BlockCrops) block;
int age = crops.getAge(state);
int maxAge = crops.getMaxAge();
pct = (age * 100) / maxAge;
} else if (block instanceof BlockNetherWart) {
BlockNetherWart wart = (BlockNetherWart) block;
int age = state.getValue(BlockNetherWart.AGE);
int maxAge = 3;
pct = (age * 100) / maxAge;
} else {
pct = 0;
int pct = 0;
for (IProperty<?> property : state.getProperties().keySet()) {
if(!"age".equals(property.getName())) continue;
if(property.getValueClass() == Integer.class) {
IProperty<Integer> integerProperty = (IProperty<Integer>)property;
int age = state.getValue(integerProperty);
int maxAge = Collections.max(integerProperty.getAllowedValues());
pct = (age * 100) / maxAge;
}
break;
}
return pct >= number;
}
Expand Down

0 comments on commit f359c8f

Please sign in to comment.