Skip to content

Commit d476b53

Browse files
committed
Fix #20: Place attachments with whitelist when holding a wrench in the offhand
1 parent 9f7c257 commit d476b53

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/main/java/dev/technici4n/moderndynamics/attachment/attached/AttachedAttachment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import net.minecraft.nbt.CompoundTag;
2929
import net.minecraft.network.chat.Component;
3030
import net.minecraft.world.MenuProvider;
31+
import net.minecraft.world.entity.player.Player;
3132
import net.minecraft.world.item.ItemStack;
3233
import org.jetbrains.annotations.MustBeInvokedByOverriders;
3334
import org.jetbrains.annotations.Nullable;
@@ -98,4 +99,7 @@ public boolean hasMenu() {
9899
public MenuProvider createMenu(PipeBlockEntity pipe, Direction side) {
99100
return null;
100101
}
102+
103+
public void onPlaced(Player player) {
104+
}
101105
}

src/main/java/dev/technici4n/moderndynamics/attachment/attached/AttachedIo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import dev.technici4n.moderndynamics.attachment.settings.FilterInversionMode;
2626
import dev.technici4n.moderndynamics.attachment.settings.RedstoneMode;
2727
import dev.technici4n.moderndynamics.pipe.PipeBlockEntity;
28+
import dev.technici4n.moderndynamics.util.WrenchHelper;
2829
import java.util.Set;
2930
import net.minecraft.nbt.CompoundTag;
3031
import net.minecraft.world.ContainerHelper;
32+
import net.minecraft.world.entity.player.Player;
3133
import net.minecraft.world.item.Item;
3234
import net.minecraft.world.item.ItemStack;
3335

@@ -149,4 +151,12 @@ public boolean isEnabledViaRedstone(PipeBlockEntity pipe) {
149151
return getRedstoneMode() == RedstoneMode.REQUIRES_LOW;
150152
}
151153
}
154+
155+
@Override
156+
public void onPlaced(Player player) {
157+
if (WrenchHelper.isWrench(player.getOffhandItem())) {
158+
// Set to whitelist mode if the player has a wrench in his offhand.
159+
filterInversion = FilterInversionMode.WHITELIST;
160+
}
161+
}
152162
}

src/main/java/dev/technici4n/moderndynamics/pipe/PipeBlockEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ public InteractionResult onUse(Player player, InteractionHand hand, BlockHitResu
395395
initialData = new CompoundTag();
396396
}
397397
host.setAttachment(hitSide, attachmentItem, initialData);
398+
host.getAttachment(hitSide).onPlaced(player);
398399
level.blockUpdated(worldPosition, getBlockState().getBlock());
399400
refreshHosts();
400401
scheduleHostUpdates();

0 commit comments

Comments
 (0)