-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add harvest compatibility for non-crops
- Loading branch information
1 parent
fffb993
commit fba5536
Showing
9 changed files
with
178 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ minecraft_version=1.20.1 | |
forge_version=47.1.0 | ||
group=net.permutated | ||
mod_id=pylons | ||
version=4.1.0 | ||
version=4.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/net/permutated/pylons/compat/harvest/HarvestCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.permutated.pylons.compat.harvest; | ||
|
||
import net.minecraft.world.level.block.Block; | ||
import net.minecraftforge.fml.ModList; | ||
import net.permutated.pylons.compat.harvest.adapters.ArsNouveauSourceBerryBush; | ||
import net.permutated.pylons.compat.harvest.adapters.MinecraftNetherWart; | ||
import net.permutated.pylons.compat.harvest.adapters.MinecraftSweetBerryBush; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class HarvestCompat { | ||
private static final Map<Block, Harvestable> compat = new ConcurrentHashMap<>(); | ||
|
||
private HarvestCompat() { | ||
// nothing to do | ||
} | ||
|
||
private static void register(Harvestable harvestable) { | ||
compat.put(harvestable.getBlock(), harvestable); | ||
} | ||
|
||
public static Harvestable getCompat(Block block) { | ||
return compat.get(block); | ||
} | ||
|
||
public static boolean hasCompat(Block block) { | ||
return compat.containsKey(block); | ||
} | ||
|
||
// FMLCommonSetupEvent | ||
public static void init() { | ||
register(new MinecraftNetherWart()); | ||
register(new MinecraftSweetBerryBush()); | ||
if (ModList.get().isLoaded("ars_nouveau")) { | ||
register(new ArsNouveauSourceBerryBush()); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/net/permutated/pylons/compat/harvest/Harvestable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package net.permutated.pylons.compat.harvest; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public interface Harvestable { | ||
Block getBlock(); | ||
boolean isHarvestable(BlockState blockState); | ||
ItemStack harvest(Level level, BlockPos blockPos, BlockState blockState); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/net/permutated/pylons/compat/harvest/adapters/ArsNouveauSourceBerryBush.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.permutated.pylons.compat.harvest.adapters; | ||
|
||
import com.hollingsworth.arsnouveau.common.block.SourceBerryBush; | ||
import com.hollingsworth.arsnouveau.setup.registry.BlockRegistry; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.permutated.pylons.compat.harvest.Harvestable; | ||
|
||
public class ArsNouveauSourceBerryBush implements Harvestable { | ||
public Block getBlock() { | ||
return BlockRegistry.SOURCEBERRY_BUSH.get(); | ||
} | ||
|
||
public boolean isHarvestable(BlockState blockState) { | ||
return blockState.getValue(SourceBerryBush.AGE) == 3; | ||
} | ||
|
||
public ItemStack harvest(Level level, BlockPos blockPos, BlockState blockState) { | ||
level.setBlock(blockPos, blockState.setValue(SourceBerryBush.AGE, 1), Block.UPDATE_CLIENTS); | ||
return new ItemStack(BlockRegistry.SOURCEBERRY_BUSH, 2); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/net/permutated/pylons/compat/harvest/adapters/MinecraftNetherWart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.permutated.pylons.compat.harvest.adapters; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.NetherWartBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.permutated.pylons.compat.harvest.Harvestable; | ||
|
||
public class MinecraftNetherWart implements Harvestable { | ||
@Override | ||
public Block getBlock() { | ||
return Blocks.NETHER_WART; | ||
} | ||
|
||
@Override | ||
public boolean isHarvestable(BlockState blockState) { | ||
return blockState.getValue(NetherWartBlock.AGE) == 3; | ||
} | ||
|
||
@Override | ||
public ItemStack harvest(Level level, BlockPos blockPos, BlockState blockState) { | ||
level.setBlock(blockPos, blockState.setValue(NetherWartBlock.AGE, 0), Block.UPDATE_CLIENTS); | ||
return new ItemStack(Items.NETHER_WART, 3); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/net/permutated/pylons/compat/harvest/adapters/MinecraftSweetBerryBush.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.permutated.pylons.compat.harvest.adapters; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.SweetBerryBushBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.permutated.pylons.compat.harvest.Harvestable; | ||
|
||
public class MinecraftSweetBerryBush implements Harvestable { | ||
@Override | ||
public Block getBlock() { | ||
return Blocks.SWEET_BERRY_BUSH; | ||
} | ||
|
||
@Override | ||
public boolean isHarvestable(BlockState blockState) { | ||
return blockState.getValue(SweetBerryBushBlock.AGE) == 3; | ||
} | ||
|
||
@Override | ||
public ItemStack harvest(Level level, BlockPos blockPos, BlockState blockState) { | ||
level.setBlock(blockPos, blockState.setValue(SweetBerryBushBlock.AGE, 1), Block.UPDATE_CLIENTS); | ||
return new ItemStack(Items.SWEET_BERRIES, 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters