Skip to content

Commit 1de4842

Browse files
implement block rotation behavior to gt wrench.
allows AE Interfaces to have its direction set
1 parent 0fc1d3c commit 1de4842

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/main/java/gregtech/common/items/ToolItems.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public static void init() {
100100
.behaviors(new GrassPathBehavior()))
101101
.toolClasses(ToolClasses.SHOVEL));
102102
WRENCH = register(ItemGTTool.Builder.of(GTValues.MODID, "wrench")
103-
.toolStats(b -> b.blockBreaking().crafting().sneakBypassUse())
103+
.toolStats(b -> b.blockBreaking().crafting().sneakBypassUse()
104+
.behaviors(new BlockRotatingBehavior()))
104105
.sound(GTSoundEvents.WRENCH_TOOL, true)
105106
.oreDict(ToolOreDicts.craftingToolWrench)
106107
.symbol('w')
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package gregtech.common.items.tool;
2+
3+
import gregtech.api.items.toolitem.behavior.IToolBehavior;
4+
import gregtech.api.metatileentity.MetaTileEntityHolder;
5+
import net.minecraft.block.Block;
6+
import net.minecraft.block.BlockRailBase;
7+
import net.minecraft.entity.player.EntityPlayer;
8+
import net.minecraft.tileentity.TileEntity;
9+
import net.minecraft.util.EnumActionResult;
10+
import net.minecraft.util.EnumFacing;
11+
import net.minecraft.util.EnumHand;
12+
import net.minecraft.util.math.BlockPos;
13+
import net.minecraft.world.World;
14+
import net.minecraftforge.fml.common.FMLCommonHandler;
15+
16+
public class BlockRotatingBehavior implements IToolBehavior {
17+
@Override
18+
public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) {
19+
TileEntity te = world.getTileEntity(pos);
20+
//MTEs have special handling on rotation
21+
if (te instanceof MetaTileEntityHolder) {
22+
return EnumActionResult.PASS;
23+
}
24+
final Block b = world.getBlockState(pos).getBlock();
25+
//leave rail rotation to Crowbar only
26+
if (b instanceof BlockRailBase) {
27+
return EnumActionResult.FAIL;
28+
}
29+
if (!player.isSneaking() && world.canMineBlockBody(player, pos)) {
30+
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
31+
return !world.isRemote ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
32+
}
33+
34+
if (b.rotateBlock(world, pos, side)) {
35+
player.swingArm(hand);
36+
return !world.isRemote ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
37+
}
38+
}
39+
return EnumActionResult.PASS;
40+
}
41+
}

0 commit comments

Comments
 (0)