Skip to content
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

Add inter-mod wrench compatibility #566

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.enderio.machines.common.block;

import com.enderio.base.common.tag.EIOTags;
import com.enderio.core.common.compat.FlywheelCompat;
import com.enderio.machines.common.blockentity.base.MachineBlockEntity;
import com.tterrag.registrate.util.entry.BlockEntityEntry;
Expand Down Expand Up @@ -95,6 +96,13 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
return InteractionResult.PASS;
}

if (player.getItemInHand(hand).is(EIOTags.Items.WRENCH)) {
InteractionResult res = machineBlockEntity.onWrenched(player, hit.getDirection());
if (res != InteractionResult.PASS) {
return res;
}
}

//pass on the use command to corresponding block entity.
InteractionResult result = machineBlockEntity.onBlockEntityUsed(state, level, pos, player, hand,hit);
if (result != InteractionResult.CONSUME) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,7 @@ public boolean stillValid(Player pPlayer) {

@UseOnly(LogicalSide.SERVER)
@Override
public InteractionResult onWrenched(UseOnContext context) {
Player player = context.getPlayer();
public InteractionResult onWrenched(@Nullable Player player, @Nullable Direction side) {
if (player != null && level != null && player.isSecondaryUseActive() && level instanceof ServerLevel serverLevel) {//aka break block
BlockPos pos = getBlockPos();
BlockState state = getBlockState();
Expand All @@ -740,7 +739,7 @@ public InteractionResult onWrenched(UseOnContext context) {
return InteractionResult.CONSUME;
} else {
// Check for side config capability
LazyOptional<ISideConfig> optSideConfig = getCapability(EIOCapabilities.SIDE_CONFIG, context.getClickedFace());
LazyOptional<ISideConfig> optSideConfig = getCapability(EIOCapabilities.SIDE_CONFIG, side);
if (optSideConfig.isPresent()) {
// Cycle state.
optSideConfig.ifPresent(ISideConfig::cycleMode);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/enderio/EnderIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.enderio.base.common.init.EIOPackets;
import com.enderio.base.common.init.EIOParticles;
import com.enderio.base.common.init.EIORecipes;
import com.enderio.base.common.integrations.EnderIOWrenchCompat;
import com.enderio.base.common.integrations.EnderIOSelfIntegration;
import com.enderio.base.common.item.tool.SoulVialItem;
import com.enderio.base.common.lang.EIOLang;
Expand Down Expand Up @@ -117,6 +118,8 @@ public EnderIO() {
EIOParticles.register();
EIOEntities.register();

MinecraftForge.EVENT_BUS.register(EnderIOWrenchCompat.class);

DoctorNefario marked this conversation as resolved.
Show resolved Hide resolved
// Run datagen after registrate is finished.
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(EventPriority.LOWEST, this::onGatherData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.enderio.base.common.blockentity;

import com.enderio.api.UseOnly;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.fml.LogicalSide;
import org.jetbrains.annotations.Nullable;

/**
* An interface that block entities may implement in order to implement special behaviours(other than to rotate the block) when right-clicked with the Yeta wrench.
*/
public interface IWrenchable {
@UseOnly(LogicalSide.CLIENT)
InteractionResult onWrenched(UseOnContext context);
InteractionResult onWrenched(@Nullable Player player, @Nullable Direction side);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.enderio.base.common.integrations;

import com.enderio.base.common.blockentity.IWrenchable;
import com.enderio.base.common.init.EIOItems;
import com.enderio.base.common.tag.EIOTags;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class EnderIOWrenchCompat {
DoctorNefario marked this conversation as resolved.
Show resolved Hide resolved
@SubscribeEvent
public static void onRightClickBlock(RightClickBlock event) {
ItemStack itemInHand = event.getEntity().getItemInHand(event.getHand());
if (itemInHand.is(EIOTags.Items.WRENCH) && !itemInHand.is(EIOItems.YETA_WRENCH.asItem()) && event
.getLevel()
.getBlockEntity(event.getPos()) instanceof IWrenchable) {
DoctorNefario marked this conversation as resolved.
Show resolved Hide resolved
event.setUseBlock(Event.Result.ALLOW);
event.setUseItem(Event.Result.DENY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext pContext)

BlockPos pos = pContext.getClickedPos();
if(level.getBlockEntity(pos) instanceof IWrenchable wrenchable) {
return wrenchable.onWrenched(pContext);
return wrenchable.onWrenched(pContext.getPlayer(), pContext.getClickedFace());
}

// Check for side config capability
Expand Down