diff --git a/build.gradle b/build.gradle index 6d7bf45..fc4a9f9 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,10 @@ minecraft { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id + // enable mixins for Jade + property 'mixin.env.remapRefMap', 'true' + property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg" + mods { "${mod_id}" { source sourceSets.main @@ -145,12 +149,14 @@ dependencies { // The userdev artifact is a special name and will get all sorts of transformations applied to it. minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - runtimeOnly fg.deobf("curse.maven:jei-238222:4574528") + runtimeOnly fg.deobf("curse.maven:jei-238222:4712868") + runtimeOnly fg.deobf("curse.maven:jade-324717:4711195") compileOnly fg.deobf("curse.maven:ftb-teams-forge-404468:4623116") compileOnly fg.deobf("maven.modrinth:argonauts:1.0.2") compileOnly fg.deobf("maven.modrinth:resourceful-lib:2.0.8") + compileOnly fg.deobf("curse.maven:ars-nouveau-401955:4683698") } jar { diff --git a/gradle.properties b/gradle.properties index da63a2f..77647ea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/net/permutated/pylons/Pylons.java b/src/main/java/net/permutated/pylons/Pylons.java index 43e9f10..5ca1eca 100644 --- a/src/main/java/net/permutated/pylons/Pylons.java +++ b/src/main/java/net/permutated/pylons/Pylons.java @@ -10,6 +10,7 @@ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.permutated.pylons.compat.harvest.HarvestCompat; import net.permutated.pylons.compat.teams.TeamCompat; import net.permutated.pylons.item.MobFilterCard; import net.permutated.pylons.item.PlayerFilterCard; @@ -44,7 +45,10 @@ public Pylons() { } public void onCommonSetupEvent(final FMLCommonSetupEvent event) { - event.enqueueWork(() -> ForgeChunkManager.setForcedChunkLoadingCallback(MODID, ChunkManager::validateTickets)); + event.enqueueWork(() -> { + ForgeChunkManager.setForcedChunkLoadingCallback(MODID, ChunkManager::validateTickets); + HarvestCompat.init(); + }); } public void onClientSetupEvent(final FMLClientSetupEvent event) { diff --git a/src/main/java/net/permutated/pylons/compat/harvest/HarvestCompat.java b/src/main/java/net/permutated/pylons/compat/harvest/HarvestCompat.java new file mode 100644 index 0000000..c0180b1 --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/harvest/HarvestCompat.java @@ -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 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()); + } + } +} diff --git a/src/main/java/net/permutated/pylons/compat/harvest/Harvestable.java b/src/main/java/net/permutated/pylons/compat/harvest/Harvestable.java new file mode 100644 index 0000000..86912ff --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/harvest/Harvestable.java @@ -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); +} diff --git a/src/main/java/net/permutated/pylons/compat/harvest/adapters/ArsNouveauSourceBerryBush.java b/src/main/java/net/permutated/pylons/compat/harvest/adapters/ArsNouveauSourceBerryBush.java new file mode 100644 index 0000000..0f0bb99 --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/harvest/adapters/ArsNouveauSourceBerryBush.java @@ -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); + } +} diff --git a/src/main/java/net/permutated/pylons/compat/harvest/adapters/MinecraftNetherWart.java b/src/main/java/net/permutated/pylons/compat/harvest/adapters/MinecraftNetherWart.java new file mode 100644 index 0000000..ae27fad --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/harvest/adapters/MinecraftNetherWart.java @@ -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); + } +} diff --git a/src/main/java/net/permutated/pylons/compat/harvest/adapters/MinecraftSweetBerryBush.java b/src/main/java/net/permutated/pylons/compat/harvest/adapters/MinecraftSweetBerryBush.java new file mode 100644 index 0000000..bfd8dcf --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/harvest/adapters/MinecraftSweetBerryBush.java @@ -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); + } +} diff --git a/src/main/java/net/permutated/pylons/machines/harvester/HarvesterPylonTile.java b/src/main/java/net/permutated/pylons/machines/harvester/HarvesterPylonTile.java index 7446e1e..c34b98b 100644 --- a/src/main/java/net/permutated/pylons/machines/harvester/HarvesterPylonTile.java +++ b/src/main/java/net/permutated/pylons/machines/harvester/HarvesterPylonTile.java @@ -15,6 +15,8 @@ import net.permutated.pylons.ConfigManager; import net.permutated.pylons.ModRegistry; import net.permutated.pylons.Pylons; +import net.permutated.pylons.compat.harvest.HarvestCompat; +import net.permutated.pylons.compat.harvest.Harvestable; import net.permutated.pylons.machines.base.AbstractPylonTile; import java.util.List; @@ -170,6 +172,34 @@ public void tick() { return; } } + } else if (HarvestCompat.hasCompat(blockState.getBlock())) { + Harvestable harvestable = HarvestCompat.getCompat(blockState.getBlock()); + if (harvestable.isHarvestable(blockState)) { + if (requiresTool()) { + if (hoeSlot == -1) { + workStatus = Status.MISSING_TOOL; + return; + } else { + ItemStack replace = itemStackHandler.getStackInSlot(hoeSlot).copy(); + if (replace.hurt(1, level.getRandom(), null)) { + replace.shrink(1); + } + itemStackHandler.setStackInSlot(hoeSlot, replace); + } + } + + ItemStack stack = harvestable.harvest(level, workPos, blockState); + if (stack.isEmpty()) { + continue; + } + + // try to insert as many drops as possible, discard the rest + boolean result = insertItemOrDiscard(itemHandler, stack); + if (!result) { + workStatus = Status.INVENTORY_FULL; + return; + } + } } } }