Skip to content

Commit

Permalink
feat: fix inability of sacrificing overweight golden apples
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Dec 11, 2024
1 parent c0e448b commit 7ae5615
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class PrimordialCradleBlock extends HorizontalDirectionalBlock implements
if (item instanceof BlockItem blockItem) {
Block block = blockItem.getBlock();

if (ModsCompatHandler.getOverweightFarmingHelper().isOverweightBlock(block)) return false;

//prevent all items that have a BlockEntity associated with it from being sacrificed
// e.g. complex modded blocks such as computers, machines, containers, etc.
if (block instanceof EntityBlock) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;

public interface OverweightFarmingHelper {

boolean isOverweightBlock(Block block);

boolean canGrowOverweight(Level level, BlockPos pos, BlockState state);

void growOverweight(ServerLevel level, BlockPos pos, BlockState state, RandomSource random);

static OverweightFarmingHelper createEmpty() {
return new OverweightFarmingHelper() {
@Override
public boolean isOverweightBlock(Block block) {
return false;
}

@Override
public boolean canGrowOverweight(Level level, BlockPos pos, BlockState state) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.DripstoneUtils;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import net.orcinus.overweightfarming.blocks.CropFullBlock;
import net.orcinus.overweightfarming.init.OFBlocks;
import net.orcinus.overweightfarming.util.OverweightGrowthManager;

import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public final class OverweightFarmingIntegration {

Expand Down Expand Up @@ -56,6 +59,18 @@ static final class OverweightFarmingHelperImpl implements OverweightFarmingHelpe

private final OverweightGrowthManager growthManager = new OverweightGrowthManager(RandomSource.create());
private Set<Block> validCrops;
private Set<Block> overweightCrops;

@Override
public boolean isOverweightBlock(Block block) {
if (overweightCrops == null) {
overweightCrops = OFBlocks.BLOCKS.getEntries().stream()
.map(RegistryObject::get)
.filter(CropFullBlock.class::isInstance)
.collect(Collectors.toSet());
}
return overweightCrops.contains(block);
}

@Override
public boolean canGrowOverweight(Level level, BlockPos pos, BlockState state) {
Expand Down

0 comments on commit 7ae5615

Please sign in to comment.