diff --git a/gradle.properties b/gradle.properties index 9a4851737..d7c775e11 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ mcp_mappings=snapshot_20160525 tesla_version=1.10.2-1.2.1.41 jei_version=3.7.3.221 -ic2_version=2.6.5-ex110 +ic2_version=2.6.15-ex110 version_major=5 version_minor=2 -version_patch=5 +version_patch=6 diff --git a/src/main/java/forestry/farming/logic/CropRubber.java b/src/main/java/forestry/farming/logic/CropRubber.java index a29688870..c7a606e46 100755 --- a/src/main/java/forestry/farming/logic/CropRubber.java +++ b/src/main/java/forestry/farming/logic/CropRubber.java @@ -10,20 +10,25 @@ ******************************************************************************/ package forestry.farming.logic; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; +import java.util.Map; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableCollection; +import forestry.core.config.Constants; +import forestry.core.network.packets.PacketFXSignal; +import forestry.core.proxy.Proxies; +import forestry.core.utils.ItemStackUtil; +import forestry.plugins.compat.PluginIC2; import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import forestry.core.config.Constants; -import forestry.core.network.packets.PacketFXSignal; -import forestry.core.proxy.Proxies; -import forestry.plugins.compat.PluginIC2; - public class CropRubber extends CropDestroy { public CropRubber(World world, IBlockState blockState, BlockPos position) { @@ -34,10 +39,44 @@ public class CropRubber extends CropDestroy { * Convert a "wet" rubber log blockstate into the dry version. * Total hack since we don't have access to the blockstates. */ - private static IBlockState getReplantState(IBlockState sappyState) { - Block block = sappyState.getBlock(); - int sappyMeta = block.getMetaFromState(sappyState); - return block.getStateFromMeta(sappyMeta - 4); + private static > IBlockState getReplantState(IBlockState sappyState) { + if (hasRubberToHarvest(sappyState)) { + for (Map.Entry, Comparable> wetPropertyEntry : sappyState.getProperties().entrySet()) { + String valueWetString = wetPropertyEntry.getValue().toString(); + String valueDryString = valueWetString.replace("wet", "dry"); + IProperty property = wetPropertyEntry.getKey(); + + IBlockState baseState = sappyState.getBlock().getBlockState().getBaseState(); + IBlockState dryState = getStateWithValue(baseState, property, valueDryString); + if (dryState != null) { + return dryState; + } + } + } + + return sappyState.getBlock().getDefaultState(); + } + + public static boolean hasRubberToHarvest(IBlockState blockState) { + Block block = blockState.getBlock(); + if (ItemStackUtil.equals(block, PluginIC2.rubberWood)) { + ImmutableCollection> propertyValues = blockState.getProperties().values(); + for (Comparable propertyValue : propertyValues) { + if (propertyValue.toString().contains("wet")) { + return true; + } + } + } + return false; + } + + @Nullable + private static > IBlockState getStateWithValue(IBlockState baseState, IProperty property, String valueString) { + Optional value = property.parseValue(valueString); + if (value.isPresent()) { + return baseState.withProperty(property, value.get()); + } + return null; } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicRubber.java b/src/main/java/forestry/farming/logic/FarmLogicRubber.java index 980240410..f8e53b86a 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicRubber.java +++ b/src/main/java/forestry/farming/logic/FarmLogicRubber.java @@ -10,27 +10,22 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; -import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Stack; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - import forestry.api.farming.FarmDirection; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.core.utils.ItemStackUtil; import forestry.core.utils.Log; import forestry.plugins.compat.PluginIC2; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public class FarmLogicRubber extends FarmLogic { @@ -114,63 +109,24 @@ public class FarmLogicRubber extends FarmLogic { } private Collection getHarvestBlocks(World world, BlockPos position) { - Set seen = new HashSet<>(); Stack crops = new Stack<>(); - // Determine what type we want to harvest. - IBlockState blockState = world.getBlockState(position); - Block block = blockState.getBlock(); - if (!ItemStackUtil.equals(block, PluginIC2.rubberWood)) { - return crops; - } + for (int j = 0; j < 10; j++) { + BlockPos candidate = position.add(0, j, 0); - int meta = block.getMetaFromState(blockState); - if (meta >= 7 && meta <= 10) { - crops.push(new CropDestroy(world, blockState, position, null)); - } - - List candidates = processHarvestBlock(world, crops, seen, position); - List temp = new ArrayList<>(); - while (!candidates.isEmpty() && crops.size() < 100) { - for (BlockPos candidate : candidates) { - temp.addAll(processHarvestBlock(world, crops, seen, candidate)); + IBlockState blockState = world.getBlockState(candidate); + Block block = blockState.getBlock(); + if (!ItemStackUtil.equals(block, PluginIC2.rubberWood)) { + break; + } + + if (CropRubber.hasRubberToHarvest(blockState)) { + crops.push(new CropRubber(world, blockState, candidate)); + break; } - candidates.clear(); - candidates.addAll(temp); - temp.clear(); } return crops; } - private List processHarvestBlock(World world, Stack crops, Set seen, BlockPos position) { - List candidates = new ArrayList<>(); - - // Get additional candidates to return - for (int j = 0; j < 2; j++) { - BlockPos candidate = position.add(0, j, 0); - if (candidate.equals(position)) { - continue; - } - - // See whether the given position has already been processed - if (seen.contains(candidate)) { - continue; - } - - IBlockState blockState = world.getBlockState(candidate); - Block block = blockState.getBlock(); - if (ItemStackUtil.equals(block, PluginIC2.rubberWood)) { - int meta = block.getMetaFromState(blockState); - if (meta >= 7 && meta <= 10) { - crops.push(new CropRubber(world, blockState, candidate)); - } - candidates.add(candidate); - seen.add(candidate); - } - } - - return candidates; - } - }