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:
parent
6c73eb7df1
commit
f5c8afa566
@ -7,6 +7,7 @@ package dan200.computercraft.shared;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.ComputerCraftTags;
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
||||
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
|
||||
@ -339,23 +340,23 @@ public final class Registry
|
||||
public static TurtleCraftingTable craftingTable =
|
||||
new TurtleCraftingTable( new ResourceLocation( "minecraft", "crafting_table" ), new ItemStack( Items.CRAFTING_TABLE ) );
|
||||
|
||||
public static TurtleSword diamondSword =
|
||||
new TurtleSword( new ResourceLocation( "minecraft", "diamond_sword" ), Items.DIAMOND_SWORD, 9.0f );
|
||||
public static TurtleTool diamondSword =
|
||||
new TurtleTool( new ResourceLocation( "minecraft", "diamond_sword" ), Items.DIAMOND_SWORD, 9.0f, ComputerCraftTags.Blocks.TURTLE_SWORD_BREAKABLE );
|
||||
|
||||
public static TurtleShovel diamondShovel =
|
||||
new TurtleShovel( new ResourceLocation( "minecraft", "diamond_shovel" ), Items.DIAMOND_SHOVEL, 1.0f );
|
||||
public static TurtleTool diamondShovel =
|
||||
new TurtleTool( new ResourceLocation( "minecraft", "diamond_shovel" ), Items.DIAMOND_SHOVEL, 1.0f, ComputerCraftTags.Blocks.TURTLE_SHOVEL_BREAKABLE );
|
||||
|
||||
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 =
|
||||
new TurtleAxe( new ResourceLocation( "minecraft", "diamond_axe" ), Items.DIAMOND_AXE, 6.0f );
|
||||
public static TurtleTool diamondAxe =
|
||||
new TurtleTool( new ResourceLocation( "minecraft", "diamond_axe" ), Items.DIAMOND_AXE, 6.0f, null );
|
||||
|
||||
public static TurtleHoe diamondHoe =
|
||||
new TurtleHoe( new ResourceLocation( "minecraft", "diamond_hoe" ), Items.DIAMOND_HOE, 1.0f );
|
||||
public static TurtleTool diamondHoe =
|
||||
new TurtleTool( new ResourceLocation( "minecraft", "diamond_hoe" ), Items.DIAMOND_HOE, 1.0f, ComputerCraftTags.Blocks.TURTLE_HOE_BREAKABLE );
|
||||
|
||||
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()
|
||||
{
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
@ -47,6 +48,7 @@ import net.minecraft.world.phys.Vec3;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static net.minecraft.nbt.Tag.TAG_COMPOUND;
|
||||
@ -59,21 +61,17 @@ public class TurtleTool extends AbstractTurtleUpgrade
|
||||
|
||||
final ItemStack item;
|
||||
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 ) );
|
||||
this.item = new ItemStack( item );
|
||||
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
|
||||
public boolean isItemSuitable( @Nonnull ItemStack stack )
|
||||
{
|
||||
@ -124,7 +122,8 @@ public class TurtleTool extends AbstractTurtleUpgrade
|
||||
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 )
|
||||
@ -247,16 +246,18 @@ public class TurtleTool extends AbstractTurtleUpgrade
|
||||
|
||||
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.
|
||||
|
||||
// Play the destruction sound and particles
|
||||
world.levelEvent( 2001, blockPosition, Block.getId( state ) );
|
||||
|
||||
// Destroy the block
|
||||
state.getBlock().destroy( world, blockPosition, 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() );
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"computercraft:computer_normal",
|
||||
"computercraft:computer_advanced",
|
||||
"computercraft:computer_command"
|
||||
]
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"computercraft:monitor_normal",
|
||||
"computercraft:monitor_advanced"
|
||||
]
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"computercraft:turtle_normal",
|
||||
"computercraft:turtle_advanced"
|
||||
]
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"#minecraft:leaves",
|
||||
"minecraft:bamboo",
|
||||
"minecraft:bamboo_sapling"
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"#minecraft:mineable/shovel",
|
||||
"minecraft:melon",
|
||||
"minecraft:pumpkin",
|
||||
"minecraft:carved_pumpkin",
|
||||
"minecraft:jack_o_lantern"
|
||||
]
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"#minecraft:wool",
|
||||
"minecraft:cobweb"
|
||||
]
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"computercraft:cable",
|
||||
"computercraft:wired_modem_full"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user