Skip to content

Change Wrench checks in Create code to use a tag rather than a hardcoded item #8566

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

Open
wants to merge 5 commits into
base: mc1.20.1/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/generated/resources/data/create/tags/items/wrench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"create:wrench"
]
}
2 changes: 1 addition & 1 deletion src/main/java/com/simibubi/create/AllItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public class AllItems {
public static final ItemEntry<WrenchItem> WRENCH = REGISTRATE.item("wrench", WrenchItem::new)
.properties(p -> p.stacksTo(1))
.model(AssetLookup.itemModelWithPartials())
.tag(AllItemTags.WRENCH.tag)
.tag(AllItemTags.FORGE_WRENCH.tag, AllItemTags.CREATE_WRENCH.tag)
.register();

public static final ItemEntry<MinecartContraptionItem> MINECART_CONTRAPTION =
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/simibubi/create/AllTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public enum AllItemTags {
CASING,
CONTRAPTION_CONTROLLED,
CREATE_INGOTS,
CREATE_WRENCH(MOD, "wrench"),
CRUSHED_RAW_MATERIALS,
INVALID_FOR_TRACK_PAVING,
DEPLOYABLE_DRINK,
Expand Down Expand Up @@ -208,7 +209,7 @@ public enum AllItemTags {
STRIPPED_WOOD(FORGE),
PLATES(FORGE),
OBSIDIAN_DUST(FORGE, "dusts/obsidian"),
WRENCH(FORGE, "tools/wrench"),
FORGE_WRENCH(FORGE, "tools/wrench"),

ALLURITE(MOD, "stone_types/galosphere/allurite"),
AMETHYST(MOD, "stone_types/galosphere/amethyst"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

import javax.annotation.Nullable;

import com.simibubi.create.AllTags.AllItemTags;

import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.lang3.tuple.MutablePair;

import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllPackets;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.api.behaviour.movement.MovementBehaviour;
Expand Down Expand Up @@ -289,7 +290,7 @@ public boolean handlePlayerInteraction(Player player, BlockPos localPos, Directi
InteractionHand interactionHand) {
int indexOfSeat = contraption.getSeats()
.indexOf(localPos);
if (indexOfSeat == -1 || AllItems.WRENCH.isIn(player.getItemInHand(interactionHand))) {
if (indexOfSeat == -1 || AllItemTags.CREATE_WRENCH.matches(player.getItemInHand(interactionHand))) {
if (contraption.interactors.containsKey(localPos))
return contraption.interactors.get(localPos)
.handlePlayerInteraction(player, interactionHand, localPos, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import javax.annotation.Nullable;

import com.simibubi.create.AllTags.AllItemTags;

import org.apache.commons.lang3.mutable.MutableObject;

import com.simibubi.create.AllItems;
import com.simibubi.create.AllPackets;
import com.simibubi.create.content.contraptions.sync.ContraptionInteractionPacket;
import com.simibubi.create.content.trains.entity.CarriageContraptionEntity;
Expand Down Expand Up @@ -136,7 +137,7 @@ public static void rightClickingOnContraptionsGetsHandledLocally(InputEvent.Inte

private static boolean handleSpecialInteractions(AbstractContraptionEntity contraptionEntity, Player player,
BlockPos localPos, Direction side, InteractionHand interactionHand) {
if (AllItems.WRENCH.isIn(player.getItemInHand(interactionHand))
if (AllItemTags.CREATE_WRENCH.matches(player.getItemInHand(interactionHand))
&& contraptionEntity instanceof CarriageContraptionEntity car)
return TrainRelocator.carriageWrenched(car.toGlobalVector(VecHelper.getCenterOf(localPos), 1), car);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.UUID;

import com.google.common.base.Objects;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.api.behaviour.interaction.MovingInteractionBehaviour;
import com.simibubi.create.content.contraptions.AbstractContraptionEntity;

Expand All @@ -19,7 +19,7 @@ public class ControlsInteractionBehaviour extends MovingInteractionBehaviour {
@Override
public boolean handlePlayerInteraction(Player player, InteractionHand activeHand, BlockPos localPos,
AbstractContraptionEntity contraptionEntity) {
if (AllItems.WRENCH.isIn(player.getItemInHand(activeHand)))
if (AllItemTags.CREATE_WRENCH.matches(player.getItemInHand(activeHand)))
return false;

UUID currentlyControlling = contraptionEntity.getControllingPlayer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import java.util.Set;

import com.mojang.datafixers.util.Pair;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllKeys;
import com.simibubi.create.AllSpecialTextures;

import com.simibubi.create.AllTags.AllItemTags;

import net.createmod.catnip.outliner.Outliner;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -89,7 +90,7 @@ protected Set<BlockPos> createSelection(ChassisBlockEntity chassis) {
public static void tick() {
Player player = Minecraft.getInstance().player;
Level world = Minecraft.getInstance().level;
boolean hasWrench = AllItems.WRENCH.isIn(player.getMainHandItem());
boolean hasWrench = AllItemTags.CREATE_WRENCH.matches(player.getMainHandItem());

for (Iterator<BlockPos> iterator = entries.keySet()
.iterator(); iterator.hasNext(); ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import com.simibubi.create.AllBlockEntityTypes;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.api.schematic.requirement.SpecialBlockItemRequirement;
import com.simibubi.create.content.contraptions.elevator.ElevatorColumn.ColumnCoords;
import com.simibubi.create.content.redstone.contact.RedstoneContactBlock;
Expand Down Expand Up @@ -229,7 +229,7 @@ public ItemRequirement getRequiredItems(BlockState state, BlockEntity be) {
@Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn,
BlockHitResult hit) {
if (player != null && AllItems.WRENCH.isIn(player.getItemInHand(handIn)))
if (player != null && AllItemTags.CREATE_WRENCH.matches(player.getItemInHand(handIn)))
return InteractionResult.PASS;
DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
() -> () -> withBlockEntityDo(worldIn, pos, be -> this.displayScreen(be, player)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.simibubi.create.AllItems;
import com.simibubi.create.AllPackets;
import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.api.contraption.BlockMovementChecks;

import net.createmod.catnip.data.Iterate;
Expand Down Expand Up @@ -64,7 +65,7 @@ public static void glueInOffHandAppliesOnBlockPlace(EntityPlaceEvent event, Bloc
AttributeInstance reachAttribute = placer.getAttribute(ForgeMod.BLOCK_REACH.get());
if (!AllItems.SUPER_GLUE.isIn(itemstack) || reachAttribute == null)
return;
if (AllItems.WRENCH.isIn(placer.getMainHandItem()))
if (AllItemTags.CREATE_WRENCH.matches(placer.getMainHandItem()))
return;
if (event.getPlacedAgainst() == IPlacementHelper.ID)
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.simibubi.create.content.contraptions.minecart;

import com.simibubi.create.AllItems;
import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.content.contraptions.minecart.capability.CapabilityMinecartController;
import com.simibubi.create.content.contraptions.minecart.capability.MinecartController;

Expand Down Expand Up @@ -48,7 +49,7 @@ public static void handleInteractionWithMinecart(PlayerInteractEvent.EntityInter
if (AllItems.MINECART_COUPLING.isIn(heldItem)) {
if (!onCouplingInteractOnMinecart(event, minecart, player, controller))
return;
} else if (AllItems.WRENCH.isIn(heldItem)) {
} else if (AllItemTags.CREATE_WRENCH.matches(heldItem)) {
if (!onWrenchInteractOnMinecart(event, minecart, player, controller))
return;
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import javax.annotation.Nullable;

import com.simibubi.create.AllTags.AllItemTags;

import org.apache.commons.lang3.tuple.MutablePair;

import com.simibubi.create.AllItems;
Expand Down Expand Up @@ -208,7 +210,7 @@ public static void wrenchCanBeUsedToPickUpMinecartContraptions(PlayerInteractEve
return;

ItemStack wrench = player.getItemInHand(event.getHand());
if (!AllItems.WRENCH.isIn(wrench))
if (!AllItemTags.CREATE_WRENCH.matches(wrench))
return;
if (entity instanceof AbstractContraptionEntity)
entity = entity.getVehicle();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.simibubi.create.content.contraptions.wrench;

import com.simibubi.create.AllItems;
import com.simibubi.create.AllKeys;

import com.simibubi.create.AllTags.AllItemTags;

import net.createmod.catnip.gui.ScreenOpener;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
Expand Down Expand Up @@ -43,7 +44,7 @@ public static void onKeyInput(int key, boolean pressed) {
Level level = player.level();

ItemStack heldItem = player.getMainHandItem();
if (heldItem.getItem() != AllItems.WRENCH.get())
if (AllItemTags.CREATE_WRENCH.matches(heldItem))
return;

HitResult objectMouseOver = mc.hitResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.WATERLOGGED;

import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTags;
import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.content.decoration.bracket.BracketBlock;
import com.simibubi.create.content.decoration.bracket.BracketedBlockEntityBehaviour;
import com.simibubi.create.content.decoration.placard.PlacardBlock;
Expand Down Expand Up @@ -120,7 +120,7 @@ public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Pla
return InteractionResult.SUCCESS;
}

if (AllItems.WRENCH.isIn(itemInHand) && !pPlayer.isShiftKeyDown()) {
if (AllItemTags.CREATE_WRENCH.matches(itemInHand) && !pPlayer.isShiftKeyDown()) {
if (GirderWrenchBehavior.handleClick(pLevel, pPos, pState, pHit))
return InteractionResult.sidedSuccess(pLevel.isClientSide);
return InteractionResult.FAIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import java.util.Collections;
import java.util.List;

import com.simibubi.create.AllTags.AllItemTags;

import org.jetbrains.annotations.Nullable;

import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;

import net.createmod.catnip.data.Iterate;
import net.createmod.catnip.data.Pair;
Expand Down Expand Up @@ -51,7 +52,7 @@ public static void tick() {
if (!AllBlocks.METAL_GIRDER.has(world.getBlockState(pos)))
return;

if (!AllItems.WRENCH.isIn(heldItem))
if (!AllItemTags.CREATE_WRENCH.matches(heldItem))
return;

Pair<Direction, Action> dirPair = getDirectionAndAction(result, world, pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import javax.annotation.Nullable;

import com.simibubi.create.AllTags.AllItemTags;

import org.apache.commons.lang3.Validate;

import com.simibubi.create.AllEntityTypes;
Expand Down Expand Up @@ -352,7 +354,7 @@ public InteractionResult interactAt(Player player, Vec3 vec, InteractionHand han
if (player instanceof FakePlayer)
return InteractionResult.PASS;

boolean holdingWrench = AllItems.WRENCH.isIn(player.getItemInHand(hand));
boolean holdingWrench = AllItemTags.CREATE_WRENCH.matches(player.getItemInHand(hand));
BlueprintSection section = getSectionAt(vec);
ItemStackHandler items = section.getItems();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public static void useOwnWrenchLogicForCreateBlocks(PlayerInteractEvent.RightCli
return;
if (itemStack.isEmpty())
return;
if (AllItems.WRENCH.isIn(itemStack))
if (AllItemTags.CREATE_WRENCH.matches(itemStack))
return;
if (!AllItemTags.WRENCH.matches(itemStack.getItem()))
if (!AllItemTags.FORGE_WRENCH.matches(itemStack.getItem()))
return;

BlockState state = event.getLevel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import javax.annotation.Nonnull;

import com.simibubi.create.AllItems;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.AllTags;
import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.Create;
import com.simibubi.create.foundation.item.render.SimpleCustomRenderer;

Expand Down Expand Up @@ -82,7 +82,7 @@ public static void wrenchInstaKillsMinecarts(AttackEntityEvent event) {
return;
Player player = event.getEntity();
ItemStack heldItem = player.getMainHandItem();
if (!AllItems.WRENCH.isIn(heldItem))
if (!AllItemTags.CREATE_WRENCH.matches(heldItem))
return;
if (player.isCreative())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.Set;
import java.util.function.Consumer;

import com.simibubi.create.AllTags.AllItemTags;

import org.apache.commons.lang3.mutable.MutableBoolean;

import com.simibubi.create.AllBlockEntityTypes;
Expand Down Expand Up @@ -257,7 +259,7 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
return InteractionResult.PASS;
ItemStack heldItem = player.getItemInHand(handIn);

boolean isWrench = AllItems.WRENCH.isIn(heldItem);
boolean isWrench = AllItemTags.CREATE_WRENCH.matches(heldItem);
boolean isConnector = AllItems.BELT_CONNECTOR.isIn(heldItem);
boolean isShaft = AllBlocks.SHAFT.isIn(heldItem);
boolean isDye = heldItem.is(Tags.Items.DYES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
import com.simibubi.create.content.kinetics.belt.BeltBlockEntity.CasingType;
import com.simibubi.create.content.kinetics.belt.item.BeltConnectorItem;
Expand Down Expand Up @@ -468,7 +469,7 @@ public static void tickHoveringInformation() {
Feedback feedback = new Feedback();

// TODO: Populate feedback in the methods for clientside
if (AllItems.WRENCH.isIn(held) || AllItems.WRENCH.isIn(heldOffHand))
if (AllItemTags.CREATE_WRENCH.matches(held) || AllItemTags.CREATE_WRENCH.matches(heldOffHand))
useWrench(state, world, pos, mc.player, InteractionHand.MAIN_HAND, result, feedback);
else if (AllItems.BELT_CONNECTOR.isIn(held) || AllItems.BELT_CONNECTOR.isIn(heldOffHand))
useConnector(state, world, pos, mc.player, InteractionHand.MAIN_HAND, result, feedback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.simibubi.create.AllBlockEntityTypes;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.content.kinetics.base.HorizontalKineticBlock;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
import com.simibubi.create.content.kinetics.crafter.ConnectedInputHandler.ConnectedInput;
Expand Down Expand Up @@ -166,7 +167,7 @@ public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Play
return InteractionResult.PASS;

boolean isHand = heldItem.isEmpty() && handIn == InteractionHand.MAIN_HAND;
boolean wrenched = AllItems.WRENCH.isIn(heldItem);
boolean wrenched = AllItemTags.CREATE_WRENCH.matches(heldItem);

if (hit.getDirection() == state.getValue(HORIZONTAL_FACING)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import java.util.List;
import java.util.Map.Entry;

import com.simibubi.create.AllTags.AllItemTags;

import org.apache.commons.lang3.tuple.Pair;

import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
import com.simibubi.create.content.kinetics.belt.behaviour.DirectBeltInputBehaviour;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
inserting = new InvManipulationBehaviour(this, this::getTargetFace);
connectivity = new EdgeInteractionBehaviour(this, ConnectedInputHandler::toggleConnection)
.connectivity(ConnectedInputHandler::shouldConnect)
.require(AllItems.WRENCH.get());
.require(AllItemTags.CREATE_WRENCH::matches);
behaviours.add(inserting);
behaviours.add(connectivity);
registerAwardables(behaviours, AllAdvancements.CRAFTER, AllAdvancements.CRAFTER_LAZY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import com.simibubi.create.AllBlockEntityTypes;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.foundation.utility.BlockHelper;

import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -62,7 +62,7 @@ public static void onBlockActivated(PlayerInteractEvent.RightClickBlock event) {
return;
if (!player.mayBuild())
return;
if (AllItems.WRENCH.isIn(player.getItemInHand(event.getHand())) && player.isShiftKeyDown())
if (AllItemTags.CREATE_WRENCH.matches(player.getItemInHand(event.getHand())) && player.isShiftKeyDown())
return;

if (vhb.clicked(level, pos, blockState, player, event.getHand())) {
Expand Down
Loading