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.turtle.blocks;
|
|
|
|
|
2024-01-31 20:55:14 +00:00
|
|
|
import com.mojang.serialization.MapCodec;
|
|
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
2022-11-09 23:58:56 +00:00
|
|
|
import dan200.computercraft.annotations.ForgeOverride;
|
2023-07-02 09:55:55 +00:00
|
|
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
2019-03-27 18:59:02 +00:00
|
|
|
import dan200.computercraft.api.turtle.TurtleSide;
|
2023-07-02 09:55:55 +00:00
|
|
|
import dan200.computercraft.api.upgrades.UpgradeData;
|
2022-11-09 23:58:56 +00:00
|
|
|
import dan200.computercraft.shared.computer.blocks.AbstractComputerBlock;
|
|
|
|
import dan200.computercraft.shared.computer.blocks.AbstractComputerBlockEntity;
|
2022-11-06 18:27:21 +00:00
|
|
|
import dan200.computercraft.shared.platform.RegistryEntry;
|
2019-03-27 18:59:02 +00:00
|
|
|
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
2023-06-04 10:24:04 +00:00
|
|
|
import dan200.computercraft.shared.turtle.items.TurtleItem;
|
2024-01-31 20:55:14 +00:00
|
|
|
import dan200.computercraft.shared.util.BlockCodecs;
|
2022-11-10 15:48:26 +00:00
|
|
|
import dan200.computercraft.shared.util.BlockEntityHelpers;
|
2021-10-13 16:46:29 +00:00
|
|
|
import dan200.computercraft.shared.util.WaterloggableHelpers;
|
2021-08-03 20:46:53 +00:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.core.Direction;
|
2022-11-10 15:48:26 +00:00
|
|
|
import net.minecraft.world.Containers;
|
2024-04-17 14:00:43 +00:00
|
|
|
import net.minecraft.world.InteractionHand;
|
|
|
|
import net.minecraft.world.InteractionResult;
|
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.entity.projectile.AbstractHurtingProjectile;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
2024-04-17 14:00:43 +00:00
|
|
|
import net.minecraft.world.item.Items;
|
2021-08-03 20:46:53 +00:00
|
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
|
|
import net.minecraft.world.level.BlockGetter;
|
|
|
|
import net.minecraft.world.level.Explosion;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.level.LevelAccessor;
|
2022-11-10 15:48:26 +00:00
|
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
import net.minecraft.world.level.block.RenderShape;
|
|
|
|
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
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;
|
|
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
|
|
import net.minecraft.world.level.material.FluidState;
|
2024-04-17 14:00:43 +00:00
|
|
|
import net.minecraft.world.phys.BlockHitResult;
|
2021-08-03 20:46:53 +00:00
|
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
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
|
|
|
import javax.annotation.Nullable;
|
2017-05-06 23:07:42 +00:00
|
|
|
|
2021-11-03 09:34:21 +00:00
|
|
|
import static dan200.computercraft.shared.util.WaterloggableHelpers.WATERLOGGED;
|
|
|
|
import static dan200.computercraft.shared.util.WaterloggableHelpers.getFluidStateForPlacement;
|
2019-06-08 12:36:31 +00:00
|
|
|
|
2022-11-09 23:58:56 +00:00
|
|
|
public class TurtleBlock extends AbstractComputerBlock<TurtleBlockEntity> implements SimpleWaterloggedBlock {
|
2024-01-31 20:55:14 +00:00
|
|
|
private static final MapCodec<TurtleBlock> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
|
|
|
|
BlockCodecs.propertiesCodec(),
|
|
|
|
BlockCodecs.blockEntityCodec(x -> x.type)
|
|
|
|
).apply(instance, TurtleBlock::new));
|
|
|
|
|
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 static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
2017-05-01 13:32:39 +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
|
|
|
/**
|
|
|
|
* The explosion resistance to use when a turtle is "immune" to explosions.
|
|
|
|
* <p>
|
|
|
|
* This is used as the default explosion resistance for advanced turtles, and the resistance for entity-based
|
|
|
|
* explosions (e.g. creepers).
|
|
|
|
*
|
|
|
|
* @see #getExplosionResistance(BlockState, BlockGetter, BlockPos, Explosion)
|
|
|
|
*/
|
|
|
|
public static final float IMMUNE_EXPLOSION_RESISTANCE = 2000f;
|
|
|
|
|
2021-08-03 20:46:53 +00:00
|
|
|
private static final VoxelShape DEFAULT_SHAPE = Shapes.box(
|
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
|
|
|
0.125, 0.125, 0.125,
|
|
|
|
0.875, 0.875, 0.875
|
|
|
|
);
|
|
|
|
|
2022-11-09 23:58:56 +00:00
|
|
|
private final BlockEntityTicker<TurtleBlockEntity> clientTicker = (level, pos, state, computer) -> computer.clientTick();
|
2021-08-03 20:46:53 +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
|
|
|
public TurtleBlock(Properties settings, RegistryEntry<BlockEntityType<TurtleBlockEntity>> type) {
|
|
|
|
super(settings, type);
|
2021-01-09 19:22:58 +00:00
|
|
|
registerDefaultState(getStateDefinition().any()
|
|
|
|
.setValue(FACING, Direction.NORTH)
|
|
|
|
.setValue(WATERLOGGED, false)
|
2017-05-01 13:32:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-08-03 20:46:53 +00:00
|
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
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
|
|
|
builder.add(FACING, WATERLOGGED);
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2024-01-31 20:55:14 +00:00
|
|
|
@Override
|
|
|
|
protected MapCodec<? extends TurtleBlock> codec() {
|
|
|
|
return CODEC;
|
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2017-05-07 00:42:32 +00:00
|
|
|
@Deprecated
|
2022-11-09 18:58:31 +00:00
|
|
|
public RenderShape getRenderShape(BlockState state) {
|
2021-08-03 20:46:53 +00:00
|
|
|
return RenderShape.ENTITYBLOCK_ANIMATED;
|
2017-09-18 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2017-05-07 00:42:32 +00:00
|
|
|
@Deprecated
|
2022-11-09 18:58:31 +00:00
|
|
|
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
|
2021-08-03 20:46:53 +00:00
|
|
|
var tile = world.getBlockEntity(pos);
|
2022-11-09 23:58:56 +00:00
|
|
|
var offset = tile instanceof TurtleBlockEntity turtle ? turtle.getRenderOffset(1.0f) : Vec3.ZERO;
|
2021-08-03 20:46:53 +00:00
|
|
|
return offset.equals(Vec3.ZERO) ? DEFAULT_SHAPE : DEFAULT_SHAPE.move(offset.x, offset.y, offset.z);
|
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
|
|
|
@Nullable
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2021-08-03 20:46:53 +00:00
|
|
|
public BlockState getStateForPlacement(BlockPlaceContext placement) {
|
2021-01-09 19:22:58 +00:00
|
|
|
return defaultBlockState()
|
|
|
|
.setValue(FACING, placement.getHorizontalDirection())
|
2021-10-13 16:46:29 +00:00
|
|
|
.setValue(WATERLOGGED, getFluidStateForPlacement(placement));
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-07 00:42:32 +00:00
|
|
|
@Deprecated
|
2022-11-09 18:58:31 +00:00
|
|
|
public FluidState getFluidState(BlockState state) {
|
2021-10-13 16:46:29 +00:00
|
|
|
return WaterloggableHelpers.getFluidState(state);
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 11:32:29 +00:00
|
|
|
@Override
|
|
|
|
@Deprecated
|
2022-11-09 18:58:31 +00:00
|
|
|
public BlockState updateShape(BlockState state, Direction side, BlockState otherState, LevelAccessor world, BlockPos pos, BlockPos otherPos) {
|
2021-10-13 16:46:29 +00:00
|
|
|
WaterloggableHelpers.updateShape(state, world, pos);
|
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 state;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2022-11-10 15:48:26 +00:00
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
public final void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
|
|
|
if (state.is(newState.getBlock())) return;
|
|
|
|
|
2022-12-29 09:02:02 +00:00
|
|
|
if (!level.isClientSide && level.getBlockEntity(pos) instanceof TurtleBlockEntity turtle && !turtle.hasMoved()) {
|
|
|
|
Containers.dropContents(level, pos, turtle);
|
2022-11-10 15:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
super.onRemove(state, level, pos, newState, isMoving);
|
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2022-11-09 18:58:31 +00:00
|
|
|
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
|
2021-08-08 11:44:56 +00:00
|
|
|
super.setPlacedBy(world, pos, state, entity, 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 TurtleBlockEntity turtle) {
|
2021-08-08 11:44:56 +00:00
|
|
|
if (entity instanceof Player player) turtle.setOwningPlayer(player.getGameProfile());
|
2019-03-27 18:59:02 +00:00
|
|
|
|
2023-06-04 10:24:04 +00:00
|
|
|
if (stack.getItem() instanceof TurtleItem item) {
|
2019-03-27 18:59:02 +00:00
|
|
|
// Set Upgrades
|
|
|
|
for (var side : TurtleSide.values()) {
|
2023-07-02 09:55:55 +00:00
|
|
|
turtle.getAccess().setUpgradeWithData(side, item.getUpgradeWithData(stack, side));
|
2019-03-27 18:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
turtle.getAccess().setFuelLevel(item.getFuelLevel(stack));
|
|
|
|
|
|
|
|
// Set colour
|
|
|
|
var colour = item.getColour(stack);
|
|
|
|
if (colour != -1) turtle.getAccess().setColour(colour);
|
|
|
|
|
|
|
|
// Set overlay
|
|
|
|
var overlay = item.getOverlay(stack);
|
|
|
|
if (overlay != null) ((TurtleBrain) turtle.getAccess()).setOverlay(overlay);
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-27 11:32:29 +00:00
|
|
|
|
2024-04-17 14:00:43 +00:00
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
|
|
|
var currentItem = player.getItemInHand(hand);
|
|
|
|
if (currentItem.getItem() == Items.NAME_TAG && currentItem.hasCustomHoverName() && level.getBlockEntity(pos) instanceof AbstractComputerBlockEntity computer) {
|
|
|
|
// Label to rename computer
|
|
|
|
if (!level.isClientSide) {
|
|
|
|
computer.setLabel(currentItem.getHoverName().getString());
|
|
|
|
currentItem.shrink(1);
|
|
|
|
}
|
|
|
|
return InteractionResult.sidedSuccess(level.isClientSide);
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.use(state, level, pos, player, hand, hit);
|
|
|
|
}
|
|
|
|
|
2022-11-09 23:58:56 +00:00
|
|
|
@ForgeOverride
|
2021-08-03 20:46:53 +00:00
|
|
|
public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) {
|
2023-05-04 17:47:22 +00:00
|
|
|
var exploder = explosion.getDirectSourceEntity();
|
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
|
|
|
if (exploder instanceof LivingEntity || exploder instanceof AbstractHurtingProjectile) {
|
|
|
|
return IMMUNE_EXPLOSION_RESISTANCE;
|
2018-12-27 11:32:29 +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
|
|
|
return getExplosionResistance();
|
2018-12-27 11:32:29 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 22:03:44 +00:00
|
|
|
@Override
|
2022-11-09 23:58:56 +00:00
|
|
|
protected ItemStack getItem(AbstractComputerBlockEntity tile) {
|
2023-06-04 10:24:04 +00:00
|
|
|
if (!(tile instanceof TurtleBlockEntity turtle)) return ItemStack.EMPTY;
|
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
|
|
|
if (!(asItem() instanceof TurtleItem item)) return ItemStack.EMPTY;
|
2023-06-04 10:24:04 +00:00
|
|
|
|
|
|
|
var access = turtle.getAccess();
|
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
|
|
|
return item.create(
|
|
|
|
turtle.getComputerID(), turtle.getLabel(), access.getColour(),
|
2023-07-02 09:55:55 +00:00
|
|
|
withPersistedData(access.getUpgradeWithData(TurtleSide.LEFT)),
|
|
|
|
withPersistedData(access.getUpgradeWithData(TurtleSide.RIGHT)),
|
2023-06-04 10:24:04 +00:00
|
|
|
access.getFuelLevel(), turtle.getOverlay()
|
|
|
|
);
|
2018-12-27 11:32:29 +00:00
|
|
|
}
|
2021-08-03 20:46:53 +00:00
|
|
|
|
2023-07-02 09:55:55 +00:00
|
|
|
private static @Nullable UpgradeData<ITurtleUpgrade> withPersistedData(@Nullable UpgradeData<ITurtleUpgrade> upgrade) {
|
|
|
|
return upgrade == null ? null : UpgradeData.of(upgrade.upgrade(), upgrade.upgrade().getPersistedData(upgrade.data()));
|
|
|
|
}
|
|
|
|
|
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 ? BlockEntityHelpers.createTickerHelper(type, this.type.get(), clientTicker) : super.getTicker(level, state, type);
|
2021-08-03 20:46:53 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|