-
Notifications
You must be signed in to change notification settings - Fork 0
Fix Tree Farm logic #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Binary file not shown.
This file contains hidden or 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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/github/gtexpert/gtbm/integration/forestry/farming/FarmLogicCEu.java
This file contains hidden or 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 com.github.gtexpert.gtbm.integration.forestry.farming; | ||
|
|
||
| import net.minecraft.item.ItemStack; | ||
|
|
||
| import gregtech.common.blocks.MetaBlocks; | ||
|
|
||
| import forestry.api.farming.IFarmProperties; | ||
| import forestry.farming.logic.FarmLogicArboreal; | ||
|
|
||
| public class FarmLogicCEu extends FarmLogicArboreal { | ||
|
|
||
| public FarmLogicCEu(IFarmProperties properties, boolean isManual) { | ||
| super(properties, isManual); | ||
| } | ||
|
|
||
| @Override | ||
| public String getUnlocalizedName() { | ||
| return "gtbm.farm.ceu"; | ||
| } | ||
|
|
||
| @Override | ||
| public ItemStack getIconItemStack() { | ||
| return new ItemStack(MetaBlocks.RUBBER_SAPLING); | ||
| } | ||
| } |
93 changes: 93 additions & 0 deletions
93
...main/java/com/github/gtexpert/gtbm/integration/forestry/farming/FarmableGTCEuSapling.java
This file contains hidden or 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,93 @@ | ||
| package com.github.gtexpert.gtbm.integration.forestry.farming; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import net.minecraft.block.Block; | ||
| import net.minecraft.block.state.IBlockState; | ||
| import net.minecraft.entity.player.EntityPlayer; | ||
| import net.minecraft.init.Blocks; | ||
| import net.minecraft.item.ItemStack; | ||
| import net.minecraft.util.EnumActionResult; | ||
| import net.minecraft.util.EnumFacing; | ||
| import net.minecraft.util.EnumHand; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraft.world.World; | ||
|
|
||
| import forestry.api.farming.ICrop; | ||
| import forestry.api.farming.IFarmable; | ||
| import forestry.api.farming.IFarmableInfo; | ||
| import forestry.core.network.packets.PacketFXSignal; | ||
| import forestry.core.utils.NetworkUtil; | ||
| import forestry.farming.logic.crops.CropDestroy; | ||
|
|
||
| public class FarmableGTCEuSapling implements IFarmable { | ||
|
|
||
| private final Block saplingBlock; | ||
| private final ItemStack germling; | ||
| private final ItemStack[] windfall; | ||
|
|
||
| public FarmableGTCEuSapling(Block saplingBlock, ItemStack[] windfall) { | ||
| this.saplingBlock = saplingBlock; | ||
| this.germling = new ItemStack(saplingBlock); | ||
| this.windfall = windfall; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { | ||
| return blockState.getBlock() == saplingBlock; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { | ||
| Block block = blockState.getBlock(); | ||
| if (!block.isWood(world, pos)) { | ||
| return null; | ||
| } | ||
| return new CropDestroy(world, blockState, pos); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isGermling(ItemStack itemstack) { | ||
| return ItemStack.areItemsEqual(germling, itemstack); | ||
| } | ||
|
|
||
| @Override | ||
| public void addInformation(IFarmableInfo info) { | ||
| info.addGermlings(Collections.singletonList(germling)); | ||
| info.addProducts(windfall); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isWindfall(ItemStack itemstack) { | ||
| for (ItemStack drop : windfall) { | ||
| if (drop.isItemEqual(itemstack)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { | ||
| ItemStack originalHeldItem = player.getHeldItem(EnumHand.MAIN_HAND); | ||
| try { | ||
| ItemStack copy = germling.copy(); | ||
| player.setHeldItem(EnumHand.MAIN_HAND, copy); | ||
| EnumActionResult result = copy.onItemUse(player, world, pos.down(), | ||
| EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0); | ||
| if (result == EnumActionResult.SUCCESS) { | ||
| PacketFXSignal packet = new PacketFXSignal( | ||
| PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, | ||
| Blocks.SAPLING.getDefaultState()); | ||
| NetworkUtil.sendNetworkPacket(packet, pos, world); | ||
| return true; | ||
| } | ||
| return false; | ||
| } finally { | ||
| player.setHeldItem(EnumHand.MAIN_HAND, originalHeldItem); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/github/gtexpert/gtbm/integration/forestry/util/ForestryFarmHelper.java
This file contains hidden or 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,37 @@ | ||
| package com.github.gtexpert.gtbm.integration.forestry.util; | ||
|
|
||
| import java.util.function.BiFunction; | ||
|
|
||
| import net.minecraft.init.Blocks; | ||
| import net.minecraft.item.ItemStack; | ||
|
|
||
| import forestry.api.circuits.ChipsetManager; | ||
| import forestry.api.circuits.ICircuitLayout; | ||
| import forestry.api.core.ForestryAPI; | ||
| import forestry.api.farming.IFarmLogic; | ||
| import forestry.api.farming.IFarmProperties; | ||
| import forestry.core.ModuleCore; | ||
| import forestry.core.items.EnumElectronTube; | ||
| import forestry.farming.circuits.CircuitFarmLogic; | ||
|
|
||
| public class ForestryFarmHelper { | ||
|
|
||
| public static IFarmProperties registerFarmType(String farmId, | ||
| BiFunction<IFarmProperties, Boolean, IFarmLogic> logicFactory, | ||
| EnumElectronTube tube) { | ||
| IFarmProperties farm = ForestryAPI.farmRegistry.registerLogic(farmId, logicFactory); | ||
| farm.registerSoil(new ItemStack(Blocks.DIRT), ModuleCore.getBlocks().humus.getDefaultState()); | ||
|
|
||
| CircuitFarmLogic managed = new CircuitFarmLogic("managed." + farmId, farm, false); | ||
| CircuitFarmLogic manual = new CircuitFarmLogic("manual." + farmId, farm, true); | ||
|
|
||
| ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed"); | ||
| ICircuitLayout layoutManual = ChipsetManager.circuitRegistry.getLayout("forestry.farms.manual"); | ||
| ItemStack tubeStack = ModuleCore.getItems().tubes.get(tube, 1); | ||
|
|
||
| ChipsetManager.solderManager.addRecipe(layoutManaged, tubeStack, managed); | ||
| ChipsetManager.solderManager.addRecipe(layoutManual, tubeStack, manual); | ||
|
|
||
| return farm; | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/github/gtexpert/gtbm/integration/gtfo/farming/FarmLogicGTFO.java
This file contains hidden or 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,24 @@ | ||
| package com.github.gtexpert.gtbm.integration.gtfo.farming; | ||
|
|
||
| import net.minecraft.init.Blocks; | ||
| import net.minecraft.item.ItemStack; | ||
|
|
||
| import forestry.api.farming.IFarmProperties; | ||
| import forestry.farming.logic.FarmLogicArboreal; | ||
|
|
||
| public class FarmLogicGTFO extends FarmLogicArboreal { | ||
|
|
||
| public FarmLogicGTFO(IFarmProperties properties, boolean isManual) { | ||
| super(properties, isManual); | ||
| } | ||
|
|
||
| @Override | ||
| public String getUnlocalizedName() { | ||
| return "gtbm.farm.gtfo"; | ||
| } | ||
|
|
||
| @Override | ||
| public ItemStack getIconItemStack() { | ||
| return new ItemStack(Blocks.SAPLING); | ||
| } | ||
| } |
93 changes: 93 additions & 0 deletions
93
src/main/java/com/github/gtexpert/gtbm/integration/gtfo/farming/FarmableGTFOSapling.java
This file contains hidden or 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,93 @@ | ||
| package com.github.gtexpert.gtbm.integration.gtfo.farming; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import net.minecraft.block.Block; | ||
| import net.minecraft.block.state.IBlockState; | ||
| import net.minecraft.entity.player.EntityPlayer; | ||
| import net.minecraft.init.Blocks; | ||
| import net.minecraft.item.ItemStack; | ||
| import net.minecraft.util.EnumActionResult; | ||
| import net.minecraft.util.EnumFacing; | ||
| import net.minecraft.util.EnumHand; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraft.world.World; | ||
|
|
||
| import forestry.api.farming.ICrop; | ||
| import forestry.api.farming.IFarmable; | ||
| import forestry.api.farming.IFarmableInfo; | ||
| import forestry.core.network.packets.PacketFXSignal; | ||
| import forestry.core.utils.NetworkUtil; | ||
| import forestry.farming.logic.crops.CropDestroy; | ||
|
|
||
| public class FarmableGTFOSapling implements IFarmable { | ||
|
|
||
| private final Block saplingBlock; | ||
| private final ItemStack germling; | ||
| private final ItemStack[] windfall; | ||
|
|
||
| public FarmableGTFOSapling(Block saplingBlock, int itemDamage, ItemStack[] windfall) { | ||
| this.saplingBlock = saplingBlock; | ||
| this.germling = new ItemStack(saplingBlock, 1, itemDamage); | ||
| this.windfall = windfall; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { | ||
| return blockState.getBlock() == saplingBlock; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { | ||
| Block block = blockState.getBlock(); | ||
| if (!block.isWood(world, pos)) { | ||
| return null; | ||
| } | ||
| return new CropDestroy(world, blockState, pos); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isGermling(ItemStack itemstack) { | ||
| return ItemStack.areItemsEqual(germling, itemstack); | ||
| } | ||
|
|
||
| @Override | ||
| public void addInformation(IFarmableInfo info) { | ||
| info.addGermlings(Collections.singletonList(germling)); | ||
| info.addProducts(windfall); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isWindfall(ItemStack itemstack) { | ||
| for (ItemStack drop : windfall) { | ||
| if (drop.isItemEqual(itemstack)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { | ||
| ItemStack originalHeldItem = player.getHeldItem(EnumHand.MAIN_HAND); | ||
| try { | ||
| ItemStack copy = germling.copy(); | ||
| player.setHeldItem(EnumHand.MAIN_HAND, copy); | ||
| EnumActionResult result = copy.onItemUse(player, world, pos.down(), | ||
| EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0); | ||
| if (result == EnumActionResult.SUCCESS) { | ||
| PacketFXSignal packet = new PacketFXSignal( | ||
| PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, | ||
| Blocks.SAPLING.getDefaultState()); | ||
| NetworkUtil.sendNetworkPacket(packet, pos, world); | ||
| return true; | ||
| } | ||
| return false; | ||
| } finally { | ||
| player.setHeldItem(EnumHand.MAIN_HAND, originalHeldItem); | ||
| } | ||
| } | ||
tier940 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.