1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-28 08:12:18 +00:00

Fix turtle tools not wanting to break blocks.

Ideally I would port over the data driven turtle/pocket upgrade system
from CC: Tweaked, but I don't understand it well enough at the moment.
This (should) bring parity to behaviors, but our api for adding upgrades
remains divergent.
This commit is contained in:
Toad-Dev 2021-12-07 15:31:55 -08:00
parent 6c73eb7df1
commit f5c8afa566
14 changed files with 90 additions and 151 deletions

View File

@ -7,6 +7,7 @@ package dan200.computercraft.shared;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.ComputerCraftTags;
import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.common.ContainerHeldItem;
import dan200.computercraft.shared.computer.blocks.BlockComputer; import dan200.computercraft.shared.computer.blocks.BlockComputer;
import dan200.computercraft.shared.computer.blocks.TileCommandComputer; import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
@ -339,23 +340,23 @@ public final class Registry
public static TurtleCraftingTable craftingTable = public static TurtleCraftingTable craftingTable =
new TurtleCraftingTable( new ResourceLocation( "minecraft", "crafting_table" ), new ItemStack( Items.CRAFTING_TABLE ) ); new TurtleCraftingTable( new ResourceLocation( "minecraft", "crafting_table" ), new ItemStack( Items.CRAFTING_TABLE ) );
public static TurtleSword diamondSword = public static TurtleTool diamondSword =
new TurtleSword( new ResourceLocation( "minecraft", "diamond_sword" ), Items.DIAMOND_SWORD, 9.0f ); new TurtleTool( new ResourceLocation( "minecraft", "diamond_sword" ), Items.DIAMOND_SWORD, 9.0f, ComputerCraftTags.Blocks.TURTLE_SWORD_BREAKABLE );
public static TurtleShovel diamondShovel = public static TurtleTool diamondShovel =
new TurtleShovel( new ResourceLocation( "minecraft", "diamond_shovel" ), Items.DIAMOND_SHOVEL, 1.0f ); new TurtleTool( new ResourceLocation( "minecraft", "diamond_shovel" ), Items.DIAMOND_SHOVEL, 1.0f, ComputerCraftTags.Blocks.TURTLE_SHOVEL_BREAKABLE );
public static TurtleTool diamondPickaxe = public static TurtleTool diamondPickaxe =
new TurtleTool( new ResourceLocation( "minecraft", "diamond_pickaxe" ), Items.DIAMOND_PICKAXE, 1.0f ); new TurtleTool( new ResourceLocation( "minecraft", "diamond_pickaxe" ), Items.DIAMOND_PICKAXE, 1.0f, null );
public static TurtleAxe diamondAxe = public static TurtleTool diamondAxe =
new TurtleAxe( new ResourceLocation( "minecraft", "diamond_axe" ), Items.DIAMOND_AXE, 6.0f ); new TurtleTool( new ResourceLocation( "minecraft", "diamond_axe" ), Items.DIAMOND_AXE, 6.0f, null );
public static TurtleHoe diamondHoe = public static TurtleTool diamondHoe =
new TurtleHoe( new ResourceLocation( "minecraft", "diamond_hoe" ), Items.DIAMOND_HOE, 1.0f ); new TurtleTool( new ResourceLocation( "minecraft", "diamond_hoe" ), Items.DIAMOND_HOE, 1.0f, ComputerCraftTags.Blocks.TURTLE_HOE_BREAKABLE );
public static TurtleTool netheritePickaxe = public static TurtleTool netheritePickaxe =
new TurtleTool( new ResourceLocation( "minecraft", "netherite_pickaxe" ), Items.NETHERITE_PICKAXE, 1.0f ); new TurtleTool( new ResourceLocation( "minecraft", "netherite_pickaxe" ), Items.NETHERITE_PICKAXE, 1.0f, null );
public static void registerTurtleUpgrades() public static void registerTurtleUpgrades()
{ {

View File

@ -1,17 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.turtle.upgrades;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
public class TurtleAxe extends TurtleTool
{
public TurtleAxe( ResourceLocation id, Item item, float damageMulitiplier )
{
super( id, item, damageMulitiplier );
}
}

View File

@ -1,39 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
public class TurtleHoe extends TurtleTool
{
public TurtleHoe( ResourceLocation id, Item item, float damageMulitiplier )
{
super( id, item, damageMulitiplier );
}
@Override
protected TurtleCommandResult checkBlockBreakable( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
{
if( super.checkBlockBreakable( state, world, pos, player ) == TurtleCommandResult.failure() )
{
return TurtleCommandResult.failure();
}
Material material = state.getMaterial();
if( material == Material.PLANT || material == Material.CACTUS || material == Material.VEGETABLE
|| material == Material.LEAVES || material == Material.WATER_PLANT || material == Material.REPLACEABLE_PLANT ) return TurtleCommandResult.success();
return TurtleCommandResult.failure();
}
}

View File

@ -1,37 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
public class TurtleShovel extends TurtleTool
{
public TurtleShovel( ResourceLocation id, Item item, float damageMulitiplier )
{
super( id, item, damageMulitiplier );
}
@Override
protected TurtleCommandResult checkBlockBreakable( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
{
TurtleCommandResult defaultResult = super.checkBlockBreakable( state, world, pos, player );
if( defaultResult.isSuccess() ) return defaultResult;
Material material = state.getMaterial();
return material == Material.DIRT || material == Material.SAND || material == Material.TOP_SNOW || material == Material.CLAY || material == Material.SNOW || material == Material.PLANT || material == Material.CACTUS || material == Material.VEGETABLE || material == Material.LEAVES || material == Material.REPLACEABLE_PLANT
? TurtleCommandResult.success()
: INEFFECTIVE;
}
}

View File

@ -1,36 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
public class TurtleSword extends TurtleTool
{
public TurtleSword( ResourceLocation id, Item item, float damageMulitiplier )
{
super( id, item, damageMulitiplier );
}
@Override
protected TurtleCommandResult checkBlockBreakable( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
{
TurtleCommandResult defaultResult = super.checkBlockBreakable( state, world, pos, player );
if( defaultResult.isSuccess() ) return defaultResult;
Material material = state.getMaterial();
return material == Material.PLANT || material == Material.LEAVES || material == Material.REPLACEABLE_PLANT || material == Material.WOOL || material == Material.WEB
? TurtleCommandResult.success()
: INEFFECTIVE;
}
}

View File

@ -27,6 +27,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
@ -47,6 +48,7 @@ import net.minecraft.world.phys.Vec3;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Function; import java.util.function.Function;
import static net.minecraft.nbt.Tag.TAG_COMPOUND; import static net.minecraft.nbt.Tag.TAG_COMPOUND;
@ -59,21 +61,17 @@ public class TurtleTool extends AbstractTurtleUpgrade
final ItemStack item; final ItemStack item;
final float damageMulitiplier; final float damageMulitiplier;
@Nullable
final Tag<Block> breakable;
public TurtleTool( ResourceLocation id, Item item, float damageMulitiplier ) public TurtleTool( ResourceLocation id, Item item, float damageMulitiplier, @Nullable Tag<Block> breakable )
{ {
super( id, TurtleUpgradeType.TOOL, new ItemStack( item ) ); super( id, TurtleUpgradeType.TOOL, new ItemStack( item ) );
this.item = new ItemStack( item ); this.item = new ItemStack( item );
this.damageMulitiplier = damageMulitiplier; this.damageMulitiplier = damageMulitiplier;
this.breakable = breakable;
} }
// public TurtleTool( ResourceLocation id, String adjective, Item craftItem, ItemStack toolItem, float damageMulitiplier )
// {
// super( id, TurtleUpgradeType.TOOL, adjective, new ItemStack( craftItem ) );
// item = toolItem;
// this.damageMulitiplier = damageMulitiplier;
// }
@Override @Override
public boolean isItemSuitable( @Nonnull ItemStack stack ) public boolean isItemSuitable( @Nonnull ItemStack stack )
{ {
@ -124,7 +122,8 @@ public class TurtleTool extends AbstractTurtleUpgrade
return UNBREAKABLE; return UNBREAKABLE;
} }
return isTriviallyBreakable( world, pos, state ) ? TurtleCommandResult.success() : INEFFECTIVE; return breakable == null || breakable.contains( state.getBlock() ) || isTriviallyBreakable( world, pos, state )
? TurtleCommandResult.success() : INEFFECTIVE;
} }
private TurtleCommandResult attack( ITurtleAccess turtle, Direction direction ) private TurtleCommandResult attack( ITurtleAccess turtle, Direction direction )
@ -247,16 +246,18 @@ public class TurtleTool extends AbstractTurtleUpgrade
BlockEntity tile = world.getBlockEntity( blockPosition ); BlockEntity tile = world.getBlockEntity( blockPosition );
// Much of this logic comes from PlayerInteractionManager#tryHarvestBlock, so it's a good idea // Much of this logic comes from MultiPlayerGameModer#destroyBlock, so it's a good idea
// to consult there before making any changes. // to consult there before making any changes.
// Play the destruction sound and particles // Play the destruction sound and particles
world.levelEvent( 2001, blockPosition, Block.getId( state ) ); world.levelEvent( 2001, blockPosition, Block.getId( state ) );
// Destroy the block // Destroy the block
state.getBlock().destroy( world, blockPosition, state );
boolean canHarvest = turtlePlayer.hasCorrectToolForDrops( state ); boolean canHarvest = turtlePlayer.hasCorrectToolForDrops( state );
if( canHarvest ) state.getBlock().playerWillDestroy( world, blockPosition, state, turtlePlayer );
boolean canBreak = world.setBlock( blockPosition, fluidState.createLegacyBlock(), 11 );
if( canBreak ) state.getBlock().destroy( world, blockPosition, state );
if( canHarvest && canBreak )
{ {
state.getBlock().playerDestroy( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getMainHandItem() ); state.getBlock().playerDestroy( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getMainHandItem() );
} }

View File

@ -0,0 +1,8 @@
{
"replace": false,
"values": [
"computercraft:computer_normal",
"computercraft:computer_advanced",
"computercraft:computer_command"
]
}

View File

@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"computercraft:monitor_normal",
"computercraft:monitor_advanced"
]
}

View File

@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"computercraft:turtle_normal",
"computercraft:turtle_advanced"
]
}

View File

@ -0,0 +1,8 @@
{
"replace": false,
"values": [
"#minecraft:leaves",
"minecraft:bamboo",
"minecraft:bamboo_sapling"
]
}

View File

@ -0,0 +1,12 @@
{
"replace": false,
"values": [
"#minecraft:crops",
"#minecraft:mineable/hoe",
"minecraft:cactus",
"minecraft:melon",
"minecraft:pumpkin",
"minecraft:carved_pumpkin",
"minecraft:jack_o_lantern"
]
}

View File

@ -0,0 +1,10 @@
{
"replace": false,
"values": [
"#minecraft:mineable/shovel",
"minecraft:melon",
"minecraft:pumpkin",
"minecraft:carved_pumpkin",
"minecraft:jack_o_lantern"
]
}

View File

@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"#minecraft:wool",
"minecraft:cobweb"
]
}

View File

@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"computercraft:cable",
"computercraft:wired_modem_full"
]
}