1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-26 07:03:22 +00:00

Use tags to what items turtle.place() can .use()

In older versions we just used a hard-coded list of items and
superclasses. This was somewhat ugly, and so in 1.19.3 I tried to make
this code more generic.

However, this has a lot of unintended consequences - for instance
turtles can now throw ender pearls, which is definitely not intended!

By using a tag, we can emulate the old behaviour, while still allowing
modders and pack devs to add additional items if needed.
This commit is contained in:
Jonathan Coates 2023-02-04 18:14:18 +00:00
parent 22cadd6730
commit 2e5cd29e12
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
5 changed files with 23 additions and 4 deletions

View File

@ -8,7 +8,11 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
/**
@ -21,6 +25,15 @@ public static class Items {
public static final TagKey<Item> WIRED_MODEM = make("wired_modem");
public static final TagKey<Item> MONITOR = make("monitor");
/**
* Items which can be {@linkplain Item#use(Level, Player, InteractionHand) used} when calling
* {@code turtle.place()}.
* <p>
* This does not cover items who handle placing inside {@link Item#useOn(UseOnContext)}, as that is always
* called.
*/
public static final TagKey<Item> TURTLE_CAN_PLACE = make("turtle_can_place");
private static TagKey<Item> make(String name) {
return TagKey.create(Registries.ITEM, new ResourceLocation(ComputerCraftAPI.MOD_ID, name));
}

View File

@ -15,6 +15,7 @@
import net.minecraft.tags.TagBuilder;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@ -85,6 +86,10 @@ public static void itemTags(ItemTagConsumer tags) {
ModRegistry.Items.WIRELESS_MODEM_ADVANCED.get(), ModRegistry.Items.POCKET_COMPUTER_ADVANCED.get(),
ModRegistry.Items.MONITOR_ADVANCED.get()
);
tags.tag(ComputerCraftTags.Items.TURTLE_CAN_PLACE)
.add(Items.GLASS_BOTTLE)
.addTag(ItemTags.BOATS);
}
/**

View File

@ -6,6 +6,7 @@
package dan200.computercraft.shared.turtle.core;
import com.google.common.base.Splitter;
import dan200.computercraft.api.ComputerCraftTags;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommand;
@ -21,9 +22,7 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SignItem;
import net.minecraft.world.item.*;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
@ -209,7 +208,7 @@ private static InteractionResult doDeployOnBlock(
// We special case some items which we allow to place "normally". Yes, this is very ugly.
var item = stack.getItem();
if (item.getUseDuration(stack) == 0) {
if (item instanceof BucketItem || item instanceof PlaceOnWaterBlockItem || stack.is(ComputerCraftTags.Items.TURTLE_CAN_PLACE)) {
return turtlePlayer.player().gameMode.useItem(turtlePlayer.player(), turtlePlayer.player().level, stack, InteractionHand.MAIN_HAND);
}

View File

@ -0,0 +1 @@
{"replace": false, "values": ["minecraft:glass_bottle", "#minecraft:boats"]}

View File

@ -0,0 +1 @@
{"values": ["minecraft:glass_bottle", "#minecraft:boats"]}