Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ repositories {
flatDir {
dir 'libs'
}
maven {
name = 'ModKit'
url 'https://jitpack.io'
content { includeGroup 'com.github.thedarkcolour' }
}
}

dependencies {
Expand Down Expand Up @@ -167,6 +172,9 @@ dependencies {
implementation fg.deobf("curse.maven:pams-harvestcraft-2-crops-361385:4687624")
implementation fg.deobf("curse.maven:pams-harvestcraft-2-pams-harvestcraft-2-trees-365460:4625518")
implementation fg.deobf("curse.maven:pams-harvestcraft-2-food-extended-402231:4606448")
implementation fg.deobf("curse.maven:forestry-community-edition-1056828:6085417")
implementation fg.deobf("curse.maven:gendustry-community-edition-1179084:6089265")
implementation fg.deobf('com.github.thedarkcolour:ModKit:0302f9aa42')
}

def resourceTargets = ['META-INF/mods.toml', 'pack.mcmeta']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cy.jdkdigital.productivetrees.integrations.forestry;

import net.minecraft.resources.ResourceLocation;

import forestry.api.plugin.IForestryPlugin;
import forestry.api.plugin.IPollenRegistration;

import cy.jdkdigital.productivetrees.ProductiveTrees;

public class ProductiveTreesForestryPlugin implements IForestryPlugin {
public static final ResourceLocation ID = new ResourceLocation(ProductiveTrees.MODID, "plugin");

@Override
public ResourceLocation id() {
return ID;
}

@Override
public void registerPollen(IPollenRegistration pollen) {
pollen.registerPollenType(new ProductiveTreesPollenType());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package cy.jdkdigital.productivetrees.integrations.forestry;

import net.minecraft.core.BlockPos;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.BlockState;

import forestry.api.genetics.pollen.IPollen;
import forestry.api.genetics.pollen.IPollenType;

import cy.jdkdigital.productivetrees.ProductiveTrees;
import cy.jdkdigital.productivetrees.common.block.ProductiveLeavesBlock;
import cy.jdkdigital.productivetrees.registry.TreeFinder;
import cy.jdkdigital.productivetrees.registry.TreeObject;
import cy.jdkdigital.productivetrees.registry.TreeRegistrator;
import cy.jdkdigital.productivetrees.util.TreeUtil;
import org.jetbrains.annotations.Nullable;

class ProductiveTreesPollenType implements IPollenType<TreeObject> {
public static final ResourceLocation ID = new ResourceLocation(ProductiveTrees.MODID, "pollen");

@Override
public ResourceLocation id() {
return ID;
}

@Override
public boolean canPollinate(LevelAccessor level, BlockPos pos, @Nullable Object pollinator) {
return level.getBlockState(pos).getBlock() instanceof ProductiveLeavesBlock;
}

@Nullable
@Override
public IPollen<TreeObject> tryCollectPollen(LevelAccessor level, BlockPos pos, @Nullable Object pollinator) {
if (level.getBlockState(pos).getBlock() instanceof ProductiveLeavesBlock leaves) {
return new Pollen(leaves.getTree());
}

return null;
}

@Override
public boolean tryPollinate(LevelAccessor levelAccessor, BlockPos pos, TreeObject tree, @Nullable Object pollinator) {
BlockState state = levelAccessor.getBlockState(pos);
if (levelAccessor instanceof Level level && state.is(BlockTags.LEAVES) && !state.is(TreeRegistrator.POLLINATED_LEAVES.get())) {
TreeUtil.tryPollinatePosition(level, pos, TreeUtil.getBlock(tree.getId(), "_leaves"));
}
return false;
}

@Override
public IPollen<TreeObject> readNbt(Tag nbt) {
if (nbt instanceof StringTag string) {
return new Pollen(TreeFinder.trees.get(ResourceLocation.tryParse(string.getAsString())));
}

return null;
}

private class Pollen implements IPollen<TreeObject> {
private final TreeObject tree;

private Pollen(TreeObject tree) {
this.tree = tree;
}

@Override
public IPollenType<TreeObject> getType() {
return ProductiveTreesPollenType.this;
}

@Override
public TreeObject getPollen() {
return this.tree;
}

@Nullable
@Override
public Tag writeNbt() {
return StringTag.valueOf(this.tree.getId().toString());
}

@Override
public ItemStack createStack() {
return TreeUtil.getPollen(TreeUtil.getBlock(this.tree.getId(), "_leaves"));
}
}
}
21 changes: 21 additions & 0 deletions src/main/java/cy/jdkdigital/productivetrees/util/TreeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import cy.jdkdigital.productivetrees.common.block.ProductiveLogBlock;
import cy.jdkdigital.productivetrees.common.block.ProductiveSaplingBlock;
import cy.jdkdigital.productivetrees.common.block.ProductiveWoodBlock;
import cy.jdkdigital.productivetrees.common.block.entity.PollinatedLeavesBlockEntity;
import cy.jdkdigital.productivetrees.common.block.entity.StripperBlockEntity;
import cy.jdkdigital.productivetrees.recipe.RecipeHelper;
import cy.jdkdigital.productivetrees.recipe.SawmillRecipe;
import cy.jdkdigital.productivetrees.registry.TreeFinder;
import cy.jdkdigital.productivetrees.registry.TreeObject;
Expand All @@ -31,6 +33,8 @@
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.LevelEvent;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.ToolActions;
Expand Down Expand Up @@ -258,4 +262,21 @@ public static Block getBlock(ResourceLocation tree, String name) {
public static TreeObject getTree(Block block) {
return TreeFinder.trees.get(ForgeRegistries.BLOCKS.getKey(block).withPath(p -> p.replace("_log", "").replace("_wood", "").replace("_sapling", "").replace("_leaves", "")));
}

public static boolean tryPollinatePosition(Level level, BlockPos pos, Block leafB) {
BlockState state = level.getBlockState(pos);
var recipe = RecipeHelper.getPollinationRecipe(level, state, leafB.defaultBlockState());
if (recipe != null) {
level.setBlock(pos, TreeRegistrator.POLLINATED_LEAVES.get().defaultBlockState(), Block.UPDATE_ALL);
if (level.getBlockEntity(pos) instanceof PollinatedLeavesBlockEntity leaves) {
leaves.setLeafA(state.getBlock());
leaves.setLeafB(leafB);
leaves.setResult(recipe.result);
leaves.setChanged();
level.levelEvent(LevelEvent.PARTICLES_PLANT_GROWTH, pos, 0);
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cy.jdkdigital.productivetrees.integrations.forestry.ProductiveTreesForestryPlugin