2017-05-07 00:18:59 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
2021-01-06 17:13:40 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
package dan200.computercraft.shared.peripheral.diskdrive;
|
|
|
|
|
|
|
|
import dan200.computercraft.api.filesystem.IMount;
|
|
|
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
|
|
|
import dan200.computercraft.api.media.IMedia;
|
|
|
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
|
|
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
2018-12-10 23:46:50 +00:00
|
|
|
import dan200.computercraft.shared.MediaProviders;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
import dan200.computercraft.shared.common.TileGeneric;
|
2020-06-27 09:23:45 +00:00
|
|
|
import dan200.computercraft.shared.util.CapabilityUtil;
|
|
|
|
import dan200.computercraft.shared.util.DefaultInventory;
|
|
|
|
import dan200.computercraft.shared.util.InventoryUtil;
|
|
|
|
import dan200.computercraft.shared.util.RecordUtil;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.entity.item.ItemEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerInventory;
|
|
|
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
|
|
import net.minecraft.inventory.container.Container;
|
|
|
|
import net.minecraft.inventory.container.INamedContainerProvider;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
|
|
|
import net.minecraft.tileentity.ITickableTileEntity;
|
2020-06-27 09:23:45 +00:00
|
|
|
import net.minecraft.tileentity.TileEntityType;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
import net.minecraft.util.*;
|
2017-05-08 23:41:20 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
2017-05-08 23:41:20 +00:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2019-06-21 20:01:40 +00:00
|
|
|
import net.minecraft.util.text.TranslationTextComponent;
|
2017-05-08 23:41:20 +00:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
import net.minecraftforge.common.util.LazyOptional;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraftforge.fml.network.NetworkHooks;
|
2017-05-08 23:41:20 +00:00
|
|
|
import net.minecraftforge.items.IItemHandlerModifiable;
|
|
|
|
import net.minecraftforge.items.wrapper.InvWrapper;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2017-05-08 23:41:20 +00:00
|
|
|
import javax.annotation.Nullable;
|
2017-05-01 13:32:39 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2020-05-15 16:09:12 +00:00
|
|
|
import static dan200.computercraft.shared.Capabilities.CAPABILITY_PERIPHERAL;
|
2017-05-08 23:41:20 +00:00
|
|
|
import static net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
|
|
|
|
2020-05-15 16:09:12 +00:00
|
|
|
public final class TileDiskDrive extends TileGeneric implements DefaultInventory, ITickableTileEntity, INameable, INamedContainerProvider
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
private static final String NBT_NAME = "CustomName";
|
|
|
|
private static final String NBT_ITEM = "Item";
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
private static class MountInfo
|
|
|
|
{
|
2019-04-02 10:50:13 +00:00
|
|
|
String mountPath;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
ITextComponent customName;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private final Map<IComputerAccess, MountInfo> computers = new HashMap<>();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
@Nonnull
|
2021-01-15 16:35:49 +00:00
|
|
|
private ItemStack diskStack = ItemStack.EMPTY;
|
2019-04-09 16:29:23 +00:00
|
|
|
private LazyOptional<IItemHandlerModifiable> itemHandlerCap;
|
2020-05-15 16:09:12 +00:00
|
|
|
private LazyOptional<IPeripheral> peripheralCap;
|
2021-01-15 16:35:49 +00:00
|
|
|
private IMount diskMount = null;
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private boolean recordQueued = false;
|
|
|
|
private boolean recordPlaying = false;
|
|
|
|
private boolean restartRecord = false;
|
|
|
|
private boolean ejectQueued;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2020-06-27 09:23:45 +00:00
|
|
|
public TileDiskDrive( TileEntityType<TileDiskDrive> type )
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
{
|
2020-06-27 09:23:45 +00:00
|
|
|
super( type );
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
|
|
|
public void destroy()
|
|
|
|
{
|
|
|
|
ejectContents( true );
|
2021-01-15 16:35:49 +00:00
|
|
|
if( recordPlaying ) stopRecord();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 16:29:23 +00:00
|
|
|
@Override
|
|
|
|
protected void invalidateCaps()
|
|
|
|
{
|
|
|
|
super.invalidateCaps();
|
2020-05-15 16:09:12 +00:00
|
|
|
itemHandlerCap = CapabilityUtil.invalidate( itemHandlerCap );
|
|
|
|
peripheralCap = CapabilityUtil.invalidate( peripheralCap );
|
2019-04-09 16:29:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 11:14:30 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2020-01-22 11:14:30 +00:00
|
|
|
public ActionResultType onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-01-22 11:14:30 +00:00
|
|
|
if( player.isCrouching() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Try to put a disk into the drive
|
2021-01-09 19:22:58 +00:00
|
|
|
ItemStack disk = player.getItemInHand( hand );
|
2020-01-22 11:14:30 +00:00
|
|
|
if( disk.isEmpty() ) return ActionResultType.PASS;
|
2021-01-09 19:22:58 +00:00
|
|
|
if( !getLevel().isClientSide && getItem( 0 ).isEmpty() && MediaProviders.get( disk ) != null )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-04-02 10:50:13 +00:00
|
|
|
setDiskStack( disk );
|
2021-01-09 19:22:58 +00:00
|
|
|
player.setItemInHand( hand, ItemStack.EMPTY );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2020-01-22 11:14:30 +00:00
|
|
|
return ActionResultType.SUCCESS;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Open the GUI
|
2021-01-09 19:22:58 +00:00
|
|
|
if( !getLevel().isClientSide ) NetworkHooks.openGui( (ServerPlayerEntity) player, this );
|
2020-01-22 11:14:30 +00:00
|
|
|
return ActionResultType.SUCCESS;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public Direction getDirection()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
return getBlockState().getValue( BlockDiskDrive.FACING );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public void load( @Nonnull CompoundNBT nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
super.load( nbt );
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null;
|
|
|
|
if( nbt.contains( NBT_ITEM ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
CompoundNBT item = nbt.getCompound( NBT_ITEM );
|
2021-01-15 16:35:49 +00:00
|
|
|
diskStack = ItemStack.of( item );
|
|
|
|
diskMount = null;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public CompoundNBT save( @Nonnull CompoundNBT nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) );
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( !diskStack.isEmpty() )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
CompoundNBT item = new CompoundNBT();
|
2021-01-15 16:35:49 +00:00
|
|
|
diskStack.save( item );
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
nbt.put( NBT_ITEM, item );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2021-01-09 19:22:58 +00:00
|
|
|
return super.save( nbt );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
public void tick()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
// Ejection
|
2021-01-15 16:35:49 +00:00
|
|
|
if( ejectQueued )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2018-08-25 20:17:48 +00:00
|
|
|
ejectContents( false );
|
2021-01-15 16:35:49 +00:00
|
|
|
ejectQueued = false;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
// Music
|
|
|
|
synchronized( this )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( !level.isClientSide && recordPlaying != recordQueued || restartRecord )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
restartRecord = false;
|
|
|
|
if( recordQueued )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
|
|
|
IMedia contents = getDiskMedia();
|
2021-01-15 16:35:49 +00:00
|
|
|
SoundEvent record = contents != null ? contents.getAudio( diskStack ) : null;
|
2017-05-01 14:48:44 +00:00
|
|
|
if( record != null )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
recordPlaying = true;
|
2017-09-12 14:46:46 +00:00
|
|
|
playRecord();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
recordQueued = false;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-12 14:46:46 +00:00
|
|
|
stopRecord();
|
2021-01-15 16:35:49 +00:00
|
|
|
recordPlaying = false;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IInventory implementation
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public int getContainerSize()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
@Override
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return diskStack.isEmpty();
|
2017-05-11 00:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public ItemStack getItem( int slot )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return diskStack;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public ItemStack removeItemNoUpdate( int slot )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
ItemStack result = diskStack;
|
|
|
|
diskStack = ItemStack.EMPTY;
|
|
|
|
diskMount = null;
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
return result;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public ItemStack removeItem( int slot, int count )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( diskStack.isEmpty() ) return ItemStack.EMPTY;
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( diskStack.getCount() <= count )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
ItemStack disk = diskStack;
|
2021-01-09 19:22:58 +00:00
|
|
|
setItem( slot, ItemStack.EMPTY );
|
2017-05-01 14:48:44 +00:00
|
|
|
return disk;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
ItemStack part = diskStack.split( count );
|
|
|
|
setItem( slot, diskStack.isEmpty() ? ItemStack.EMPTY : diskStack );
|
2017-05-01 14:48:44 +00:00
|
|
|
return part;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public void setItem( int slot, @Nonnull ItemStack stack )
|
2018-12-23 17:46:58 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( getLevel().isClientSide )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
diskStack = stack;
|
|
|
|
diskMount = null;
|
2021-01-09 19:22:58 +00:00
|
|
|
setChanged();
|
2017-05-01 14:48:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
synchronized( this )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( InventoryUtil.areItemsStackable( stack, diskStack ) )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
diskStack = stack;
|
2017-05-01 14:48:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
// Unmount old disk
|
2021-01-15 16:35:49 +00:00
|
|
|
if( !diskStack.isEmpty() )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
// TODO: Is this iteration thread safe?
|
2021-01-15 16:35:49 +00:00
|
|
|
Set<IComputerAccess> computers = this.computers.keySet();
|
2019-04-02 10:50:13 +00:00
|
|
|
for( IComputerAccess computer : computers ) unmountDisk( computer );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
// Stop music
|
2021-01-15 16:35:49 +00:00
|
|
|
if( recordPlaying )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2017-09-12 14:46:46 +00:00
|
|
|
stopRecord();
|
2021-01-15 16:35:49 +00:00
|
|
|
recordPlaying = false;
|
|
|
|
recordQueued = false;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
// Swap disk over
|
2021-01-15 16:35:49 +00:00
|
|
|
diskStack = stack;
|
|
|
|
diskMount = null;
|
2021-01-09 19:22:58 +00:00
|
|
|
setChanged();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
// Mount new disk
|
2021-01-15 16:35:49 +00:00
|
|
|
if( !diskStack.isEmpty() )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
Set<IComputerAccess> computers = this.computers.keySet();
|
2019-04-02 10:50:13 +00:00
|
|
|
for( IComputerAccess computer : computers ) mountDisk( computer );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public void setChanged()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( !level.isClientSide ) updateBlockState();
|
|
|
|
super.setChanged();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public boolean stillValid( @Nonnull PlayerEntity player )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
return isUsable( player, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public void clearContent()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
setItem( 0, ItemStack.EMPTY );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2018-03-29 10:36:59 +00:00
|
|
|
@Nonnull
|
2019-04-02 12:17:06 +00:00
|
|
|
ItemStack getDiskStack()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
return getItem( 0 );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 12:17:06 +00:00
|
|
|
void setDiskStack( @Nonnull ItemStack stack )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
setItem( 0, stack );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 12:17:06 +00:00
|
|
|
private IMedia getDiskMedia()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
return MediaProviders.get( getDiskStack() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 12:17:06 +00:00
|
|
|
String getDiskMountPath( IComputerAccess computer )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
synchronized( this )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
MountInfo info = computers.get( computer );
|
2019-04-02 12:17:06 +00:00
|
|
|
return info != null ? info.mountPath : null;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 12:17:06 +00:00
|
|
|
void mount( IComputerAccess computer )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
synchronized( this )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
computers.put( computer, new MountInfo() );
|
2017-05-01 13:32:39 +00:00
|
|
|
mountDisk( computer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 12:17:06 +00:00
|
|
|
void unmount( IComputerAccess computer )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
synchronized( this )
|
|
|
|
{
|
|
|
|
unmountDisk( computer );
|
2021-01-15 16:35:49 +00:00
|
|
|
computers.remove( computer );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 12:17:06 +00:00
|
|
|
void playDiskAudio()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
synchronized( this )
|
|
|
|
{
|
|
|
|
IMedia media = getDiskMedia();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( media != null && media.getAudioTitle( diskStack ) != null )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
recordQueued = true;
|
|
|
|
restartRecord = recordPlaying;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 12:17:06 +00:00
|
|
|
void stopDiskAudio()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
synchronized( this )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
recordQueued = false;
|
|
|
|
restartRecord = false;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 12:17:06 +00:00
|
|
|
void ejectDisk()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
synchronized( this )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
ejectQueued = true;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// private methods
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
private synchronized void mountDisk( IComputerAccess computer )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( !diskStack.isEmpty() )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
MountInfo info = computers.get( computer );
|
2017-05-01 14:48:44 +00:00
|
|
|
IMedia contents = getDiskMedia();
|
|
|
|
if( contents != null )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( diskMount == null )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
diskMount = contents.createDataMount( diskStack, getLevel() );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2021-01-15 16:35:49 +00:00
|
|
|
if( diskMount != null )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( diskMount instanceof IWritableMount )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
|
|
|
// Try mounting at the lowest numbered "disk" name we can
|
|
|
|
int n = 1;
|
|
|
|
while( info.mountPath == null )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
info.mountPath = computer.mountWritable( n == 1 ? "disk" : "disk" + n, (IWritableMount) diskMount );
|
2018-12-23 17:46:58 +00:00
|
|
|
n++;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Try mounting at the lowest numbered "disk" name we can
|
|
|
|
int n = 1;
|
|
|
|
while( info.mountPath == null )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
info.mountPath = computer.mount( n == 1 ? "disk" : "disk" + n, diskMount );
|
2018-12-23 17:46:58 +00:00
|
|
|
n++;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info.mountPath = null;
|
|
|
|
}
|
|
|
|
}
|
Replace getMethodNames/callMethod with annotations (#447)
When creating a peripheral or custom Lua object, one must implement two
methods:
- getMethodNames(): String[] - Returns the name of the methods
- callMethod(int, ...): Object[] - Invokes the method using an index in
the above array.
This has a couple of problems:
- It's somewhat unwieldy to use - you need to keep track of array
indices, which leads to ugly code.
- Functions which yield (for instance, those which run on the main
thread) are blocking. This means we need to spawn new threads for
each CC-side yield.
We replace this system with a few changes:
- @LuaFunction annotation: One may annotate a public instance method
with this annotation. This then exposes a peripheral/lua object
method.
Furthermore, this method can accept and return a variety of types,
which often makes functions cleaner (e.g. can return an int rather
than an Object[], and specify and int argument rather than
Object[]).
- MethodResult: Instead of returning an Object[] and having blocking
yields, functions return a MethodResult. This either contains an
immediate return, or an instruction to yield with some continuation
to resume with.
MethodResult is then interpreted by the Lua runtime (i.e. Cobalt),
rather than our weird bodgey hacks before. This means we no longer
spawn new threads when yielding within CC.
- Methods accept IArguments instead of a raw Object array. This has a
few benefits:
- Consistent argument handling - people no longer need to use
ArgumentHelper (as it doesn't exist!), or even be aware of its
existence - you're rather forced into using it.
- More efficient code in some cases. We provide a Cobalt-specific
implementation of IArguments, which avoids the boxing/unboxing when
handling numbers and binary strings.
2020-05-15 12:21:16 +00:00
|
|
|
computer.queueEvent( "disk", computer.getAttachmentName() );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private synchronized void unmountDisk( IComputerAccess computer )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( !diskStack.isEmpty() )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
MountInfo info = computers.get( computer );
|
2019-03-29 21:21:39 +00:00
|
|
|
assert info != null;
|
2017-05-01 14:48:44 +00:00
|
|
|
if( info.mountPath != null )
|
|
|
|
{
|
|
|
|
computer.unmount( info.mountPath );
|
|
|
|
info.mountPath = null;
|
|
|
|
}
|
Replace getMethodNames/callMethod with annotations (#447)
When creating a peripheral or custom Lua object, one must implement two
methods:
- getMethodNames(): String[] - Returns the name of the methods
- callMethod(int, ...): Object[] - Invokes the method using an index in
the above array.
This has a couple of problems:
- It's somewhat unwieldy to use - you need to keep track of array
indices, which leads to ugly code.
- Functions which yield (for instance, those which run on the main
thread) are blocking. This means we need to spawn new threads for
each CC-side yield.
We replace this system with a few changes:
- @LuaFunction annotation: One may annotate a public instance method
with this annotation. This then exposes a peripheral/lua object
method.
Furthermore, this method can accept and return a variety of types,
which often makes functions cleaner (e.g. can return an int rather
than an Object[], and specify and int argument rather than
Object[]).
- MethodResult: Instead of returning an Object[] and having blocking
yields, functions return a MethodResult. This either contains an
immediate return, or an instruction to yield with some continuation
to resume with.
MethodResult is then interpreted by the Lua runtime (i.e. Cobalt),
rather than our weird bodgey hacks before. This means we no longer
spawn new threads when yielding within CC.
- Methods accept IArguments instead of a raw Object array. This has a
few benefits:
- Consistent argument handling - people no longer need to use
ArgumentHelper (as it doesn't exist!), or even be aware of its
existence - you're rather forced into using it.
- More efficient code in some cases. We provide a Cobalt-specific
implementation of IArguments, which avoids the boxing/unboxing when
handling numbers and binary strings.
2020-05-15 12:21:16 +00:00
|
|
|
computer.queueEvent( "disk_eject", computer.getAttachmentName() );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
private void updateBlockState()
|
2018-12-23 17:46:58 +00:00
|
|
|
{
|
2021-07-15 11:13:38 +00:00
|
|
|
if( remove || level == null ) return;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( !diskStack.isEmpty() )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
|
|
|
IMedia contents = getDiskMedia();
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
updateBlockState( contents != null ? DiskDriveState.FULL : DiskDriveState.INVALID );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
updateBlockState( DiskDriveState.EMPTY );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
private void updateBlockState( DiskDriveState state )
|
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
BlockState blockState = getBlockState();
|
2021-01-09 19:22:58 +00:00
|
|
|
if( blockState.getValue( BlockDiskDrive.STATE ) == state ) return;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
getLevel().setBlockAndUpdate( getBlockPos(), blockState.setValue( BlockDiskDrive.STATE, state ) );
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
private synchronized void ejectContents( boolean destroyed )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( getLevel().isClientSide || diskStack.isEmpty() ) return;
|
2019-04-02 10:50:13 +00:00
|
|
|
|
|
|
|
// Remove the disks from the inventory
|
2021-01-15 16:35:49 +00:00
|
|
|
ItemStack disks = diskStack;
|
2019-04-02 10:50:13 +00:00
|
|
|
setDiskStack( ItemStack.EMPTY );
|
|
|
|
|
|
|
|
// Spawn the item in the world
|
|
|
|
int xOff = 0;
|
|
|
|
int zOff = 0;
|
|
|
|
if( !destroyed )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
Direction dir = getDirection();
|
2021-01-09 19:22:58 +00:00
|
|
|
xOff = dir.getStepX();
|
|
|
|
zOff = dir.getStepZ();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
BlockPos pos = getBlockPos();
|
2019-04-02 10:50:13 +00:00
|
|
|
double x = pos.getX() + 0.5 + xOff * 0.5;
|
|
|
|
double y = pos.getY() + 0.75;
|
|
|
|
double z = pos.getZ() + 0.5 + zOff * 0.5;
|
2021-01-09 19:22:58 +00:00
|
|
|
ItemEntity entityitem = new ItemEntity( getLevel(), x, y, z, disks );
|
|
|
|
entityitem.setDeltaMovement( xOff * 0.15, 0, zOff * 0.15 );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
getLevel().addFreshEntity( entityitem );
|
|
|
|
if( !destroyed ) getLevel().globalLevelEvent( 1000, getBlockPos(), 0 );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Private methods
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
private void playRecord()
|
|
|
|
{
|
2017-05-01 13:32:39 +00:00
|
|
|
IMedia contents = getDiskMedia();
|
2021-01-15 16:35:49 +00:00
|
|
|
SoundEvent record = contents != null ? contents.getAudio( diskStack ) : null;
|
2017-05-01 13:32:39 +00:00
|
|
|
if( record != null )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
RecordUtil.playRecord( record, contents.getAudioTitle( diskStack ), getLevel(), getBlockPos() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
RecordUtil.playRecord( null, null, getLevel(), getBlockPos() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
private void stopRecord()
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
RecordUtil.playRecord( null, null, getLevel(), getBlockPos() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-08 23:41:20 +00:00
|
|
|
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
@Nonnull
|
2017-05-08 23:41:20 +00:00
|
|
|
@Override
|
2019-06-08 12:36:31 +00:00
|
|
|
public <T> LazyOptional<T> getCapability( @Nonnull Capability<T> cap, @Nullable final Direction side )
|
2017-05-08 23:41:20 +00:00
|
|
|
{
|
2019-04-09 16:29:23 +00:00
|
|
|
if( cap == ITEM_HANDLER_CAPABILITY )
|
|
|
|
{
|
|
|
|
if( itemHandlerCap == null ) itemHandlerCap = LazyOptional.of( () -> new InvWrapper( this ) );
|
|
|
|
return itemHandlerCap.cast();
|
|
|
|
}
|
2020-05-15 16:09:12 +00:00
|
|
|
|
|
|
|
if( cap == CAPABILITY_PERIPHERAL )
|
|
|
|
{
|
|
|
|
if( peripheralCap == null ) peripheralCap = LazyOptional.of( () -> new DiskDrivePeripheral( this ) );
|
|
|
|
return peripheralCap.cast();
|
|
|
|
}
|
|
|
|
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
return super.getCapability( cap, side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomName()
|
|
|
|
{
|
|
|
|
return customName != null;
|
2017-05-08 23:41:20 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
@Nullable
|
2017-05-08 23:41:20 +00:00
|
|
|
@Override
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
public ITextComponent getCustomName()
|
2017-05-08 23:41:20 +00:00
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
return customName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public ITextComponent getName()
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
return customName != null ? customName : new TranslationTextComponent( getBlockState().getBlock().getDescriptionId() );
|
2017-05-08 23:41:20 +00:00
|
|
|
}
|
2019-06-08 12:36:31 +00:00
|
|
|
|
2019-06-11 20:03:40 +00:00
|
|
|
@Nonnull
|
2019-06-08 12:36:31 +00:00
|
|
|
@Override
|
|
|
|
public ITextComponent getDisplayName()
|
|
|
|
{
|
2019-06-11 20:03:40 +00:00
|
|
|
return INameable.super.getDisplayName();
|
2019-06-08 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public Container createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
|
|
|
|
{
|
|
|
|
return new ContainerDiskDrive( id, inventory, this );
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|