1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-29 21:02:59 +00:00
This commit is contained in:
Devan-Kerman
2020-09-04 18:07:48 -05:00
parent 3fa6b5bc9d
commit c5eb7a9501
401 changed files with 23699 additions and 25873 deletions

View File

@@ -3,8 +3,14 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import java.util.Random;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
@@ -20,67 +26,65 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Random;
public abstract class BlockGeneric extends BlockWithEntity
{
public abstract class BlockGeneric extends BlockWithEntity {
private final BlockEntityType<? extends TileGeneric> type;
public BlockGeneric( Settings settings, BlockEntityType<? extends TileGeneric> type )
{
super( settings );
public BlockGeneric(Settings settings, BlockEntityType<? extends TileGeneric> type) {
super(settings);
this.type = type;
}
@Override
public BlockRenderType getRenderType( BlockState state )
{
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@Override
@Deprecated
public final void onStateReplaced( @Nonnull BlockState block, @Nonnull World world, @Nonnull BlockPos pos, BlockState replace, boolean bool )
{
if( block.getBlock() == replace.getBlock() ) return;
public final void neighborUpdate(@Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull Block neighbourBlock,
@Nonnull BlockPos neighbourPos, boolean isMoving) {
BlockEntity tile = world.getBlockEntity(pos);
if (tile instanceof TileGeneric) {
((TileGeneric) tile).onNeighbourChange(neighbourPos);
}
}
BlockEntity tile = world.getBlockEntity( pos );
super.onStateReplaced( block, world, pos, replace, bool );
world.removeBlockEntity( pos );
if( tile instanceof TileGeneric ) ((TileGeneric) tile).destroy();
@Override
@Deprecated
public final void onStateReplaced(@Nonnull BlockState block, @Nonnull World world, @Nonnull BlockPos pos, BlockState replace, boolean bool) {
if (block.getBlock() == replace.getBlock()) {
return;
}
BlockEntity tile = world.getBlockEntity(pos);
super.onStateReplaced(block, world, pos, replace, bool);
world.removeBlockEntity(pos);
if (tile instanceof TileGeneric) {
((TileGeneric) tile).destroy();
}
}
@Nonnull
@Override
@Deprecated
public final ActionResult onUse( @Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockHitResult hit )
{
BlockEntity tile = world.getBlockEntity( pos );
return tile instanceof TileGeneric ? ((TileGeneric) tile).onActivate( player, hand, hit ) : ActionResult.PASS;
public final ActionResult onUse(@Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand,
@Nonnull BlockHitResult hit) {
BlockEntity tile = world.getBlockEntity(pos);
return tile instanceof TileGeneric ? ((TileGeneric) tile).onActivate(player, hand, hit) : ActionResult.PASS;
}
@Override
@Deprecated
public final void neighborUpdate( @Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull Block neighbourBlock, @Nonnull BlockPos neighbourPos, boolean isMoving )
{
BlockEntity tile = world.getBlockEntity( pos );
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos );
}
@Override
@Deprecated
public void scheduledTick( @Nonnull BlockState state, ServerWorld world, @Nonnull BlockPos pos, @Nonnull Random rand )
{
BlockEntity te = world.getBlockEntity( pos );
if( te instanceof TileGeneric ) ((TileGeneric) te).blockTick();
public void scheduledTick(@Nonnull BlockState state, ServerWorld world, @Nonnull BlockPos pos, @Nonnull Random rand) {
BlockEntity te = world.getBlockEntity(pos);
if (te instanceof TileGeneric) {
((TileGeneric) te).blockTick();
}
}
@Nullable
@Override
public BlockEntity createBlockEntity(@Nonnull BlockView world )
{
return type.instantiate();
public BlockEntity createBlockEntity(@Nonnull BlockView world) {
return this.type.instantiate();
}
}

View File

@@ -3,57 +3,66 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState;
import net.minecraft.nbt.CompoundTag;
public class ClientTerminal implements ITerminal
{
public class ClientTerminal implements ITerminal {
private boolean m_colour;
private Terminal m_terminal;
private boolean m_terminalChanged;
public ClientTerminal( boolean colour )
{
m_colour = colour;
m_terminal = null;
m_terminalChanged = false;
public ClientTerminal(boolean colour) {
this.m_colour = colour;
this.m_terminal = null;
this.m_terminalChanged = false;
}
public boolean pollTerminalChanged()
{
boolean changed = m_terminalChanged;
m_terminalChanged = false;
public boolean pollTerminalChanged() {
boolean changed = this.m_terminalChanged;
this.m_terminalChanged = false;
return changed;
}
// ITerminal implementation
@Override
public Terminal getTerminal()
{
return m_terminal;
public Terminal getTerminal() {
return this.m_terminal;
}
@Override
public boolean isColour()
{
return m_colour;
public boolean isColour() {
return this.m_colour;
}
public void read( TerminalState state )
{
m_colour = state.colour;
if( state.hasTerminal() )
{
resizeTerminal( state.width, state.height );
state.apply( m_terminal );
public void read(TerminalState state) {
this.m_colour = state.colour;
if (state.hasTerminal()) {
this.resizeTerminal(state.width, state.height);
state.apply(this.m_terminal);
} else {
this.deleteTerminal();
}
else
{
deleteTerminal();
}
private void resizeTerminal(int width, int height) {
if (this.m_terminal == null) {
this.m_terminal = new Terminal(width, height, () -> this.m_terminalChanged = true);
this.m_terminalChanged = true;
} else {
this.m_terminal.resize(width, height);
}
}
private void deleteTerminal() {
if (this.m_terminal != null) {
this.m_terminal = null;
this.m_terminalChanged = true;
}
}
@@ -67,26 +76,4 @@ public class ClientTerminal implements ITerminal
this.deleteTerminal();
}
}
private void resizeTerminal( int width, int height )
{
if( m_terminal == null )
{
m_terminal = new Terminal( width, height, () -> m_terminalChanged = true );
m_terminalChanged = true;
}
else
{
m_terminal.resize( width, height );
}
}
private void deleteTerminal()
{
if( m_terminal != null )
{
m_terminal = null;
m_terminalChanged = true;
}
}
}

View File

@@ -3,11 +3,15 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import javax.annotation.Nonnull;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.ColourTracker;
import dan200.computercraft.shared.util.ColourUtils;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeSerializer;
@@ -17,36 +21,31 @@ import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
public final class ColourableRecipe extends SpecialCraftingRecipe {
public static final RecipeSerializer<?> SERIALIZER = new SpecialRecipeSerializer<>(ColourableRecipe::new);
public final class ColourableRecipe extends SpecialCraftingRecipe
{
private ColourableRecipe( Identifier id )
{
super( id );
private ColourableRecipe(Identifier id) {
super(id);
}
@Override
public boolean matches( @Nonnull CraftingInventory inv, @Nonnull World world )
{
public boolean matches(@Nonnull CraftingInventory inv, @Nonnull World world) {
boolean hasColourable = false;
boolean hasDye = false;
for( int i = 0; i < inv.size(); i++ )
{
ItemStack stack = inv.getStack( i );
if( stack.isEmpty() ) continue;
for (int i = 0; i < inv.size(); i++) {
ItemStack stack = inv.getStack(i);
if (stack.isEmpty()) {
continue;
}
if( stack.getItem() instanceof IColouredItem )
{
if( hasColourable ) return false;
if (stack.getItem() instanceof IColouredItem) {
if (hasColourable) {
return false;
}
hasColourable = true;
}
else if( ColourUtils.getStackColour( stack ) != null )
{
} else if (ColourUtils.getStackColour(stack) != null) {
hasDye = true;
}
else
{
} else {
return false;
}
}
@@ -56,48 +55,45 @@ public final class ColourableRecipe extends SpecialCraftingRecipe
@Nonnull
@Override
public ItemStack craft( @Nonnull CraftingInventory inv )
{
public ItemStack craft(@Nonnull CraftingInventory inv) {
ItemStack colourable = ItemStack.EMPTY;
ColourTracker tracker = new ColourTracker();
for( int i = 0; i < inv.size(); i++ )
{
ItemStack stack = inv.getStack( i );
for (int i = 0; i < inv.size(); i++) {
ItemStack stack = inv.getStack(i);
if( stack.isEmpty() ) continue;
if( stack.getItem() instanceof IColouredItem )
{
colourable = stack;
if (stack.isEmpty()) {
continue;
}
else
{
DyeColor dye = ColourUtils.getStackColour( stack );
if( dye == null ) continue;
Colour colour = Colour.fromInt( 15 - dye.getId() );
tracker.addColour( colour.getR(), colour.getG(), colour.getB() );
if (stack.getItem() instanceof IColouredItem) {
colourable = stack;
} else {
DyeColor dye = ColourUtils.getStackColour(stack);
if (dye == null) {
continue;
}
Colour colour = Colour.fromInt(15 - dye.getId());
tracker.addColour(colour.getR(), colour.getG(), colour.getB());
}
}
if( colourable.isEmpty() ) return ItemStack.EMPTY;
return ((IColouredItem) colourable.getItem()).withColour( colourable, tracker.getColour() );
if (colourable.isEmpty()) {
return ItemStack.EMPTY;
}
return ((IColouredItem) colourable.getItem()).withColour(colourable, tracker.getColour());
}
@Override
public boolean fits( int x, int y )
{
public boolean fits(int x, int y) {
return x >= 2 && y >= 2;
}
@Override
@Nonnull
public RecipeSerializer<?> getSerializer()
{
public RecipeSerializer<?> getSerializer() {
return SERIALIZER;
}
public static final RecipeSerializer<?> SERIALIZER = new SpecialRecipeSerializer<>( ColourableRecipe::new );
}

View File

@@ -3,11 +3,15 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.network.container.HeldItemContainerData;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
@@ -18,55 +22,50 @@ import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ContainerHeldItem extends ScreenHandler
{
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
public class ContainerHeldItem extends ScreenHandler {
private final ItemStack stack;
private final Hand hand;
public ContainerHeldItem( ScreenHandlerType<? extends ContainerHeldItem> type, int id, PlayerEntity player, Hand hand )
{
super( type, id );
public ContainerHeldItem(ScreenHandlerType<? extends ContainerHeldItem> type, int id, PlayerEntity player, Hand hand) {
super(type, id);
this.hand = hand;
stack = player.getStackInHand( hand ).copy();
this.stack = player.getStackInHand(hand)
.copy();
}
public static ContainerHeldItem createPrintout( int id, PlayerInventory inventory, PacketByteBuf data )
{
public static ContainerHeldItem createPrintout(int id, PlayerInventory inventory, PacketByteBuf data) {
return createPrintout(id, inventory, new HeldItemContainerData(data));
}
public static ContainerHeldItem createPrintout( int id, PlayerInventory inventory, HeldItemContainerData data )
{
return new ContainerHeldItem( ComputerCraftRegistry.ModContainers.PRINTOUT, id, inventory.player, data.getHand() );
public static ContainerHeldItem createPrintout(int id, PlayerInventory inventory, HeldItemContainerData data) {
return new ContainerHeldItem(ComputerCraftRegistry.ModContainers.PRINTOUT, id, inventory.player, data.getHand());
}
@Nonnull
public ItemStack getStack()
{
return stack;
public ItemStack getStack() {
return this.stack;
}
@Override
public boolean canUse( @Nonnull PlayerEntity player )
{
if( !player.isAlive() ) return false;
public boolean canUse(@Nonnull PlayerEntity player) {
if (!player.isAlive()) {
return false;
}
ItemStack stack = player.getStackInHand( hand );
ItemStack stack = player.getStackInHand(this.hand);
return stack == this.stack || !stack.isEmpty() && !this.stack.isEmpty() && stack.getItem() == this.stack.getItem();
}
public static class Factory implements NamedScreenHandlerFactory, ExtendedScreenHandlerFactory
{
public static class Factory implements NamedScreenHandlerFactory, ExtendedScreenHandlerFactory {
private final ScreenHandlerType<ContainerHeldItem> type;
private final Text name;
private final Hand hand;
public Factory( ScreenHandlerType<ContainerHeldItem> type, ItemStack stack, Hand hand )
{
public Factory(ScreenHandlerType<ContainerHeldItem> type, ItemStack stack, Hand hand) {
this.type = type;
this.name = stack.getName();
this.hand = hand;
@@ -74,21 +73,19 @@ public class ContainerHeldItem extends ScreenHandler
@Nonnull
@Override
public Text getDisplayName()
{
return name;
public Text getDisplayName() {
return this.name;
}
@Nullable
@Override
public ScreenHandler createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
{
return new ContainerHeldItem( type, id, player, hand );
public ScreenHandler createMenu(int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player) {
return new ContainerHeldItem(this.type, id, player, this.hand);
}
@Override
public void writeScreenOpeningData(ServerPlayerEntity serverPlayerEntity, PacketByteBuf packetByteBuf) {
packetByteBuf.writeEnumConstant(hand);
packetByteBuf.writeEnumConstant(this.hand);
}
}
}

View File

@@ -3,33 +3,31 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import javax.annotation.Nonnull;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import net.minecraft.block.Block;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider
{
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider {
@Override
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
{
return getDefaultBundledRedstoneOutput( world, pos, side );
public int getBundledRedstoneOutput(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side) {
return getDefaultBundledRedstoneOutput(world, pos, side);
}
public static int getDefaultBundledRedstoneOutput( World world, BlockPos pos, Direction side )
{
Block block = world.getBlockState( pos ).getBlock();
if( block instanceof IBundledRedstoneBlock )
{
public static int getDefaultBundledRedstoneOutput(World world, BlockPos pos, Direction side) {
Block block = world.getBlockState(pos)
.getBlock();
if (block instanceof IBundledRedstoneBlock) {
IBundledRedstoneBlock generic = (IBundledRedstoneBlock) block;
if( generic.getBundledRedstoneConnectivity( world, pos, side ) )
{
return generic.getBundledRedstoneOutput( world, pos, side );
if (generic.getBundledRedstoneConnectivity(world, pos, side)) {
return generic.getBundledRedstoneOutput(world, pos, side);
}
}
return -1;

View File

@@ -3,15 +3,15 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
public interface IBundledRedstoneBlock
{
boolean getBundledRedstoneConnectivity( World world, BlockPos pos, Direction side );
public interface IBundledRedstoneBlock {
boolean getBundledRedstoneConnectivity(World world, BlockPos pos, Direction side);
int getBundledRedstoneOutput( World world, BlockPos pos, Direction side );
int getBundledRedstoneOutput(World world, BlockPos pos, Direction side);
}

View File

@@ -3,43 +3,39 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
public interface IColouredItem
{
public interface IColouredItem {
String NBT_COLOUR = "Color";
default int getColour( ItemStack stack )
{
return getColourBasic( stack );
default int getColour(ItemStack stack) {
return getColourBasic(stack);
}
default ItemStack withColour( ItemStack stack, int colour )
{
static int getColourBasic(ItemStack stack) {
CompoundTag tag = stack.getTag();
return tag != null && tag.contains(NBT_COLOUR) ? tag.getInt(NBT_COLOUR) : -1;
}
default ItemStack withColour(ItemStack stack, int colour) {
ItemStack copy = stack.copy();
setColourBasic( copy, colour );
setColourBasic(copy, colour);
return copy;
}
static int getColourBasic( ItemStack stack )
{
CompoundTag tag = stack.getTag();
return tag != null && tag.contains( NBT_COLOUR ) ? tag.getInt( NBT_COLOUR ) : -1;
}
static void setColourBasic( ItemStack stack, int colour )
{
if( colour == -1 )
{
static void setColourBasic(ItemStack stack, int colour) {
if (colour == -1) {
CompoundTag tag = stack.getTag();
if( tag != null ) tag.remove( NBT_COLOUR );
}
else
{
stack.getOrCreateTag().putInt( NBT_COLOUR, colour );
if (tag != null) {
tag.remove(NBT_COLOUR);
}
} else {
stack.getOrCreateTag()
.putInt(NBT_COLOUR, colour);
}
}
}

View File

@@ -3,12 +3,12 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal;
public interface ITerminal
{
public interface ITerminal {
Terminal getTerminal();
boolean isColour();

View File

@@ -3,85 +3,72 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState;
import net.minecraft.nbt.CompoundTag;
package dan200.computercraft.shared.common;
import java.util.concurrent.atomic.AtomicBoolean;
public class ServerTerminal implements ITerminal
{
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState;
import net.minecraft.nbt.CompoundTag;
public class ServerTerminal implements ITerminal {
private final boolean m_colour;
private final AtomicBoolean m_terminalChanged = new AtomicBoolean(false);
private Terminal m_terminal;
private final AtomicBoolean m_terminalChanged = new AtomicBoolean( false );
private boolean m_terminalChangedLastFrame = false;
public ServerTerminal( boolean colour )
{
m_colour = colour;
m_terminal = null;
public ServerTerminal(boolean colour) {
this.m_colour = colour;
this.m_terminal = null;
}
public ServerTerminal( boolean colour, int terminalWidth, int terminalHeight )
{
m_colour = colour;
m_terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged );
public ServerTerminal(boolean colour, int terminalWidth, int terminalHeight) {
this.m_colour = colour;
this.m_terminal = new Terminal(terminalWidth, terminalHeight, this::markTerminalChanged);
}
protected void resize( int width, int height )
{
if( m_terminal == null )
{
m_terminal = new Terminal( width, height, this::markTerminalChanged );
markTerminalChanged();
}
else
{
m_terminal.resize( width, height );
protected void markTerminalChanged() {
this.m_terminalChanged.set(true);
}
protected void resize(int width, int height) {
if (this.m_terminal == null) {
this.m_terminal = new Terminal(width, height, this::markTerminalChanged);
this.markTerminalChanged();
} else {
this.m_terminal.resize(width, height);
}
}
public void delete()
{
if( m_terminal != null )
{
m_terminal = null;
markTerminalChanged();
public void delete() {
if (this.m_terminal != null) {
this.m_terminal = null;
this.markTerminalChanged();
}
}
protected void markTerminalChanged()
{
m_terminalChanged.set( true );
public void update() {
this.m_terminalChangedLastFrame = this.m_terminalChanged.getAndSet(false);
}
public void update()
{
m_terminalChangedLastFrame = m_terminalChanged.getAndSet( false );
}
public boolean hasTerminalChanged()
{
return m_terminalChangedLastFrame;
public boolean hasTerminalChanged() {
return this.m_terminalChangedLastFrame;
}
@Override
public Terminal getTerminal()
{
return m_terminal;
public Terminal getTerminal() {
return this.m_terminal;
}
@Override
public boolean isColour()
{
return m_colour;
public boolean isColour() {
return this.m_colour;
}
public TerminalState write()
{
return new TerminalState( m_colour, m_terminal );
public TerminalState write() {
return new TerminalState(this.m_colour, this.m_terminal);
}
public void writeDescription(CompoundTag nbt) {

View File

@@ -3,91 +3,83 @@
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import javax.annotation.Nonnull;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import javax.annotation.Nonnull;
public abstract class TileGeneric extends BlockEntity implements BlockEntityClientSerializable
{
public TileGeneric( BlockEntityType<? extends TileGeneric> type )
{
super( type );
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
public abstract class TileGeneric extends BlockEntity implements BlockEntityClientSerializable {
public TileGeneric(BlockEntityType<? extends TileGeneric> type) {
super(type);
}
public void destroy()
{
public void destroy() {
}
public final void updateBlock()
{
markDirty();
BlockPos pos = getPos();
BlockState state = getCachedState();
getWorld().updateListeners( pos, state, state, 3 );
public final void updateBlock() {
this.markDirty();
BlockPos pos = this.getPos();
BlockState state = this.getCachedState();
this.getWorld().updateListeners(pos, state, state, 3);
}
@Nonnull
public ActionResult onActivate( PlayerEntity player, Hand hand, BlockHitResult hit )
{
public ActionResult onActivate(PlayerEntity player, Hand hand, BlockHitResult hit) {
return ActionResult.PASS;
}
public void onNeighbourChange( @Nonnull BlockPos neighbour )
{
public void onNeighbourChange(@Nonnull BlockPos neighbour) {
}
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
{
public void onNeighbourTileEntityChange(@Nonnull BlockPos neighbour) {
}
protected void blockTick()
{
protected void blockTick() {
}
protected double getInteractRange( PlayerEntity player )
{
public boolean isUsable(PlayerEntity player, boolean ignoreRange) {
if (player == null || !player.isAlive() || this.getWorld().getBlockEntity(this.getPos()) != this) {
return false;
}
if (ignoreRange) {
return true;
}
double range = this.getInteractRange(player);
BlockPos pos = this.getPos();
return player.getEntityWorld() == this.getWorld() && player.squaredDistanceTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5) <= range * range;
}
protected double getInteractRange(PlayerEntity player) {
return 8.0;
}
public boolean isUsable( PlayerEntity player, boolean ignoreRange )
{
if( player == null || !player.isAlive() || getWorld().getBlockEntity( getPos() ) != this ) return false;
if( ignoreRange ) return true;
double range = getInteractRange( player );
BlockPos pos = getPos();
return player.getEntityWorld() == getWorld() &&
player.squaredDistanceTo( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range;
}
protected void writeDescription( @Nonnull CompoundTag nbt )
{
}
protected void readDescription( @Nonnull CompoundTag nbt )
{
}
@Override
public CompoundTag toClientTag(CompoundTag compoundTag) {
writeDescription(compoundTag);
return compoundTag;
}
@Override
public void fromClientTag(CompoundTag compoundTag) {
readDescription(compoundTag);
this.readDescription(compoundTag);
}
protected void readDescription(@Nonnull CompoundTag nbt) {
}
@Override
public CompoundTag toClientTag(CompoundTag compoundTag) {
this.writeDescription(compoundTag);
return compoundTag;
}
protected void writeDescription(@Nonnull CompoundTag nbt) {
}
}