mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-04 11:02:54 +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:
parent
22cadd6730
commit
2e5cd29e12
@ -8,7 +8,11 @@ package dan200.computercraft.api;
|
|||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.TagKey;
|
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.Item;
|
||||||
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,6 +25,15 @@ public class ComputerCraftTags {
|
|||||||
public static final TagKey<Item> WIRED_MODEM = make("wired_modem");
|
public static final TagKey<Item> WIRED_MODEM = make("wired_modem");
|
||||||
public static final TagKey<Item> MONITOR = make("monitor");
|
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) {
|
private static TagKey<Item> make(String name) {
|
||||||
return TagKey.create(Registries.ITEM, new ResourceLocation(ComputerCraftAPI.MOD_ID, name));
|
return TagKey.create(Registries.ITEM, new ResourceLocation(ComputerCraftAPI.MOD_ID, name));
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import net.minecraft.tags.ItemTags;
|
|||||||
import net.minecraft.tags.TagBuilder;
|
import net.minecraft.tags.TagBuilder;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.item.Item;
|
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.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
|
||||||
@ -85,6 +86,10 @@ class TagProvider {
|
|||||||
ModRegistry.Items.WIRELESS_MODEM_ADVANCED.get(), ModRegistry.Items.POCKET_COMPUTER_ADVANCED.get(),
|
ModRegistry.Items.WIRELESS_MODEM_ADVANCED.get(), ModRegistry.Items.POCKET_COMPUTER_ADVANCED.get(),
|
||||||
ModRegistry.Items.MONITOR_ADVANCED.get()
|
ModRegistry.Items.MONITOR_ADVANCED.get()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
tags.tag(ComputerCraftTags.Items.TURTLE_CAN_PLACE)
|
||||||
|
.add(Items.GLASS_BOTTLE)
|
||||||
|
.addTag(ItemTags.BOATS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
import dan200.computercraft.api.ComputerCraftTags;
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommand;
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
@ -21,9 +22,7 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.*;
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.SignItem;
|
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
@ -209,7 +208,7 @@ public class TurtlePlaceCommand implements TurtleCommand {
|
|||||||
|
|
||||||
// We special case some items which we allow to place "normally". Yes, this is very ugly.
|
// We special case some items which we allow to place "normally". Yes, this is very ugly.
|
||||||
var item = stack.getItem();
|
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);
|
return turtlePlayer.player().gameMode.useItem(turtlePlayer.player(), turtlePlayer.player().level, stack, InteractionHand.MAIN_HAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
projects/fabric/src/generated/resources/data/computercraft/tags/items/turtle_can_place.json
generated
Normal file
1
projects/fabric/src/generated/resources/data/computercraft/tags/items/turtle_can_place.json
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"replace": false, "values": ["minecraft:glass_bottle", "#minecraft:boats"]}
|
1
projects/forge/src/generated/resources/data/computercraft/tags/items/turtle_can_place.json
generated
Normal file
1
projects/forge/src/generated/resources/data/computercraft/tags/items/turtle_can_place.json
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"values": ["minecraft:glass_bottle", "#minecraft:boats"]}
|
Loading…
x
Reference in New Issue
Block a user