Skip to content

Commit

Permalink
Implement right-click functionality for crops (#40)
Browse files Browse the repository at this point in the history
* Implement right-click for crops

* Use the EnchantmentHelper instead of iteration

* spotless...
  • Loading branch information
Ethryan authored Aug 9, 2024
1 parent a047018 commit 01525d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 4 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Add your dependencies here

dependencies {
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.56:dev') {transitive=false}
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.140:dev') {transitive=false}

compile('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev')
compile('com.github.GTNewHorizons:CodeChickenLib:1.2.1:dev')
compile('com.github.GTNewHorizons:CodeChickenLib:1.3.0:dev')
compile('com.github.GTNewHorizons:DummyCore:1.19.0:dev')
runtimeOnly("com.github.GTNewHorizons:NotEnoughItems:2.6.11-GTNH:dev")
runtimeOnly("com.github.GTNewHorizons:NotEnoughItems:2.6.22-GTNH:dev")

runtimeOnly('com.github.GTNewHorizons:Baubles:1.0.4:dev')
runtimeOnly('com.github.GTNewHorizons:CodeChickenCore:1.2.1:dev') // Required to allow dummycore to run in dev
runtimeOnly('com.github.GTNewHorizons:CodeChickenCore:1.3.6:dev') // Required to allow dummycore to run in dev
}
22 changes: 21 additions & 1 deletion src/main/java/tb/common/block/BlockTBPlant.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.minecraft.block.BlockBush;
import net.minecraft.block.IGrowable;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -27,6 +29,7 @@ public class BlockTBPlant extends BlockBush implements IGrowable {
public IIcon[] growthIcons;
public ItemStack dropItem;
public ItemStack dropSeed;
private boolean pRightClick = false;

public BlockTBPlant(int stages, int delay, boolean isCrop) {
super();
Expand Down Expand Up @@ -140,6 +143,23 @@ public void func_149853_b(World w, Random r, int x, int y, int z) {
3);
}

@Override
public boolean onBlockActivated(World aWorld, int aX, int aY, int aZ, EntityPlayer aPlayer, int aSide, float pX,
float pY, float pZ) {
int aMeta = aWorld.getBlockMetadata(aX, aY, aZ);
// check for Growth Stage
if (aMeta >= growthStages - 1) {
// eval fortune on rightclick
int fortune = EnchantmentHelper.getFortuneModifier(aPlayer);
this.pRightClick = true;
this.dropBlockAsItem(aWorld, aX, aY, aZ, aMeta, fortune);
this.pRightClick = false;

aWorld.setBlock(aX, aY, aZ, this, 0, 2);
}
return false;
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister reg) {
growthIcons = new IIcon[growthStages];
Expand Down Expand Up @@ -192,7 +212,7 @@ public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metad
ret.add(drop);
}
}
if (dropSeed != null) ret.add(dropSeed.copy());
if (dropSeed != null && !pRightClick) ret.add(dropSeed.copy());

return ret;
}
Expand Down

0 comments on commit 01525d0

Please sign in to comment.