1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-16 05:07:12 +00:00

Merge branch 'mc-1.16.x' into mc-1.17.x

This commit is contained in:
Jonathan Coates
2021-11-03 09:34:21 +00:00
73 changed files with 422 additions and 236 deletions

View File

@@ -0,0 +1,48 @@
/*
* 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;
import dan200.computercraft.ComputerCraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
public class ComputerCraftTags
{
public static class Items
{
public static final Tag.Named<Item> COMPUTER = make( "computer" );
public static final Tag.Named<Item> TURTLE = make( "turtle" );
public static final Tag.Named<Item> WIRED_MODEM = make( "wired_modem" );
public static final Tag.Named<Item> MONITOR = make( "monitor" );
private static Tag.Named<Item> make( String name )
{
return ItemTags.bind( new ResourceLocation( ComputerCraft.MOD_ID, name ).toString() );
}
}
public static class Blocks
{
public static final Tag.Named<Block> COMPUTER = make( "computer" );
public static final Tag.Named<Block> TURTLE = make( "turtle" );
public static final Tag.Named<Block> WIRED_MODEM = make( "wired_modem" );
public static final Tag.Named<Block> MONITOR = make( "monitor" );
public static final Tag.Named<Block> TURTLE_ALWAYS_BREAKABLE = make( "turtle_always_breakable" );
public static final Tag.Named<Block> TURTLE_SHOVEL_BREAKABLE = make( "turtle_shovel_harvestable" );
public static final Tag.Named<Block> TURTLE_SWORD_BREAKABLE = make( "turtle_sword_harvestable" );
public static final Tag.Named<Block> TURTLE_HOE_BREAKABLE = make( "turtle_hoe_harvestable" );
private static Tag.Named<Block> make( String name )
{
return BlockTags.bind( new ResourceLocation( ComputerCraft.MOD_ID, name ).toString() );
}
}
}

View File

@@ -341,6 +341,7 @@ public final class Config
ComputerCraft.httpMaxRequests = httpMaxRequests.get();
ComputerCraft.httpMaxWebsockets = httpMaxWebsockets.get();
ComputerCraft.httpDownloadBandwidth = httpDownloadBandwidth.get();
ComputerCraft.httpUploadBandwidth = httpUploadBandwidth.get();
NetworkUtils.reloadConfig();
// Peripheral

View File

@@ -9,12 +9,10 @@ import dan200.computercraft.client.SoundManager;
import dan200.computercraft.shared.network.NetworkMessage;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fmllegacy.network.NetworkEvent;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nonnull;
import java.util.UUID;
@@ -68,7 +66,6 @@ public class SpeakerPlayClientMessage implements NetworkMessage
@OnlyIn( Dist.CLIENT )
public void handle( NetworkEvent.Context context )
{
SoundEvent sound = ForgeRegistries.SOUND_EVENTS.getValue( this.sound );
if( sound != null ) SoundManager.playSound( source, pos, sound, volume, pitch );
SoundManager.playSound( source, pos, sound, volume, pitch );
}
}

View File

@@ -35,7 +35,8 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.EnumMap;
import static dan200.computercraft.shared.util.WaterloggableHelpers.*;
import static dan200.computercraft.shared.util.WaterloggableHelpers.WATERLOGGED;
import static dan200.computercraft.shared.util.WaterloggableHelpers.getFluidStateForPlacement;
public class BlockCable extends BlockGeneric implements SimpleWaterloggedBlock
{

View File

@@ -30,7 +30,8 @@ import net.minecraftforge.fmllegacy.RegistryObject;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static dan200.computercraft.shared.util.WaterloggableHelpers.*;
import static dan200.computercraft.shared.util.WaterloggableHelpers.WATERLOGGED;
import static dan200.computercraft.shared.util.WaterloggableHelpers.getFluidStateForPlacement;
public class BlockWirelessModem extends BlockGeneric implements SimpleWaterloggedBlock
{

View File

@@ -47,7 +47,8 @@ import net.minecraftforge.fmllegacy.RegistryObject;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static dan200.computercraft.shared.util.WaterloggableHelpers.*;
import static dan200.computercraft.shared.util.WaterloggableHelpers.WATERLOGGED;
import static dan200.computercraft.shared.util.WaterloggableHelpers.getFluidStateForPlacement;
public class BlockTurtle extends BlockComputerBase<TileTurtle> implements SimpleWaterloggedBlock
{

View File

@@ -9,6 +9,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleVerb;
import dan200.computercraft.shared.ComputerCraftTags;
import dan200.computercraft.shared.turtle.core.TurtlePlaceCommand;
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
import net.minecraft.core.BlockPos;
@@ -18,7 +19,6 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import javax.annotation.Nonnull;
@@ -40,17 +40,14 @@ public class TurtleHoe extends TurtleTool
}
@Override
protected boolean canBreakBlock( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
protected TurtleCommandResult checkBlockBreakable( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
{
if( !super.canBreakBlock( state, world, pos, player ) ) return false;
TurtleCommandResult result = super.checkBlockBreakable( state, world, pos, player );
if( !result.isSuccess() ) return result;
Material material = state.getMaterial();
return material == Material.PLANT ||
material == Material.CACTUS ||
material == Material.VEGETABLE ||
material == Material.LEAVES ||
material == Material.WATER_PLANT ||
material == Material.REPLACEABLE_PLANT;
return state.is( ComputerCraftTags.Blocks.TURTLE_HOE_BREAKABLE )
|| isTriviallyBreakable( world, pos, state )
? result : INEFFECTIVE;
}
@Nonnull

View File

@@ -9,6 +9,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleVerb;
import dan200.computercraft.shared.ComputerCraftTags;
import dan200.computercraft.shared.turtle.core.TurtlePlaceCommand;
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
import net.minecraft.core.BlockPos;
@@ -18,7 +19,6 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import javax.annotation.Nonnull;
@@ -40,21 +40,14 @@ public class TurtleShovel extends TurtleTool
}
@Override
protected boolean canBreakBlock( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
protected TurtleCommandResult checkBlockBreakable( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
{
if( !super.canBreakBlock( state, world, pos, player ) ) return false;
TurtleCommandResult result = super.checkBlockBreakable( state, world, pos, player );
if( !result.isSuccess() ) return result;
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;
return state.is( ComputerCraftTags.Blocks.TURTLE_SHOVEL_BREAKABLE )
|| isTriviallyBreakable( world, pos, state )
? result : INEFFECTIVE;
}
@Nonnull

View File

@@ -5,6 +5,8 @@
*/
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.ComputerCraftTags;
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
@@ -12,7 +14,6 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
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
{
@@ -32,16 +33,14 @@ public class TurtleSword extends TurtleTool
}
@Override
protected boolean canBreakBlock( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
protected TurtleCommandResult checkBlockBreakable( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
{
if( !super.canBreakBlock( state, world, pos, player ) ) return false;
TurtleCommandResult result = super.checkBlockBreakable( state, world, pos, player );
if( !result.isSuccess() ) return result;
Material material = state.getMaterial();
return material == Material.PLANT ||
material == Material.LEAVES ||
material == Material.REPLACEABLE_PLANT ||
material == Material.WOOL ||
material == Material.WEB;
return state.is( ComputerCraftTags.Blocks.TURTLE_SWORD_BREAKABLE )
|| isTriviallyBreakable( world, pos, state )
? result : INEFFECTIVE;
}
@Override

View File

@@ -10,6 +10,7 @@ import com.mojang.math.Transformation;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.turtle.*;
import dan200.computercraft.shared.ComputerCraftTags;
import dan200.computercraft.shared.TurtlePermissions;
import dan200.computercraft.shared.turtle.core.TurtleBrain;
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
@@ -27,6 +28,7 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@@ -46,6 +48,9 @@ import java.util.function.Function;
public class TurtleTool extends AbstractTurtleUpgrade
{
protected static final TurtleCommandResult UNBREAKABLE = TurtleCommandResult.failure( "Unbreakable block detected" );
protected static final TurtleCommandResult INEFFECTIVE = TurtleCommandResult.failure( "Cannot break block with this tool" );
protected final ItemStack item;
public TurtleTool( ResourceLocation id, String adjective, Item item )
@@ -107,13 +112,14 @@ public class TurtleTool extends AbstractTurtleUpgrade
}
}
protected boolean canBreakBlock( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
protected TurtleCommandResult checkBlockBreakable( BlockState state, Level world, BlockPos pos, TurtlePlayer player )
{
Block block = state.getBlock();
return !state.isAir()
&& block != Blocks.BEDROCK
&& state.getDestroyProgress( player, world, pos ) > 0
&& block.canEntityDestroy( state, world, pos, player );
&& block.canEntityDestroy( state, world, pos, player )
? TurtleCommandResult.success() : UNBREAKABLE;
}
protected float getDamageMultiplier()
@@ -158,6 +164,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
{
float damage = (float) turtlePlayer.getAttributeValue( Attributes.ATTACK_DAMAGE );
damage *= getDamageMultiplier();
ComputerCraft.log.info( "Dealing {} damage", damage );
if( damage > 0.0f )
{
DamageSource source = DamageSource.playerAttack( turtlePlayer );
@@ -224,10 +231,8 @@ public class TurtleTool extends AbstractTurtleUpgrade
}
// Check if we can break the block
if( !canBreakBlock( state, world, blockPosition, turtlePlayer ) )
{
return TurtleCommandResult.failure( "Unbreakable block detected" );
}
TurtleCommandResult breakable = checkBlockBreakable( state, world, blockPosition, turtlePlayer );
if( !breakable.isSuccess() ) return breakable;
// Consume the items the block drops
DropConsumer.set( world, blockPosition, turtleDropConsumer( turtleTile, turtle ) );
@@ -281,4 +286,11 @@ public class TurtleTool extends AbstractTurtleUpgrade
} ) );
}
}
protected boolean isTriviallyBreakable( BlockGetter reader, BlockPos pos, BlockState state )
{
return state.is( ComputerCraftTags.Blocks.TURTLE_ALWAYS_BREAKABLE )
// Allow breaking any "instabreak" block.
|| state.getDestroySpeed( reader, pos ) == 0;
}
}

View File

@@ -97,6 +97,7 @@ public final class DropConsumer
if( dropEntity == null || drops.getEntity() != dropEntity ) return;
for( ItemEntity drop : drops.getDrops() ) handleDrops( drop.getItem() );
drops.getDrops().clear();
drops.setCanceled( true );
}
}