mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-15 11:45:42 +00:00
Merge branch 'mc-1.16.x' into mc-1.18.x
This commit is contained in:
commit
a07bba4ece
@ -62,10 +62,9 @@ public abstract class TileGeneric extends BlockEntity
|
|||||||
return 8.0;
|
return 8.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUsable( Player player, boolean ignoreRange )
|
public boolean isUsable( Player player )
|
||||||
{
|
{
|
||||||
if( player == null || !player.isAlive() || getLevel().getBlockEntity( getBlockPos() ) != this ) return false;
|
if( player == null || !player.isAlive() || getLevel().getBlockEntity( getBlockPos() ) != this ) return false;
|
||||||
if( ignoreRange ) return true;
|
|
||||||
|
|
||||||
double range = getInteractRange( player );
|
double range = getInteractRange( player );
|
||||||
BlockPos pos = getBlockPos();
|
BlockPos pos = getBlockPos();
|
||||||
|
@ -115,12 +115,12 @@ public class TileCommandComputer extends TileComputer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUsable( Player player, boolean ignoreRange )
|
public boolean isUsable( Player player )
|
||||||
{
|
{
|
||||||
return isUsable( player ) && super.isUsable( player, ignoreRange );
|
return isCommandUsable( player ) && super.isUsable( player );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUsable( Player player )
|
public static boolean isCommandUsable( Player player )
|
||||||
{
|
{
|
||||||
MinecraftServer server = player.getServer();
|
MinecraftServer server = player.getServer();
|
||||||
if( server == null || !server.isCommandBlockEnabled() )
|
if( server == null || !server.isCommandBlockEnabled() )
|
||||||
|
@ -54,7 +54,7 @@ public class TileComputer extends TileComputerBase
|
|||||||
|
|
||||||
protected boolean isUsableByPlayer( Player player )
|
protected boolean isUsableByPlayer( Player player )
|
||||||
{
|
{
|
||||||
return isUsable( player, false );
|
return isUsable( player );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,13 +25,11 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.network.chat.TextComponent;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
import net.minecraft.network.chat.TranslatableComponent;
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.*;
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.MenuProvider;
|
|
||||||
import net.minecraft.world.Nameable;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
@ -57,6 +55,8 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
private int invalidSides = 0;
|
private int invalidSides = 0;
|
||||||
private final NonNullConsumer<Object>[] invalidate;
|
private final NonNullConsumer<Object>[] invalidate;
|
||||||
|
|
||||||
|
private LockCode lockCode = LockCode.NO_LOCK;
|
||||||
|
|
||||||
private final ComputerFamily family;
|
private final ComputerFamily family;
|
||||||
|
|
||||||
public TileComputerBase( BlockEntityType<? extends TileGeneric> type, BlockPos pos, BlockState state, ComputerFamily family )
|
public TileComputerBase( BlockEntityType<? extends TileGeneric> type, BlockPos pos, BlockState state, ComputerFamily family )
|
||||||
@ -111,6 +111,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUsable( Player player )
|
||||||
|
{
|
||||||
|
return super.isUsable( player ) && BaseContainerBlockEntity.canUnlock( player, lockCode, getDisplayName() );
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public InteractionResult onActivate( Player player, InteractionHand hand, BlockHitResult hit )
|
public InteractionResult onActivate( Player player, InteractionHand hand, BlockHitResult hit )
|
||||||
@ -129,7 +135,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
else if( !player.isCrouching() )
|
else if( !player.isCrouching() )
|
||||||
{
|
{
|
||||||
// Regular right click to activate computer
|
// Regular right click to activate computer
|
||||||
if( !getLevel().isClientSide && isUsable( player, false ) )
|
if( !getLevel().isClientSide && isUsable( player ) )
|
||||||
{
|
{
|
||||||
createServerComputer().turnOn();
|
createServerComputer().turnOn();
|
||||||
new ComputerContainerData( createServerComputer() ).open( player, this );
|
new ComputerContainerData( createServerComputer() ).open( player, this );
|
||||||
@ -196,6 +202,8 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
if( label != null ) nbt.putString( NBT_LABEL, label );
|
if( label != null ) nbt.putString( NBT_LABEL, label );
|
||||||
nbt.putBoolean( NBT_ON, on );
|
nbt.putBoolean( NBT_ON, on );
|
||||||
|
|
||||||
|
lockCode.addToTag( nbt );
|
||||||
|
|
||||||
super.saveAdditional( nbt );
|
super.saveAdditional( nbt );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +216,8 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
|
computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
|
||||||
label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
|
label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
|
||||||
on = startOn = nbt.getBoolean( NBT_ON );
|
on = startOn = nbt.getBoolean( NBT_ON );
|
||||||
|
|
||||||
|
lockCode = LockCode.fromTag( nbt );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isPeripheralBlockedOnSide( ComputerSide localSide )
|
protected boolean isPeripheralBlockedOnSide( ComputerSide localSide )
|
||||||
|
@ -43,7 +43,7 @@ public class ContainerViewComputer extends ComputerMenuWithoutInventory
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're a command computer then ensure we're in creative
|
// If we're a command computer then ensure we're in creative
|
||||||
if( computer.getFamily() == ComputerFamily.COMMAND && !TileCommandComputer.isUsable( player ) )
|
if( computer.getFamily() == ComputerFamily.COMMAND && !TileCommandComputer.isCommandUsable( player ) )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,13 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.network.chat.TranslatableComponent;
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.*;
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.MenuProvider;
|
|
||||||
import net.minecraft.world.Nameable;
|
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
@ -61,6 +59,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
|||||||
}
|
}
|
||||||
|
|
||||||
Component customName;
|
Component customName;
|
||||||
|
private LockCode lockCode;
|
||||||
|
|
||||||
private final Map<IComputerAccess, MountInfo> computers = new HashMap<>();
|
private final Map<IComputerAccess, MountInfo> computers = new HashMap<>();
|
||||||
|
|
||||||
@ -95,6 +94,12 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
|||||||
peripheralCap = CapabilityUtil.invalidate( peripheralCap );
|
peripheralCap = CapabilityUtil.invalidate( peripheralCap );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUsable( Player player )
|
||||||
|
{
|
||||||
|
return super.isUsable( player ) && BaseContainerBlockEntity.canUnlock( player, lockCode, getDisplayName() );
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public InteractionResult onActivate( Player player, InteractionHand hand, BlockHitResult hit )
|
public InteractionResult onActivate( Player player, InteractionHand hand, BlockHitResult hit )
|
||||||
@ -114,7 +119,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Open the GUI
|
// Open the GUI
|
||||||
if( !getLevel().isClientSide ) NetworkHooks.openGui( (ServerPlayer) player, this );
|
if( !getLevel().isClientSide && isUsable( player ) )
|
||||||
|
{
|
||||||
|
NetworkHooks.openGui( (ServerPlayer) player, this );
|
||||||
|
}
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,6 +143,8 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
|||||||
diskStack = ItemStack.of( item );
|
diskStack = ItemStack.of( item );
|
||||||
diskMount = null;
|
diskMount = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lockCode = LockCode.fromTag( nbt );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -148,6 +158,9 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
|||||||
diskStack.save( item );
|
diskStack.save( item );
|
||||||
nbt.put( NBT_ITEM, item );
|
nbt.put( NBT_ITEM, item );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lockCode.addToTag( nbt );
|
||||||
|
|
||||||
super.saveAdditional( nbt );
|
super.saveAdditional( nbt );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +311,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
|||||||
@Override
|
@Override
|
||||||
public boolean stillValid( @Nonnull Player player )
|
public boolean stillValid( @Nonnull Player player )
|
||||||
{
|
{
|
||||||
return isUsable( player, false );
|
return isUsable( player );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,6 +25,7 @@ import net.minecraft.world.item.DyeColor;
|
|||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
@ -55,6 +56,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
|||||||
private static final int[] SIDE_SLOTS = new int[] { 0 };
|
private static final int[] SIDE_SLOTS = new int[] { 0 };
|
||||||
|
|
||||||
Component customName;
|
Component customName;
|
||||||
|
private LockCode lockCode;
|
||||||
|
|
||||||
private final NonNullList<ItemStack> inventory = NonNullList.withSize( SLOTS, ItemStack.EMPTY );
|
private final NonNullList<ItemStack> inventory = NonNullList.withSize( SLOTS, ItemStack.EMPTY );
|
||||||
private final SidedCaps<IItemHandler> itemHandlerCaps =
|
private final SidedCaps<IItemHandler> itemHandlerCaps =
|
||||||
@ -84,13 +86,22 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
|||||||
peripheralCap = CapabilityUtil.invalidate( peripheralCap );
|
peripheralCap = CapabilityUtil.invalidate( peripheralCap );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUsable( Player player )
|
||||||
|
{
|
||||||
|
return super.isUsable( player ) && BaseContainerBlockEntity.canUnlock( player, lockCode, getDisplayName() );
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public InteractionResult onActivate( Player player, InteractionHand hand, BlockHitResult hit )
|
public InteractionResult onActivate( Player player, InteractionHand hand, BlockHitResult hit )
|
||||||
{
|
{
|
||||||
if( player.isCrouching() ) return InteractionResult.PASS;
|
if( player.isCrouching() ) return InteractionResult.PASS;
|
||||||
|
|
||||||
if( !getLevel().isClientSide ) NetworkHooks.openGui( (ServerPlayer) player, this );
|
if( !getLevel().isClientSide && isUsable( player ) )
|
||||||
|
{
|
||||||
|
NetworkHooks.openGui( (ServerPlayer) player, this );
|
||||||
|
}
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +122,8 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
|||||||
|
|
||||||
// Read inventory
|
// Read inventory
|
||||||
ContainerHelper.loadAllItems( nbt, inventory );
|
ContainerHelper.loadAllItems( nbt, inventory );
|
||||||
|
|
||||||
|
lockCode = LockCode.fromTag( nbt );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -129,6 +142,8 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
|||||||
// Write inventory
|
// Write inventory
|
||||||
ContainerHelper.saveAllItems( nbt, inventory );
|
ContainerHelper.saveAllItems( nbt, inventory );
|
||||||
|
|
||||||
|
lockCode.addToTag( nbt );
|
||||||
|
|
||||||
super.saveAdditional( nbt );
|
super.saveAdditional( nbt );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +246,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
|||||||
@Override
|
@Override
|
||||||
public boolean stillValid( @Nonnull Player playerEntity )
|
public boolean stillValid( @Nonnull Player playerEntity )
|
||||||
{
|
{
|
||||||
return isUsable( playerEntity, false );
|
return isUsable( playerEntity );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ISidedInventory implementation
|
// ISidedInventory implementation
|
||||||
|
@ -50,6 +50,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
|||||||
private static final String NBT_UPGRADE = "Upgrade";
|
private static final String NBT_UPGRADE = "Upgrade";
|
||||||
private static final String NBT_UPGRADE_INFO = "UpgradeInfo";
|
private static final String NBT_UPGRADE_INFO = "UpgradeInfo";
|
||||||
public static final String NBT_LIGHT = "Light";
|
public static final String NBT_LIGHT = "Light";
|
||||||
|
private static final String NBT_ON = "On";
|
||||||
|
|
||||||
private static final String NBT_INSTANCE = "Instanceid";
|
private static final String NBT_INSTANCE = "Instanceid";
|
||||||
private static final String NBT_SESSION = "SessionId";
|
private static final String NBT_SESSION = "SessionId";
|
||||||
@ -105,6 +106,13 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
|||||||
setLabel( stack, label );
|
setLabel( stack, label );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean on = computer.isOn();
|
||||||
|
if( on != isMarkedOn( stack ) )
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
stack.getOrCreateTag().putBoolean( NBT_ON, on );
|
||||||
|
}
|
||||||
|
|
||||||
// Update pocket upgrade
|
// Update pocket upgrade
|
||||||
if( upgrade != null ) upgrade.update( computer, computer.getPeripheral( ComputerSide.BACK ) );
|
if( upgrade != null ) upgrade.update( computer, computer.getPeripheral( ComputerSide.BACK ) );
|
||||||
|
|
||||||
@ -247,6 +255,10 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
|||||||
computer.updateValues( entity, stack, getUpgrade( stack ) );
|
computer.updateValues( entity, stack, getUpgrade( stack ) );
|
||||||
computer.addAPI( new PocketAPI( computer ) );
|
computer.addAPI( new PocketAPI( computer ) );
|
||||||
ComputerCraft.serverComputerRegistry.add( instanceID, computer );
|
ComputerCraft.serverComputerRegistry.add( instanceID, computer );
|
||||||
|
|
||||||
|
// Only turn on when initially creating the computer, rather than each tick.
|
||||||
|
if( isMarkedOn( stack ) && entity instanceof Player ) computer.turnOn();
|
||||||
|
|
||||||
if( inventory != null ) inventory.setChanged();
|
if( inventory != null ) inventory.setChanged();
|
||||||
}
|
}
|
||||||
computer.setLevel( world );
|
computer.setLevel( world );
|
||||||
@ -362,6 +374,12 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
|||||||
stack.getOrCreateTag().putInt( NBT_SESSION, sessionID );
|
stack.getOrCreateTag().putInt( NBT_SESSION, sessionID );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isMarkedOn( @Nonnull ItemStack stack )
|
||||||
|
{
|
||||||
|
CompoundTag nbt = stack.getTag();
|
||||||
|
return nbt != null && nbt.getBoolean( NBT_ON );
|
||||||
|
}
|
||||||
|
|
||||||
public static ComputerState getState( @Nonnull ItemStack stack )
|
public static ComputerState getState( @Nonnull ItemStack stack )
|
||||||
{
|
{
|
||||||
ClientComputer computer = getClientComputer( stack );
|
ClientComputer computer = getClientComputer( stack );
|
||||||
|
@ -487,7 +487,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
|||||||
@Override
|
@Override
|
||||||
public boolean stillValid( @Nonnull Player player )
|
public boolean stillValid( @Nonnull Player player )
|
||||||
{
|
{
|
||||||
return isUsable( player, false );
|
return isUsable( player );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onInventoryDefinitelyChanged()
|
private void onInventoryDefinitelyChanged()
|
||||||
|
Loading…
Reference in New Issue
Block a user