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.monitor;
|
|
|
|
|
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.ComputerCraft;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
|
|
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
|
|
|
import dan200.computercraft.core.terminal.Terminal;
|
|
|
|
import dan200.computercraft.shared.common.ServerTerminal;
|
2019-01-20 15:35:48 +00:00
|
|
|
import dan200.computercraft.shared.common.TileGeneric;
|
2020-05-20 07:44:44 +00:00
|
|
|
import dan200.computercraft.shared.network.client.TerminalState;
|
2020-06-19 17:49:19 +00:00
|
|
|
import dan200.computercraft.shared.util.CapabilityUtil;
|
2019-06-21 19:57:38 +00:00
|
|
|
import dan200.computercraft.shared.util.TickScheduler;
|
2020-12-10 19:13:49 +00:00
|
|
|
import net.minecraft.block.BlockState;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
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.tileentity.TileEntityType;
|
2020-01-22 11:14:30 +00:00
|
|
|
import net.minecraft.util.ActionResultType;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.util.Direction;
|
|
|
|
import net.minecraft.util.Hand;
|
2020-01-30 09:00:37 +00:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2017-05-01 13:51:26 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.world.World;
|
2020-05-15 16:09:12 +00:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
|
|
import net.minecraftforge.common.util.LazyOptional;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2020-05-15 16:09:12 +00:00
|
|
|
import javax.annotation.Nullable;
|
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 java.util.HashSet;
|
2017-05-01 13:32:39 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
2020-05-15 16:09:12 +00:00
|
|
|
import static dan200.computercraft.shared.Capabilities.CAPABILITY_PERIPHERAL;
|
|
|
|
|
|
|
|
public class TileMonitor extends TileGeneric
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-03-29 21:21:39 +00:00
|
|
|
public static final double RENDER_BORDER = 2.0 / 16.0;
|
|
|
|
public static final double RENDER_MARGIN = 0.5 / 16.0;
|
|
|
|
public static final double RENDER_PIXEL_SCALE = 1.0 / 64.0;
|
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 static final String NBT_X = "XIndex";
|
|
|
|
private static final String NBT_Y = "YIndex";
|
|
|
|
private static final String NBT_WIDTH = "Width";
|
|
|
|
private static final String NBT_HEIGHT = "Height";
|
|
|
|
|
|
|
|
private final boolean advanced;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private ServerMonitor serverMonitor;
|
|
|
|
private ClientMonitor clientMonitor;
|
2020-05-15 16:09:12 +00:00
|
|
|
private MonitorPeripheral peripheral;
|
|
|
|
private LazyOptional<IPeripheral> peripheralCap;
|
2021-01-15 16:35:49 +00:00
|
|
|
private final Set<IComputerAccess> computers = new HashSet<>();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-05-04 21:24:58 +00:00
|
|
|
private boolean needsUpdate = false;
|
2021-07-25 13:18:07 +00:00
|
|
|
private boolean needsValidating = false;
|
2021-01-15 16:35:49 +00:00
|
|
|
private boolean destroyed = false;
|
2019-04-02 10:50:13 +00:00
|
|
|
private boolean visiting = false;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2020-05-20 07:44:44 +00:00
|
|
|
// MonitorWatcher state.
|
|
|
|
boolean enqueued;
|
|
|
|
TerminalState cached;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private int width = 1;
|
|
|
|
private int height = 1;
|
|
|
|
private int xIndex = 0;
|
|
|
|
private int yIndex = 0;
|
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
|
|
|
public TileMonitor( TileEntityType<? extends TileMonitor> type, boolean advanced )
|
|
|
|
{
|
|
|
|
super( type );
|
|
|
|
this.advanced = advanced;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-02-14 21:21:00 +00:00
|
|
|
@Override
|
|
|
|
public void onLoad()
|
|
|
|
{
|
|
|
|
super.onLoad();
|
2021-07-25 13:18:07 +00:00
|
|
|
needsValidating = true;
|
2019-06-21 19:57:38 +00:00
|
|
|
TickScheduler.schedule( this );
|
2018-02-14 21:21:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
|
|
|
public void destroy()
|
|
|
|
{
|
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: Call this before using the block
|
2021-01-15 16:35:49 +00:00
|
|
|
if( destroyed ) return;
|
|
|
|
destroyed = true;
|
2021-01-09 19:22:58 +00:00
|
|
|
if( !getLevel().isClientSide ) contractNeighbours();
|
2018-02-14 21:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public void setRemoved()
|
2018-02-14 21:21:00 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
super.setRemoved();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( clientMonitor != null && xIndex == 0 && yIndex == 0 ) clientMonitor.destroy();
|
2018-02-14 21:21:00 +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 onChunkUnloaded()
|
2018-02-14 21:21:00 +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
|
|
|
super.onChunkUnloaded();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( clientMonitor != null && xIndex == 0 && yIndex == 0 ) clientMonitor.destroy();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +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
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( !player.isCrouching() && getFront() == hit.getDirection() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( !getLevel().isClientSide )
|
2019-06-08 12:36:31 +00:00
|
|
|
{
|
|
|
|
monitorTouched(
|
2021-01-09 19:22:58 +00:00
|
|
|
(float) (hit.getLocation().x - hit.getBlockPos().getX()),
|
|
|
|
(float) (hit.getLocation().y - hit.getBlockPos().getY()),
|
|
|
|
(float) (hit.getLocation().z - hit.getBlockPos().getZ())
|
2019-06-08 12:36:31 +00:00
|
|
|
);
|
|
|
|
}
|
2020-01-22 11:14:30 +00:00
|
|
|
return ActionResultType.SUCCESS;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2019-04-02 10:50:13 +00:00
|
|
|
|
2020-01-22 11:14:30 +00:00
|
|
|
return ActionResultType.PASS;
|
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( CompoundNBT tag )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
tag.putInt( NBT_X, xIndex );
|
|
|
|
tag.putInt( NBT_Y, yIndex );
|
|
|
|
tag.putInt( NBT_WIDTH, width );
|
|
|
|
tag.putInt( NBT_HEIGHT, height );
|
2021-01-09 19:22:58 +00:00
|
|
|
return super.save( tag );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public void load( @Nonnull CompoundNBT tag )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
super.load( tag );
|
2021-01-15 16:35:49 +00:00
|
|
|
xIndex = tag.getInt( NBT_X );
|
|
|
|
yIndex = tag.getInt( NBT_Y );
|
|
|
|
width = tag.getInt( NBT_WIDTH );
|
|
|
|
height = tag.getInt( NBT_HEIGHT );
|
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 blockTick()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
if( needsValidating )
|
|
|
|
{
|
|
|
|
needsValidating = false;
|
|
|
|
validate();
|
|
|
|
}
|
|
|
|
|
2021-06-01 17:55:12 +00:00
|
|
|
if( needsUpdate )
|
2021-05-04 21:24:58 +00:00
|
|
|
{
|
|
|
|
needsUpdate = false;
|
|
|
|
updateNeighbors();
|
|
|
|
}
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( xIndex != 0 || yIndex != 0 || serverMonitor == null ) return;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
serverMonitor.clearChanged();
|
2019-01-20 15:35:48 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( serverMonitor.pollResized() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
for( int x = 0; x < width; x++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
for( int y = 0; y < height; y++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
2019-01-20 15:35:48 +00:00
|
|
|
if( monitor == null ) continue;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
for( IComputerAccess computer : monitor.computers )
|
2018-02-14 21:21:00 +00:00
|
|
|
{
|
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( "monitor_resize", computer.getAttachmentName() );
|
2018-02-14 21:21:00 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-02-14 21:21:00 +00:00
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2019-01-20 15:35:48 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( serverMonitor.pollTerminalChanged() ) MonitorWatcher.enqueue( this );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2020-05-15 16:09:12 +00:00
|
|
|
@Override
|
|
|
|
protected void invalidateCaps()
|
|
|
|
{
|
|
|
|
super.invalidateCaps();
|
|
|
|
peripheralCap = CapabilityUtil.invalidate( peripheralCap );
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2020-05-15 16:09:12 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2020-05-15 16:09:12 +00:00
|
|
|
public <T> LazyOptional<T> getCapability( @Nonnull Capability<T> cap, @Nullable Direction side )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-05-15 16:09:12 +00:00
|
|
|
if( cap == CAPABILITY_PERIPHERAL )
|
|
|
|
{
|
|
|
|
createServerMonitor(); // Ensure the monitor is created before doing anything else.
|
|
|
|
if( peripheral == null ) peripheral = new MonitorPeripheral( this );
|
|
|
|
if( peripheralCap == null ) peripheralCap = LazyOptional.of( () -> peripheral );
|
|
|
|
return peripheralCap.cast();
|
|
|
|
}
|
|
|
|
return super.getCapability( cap, side );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 21:21:00 +00:00
|
|
|
public ServerMonitor getCachedServerMonitor()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return serverMonitor;
|
2018-02-14 21:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private ServerMonitor getServerMonitor()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( serverMonitor != null ) return serverMonitor;
|
2018-02-14 21:21:00 +00:00
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor origin = getOrigin().getMonitor();
|
2018-02-14 21:21:00 +00:00
|
|
|
if( origin == null ) return null;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
return serverMonitor = origin.serverMonitor;
|
2018-02-14 21:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private ServerMonitor createServerMonitor()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( serverMonitor != null ) return serverMonitor;
|
2019-04-02 10:50:13 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( xIndex == 0 && yIndex == 0 )
|
2018-02-14 21:21:00 +00:00
|
|
|
{
|
|
|
|
// If we're the origin, set up the new monitor
|
2021-01-15 16:35:49 +00:00
|
|
|
serverMonitor = new ServerMonitor( advanced, this );
|
|
|
|
serverMonitor.rebuild();
|
2018-02-14 21:21:00 +00:00
|
|
|
|
|
|
|
// And propagate it to child monitors
|
2021-01-15 16:35:49 +00:00
|
|
|
for( int x = 0; x < width; x++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
for( int y = 0; y < height; y++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( monitor != null ) monitor.serverMonitor = serverMonitor;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-14 21:21:00 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
return serverMonitor;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-02-14 21:21:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Otherwise fetch the origin and attempt to get its monitor
|
|
|
|
// Note this may load chunks, but we don't really have a choice here.
|
2021-01-09 19:22:58 +00:00
|
|
|
BlockPos pos = getBlockPos();
|
2021-01-15 16:35:49 +00:00
|
|
|
TileEntity te = level.getBlockEntity( pos.relative( getRight(), -xIndex ).relative( getDown(), -yIndex ) );
|
2018-02-14 21:21:00 +00:00
|
|
|
if( !(te instanceof TileMonitor) ) return null;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
return serverMonitor = ((TileMonitor) te).createServerMonitor();
|
2018-02-14 21:21:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ClientMonitor getClientMonitor()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( clientMonitor != null ) return clientMonitor;
|
2018-02-14 21:21:00 +00:00
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
BlockPos pos = getBlockPos();
|
2021-01-15 16:35:49 +00:00
|
|
|
TileEntity te = level.getBlockEntity( pos.relative( getRight(), -xIndex ).relative( getDown(), -yIndex ) );
|
2018-02-14 21:21:00 +00:00
|
|
|
if( !(te instanceof TileMonitor) ) return null;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
return clientMonitor = ((TileMonitor) te).clientMonitor;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
// Networking stuff
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
@Override
|
2019-06-08 12:36:31 +00:00
|
|
|
protected void writeDescription( @Nonnull CompoundNBT nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-29 14:01:00 +00:00
|
|
|
super.writeDescription( nbt );
|
2021-01-15 16:35:49 +00:00
|
|
|
nbt.putInt( NBT_X, xIndex );
|
|
|
|
nbt.putInt( NBT_Y, yIndex );
|
|
|
|
nbt.putInt( NBT_WIDTH, width );
|
|
|
|
nbt.putInt( NBT_HEIGHT, height );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-08 12:36:31 +00:00
|
|
|
protected final void readDescription( @Nonnull CompoundNBT nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-29 14:01:00 +00:00
|
|
|
super.readDescription( nbt );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
int oldXIndex = xIndex;
|
|
|
|
int oldYIndex = yIndex;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
xIndex = nbt.getInt( NBT_X );
|
|
|
|
yIndex = nbt.getInt( NBT_Y );
|
|
|
|
width = nbt.getInt( NBT_WIDTH );
|
|
|
|
height = nbt.getInt( NBT_HEIGHT );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( oldXIndex != xIndex || oldYIndex != yIndex )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-02-14 21:21:00 +00:00
|
|
|
// If our index has changed then it's possible the origin monitor has changed. Thus
|
|
|
|
// we'll clear our cache. If we're the origin then we'll need to remove the glList as well.
|
2021-01-15 16:35:49 +00:00
|
|
|
if( oldXIndex == 0 && oldYIndex == 0 && clientMonitor != null ) clientMonitor.destroy();
|
|
|
|
clientMonitor = null;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( xIndex == 0 && yIndex == 0 )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-05-20 07:44:44 +00:00
|
|
|
// If we're the origin terminal then create it.
|
2021-01-15 16:35:49 +00:00
|
|
|
if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-20 07:44:44 +00:00
|
|
|
public final void read( TerminalState state )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( xIndex != 0 || yIndex != 0 )
|
2020-05-20 07:44:44 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
ComputerCraft.log.warn( "Receiving monitor state for non-origin terminal at {}", getBlockPos() );
|
2020-05-20 07:44:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this );
|
|
|
|
clientMonitor.read( state );
|
2020-05-20 07:44:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
// Sizing and placement stuff
|
|
|
|
|
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()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
getLevel().setBlock( getBlockPos(), getBlockState()
|
|
|
|
.setValue( BlockMonitor.STATE, MonitorEdgeState.fromConnections(
|
2021-01-15 16:35:49 +00:00
|
|
|
yIndex < height - 1, yIndex > 0,
|
|
|
|
xIndex > 0, xIndex < width - 1 ) ), 2 );
|
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
|
|
|
// region Sizing and placement stuff
|
2019-06-08 12:36:31 +00:00
|
|
|
public Direction getDirection()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-12-10 19:13:49 +00:00
|
|
|
// Ensure we're actually a monitor block. This _should_ always be the case, but sometimes there's
|
|
|
|
// fun problems with the block being missing on the client.
|
|
|
|
BlockState state = getBlockState();
|
2021-01-09 19:22:58 +00:00
|
|
|
return state.hasProperty( BlockMonitor.FACING ) ? state.getValue( BlockMonitor.FACING ) : Direction.NORTH;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public Direction getOrientation()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-12-10 19:13:49 +00:00
|
|
|
BlockState state = getBlockState();
|
2021-01-09 19:22:58 +00:00
|
|
|
return state.hasProperty( BlockMonitor.ORIENTATION ) ? state.getValue( BlockMonitor.ORIENTATION ) : Direction.NORTH;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public Direction getFront()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
Direction orientation = getOrientation();
|
|
|
|
return orientation == Direction.NORTH ? getDirection() : orientation;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public Direction getRight()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
return getDirection().getCounterClockWise();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public Direction getDown()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
Direction orientation = getOrientation();
|
|
|
|
if( orientation == Direction.NORTH ) return Direction.UP;
|
|
|
|
return orientation == Direction.DOWN ? getDirection() : getDirection().getOpposite();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public int getWidth()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return width;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public int getHeight()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return height;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public int getXIndex()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return xIndex;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public int getYIndex()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return yIndex;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
@Nonnull
|
|
|
|
private MonitorState getSimilarMonitorAt( BlockPos pos )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
if( pos.equals( getBlockPos() ) ) return MonitorState.present( this );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
World world = getLevel();
|
2021-07-25 13:18:07 +00:00
|
|
|
if( world == null || !world.isAreaLoaded( pos, 0 ) ) return MonitorState.UNLOADED;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
TileEntity tile = world.getBlockEntity( pos );
|
2021-07-25 13:18:07 +00:00
|
|
|
if( !(tile instanceof TileMonitor) ) return MonitorState.MISSING;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
|
|
|
TileMonitor monitor = (TileMonitor) tile;
|
2021-01-15 16:35:49 +00:00
|
|
|
return !monitor.visiting && !monitor.destroyed && advanced == monitor.advanced
|
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
|
|
|
&& getDirection() == monitor.getDirection() && getOrientation() == monitor.getOrientation()
|
2021-07-25 13:18:07 +00:00
|
|
|
? MonitorState.present( monitor ) : MonitorState.MISSING;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
private MonitorState getNeighbour( int x, int y )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
BlockPos pos = getBlockPos();
|
2019-06-08 12:36:31 +00:00
|
|
|
Direction right = getRight();
|
|
|
|
Direction down = getDown();
|
2021-01-15 16:35:49 +00:00
|
|
|
int xOffset = -xIndex + x;
|
|
|
|
int yOffset = -yIndex + y;
|
2021-01-09 19:22:58 +00:00
|
|
|
return getSimilarMonitorAt( pos.relative( right, xOffset ).relative( down, yOffset ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
private MonitorState getOrigin()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return getNeighbour( 0, 0 );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void resize( int width, int height )
|
|
|
|
{
|
2018-02-14 21:21:00 +00:00
|
|
|
// If we're not already the origin then we'll need to generate a new terminal.
|
2021-01-15 16:35:49 +00:00
|
|
|
if( xIndex != 0 || yIndex != 0 ) serverMonitor = null;
|
2018-02-14 21:21:00 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
xIndex = 0;
|
|
|
|
yIndex = 0;
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
2018-02-14 21:21:00 +00:00
|
|
|
|
|
|
|
// Determine if we actually need a monitor. In order to do this, simply check if
|
|
|
|
// any component monitor been wrapped as a peripheral. Whilst this flag may be
|
|
|
|
// out of date,
|
|
|
|
boolean needsTerminal = false;
|
|
|
|
terminalCheck:
|
|
|
|
for( int x = 0; x < width; x++ )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2018-02-14 21:21:00 +00:00
|
|
|
for( int y = 0; y < height; y++ )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
2020-05-15 16:09:12 +00:00
|
|
|
if( monitor != null && monitor.peripheral != null )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2018-02-14 21:21:00 +00:00
|
|
|
needsTerminal = true;
|
|
|
|
break terminalCheck;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-02-14 21:21:00 +00:00
|
|
|
// Either delete the current monitor or sync a new one.
|
|
|
|
if( needsTerminal )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( serverMonitor == null ) serverMonitor = new ServerMonitor( advanced, this );
|
2018-02-14 21:21:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
serverMonitor = null;
|
2018-02-14 21:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the terminal's width and height and rebuild it. This ensures the monitor
|
|
|
|
// is consistent when syncing it to other monitors.
|
2021-01-15 16:35:49 +00:00
|
|
|
if( serverMonitor != null ) serverMonitor.rebuild();
|
2018-02-14 21:21:00 +00:00
|
|
|
|
|
|
|
// Update the other monitors, setting coordinates, dimensions and the server terminal
|
|
|
|
for( int x = 0; x < width; x++ )
|
|
|
|
{
|
|
|
|
for( int y = 0; y < height; y++ )
|
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
2018-02-14 21:21:00 +00:00
|
|
|
if( monitor == null ) continue;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
monitor.xIndex = x;
|
|
|
|
monitor.yIndex = y;
|
|
|
|
monitor.width = width;
|
|
|
|
monitor.height = height;
|
|
|
|
monitor.serverMonitor = serverMonitor;
|
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
|
|
|
monitor.updateBlockState();
|
2018-02-14 21:21:00 +00:00
|
|
|
monitor.updateBlock();
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
private boolean mergeLeft()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor left = getNeighbour( -1, 0 ).getMonitor();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( left == null || left.yIndex != 0 || left.height != height ) return false;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
int width = left.width + this.width;
|
2020-06-28 15:33:03 +00:00
|
|
|
if( width > ComputerCraft.monitorWidth ) return false;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor origin = left.getOrigin().getMonitor();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( origin != null ) origin.resize( width, height );
|
2018-12-30 16:14:07 +00:00
|
|
|
left.expand();
|
|
|
|
return true;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
private boolean mergeRight()
|
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor right = getNeighbour( width, 0 ).getMonitor();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( right == null || right.yIndex != 0 || right.height != height ) return false;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
int width = this.width + right.width;
|
2020-06-28 15:33:03 +00:00
|
|
|
if( width > ComputerCraft.monitorWidth ) return false;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor origin = getOrigin().getMonitor();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( origin != null ) origin.resize( width, height );
|
2018-12-30 16:14:07 +00:00
|
|
|
expand();
|
|
|
|
return true;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
private boolean mergeUp()
|
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor above = getNeighbour( 0, height ).getMonitor();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( above == null || above.xIndex != 0 || above.width != width ) return false;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
int height = above.height + this.height;
|
2020-06-28 15:33:03 +00:00
|
|
|
if( height > ComputerCraft.monitorHeight ) return false;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor origin = getOrigin().getMonitor();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( origin != null ) origin.resize( width, height );
|
2018-12-30 16:14:07 +00:00
|
|
|
expand();
|
|
|
|
return true;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
private boolean mergeDown()
|
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor below = getNeighbour( 0, -1 ).getMonitor();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( below == null || below.xIndex != 0 || below.width != width ) return false;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
int height = this.height + below.height;
|
2020-06-28 15:33:03 +00:00
|
|
|
if( height > ComputerCraft.monitorHeight ) return false;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor origin = below.getOrigin().getMonitor();
|
2021-01-15 16:35:49 +00:00
|
|
|
if( origin != null ) origin.resize( width, height );
|
2018-12-30 16:14:07 +00:00
|
|
|
below.expand();
|
|
|
|
return true;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-05-04 21:24:58 +00:00
|
|
|
void updateNeighborsDeferred()
|
|
|
|
{
|
|
|
|
needsUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateNeighbors()
|
|
|
|
{
|
|
|
|
contractNeighbours();
|
|
|
|
contract();
|
|
|
|
expand();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
@SuppressWarnings( "StatementWithEmptyBody" )
|
|
|
|
void expand()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-30 16:14:07 +00:00
|
|
|
while( mergeLeft() || mergeRight() || mergeUp() || mergeDown() ) ;
|
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
|
|
|
void contractNeighbours()
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2019-04-02 10:50:13 +00:00
|
|
|
visiting = true;
|
2021-01-15 16:35:49 +00:00
|
|
|
if( xIndex > 0 )
|
2018-12-23 17:46:58 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor left = getNeighbour( xIndex - 1, yIndex ).getMonitor();
|
2018-12-30 16:14:07 +00:00
|
|
|
if( left != null ) left.contract();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2021-01-15 16:35:49 +00:00
|
|
|
if( xIndex + 1 < width )
|
2018-12-23 17:46:58 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor right = getNeighbour( xIndex + 1, yIndex ).getMonitor();
|
2018-12-30 16:14:07 +00:00
|
|
|
if( right != null ) right.contract();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2021-01-15 16:35:49 +00:00
|
|
|
if( yIndex > 0 )
|
2018-12-23 17:46:58 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor below = getNeighbour( xIndex, yIndex - 1 ).getMonitor();
|
2018-12-30 16:14:07 +00:00
|
|
|
if( below != null ) below.contract();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2021-01-15 16:35:49 +00:00
|
|
|
if( yIndex + 1 < height )
|
2018-12-23 17:46:58 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor above = getNeighbour( xIndex, yIndex + 1 ).getMonitor();
|
2018-12-30 16:14:07 +00:00
|
|
|
if( above != null ) above.contract();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2019-04-02 10:50:13 +00:00
|
|
|
visiting = false;
|
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
|
|
|
void contract()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
int height = this.height;
|
|
|
|
int width = this.width;
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor origin = getOrigin().getMonitor();
|
2017-05-01 14:48:44 +00:00
|
|
|
if( origin == null )
|
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor right = width > 1 ? getNeighbour( 1, 0 ).getMonitor() : null;
|
|
|
|
TileMonitor below = height > 1 ? getNeighbour( 0, 1 ).getMonitor() : null;
|
2018-12-30 16:14:07 +00:00
|
|
|
|
|
|
|
if( right != null ) right.resize( width - 1, 1 );
|
|
|
|
if( below != null ) below.resize( width, height - 1 );
|
|
|
|
if( right != null ) right.expand();
|
|
|
|
if( below != null ) below.expand();
|
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 14:48:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
|
|
|
for( int y = 0; y < height; y++ )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
for( int x = 0; x < width; x++ )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor monitor = origin.getNeighbour( x, y ).getMonitor();
|
2018-12-30 16:14:07 +00:00
|
|
|
if( monitor != null ) continue;
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2018-12-30 16:14:07 +00:00
|
|
|
// Decompose
|
|
|
|
TileMonitor above = null;
|
|
|
|
TileMonitor left = null;
|
|
|
|
TileMonitor right = null;
|
|
|
|
TileMonitor below = null;
|
2017-05-01 14:48:44 +00:00
|
|
|
|
2018-12-30 16:14:07 +00:00
|
|
|
if( y > 0 )
|
|
|
|
{
|
|
|
|
above = origin;
|
|
|
|
above.resize( width, y );
|
|
|
|
}
|
|
|
|
if( x > 0 )
|
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
left = origin.getNeighbour( 0, y ).getMonitor();
|
2018-12-30 16:14:07 +00:00
|
|
|
left.resize( x, 1 );
|
|
|
|
}
|
|
|
|
if( x + 1 < width )
|
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
right = origin.getNeighbour( x + 1, y ).getMonitor();
|
2018-12-30 16:14:07 +00:00
|
|
|
right.resize( width - (x + 1), 1 );
|
|
|
|
}
|
|
|
|
if( y + 1 < height )
|
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
below = origin.getNeighbour( 0, y + 1 ).getMonitor();
|
2018-12-30 16:14:07 +00:00
|
|
|
below.resize( width, height - (y + 1) );
|
2018-12-23 17:46:58 +00:00
|
|
|
}
|
2018-12-30 16:14:07 +00:00
|
|
|
|
|
|
|
// Re-expand
|
|
|
|
if( above != null ) above.expand();
|
|
|
|
if( left != null ) left.expand();
|
|
|
|
if( right != null ) right.expand();
|
|
|
|
if( below != null ) below.expand();
|
|
|
|
return;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-07-25 13:18:07 +00:00
|
|
|
private boolean checkMonitorAt( int xIndex, int yIndex )
|
|
|
|
{
|
|
|
|
BlockPos pos = getBlockPos();
|
|
|
|
Direction right = getRight();
|
|
|
|
Direction down = getDown();
|
|
|
|
|
|
|
|
MonitorState state = getSimilarMonitorAt( pos.relative( right, xIndex ).relative( down, yIndex ) );
|
|
|
|
|
|
|
|
if( state.isMissing() ) return false;
|
|
|
|
|
|
|
|
TileMonitor monitor = state.getMonitor();
|
|
|
|
if( monitor == null ) return true;
|
|
|
|
|
|
|
|
return monitor.xIndex == xIndex && monitor.yIndex == yIndex && monitor.width == width && monitor.height == height;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void validate()
|
|
|
|
{
|
|
|
|
if( xIndex == 0 && yIndex == 0 && width == 1 || height == 1 ) return;
|
|
|
|
|
|
|
|
if( checkMonitorAt( 0, 0 ) && checkMonitorAt( 0, height - 1 ) &&
|
|
|
|
checkMonitorAt( width - 1, 0 ) && checkMonitorAt( width - 1, height - 1 ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Something in our monitor is invalid. For now, let's just reset ourselves and then try to integrate ourselves
|
|
|
|
// later.
|
|
|
|
resize( 1, 1 );
|
|
|
|
needsUpdate = true;
|
|
|
|
}
|
|
|
|
|
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 monitorTouched( float xPos, float yPos, float zPos )
|
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
|
|
|
XYPair pair = XYPair
|
|
|
|
.of( xPos, yPos, zPos, getDirection(), getOrientation() )
|
2021-01-15 16:35:49 +00:00
|
|
|
.add( xIndex, height - yIndex - 1 );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( pair.x > width - RENDER_BORDER || pair.y > height - RENDER_BORDER || pair.x < RENDER_BORDER || pair.y < RENDER_BORDER )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-02-14 21:21:00 +00:00
|
|
|
|
|
|
|
ServerTerminal serverTerminal = getServerMonitor();
|
|
|
|
if( serverTerminal == null || !serverTerminal.isColour() ) return;
|
|
|
|
|
|
|
|
Terminal originTerminal = serverTerminal.getTerminal();
|
|
|
|
if( originTerminal == null ) return;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
double xCharWidth = (width - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getWidth();
|
|
|
|
double yCharHeight = (height - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getHeight();
|
2018-02-14 21:21:00 +00:00
|
|
|
|
2019-03-29 21:21:39 +00:00
|
|
|
int xCharPos = (int) Math.min( originTerminal.getWidth(), Math.max( (pair.x - RENDER_BORDER - RENDER_MARGIN) / xCharWidth + 1.0, 1.0 ) );
|
|
|
|
int yCharPos = (int) Math.min( originTerminal.getHeight(), Math.max( (pair.y - RENDER_BORDER - RENDER_MARGIN) / yCharHeight + 1.0, 1.0 ) );
|
2018-02-14 21:21:00 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
for( int y = 0; y < height; y++ )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
for( int x = 0; x < width; x++ )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
2018-12-23 17:46:58 +00:00
|
|
|
if( monitor == null ) continue;
|
2018-02-14 21:21:00 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
for( IComputerAccess computer : monitor.computers )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
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( "monitor_touch", computer.getAttachmentName(), xCharPos, yCharPos );
|
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
|
|
|
// endregion
|
2018-02-14 21:21:00 +00:00
|
|
|
|
2019-01-25 22:59:01 +00:00
|
|
|
void addComputer( IComputerAccess computer )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
computers.add( computer );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2019-01-25 22:59:01 +00:00
|
|
|
void removeComputer( IComputerAccess computer )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
computers.remove( computer );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 14:48:44 +00:00
|
|
|
@Override
|
2017-05-01 13:32:39 +00:00
|
|
|
public AxisAlignedBB getRenderBoundingBox()
|
|
|
|
{
|
2021-07-25 13:18:07 +00:00
|
|
|
TileMonitor start = getNeighbour( 0, 0 ).getMonitor();
|
|
|
|
TileMonitor end = getNeighbour( width - 1, height - 1 ).getMonitor();
|
2017-05-01 14:48:44 +00:00
|
|
|
if( start != null && end != null )
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
BlockPos startPos = start.getBlockPos();
|
|
|
|
BlockPos endPos = end.getBlockPos();
|
2017-05-01 14:48:44 +00:00
|
|
|
int minX = Math.min( startPos.getX(), endPos.getX() );
|
|
|
|
int minY = Math.min( startPos.getY(), endPos.getY() );
|
|
|
|
int minZ = Math.min( startPos.getZ(), endPos.getZ() );
|
|
|
|
int maxX = Math.max( startPos.getX(), endPos.getX() ) + 1;
|
|
|
|
int maxY = Math.max( startPos.getY(), endPos.getY() ) + 1;
|
|
|
|
int maxZ = Math.max( startPos.getZ(), endPos.getZ() ) + 1;
|
|
|
|
return new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ );
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
else
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
BlockPos pos = getBlockPos();
|
2017-05-01 13:32:39 +00:00
|
|
|
return new AxisAlignedBB( pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1 );
|
|
|
|
}
|
|
|
|
}
|
2020-07-18 09:25:21 +00:00
|
|
|
|
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public double getViewDistance()
|
2020-07-18 09:25:21 +00:00
|
|
|
{
|
|
|
|
return ComputerCraft.monitorDistanceSq;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|