1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-01 06:03:00 +00:00

Merge branch 'mc-1.20.x' into mc-1.20.y

This commit is contained in:
Jonathan Coates
2024-04-24 20:30:59 +01:00
22 changed files with 140 additions and 121 deletions

View File

@@ -8,6 +8,7 @@ import dan200.computercraft.annotations.ForgeOverride;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.shared.common.IBundledRedstoneBlock;
import dan200.computercraft.shared.computer.items.IComputerItem;
import dan200.computercraft.shared.network.container.ComputerContainerData;
import dan200.computercraft.shared.platform.RegistryEntry;
import dan200.computercraft.shared.util.BlockEntityHelpers;
import net.minecraft.core.BlockPos;
@@ -160,8 +161,19 @@ public abstract class AbstractComputerBlock<T extends AbstractComputerBlockEntit
@Override
@Deprecated
public final InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
return world.getBlockEntity(pos) instanceof AbstractComputerBlockEntity computer ? computer.use(player, hand) : InteractionResult.PASS;
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (!player.isCrouching() && level.getBlockEntity(pos) instanceof AbstractComputerBlockEntity computer) {
// Regular right click to activate computer
if (!level.isClientSide && computer.isUsable(player)) {
var serverComputer = computer.createServerComputer();
serverComputer.turnOn();
new ComputerContainerData(serverComputer, getItem(computer)).open(player, computer);
}
return InteractionResult.sidedSuccess(level.isClientSide);
}
return super.use(state, level, pos, player, hand, hit);
}
@Override

View File

@@ -13,7 +13,6 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.computer.core.ServerContext;
import dan200.computercraft.shared.network.container.ComputerContainerData;
import dan200.computercraft.shared.platform.ComponentAccess;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.util.BlockEntityHelpers;
@@ -25,10 +24,10 @@ import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.*;
import net.minecraft.world.LockCode;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.Nameable;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
@@ -76,10 +75,6 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
unload();
}
protected boolean canNameWithTag(Player player) {
return false;
}
protected double getInteractRange() {
return BlockEntityHelpers.DEFAULT_INTERACT_RANGE;
}
@@ -89,31 +84,6 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
&& BlockEntityHelpers.isUsable(this, player, getInteractRange());
}
public InteractionResult use(Player player, InteractionHand hand) {
var currentItem = player.getItemInHand(hand);
if (!currentItem.isEmpty() && currentItem.getItem() == Items.NAME_TAG && canNameWithTag(player) && currentItem.hasCustomHoverName()) {
// Label to rename computer
if (!getLevel().isClientSide) {
setLabel(currentItem.getHoverName().getString());
currentItem.shrink(1);
}
return InteractionResult.sidedSuccess(getLevel().isClientSide);
} else if (!player.isCrouching()) {
// Regular right click to activate computer
if (!getLevel().isClientSide && isUsable(player)) {
var computer = createServerComputer();
computer.turnOn();
var stack = getBlockState().getBlock() instanceof AbstractComputerBlock<?>
? ((AbstractComputerBlock<?>) getBlockState().getBlock()).getItem(this)
: ItemStack.EMPTY;
new ComputerContainerData(computer, stack).open(player, this);
}
return InteractionResult.sidedSuccess(getLevel().isClientSide);
}
return InteractionResult.PASS;
}
protected void serverTick() {
if (getLevel().isClientSide) return;
if (computerID < 0 && !startOn) return; // Don't tick if we don't need a computer!
@@ -343,7 +313,7 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
if (getLevel().isClientSide || computerID == id) return;
computerID = id;
setChanged();
BlockEntityHelpers.updateBlock(this);
}
@Override
@@ -353,7 +323,7 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
this.label = label;
var computer = getServerComputer();
if (computer != null) computer.setLabel(label);
setChanged();
BlockEntityHelpers.updateBlock(this);
}
@Override

View File

@@ -21,10 +21,13 @@ import dan200.computercraft.shared.util.WaterloggableHelpers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractHurtingProjectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
@@ -41,6 +44,7 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
@@ -168,6 +172,22 @@ public class TurtleBlock extends AbstractComputerBlock<TurtleBlockEntity> implem
}
}
@Override
@Deprecated
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
var currentItem = player.getItemInHand(hand);
if (currentItem.getItem() == Items.NAME_TAG && currentItem.hasCustomHoverName() && level.getBlockEntity(pos) instanceof AbstractComputerBlockEntity computer) {
// Label to rename computer
if (!level.isClientSide) {
computer.setLabel(currentItem.getHoverName().getString());
currentItem.shrink(1);
}
return InteractionResult.sidedSuccess(level.isClientSide);
}
return super.use(state, level, pos, player, hand, hit);
}
@ForgeOverride
public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) {
var exploder = explosion.getDirectSourceEntity();

View File

@@ -87,11 +87,6 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba
if (!hasMoved()) super.unload();
}
@Override
protected boolean canNameWithTag(Player player) {
return true;
}
@Override
protected double getInteractRange() {
return 12.0;

View File

@@ -136,7 +136,7 @@
"gui.computercraft.config.term_sizes": "Velikosti terminálu",
"gui.computercraft.config.term_sizes.computer": "Počítač",
"gui.computercraft.config.term_sizes.computer.height": "Výška terminálu",
"gui.computercraft.config.term_sizes.computer.height.tooltip": "Rozsash: 1 ~ 255",
"gui.computercraft.config.term_sizes.computer.height.tooltip": "Rozsah: 1 ~ 255",
"gui.computercraft.config.term_sizes.computer.tooltip": "Velikost počítačového terminálu.",
"gui.computercraft.config.term_sizes.computer.width": "Šířka terminálu",
"gui.computercraft.config.term_sizes.computer.width.tooltip": "Rozsah: 1 ~ 255",
@@ -177,7 +177,7 @@
"gui.computercraft.tooltip.turn_off.key": "Zmáčkni Ctrl+S",
"gui.computercraft.tooltip.turn_on": "Zapnout teno počítač",
"gui.computercraft.upload.failed": "Nahrávání se nezdařilo",
"gui.computercraft.upload.failed.computer_off": "Před nahráním souborů musíš vypnout počítač.",
"gui.computercraft.upload.failed.computer_off": "Před nahráním souborů musíš zapnout počítač.",
"gui.computercraft.upload.failed.corrupted": "Soubory byly porušeny při nahrávání. Prosím zkus to znovu.",
"gui.computercraft.upload.failed.generic": "Nahrávání souborů se nezdařilo (%s)",
"gui.computercraft.upload.failed.name_too_long": "Jména souborů pro nahrání jsou příliš dlouhá.",
@@ -216,5 +216,11 @@
"upgrade.minecraft.diamond_hoe.adjective": "Farmářský",
"upgrade.minecraft.diamond_pickaxe.adjective": "Těžební",
"upgrade.minecraft.diamond_shovel.adjective": "Kopací",
"upgrade.minecraft.diamond_sword.adjective": "Bojový"
"upgrade.minecraft.diamond_sword.adjective": "Bojový",
"tag.item.computercraft.computer": "Počítače",
"tag.item.computercraft.monitor": "Monitory",
"tag.item.computercraft.turtle": "Roboti",
"tag.item.computercraft.wired_modem": "Drátové modemy",
"gui.computercraft.config.http.proxy": "Proxy",
"gui.computercraft.config.upload_max_size.tooltip": "Limit velikosti nahrávaného souboru v bytech. Musí být v rozmezí od 1 KiB do 16 MiB.\nMěj na paměti, že nahrávání souborů je zpracováváno v jednom ticku - velké soubory nebo\nšpatný výkon sítě mohou zpomalit síťové vlákno. A nezapomeň na místo na disku!\nRozsah: 1024 ~ 16777216"
}

View File

@@ -17,7 +17,6 @@ import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.gametest.framework.GameTest
import net.minecraft.gametest.framework.GameTestHelper
import net.minecraft.world.InteractionHand
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraft.world.level.block.Blocks
@@ -140,8 +139,7 @@ class Computer_Test {
// Teleport the player to the computer and then open it.
thenExecute {
context.positionAt(BlockPos(2, 2, 1))
val computer = context.getBlockEntity(BlockPos(2, 2, 2), ModRegistry.BlockEntities.COMPUTER_ADVANCED.get())
computer.use(context.level.randomPlayer!!, InteractionHand.MAIN_HAND)
context.useBlock(BlockPos(2, 2, 2), context.level.randomPlayer!!)
}
// Assert the terminal is synced to the client.
thenIdle(2)