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
|
2019-01-01 01:10:18 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dan200.computercraft.shared.computer.core;
|
|
|
|
|
|
|
|
import dan200.computercraft.ComputerCraft;
|
|
|
|
import dan200.computercraft.api.ComputerCraftAPI;
|
|
|
|
import dan200.computercraft.api.filesystem.IMount;
|
|
|
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
2017-12-07 09:24:44 +00:00
|
|
|
import dan200.computercraft.api.lua.ILuaAPI;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
|
|
|
import dan200.computercraft.core.apis.IAPIEnvironment;
|
|
|
|
import dan200.computercraft.core.computer.Computer;
|
|
|
|
import dan200.computercraft.core.computer.IComputerEnvironment;
|
|
|
|
import dan200.computercraft.shared.common.ServerTerminal;
|
2019-01-12 19:42:34 +00:00
|
|
|
import dan200.computercraft.shared.network.NetworkHandler;
|
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.network.NetworkMessage;
|
2018-12-29 12:18:05 +00:00
|
|
|
import dan200.computercraft.shared.network.client.ComputerDataClientMessage;
|
|
|
|
import dan200.computercraft.shared.network.client.ComputerDeletedClientMessage;
|
|
|
|
import dan200.computercraft.shared.network.client.ComputerTerminalClientMessage;
|
2019-04-03 22:27:10 +00:00
|
|
|
import net.minecraft.SharedConstants;
|
|
|
|
import net.minecraft.container.Container;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
2017-10-12 09:42:37 +00:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
2017-05-01 13:51:26 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2019-03-24 21:58:13 +00:00
|
|
|
import javax.annotation.Nullable;
|
2017-07-14 20:50:51 +00:00
|
|
|
import java.io.InputStream;
|
|
|
|
|
2018-12-29 12:18:05 +00:00
|
|
|
public class ServerComputer extends ServerTerminal implements IComputer, IComputerEnvironment
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
private final int m_instanceID;
|
|
|
|
|
|
|
|
private World m_world;
|
|
|
|
private BlockPos m_position;
|
|
|
|
|
2017-11-14 23:27:11 +00:00
|
|
|
private final ComputerFamily m_family;
|
2017-05-01 13:32:39 +00:00
|
|
|
private final Computer m_computer;
|
2019-04-03 22:27:10 +00:00
|
|
|
private CompoundTag m_userData;
|
2017-05-01 13:32:39 +00:00
|
|
|
private boolean m_changed;
|
|
|
|
|
|
|
|
private boolean m_changedLastFrame;
|
|
|
|
private int m_ticksSincePing;
|
|
|
|
|
|
|
|
public ServerComputer( World world, int computerID, String label, int instanceID, ComputerFamily family, int terminalWidth, int terminalHeight )
|
|
|
|
{
|
|
|
|
super( family != ComputerFamily.Normal, terminalWidth, terminalHeight );
|
|
|
|
m_instanceID = instanceID;
|
|
|
|
|
|
|
|
m_world = world;
|
|
|
|
m_position = null;
|
|
|
|
|
2017-11-14 23:27:11 +00:00
|
|
|
m_family = family;
|
2017-05-01 13:32:39 +00:00
|
|
|
m_computer = new Computer( this, getTerminal(), computerID );
|
|
|
|
m_computer.setLabel( label );
|
|
|
|
m_userData = null;
|
|
|
|
m_changed = false;
|
|
|
|
|
|
|
|
m_changedLastFrame = false;
|
|
|
|
m_ticksSincePing = 0;
|
|
|
|
}
|
|
|
|
|
2018-12-23 17:46:58 +00:00
|
|
|
public ComputerFamily getFamily()
|
|
|
|
{
|
2017-11-14 23:27:11 +00:00
|
|
|
return m_family;
|
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public World getWorld()
|
|
|
|
{
|
|
|
|
return m_world;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setWorld( World world )
|
|
|
|
{
|
|
|
|
m_world = world;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPos getPosition()
|
|
|
|
{
|
|
|
|
return m_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPosition( BlockPos pos )
|
|
|
|
{
|
|
|
|
m_position = new BlockPos( pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
public IAPIEnvironment getAPIEnvironment()
|
|
|
|
{
|
|
|
|
return m_computer.getAPIEnvironment();
|
|
|
|
}
|
|
|
|
|
2018-02-02 13:34:27 +00:00
|
|
|
public Computer getComputer()
|
|
|
|
{
|
|
|
|
return m_computer;
|
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
|
|
|
public void update()
|
|
|
|
{
|
|
|
|
super.update();
|
2019-02-26 08:44:17 +00:00
|
|
|
m_computer.tick();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-11-19 15:09:33 +00:00
|
|
|
m_changedLastFrame = m_computer.pollAndResetChanged() || m_changed;
|
2017-05-01 13:32:39 +00:00
|
|
|
m_changed = false;
|
|
|
|
|
|
|
|
m_ticksSincePing++;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void keepAlive()
|
|
|
|
{
|
|
|
|
m_ticksSincePing = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasTimedOut()
|
|
|
|
{
|
|
|
|
return m_ticksSincePing > 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasOutputChanged()
|
|
|
|
{
|
|
|
|
return m_changedLastFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unload()
|
|
|
|
{
|
|
|
|
m_computer.unload();
|
|
|
|
}
|
|
|
|
|
2019-04-03 22:27:10 +00:00
|
|
|
public CompoundTag getUserData()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
if( m_userData == null )
|
|
|
|
{
|
2019-04-03 22:27:10 +00:00
|
|
|
m_userData = new CompoundTag();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
return m_userData;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateUserData()
|
|
|
|
{
|
|
|
|
m_changed = true;
|
|
|
|
}
|
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 NetworkMessage createComputerPacket()
|
2018-12-23 17:46:58 +00:00
|
|
|
{
|
2018-12-29 12:18:05 +00:00
|
|
|
return new ComputerDataClientMessage( this );
|
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
|
|
|
protected NetworkMessage createTerminalPacket()
|
2018-12-23 17:46:58 +00:00
|
|
|
{
|
2019-04-03 22:27:10 +00:00
|
|
|
CompoundTag tagCompound = new CompoundTag();
|
2018-12-29 12:18:05 +00:00
|
|
|
writeDescription( tagCompound );
|
|
|
|
return new ComputerTerminalClientMessage( getInstanceID(), tagCompound );
|
2017-10-12 09:42:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-23 17:46:58 +00:00
|
|
|
public void broadcastState( boolean force )
|
2017-10-12 09:42:37 +00:00
|
|
|
{
|
2019-04-03 22:27:10 +00:00
|
|
|
MinecraftServer server = m_world == null ? null : m_world.getServer();
|
|
|
|
if( server == null ) return;
|
|
|
|
|
2018-12-23 17:46:58 +00:00
|
|
|
if( hasOutputChanged() || force )
|
2017-10-12 09:42:37 +00:00
|
|
|
{
|
|
|
|
// Send computer state to all clients
|
2019-04-03 22:27:10 +00:00
|
|
|
NetworkHandler.sendToAllPlayers( server, createComputerPacket() );
|
2017-10-12 09:42:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( hasTerminalChanged() || force )
|
|
|
|
{
|
|
|
|
// Send terminal state to clients who are currently interacting with the computer.
|
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
|
|
|
|
|
|
|
NetworkMessage packet = createTerminalPacket();
|
2019-04-03 22:27:10 +00:00
|
|
|
for( PlayerEntity player : server.getPlayerManager().getPlayerList() )
|
2017-10-12 09:42:37 +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( isInteracting( player ) ) NetworkHandler.sendToPlayer( player, packet );
|
2017-10-12 09:42:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 22:27:10 +00:00
|
|
|
public void sendComputerState( PlayerEntity player )
|
2017-10-12 09:42:37 +00:00
|
|
|
{
|
|
|
|
// Send state to client
|
2019-01-12 19:42:34 +00:00
|
|
|
NetworkHandler.sendToPlayer( player, createComputerPacket() );
|
2017-10-12 09:42:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 22:27:10 +00:00
|
|
|
public void sendTerminalState( PlayerEntity player )
|
2017-10-12 09:42:37 +00:00
|
|
|
{
|
|
|
|
// Send terminal state to client
|
2019-01-12 19:42:34 +00:00
|
|
|
NetworkHandler.sendToPlayer( player, createTerminalPacket() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void broadcastDelete()
|
|
|
|
{
|
|
|
|
// Send deletion to client
|
2019-04-03 22:27:10 +00:00
|
|
|
MinecraftServer server = m_world == null ? null : m_world.getServer();
|
|
|
|
if( server == null ) return;
|
|
|
|
NetworkHandler.sendToAllPlayers( server, new ComputerDeletedClientMessage( getInstanceID() ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setID( int id )
|
|
|
|
{
|
|
|
|
m_computer.setID( id );
|
|
|
|
}
|
|
|
|
|
|
|
|
// IComputer
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInstanceID()
|
|
|
|
{
|
|
|
|
return m_instanceID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getID()
|
|
|
|
{
|
|
|
|
return m_computer.getID();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLabel()
|
|
|
|
{
|
|
|
|
return m_computer.getLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOn()
|
|
|
|
{
|
|
|
|
return m_computer.isOn();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isCursorDisplayed()
|
|
|
|
{
|
|
|
|
return m_computer.isOn() && m_computer.isBlinking();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void turnOn()
|
|
|
|
{
|
|
|
|
// Turn on
|
|
|
|
m_computer.turnOn();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void shutdown()
|
|
|
|
{
|
|
|
|
// Shutdown
|
|
|
|
m_computer.shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void reboot()
|
|
|
|
{
|
|
|
|
// Reboot
|
|
|
|
m_computer.reboot();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void queueEvent( String event, Object[] arguments )
|
|
|
|
{
|
|
|
|
// Queue event
|
|
|
|
m_computer.queueEvent( event, arguments );
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getRedstoneOutput( int side )
|
|
|
|
{
|
2019-02-11 16:21:51 +00:00
|
|
|
return m_computer.getEnvironment().getExternalRedstoneOutput( side );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setRedstoneInput( int side, int level )
|
|
|
|
{
|
2019-02-11 16:21:51 +00:00
|
|
|
m_computer.getEnvironment().setRedstoneInput( side, level );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getBundledRedstoneOutput( int side )
|
|
|
|
{
|
2019-02-11 16:21:51 +00:00
|
|
|
return m_computer.getEnvironment().getExternalBundledRedstoneOutput( side );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setBundledRedstoneInput( int side, int combination )
|
|
|
|
{
|
2019-02-11 16:21:51 +00:00
|
|
|
m_computer.getEnvironment().setBundledRedstoneInput( side, combination );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addAPI( ILuaAPI api )
|
|
|
|
{
|
2019-02-26 10:31:29 +00:00
|
|
|
m_computer.addApi( api );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setPeripheral( int side, IPeripheral peripheral )
|
|
|
|
{
|
2019-02-11 16:21:51 +00:00
|
|
|
m_computer.getEnvironment().setPeripheral( side, peripheral );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public IPeripheral getPeripheral( int side )
|
|
|
|
{
|
2019-02-11 16:21:51 +00:00
|
|
|
return m_computer.getEnvironment().getPeripheral( side );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setLabel( String label )
|
|
|
|
{
|
|
|
|
m_computer.setLabel( label );
|
|
|
|
}
|
|
|
|
|
|
|
|
// IComputerEnvironment implementation
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getTimeOfDay()
|
|
|
|
{
|
2019-04-03 22:27:10 +00:00
|
|
|
return (m_world.getTime() + 6000) % 24000 / 1000.0;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getDay()
|
|
|
|
{
|
2019-04-03 22:27:10 +00:00
|
|
|
return (int) ((m_world.getTime() + 6000) / 24000) + 1;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IWritableMount createSaveDirMount( String subPath, long capacity )
|
|
|
|
{
|
|
|
|
return ComputerCraftAPI.createSaveDirMount( m_world, subPath, capacity );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMount createResourceMount( String domain, String subPath )
|
|
|
|
{
|
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 ComputerCraftAPI.createResourceMount( domain, subPath );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 20:50:51 +00:00
|
|
|
@Override
|
|
|
|
public InputStream createResourceFile( String domain, String subPath )
|
|
|
|
{
|
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 ComputerCraft.getResourceFile( domain, subPath );
|
2017-07-14 20:50:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
|
|
|
public long getComputerSpaceLimit()
|
|
|
|
{
|
|
|
|
return ComputerCraft.computerSpaceLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHostString()
|
|
|
|
{
|
2019-04-03 22:27:10 +00:00
|
|
|
return "ComputerCraft ${version} (Minecraft " + SharedConstants.getGameVersion() + ")";
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int assignNewID()
|
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
return ComputerCraftAPI.createUniqueNumberedSaveDir( m_world, "computer" );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-24 21:58:13 +00:00
|
|
|
@Nullable
|
2019-04-03 22:27:10 +00:00
|
|
|
public IContainerComputer getContainer( PlayerEntity player )
|
2017-10-12 09:42:37 +00:00
|
|
|
{
|
2019-03-24 21:58:13 +00:00
|
|
|
if( player == null ) return null;
|
2017-10-12 09:42:37 +00:00
|
|
|
|
2019-04-03 22:27:10 +00:00
|
|
|
Container container = player.container;
|
2019-03-24 21:58:13 +00:00
|
|
|
if( !(container instanceof IContainerComputer) ) return null;
|
2017-10-12 09:42:37 +00:00
|
|
|
|
2019-03-29 21:21:39 +00:00
|
|
|
IContainerComputer computerContainer = (IContainerComputer) container;
|
|
|
|
return computerContainer.getComputer() != this ? null : computerContainer;
|
2019-03-24 21:58:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 22:27:10 +00:00
|
|
|
protected boolean isInteracting( PlayerEntity player )
|
2019-03-24 21:58:13 +00:00
|
|
|
{
|
|
|
|
return getContainer( player ) != null;
|
2017-10-12 09:42:37 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|