2023-03-15 21:52:13 +00:00
|
|
|
// Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LicenseRef-CCPL
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
package dan200.computercraft.shared.computer.blocks;
|
|
|
|
|
2022-11-10 15:48:26 +00:00
|
|
|
import dan200.computercraft.annotations.ForgeOverride;
|
2022-11-09 20:10:24 +00:00
|
|
|
import dan200.computercraft.api.ComputerCraftAPI;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
import dan200.computercraft.shared.common.IBundledRedstoneBlock;
|
2019-03-27 18:59:02 +00:00
|
|
|
import dan200.computercraft.shared.computer.items.IComputerItem;
|
2024-04-17 14:00:43 +00:00
|
|
|
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
2022-11-06 18:27:21 +00:00
|
|
|
import dan200.computercraft.shared.platform.RegistryEntry;
|
2022-11-10 15:48:26 +00:00
|
|
|
import dan200.computercraft.shared.util.BlockEntityHelpers;
|
2021-08-03 20:46:53 +00:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.core.Direction;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
2019-06-15 08:07:31 +00:00
|
|
|
import net.minecraft.stats.Stats;
|
2022-11-10 15:48:26 +00:00
|
|
|
import net.minecraft.world.InteractionHand;
|
|
|
|
import net.minecraft.world.InteractionResult;
|
|
|
|
import net.minecraft.world.MenuProvider;
|
2021-08-03 20:46:53 +00:00
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.level.BlockGetter;
|
|
|
|
import net.minecraft.world.level.Level;
|
2024-03-20 10:07:29 +00:00
|
|
|
import net.minecraft.world.level.LevelAccessor;
|
2022-11-10 15:48:26 +00:00
|
|
|
import net.minecraft.world.level.LevelReader;
|
|
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
import net.minecraft.world.level.block.EntityBlock;
|
|
|
|
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
2021-08-03 20:46:53 +00:00
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
2023-06-08 08:48:37 +00:00
|
|
|
import net.minecraft.world.level.storage.loot.LootParams;
|
2021-08-03 20:46:53 +00:00
|
|
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
2022-11-10 15:48:26 +00:00
|
|
|
import net.minecraft.world.phys.BlockHitResult;
|
2021-08-03 20:46:53 +00:00
|
|
|
import net.minecraft.world.phys.Vec3;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2019-06-15 08:07:31 +00:00
|
|
|
import javax.annotation.Nullable;
|
2019-01-14 10:27:19 +00:00
|
|
|
|
2022-11-10 15:48:26 +00:00
|
|
|
public abstract class AbstractComputerBlock<T extends AbstractComputerBlockEntity> extends HorizontalDirectionalBlock implements IBundledRedstoneBlock, EntityBlock {
|
2022-11-09 20:10:24 +00:00
|
|
|
private static final ResourceLocation DROP = new ResourceLocation(ComputerCraftAPI.MOD_ID, "computer");
|
2019-06-15 08:07:31 +00:00
|
|
|
|
2022-11-06 18:27:21 +00:00
|
|
|
protected final RegistryEntry<BlockEntityType<T>> type;
|
2021-08-03 20:46:53 +00:00
|
|
|
private final BlockEntityTicker<T> serverTicker = (level, pos, state, computer) -> computer.serverTick();
|
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
|
|
|
|
Remove several usages of ComputerFamily
While ComputerFamily is still useful, there's definitely some places
where it adds an extra layer of indirection. This commit attempts to
clean up some places where we no longer need it.
- Remove ComputerFamily from AbstractComputerBlock. The only place this
was needed is in TurtleBlock, and that can be replaced with normal
Minecraft explosion resistence!
- Pass in the fuel limit to the turtle block entity, rather than
deriving it from current family.
- The turtle BERs now derive their model from the turtle's item, rather
than the turtle's family.
- When creating upgrade/overlay recipes, use the item's name, rather
than {pocket,turtle}_family. This means we can drop getFamily() from
IComputerItem (it is still needed on to handle the UI).
- We replace IComputerItem.withFamily with a method to change to a
different item of the same type. ComputerUpgradeRecipe no longer
takes a family, and instead just uses the result's item.
- Computer blocks now use the normal Block.asItem() to find their
corresponding item, rather than looking it up via family.
The above means we can remove all the family-based XyzItem.create(...)
methods, which have always felt a little ugly.
We still need ComputerFamily for a couple of things:
- Permission checks for command computers.
- Checks for mouse/colour support in ServerComputer.
- UI textures.
2023-12-20 14:16:56 +00:00
|
|
|
protected AbstractComputerBlock(Properties settings, RegistryEntry<BlockEntityType<T>> type) {
|
2022-11-10 15:48:26 +00:00
|
|
|
super(settings);
|
2021-08-03 20:46:53 +00:00
|
|
|
this.type = type;
|
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
|
|
|
@Deprecated
|
2022-11-09 18:58:31 +00:00
|
|
|
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean isMoving) {
|
2021-01-09 19:22:58 +00:00
|
|
|
super.onPlace(state, world, pos, oldState, isMoving);
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
|
2021-08-03 20:46:53 +00:00
|
|
|
var tile = world.getBlockEntity(pos);
|
2022-11-09 23:58:56 +00:00
|
|
|
if (tile instanceof AbstractComputerBlockEntity computer) computer.updateInputsImmediately();
|
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
|
|
|
@Deprecated
|
2022-11-09 18:58:31 +00:00
|
|
|
public boolean isSignalSource(BlockState state) {
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
return true;
|
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
|
|
|
@Override
|
|
|
|
@Deprecated
|
2022-11-09 18:58:31 +00:00
|
|
|
public int getDirectSignal(BlockState state, BlockGetter world, BlockPos pos, Direction incomingSide) {
|
2021-08-03 20:46:53 +00:00
|
|
|
var entity = world.getBlockEntity(pos);
|
2022-11-09 23:58:56 +00:00
|
|
|
if (!(entity instanceof AbstractComputerBlockEntity computerEntity)) return 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
|
|
|
var computer = computerEntity.getServerComputer();
|
|
|
|
if (computer == null) return 0;
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2019-04-09 10:11:12 +00:00
|
|
|
var localSide = computerEntity.remapToLocalSide(incomingSide.getOpposite());
|
2019-04-24 09:11:18 +00:00
|
|
|
return computer.getRedstoneOutput(localSide);
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2022-11-09 23:58:56 +00:00
|
|
|
protected abstract ItemStack getItem(AbstractComputerBlockEntity tile);
|
2019-01-25 22:03:44 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
@Deprecated
|
2022-11-09 18:58:31 +00:00
|
|
|
public int getSignal(BlockState state, BlockGetter world, BlockPos pos, Direction incomingSide) {
|
2021-01-09 19:22:58 +00:00
|
|
|
return getDirectSignal(state, world, pos, incomingSide);
|
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
|
|
|
@Override
|
2021-08-03 20:46:53 +00:00
|
|
|
public int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side) {
|
|
|
|
var entity = world.getBlockEntity(pos);
|
2022-11-09 23:58:56 +00:00
|
|
|
if (!(entity instanceof AbstractComputerBlockEntity computerEntity)) return 0;
|
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
|
|
|
|
|
|
|
var computer = computerEntity.getServerComputer();
|
|
|
|
if (computer == null) return 0;
|
|
|
|
|
2019-04-09 10:11:12 +00:00
|
|
|
var localSide = computerEntity.remapToLocalSide(side);
|
2019-04-24 09:11:18 +00:00
|
|
|
return computer.getBundledRedstoneOutput(localSide);
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2019-01-25 22:03: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
|
|
|
@Override
|
2022-11-09 22:02:47 +00:00
|
|
|
@Deprecated
|
2024-01-31 20:55:14 +00:00
|
|
|
public ItemStack getCloneItemStack(LevelReader world, BlockPos pos, BlockState state) {
|
2021-08-03 20:46:53 +00:00
|
|
|
var tile = world.getBlockEntity(pos);
|
2022-11-09 23:58:56 +00:00
|
|
|
if (tile instanceof AbstractComputerBlockEntity computer) {
|
2022-11-09 22:02:47 +00:00
|
|
|
var result = getItem(computer);
|
2019-01-25 22:03:44 +00:00
|
|
|
if (!result.isEmpty()) return result;
|
|
|
|
}
|
|
|
|
|
2022-11-09 22:02:47 +00:00
|
|
|
return super.getCloneItemStack(world, pos, state);
|
2019-01-25 22:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-11-09 18:58:31 +00:00
|
|
|
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity tile, ItemStack tool) {
|
2019-06-15 08:07:31 +00:00
|
|
|
// Don't drop blocks here - see onBlockHarvested.
|
2021-01-09 19:22:58 +00:00
|
|
|
player.awardStat(Stats.BLOCK_MINED.get(this));
|
|
|
|
player.causeFoodExhaustion(0.005F);
|
2019-01-25 22:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-01-31 20:55:14 +00:00
|
|
|
public BlockState playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) {
|
|
|
|
var result = super.playerWillDestroy(world, pos, state, player);
|
|
|
|
if (!(world instanceof ServerLevel serverWorld)) return result;
|
2019-06-15 08:07:31 +00:00
|
|
|
|
|
|
|
// We drop the item here instead of doing it in the harvest method, as we should
|
|
|
|
// drop computers for creative players too.
|
|
|
|
|
2021-08-03 20:46:53 +00:00
|
|
|
var tile = world.getBlockEntity(pos);
|
2022-11-09 23:58:56 +00:00
|
|
|
if (tile instanceof AbstractComputerBlockEntity computer) {
|
2023-06-08 08:48:37 +00:00
|
|
|
var context = new LootParams.Builder(serverWorld)
|
2021-08-03 20:46:53 +00:00
|
|
|
.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
|
|
|
|
.withParameter(LootContextParams.TOOL, player.getMainHandItem())
|
|
|
|
.withParameter(LootContextParams.THIS_ENTITY, player)
|
|
|
|
.withParameter(LootContextParams.BLOCK_ENTITY, tile)
|
2023-06-08 08:48:37 +00:00
|
|
|
.withDynamicDrop(DROP, out -> out.accept(getItem(computer)));
|
2019-06-15 08:07:31 +00:00
|
|
|
for (var item : state.getDrops(context)) {
|
2021-01-09 19:22:58 +00:00
|
|
|
popResource(world, pos, item);
|
2019-01-25 22:03:44 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 23:08:24 +00:00
|
|
|
state.spawnAfterBreak(serverWorld, pos, player.getMainHandItem(), true);
|
2019-06-15 08:07:31 +00:00
|
|
|
}
|
2024-01-31 20:55:14 +00:00
|
|
|
|
|
|
|
return result;
|
2019-01-25 22:03:44 +00:00
|
|
|
}
|
2019-03-27 18:59:02 +00:00
|
|
|
|
|
|
|
@Override
|
2022-11-09 18:58:31 +00:00
|
|
|
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
|
2021-01-09 19:22:58 +00:00
|
|
|
super.setPlacedBy(world, pos, state, placer, stack);
|
2019-03-27 18:59:02 +00:00
|
|
|
|
2021-08-03 20:46:53 +00:00
|
|
|
var tile = world.getBlockEntity(pos);
|
2022-11-09 23:58:56 +00:00
|
|
|
if (!world.isClientSide && tile instanceof IComputerBlockEntity computer && stack.getItem() instanceof IComputerItem item) {
|
2019-03-27 18:59:02 +00:00
|
|
|
|
|
|
|
var id = item.getComputerID(stack);
|
|
|
|
if (id != -1) computer.setComputerID(id);
|
|
|
|
|
|
|
|
var label = item.getLabel(stack);
|
|
|
|
if (label != null) computer.setLabel(label);
|
|
|
|
}
|
|
|
|
}
|
2020-10-04 10:14:22 +00:00
|
|
|
|
2022-11-10 15:48:26 +00:00
|
|
|
@Override
|
|
|
|
@Deprecated
|
2024-04-17 14:00:43 +00:00
|
|
|
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
|
|
|
if (!player.isCrouching() && level.getBlockEntity(pos) instanceof AbstractComputerBlockEntity computer) {
|
|
|
|
// Regular right click to activate computer
|
|
|
|
if (!level.isClientSide && computer.isUsable(player)) {
|
|
|
|
var serverComputer = computer.createServerComputer();
|
|
|
|
serverComputer.turnOn();
|
|
|
|
|
|
|
|
new ComputerContainerData(serverComputer, getItem(computer)).open(player, computer);
|
|
|
|
}
|
|
|
|
return InteractionResult.sidedSuccess(level.isClientSide);
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.use(state, level, pos, player, hand, hit);
|
2022-11-10 15:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
public final void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos, boolean isMoving) {
|
|
|
|
var be = world.getBlockEntity(pos);
|
|
|
|
if (be instanceof AbstractComputerBlockEntity computer) computer.neighborChanged(neighbourPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForgeOverride
|
|
|
|
public final void onNeighborChange(BlockState state, LevelReader world, BlockPos pos, BlockPos neighbour) {
|
|
|
|
var be = world.getBlockEntity(pos);
|
|
|
|
if (be instanceof AbstractComputerBlockEntity computer) computer.neighborChanged(neighbour);
|
|
|
|
}
|
|
|
|
|
2024-03-20 10:07:29 +00:00
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos pos, BlockPos neighborPos) {
|
|
|
|
var be = level.getBlockEntity(pos);
|
|
|
|
if (be instanceof AbstractComputerBlockEntity computer) computer.neighbourShapeChanged(direction);
|
|
|
|
|
|
|
|
return super.updateShape(state, direction, neighborState, level, pos, neighborPos);
|
|
|
|
}
|
|
|
|
|
2022-11-10 15:48:26 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
public MenuProvider getMenuProvider(BlockState state, Level level, BlockPos pos) {
|
|
|
|
return level.getBlockEntity(pos) instanceof AbstractComputerBlockEntity computer ? computer : null;
|
|
|
|
}
|
|
|
|
|
2021-08-03 20:46:53 +00:00
|
|
|
@Override
|
|
|
|
@Nullable
|
2022-11-09 18:58:31 +00:00
|
|
|
public <U extends BlockEntity> BlockEntityTicker<U> getTicker(Level level, BlockState state, BlockEntityType<U> type) {
|
2022-11-10 15:48:26 +00:00
|
|
|
return level.isClientSide ? null : BlockEntityHelpers.createTickerHelper(type, this.type.get(), serverTicker);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
|
|
return type.get().create(pos, state);
|
2021-08-03 20:46:53 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|