Skip to content

Commit

Permalink
Pitcher Pod and Torch Flower support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryhon0 committed Jul 27, 2023
1 parent fb94334 commit ed74f02
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 75 deletions.
69 changes: 0 additions & 69 deletions remappedSrc/com/loucaskreger/replanter/Replanter.java

This file was deleted.

19 changes: 14 additions & 5 deletions src/main/java/link/ryhn/replanter/Replanter.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package link.ryhn.replanter;

import link.ryhn.replanter.mixins.PitcherCropBlockMixin;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;

public class Replanter implements ModInitializer {

private static final MinecraftClient mc = MinecraftClient.getInstance();

@Override
Expand All @@ -27,16 +29,16 @@ public void onInitialize() {
ItemStack offhandStack = player.getOffHandStack();

if (hand == Hand.MAIN_HAND && !heldStack.isEmpty()) {
this.replaceCrop(heldStack, pos, world);
this.replaceCrop(player, hand, heldStack, pos, world);
} else if (hand == Hand.OFF_HAND && !offhandStack.isEmpty()) {
this.replaceCrop(offhandStack, pos, world);
this.replaceCrop(player, hand, offhandStack, pos, world);
}
}
return ActionResult.PASS;
});
}

private void replaceCrop(ItemStack stack, BlockPos pos, World world) {
private void replaceCrop(PlayerEntity player, Hand hand, ItemStack stack, BlockPos pos, World world) {
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
ClientPlayerInteractionManager im = mc.interactionManager;
Expand All @@ -60,9 +62,16 @@ private void replaceCrop(ItemStack stack, BlockPos pos, World world) {
im.attackBlock(pos, Direction.DOWN);
}
} else if (block instanceof CocoaBlock cocoaBlock) {
if ((cocoaBlock.getOutlineShape(state, world, pos, ShapeContext.absent()).getBoundingBox().getYLength() == 0.5625)) {
if ((cocoaBlock.getOutlineShape(state, world, pos, ShapeContext.absent()).getBoundingBox()
.getYLength() == 0.5625)) {
im.attackBlock(pos, world.getBlockState(pos).get(CocoaBlock.FACING));
}
} else if (block instanceof PitcherCropBlock pitcherCropBlock) {
if (PitcherCropBlockMixin.invokeIsLowerHalf(state))
if (((PitcherCropBlockMixin) pitcherCropBlock).invokeIsFullyGrown(state))
im.attackBlock(pos, Direction.DOWN);
} else if (block == Blocks.TORCHFLOWER) {
im.attackBlock(pos, Direction.DOWN);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package link.ryhn.replanter.mixins;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

import net.minecraft.block.*;

@Mixin(PitcherCropBlock.class)
public interface PitcherCropBlockMixin {
@Invoker("isFullyGrown")
public boolean invokeIsFullyGrown(BlockState state);

@Invoker("isLowerHalf")
public static boolean invokeIsLowerHalf(BlockState state) {
throw new AssertionError();
}
}
6 changes: 5 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"fabric": "*",
"minecraft": "~1.20",
"java": ">=17"
}
},
"mixins":
[
"replanter.mixins.json"
]
}
14 changes: 14 additions & 0 deletions src/main/resources/replanter.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "link.ryhn.replanter.mixins",
"compatibilityLevel": "JAVA_17",
"mixins": [],
"client": [
"PitcherCropBlockMixin"
],
"server": [],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit ed74f02

Please sign in to comment.