8 Commits

Author SHA1 Message Date
TechnoDraconic
f44670d44e reorganized and renamed classes 2026-03-10 16:05:52 -07:00
TechnoDraconic
ab78582cce technically works, but needs visuals on attachments and a lot of organization 2026-03-09 15:58:36 -07:00
TechnoDraconic
97879e47ef added a "PipeGraph" so pipes can keep track of what they're connected to 2026-02-18 20:10:52 -08:00
TechnoDraconic
851645e93f added a pipe test block which connects to copies of itself and changes its visual and gameplay shapes 2026-02-15 18:28:22 -08:00
XevianLight
af1efb5c57 Rocket assembler block bounds calculation and debug renderer 2026-02-07 16:38:46 -07:00
XevianLight
9d186a0dd5 Things n stuff 2026-02-04 22:01:46 -07:00
XevianLight
3557dcdb17 Converted EnvironmentData and GravityData to records cause we never need to modify them 2026-02-04 19:13:15 -07:00
XevianLight
bf09330426 Create test.txt 2026-02-04 11:35:27 -07:00
40 changed files with 1144 additions and 178 deletions

View File

@@ -1,11 +1,11 @@
// 1.21.1 2026-01-28T08:47:15.3186366 Loot Tables // 1.21.1 2026-02-04T21:03:31.3164337 Loot Tables
// 1.21.1 2026-01-26T19:04:46.4976369 Loot Tables
69d8318ddba171526d1fabb87d9d93548ed8598e data/aphelion/loot_table/blocks/arc_furnace_casing.json 69d8318ddba171526d1fabb87d9d93548ed8598e data/aphelion/loot_table/blocks/arc_furnace_casing.json
05f08985e601d30116f67e2f07b48b03b40cdca6 data/aphelion/loot_table/blocks/block_steel.json 05f08985e601d30116f67e2f07b48b03b40cdca6 data/aphelion/loot_table/blocks/block_steel.json
ff43a9c3741faf10b1e156a7a74d5cfb035cc118 data/aphelion/loot_table/blocks/dimension_changer.json ff43a9c3741faf10b1e156a7a74d5cfb035cc118 data/aphelion/loot_table/blocks/dimension_changer.json
b63130d9c10485676303d729807b6fcaac080294 data/aphelion/loot_table/blocks/electric_arc_furnace.json b63130d9c10485676303d729807b6fcaac080294 data/aphelion/loot_table/blocks/electric_arc_furnace.json
afb6519a03415b8e0d5bafc9fadb70905a398046 data/aphelion/loot_table/blocks/oxygen_test_block.json
b9cfe672ead8e2673a7b2f5c4cec831e7e8e7040 data/aphelion/loot_table/blocks/launch_pad.json b9cfe672ead8e2673a7b2f5c4cec831e7e8e7040 data/aphelion/loot_table/blocks/launch_pad.json
afb6519a03415b8e0d5bafc9fadb70905a398046 data/aphelion/loot_table/blocks/oxygen_test_block.json
f3178154dadee30cc28f5ff23af45be98f2766cf data/aphelion/loot_table/blocks/rocket_assembler_block.json
1ab50c99e9f478840b9d003fd56ebdcab12fbbce data/aphelion/loot_table/blocks/test_block.json 1ab50c99e9f478840b9d003fd56ebdcab12fbbce data/aphelion/loot_table/blocks/test_block.json
7d8eeb99a1bc942a6e2cf292b21fd4534062b5ab data/aphelion/loot_table/blocks/vacuum_arc_furnace_controller.json 7d8eeb99a1bc942a6e2cf292b21fd4534062b5ab data/aphelion/loot_table/blocks/vacuum_arc_furnace_controller.json
797bf9839d79e08b4832c9eaf3cb303b0471ed0c data/aphelion/loot_table/blocks/vaf_dummy_block.json 797bf9839d79e08b4832c9eaf3cb303b0471ed0c data/aphelion/loot_table/blocks/vaf_dummy_block.json

View File

@@ -1,19 +1,21 @@
// 1.21.1 2026-01-28T08:47:15.3176368 Block States: aphelion // 1.21.1 2026-02-04T21:03:31.3154339 Block States: aphelion
// 1.21.1 2026-01-26T20:40:43.8251623 Block States: aphelion
851ff42f7b21dec86107c8e0cefb3934ae4ebc08 assets/aphelion/blockstates/block_steel.json 851ff42f7b21dec86107c8e0cefb3934ae4ebc08 assets/aphelion/blockstates/block_steel.json
30b9c0efd7aaadb5412d98e4568f98b3632adbb9 assets/aphelion/blockstates/dimension_changer.json 30b9c0efd7aaadb5412d98e4568f98b3632adbb9 assets/aphelion/blockstates/dimension_changer.json
cb4287104006c80c8396b290ab5258df65d62cef assets/aphelion/blockstates/electric_arc_furnace.json cb4287104006c80c8396b290ab5258df65d62cef assets/aphelion/blockstates/electric_arc_furnace.json
28131a570d3666b7f323de4ad8a69e52ceec92e2 assets/aphelion/blockstates/oxygen_test_block.json 28131a570d3666b7f323de4ad8a69e52ceec92e2 assets/aphelion/blockstates/oxygen_test_block.json
85c7c0dab53d0219b315c822147a90ade9075844 assets/aphelion/blockstates/rocket_assembler_block.json
b86c50fddcf6c8c6c19cb748529239d5962a3ede assets/aphelion/blockstates/test_block.json b86c50fddcf6c8c6c19cb748529239d5962a3ede assets/aphelion/blockstates/test_block.json
a810b97f4dace35d026f28d96cb9c47c93600d75 assets/aphelion/models/block/block_steel.json a810b97f4dace35d026f28d96cb9c47c93600d75 assets/aphelion/models/block/block_steel.json
2d3592b7ab7132908709243e97540151e0fb762e assets/aphelion/models/block/dimension_changer.json 2d3592b7ab7132908709243e97540151e0fb762e assets/aphelion/models/block/dimension_changer.json
5f7e8674070f31a63875b5d6147153bfa0eef61a assets/aphelion/models/block/electric_arc_furnace.json 5f7e8674070f31a63875b5d6147153bfa0eef61a assets/aphelion/models/block/electric_arc_furnace.json
746f23f150a01524ad03cbd1eb822bfbb7cf453b assets/aphelion/models/block/oxygen_test_block.json 746f23f150a01524ad03cbd1eb822bfbb7cf453b assets/aphelion/models/block/oxygen_test_block.json
17eb7327e504f7a88028af804e046281d9719fdf assets/aphelion/models/block/rocket_assembler_block.json
e0971228b4a1c4bc9dbab58a7dacdc3ae6037e02 assets/aphelion/models/block/test_block.json e0971228b4a1c4bc9dbab58a7dacdc3ae6037e02 assets/aphelion/models/block/test_block.json
cdc831b0f1c462be64825fd34bd446e5b95afac6 assets/aphelion/models/item/arc_furnace_casing.json cdc831b0f1c462be64825fd34bd446e5b95afac6 assets/aphelion/models/item/arc_furnace_casing.json
3599f9037eb2f66de1765318b97ab564c3eae92f assets/aphelion/models/item/block_steel.json 3599f9037eb2f66de1765318b97ab564c3eae92f assets/aphelion/models/item/block_steel.json
db0ec473a016ce05c258cde18a217d47a9ea8324 assets/aphelion/models/item/dimension_changer.json db0ec473a016ce05c258cde18a217d47a9ea8324 assets/aphelion/models/item/dimension_changer.json
279080c06ada87f54fd0a7b885b256dbe25a946a assets/aphelion/models/item/electric_arc_furnace.json 279080c06ada87f54fd0a7b885b256dbe25a946a assets/aphelion/models/item/electric_arc_furnace.json
24cf60e70f7d9450b0e70cf017662e80971bae17 assets/aphelion/models/item/oxygen_test_block.json 24cf60e70f7d9450b0e70cf017662e80971bae17 assets/aphelion/models/item/oxygen_test_block.json
dafa6e1a3cfd753e211ae94179a433c69e9d2a28 assets/aphelion/models/item/rocket_assembler_block.json
74418ef1cf678e72e7534924274688ef5a68af0e assets/aphelion/models/item/test_block.json 74418ef1cf678e72e7534924274688ef5a68af0e assets/aphelion/models/item/test_block.json
88ca3602517e99f7feaed57eddfc96965a25761c assets/aphelion/models/item/vacuum_arc_furnace_controller.json 88ca3602517e99f7feaed57eddfc96965a25761c assets/aphelion/models/item/vacuum_arc_furnace_controller.json

View File

@@ -0,0 +1,3 @@
{
"parent": "aphelion:block/rocket_assembler_block"
}

View File

@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "aphelion:rocket_assembler_block"
}
],
"rolls": 1.0
}
],
"random_sequence": "aphelion:blocks/rocket_assembler_block"
}

View File

@@ -15,6 +15,7 @@ import net.neoforged.neoforge.event.tick.ServerTickEvent;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
import net.xevianlight.aphelion.block.dummy.renderer.MultiblockDummyRenderer; import net.xevianlight.aphelion.block.dummy.renderer.MultiblockDummyRenderer;
import net.xevianlight.aphelion.block.entity.custom.renderer.OxygenTestRenderer; import net.xevianlight.aphelion.block.entity.custom.renderer.OxygenTestRenderer;
import net.xevianlight.aphelion.block.entity.custom.renderer.RocketAssemblerBlockEntityRenderer;
import net.xevianlight.aphelion.client.AphelionConfig; import net.xevianlight.aphelion.client.AphelionConfig;
import net.xevianlight.aphelion.core.saveddata.EnvironmentSavedData; import net.xevianlight.aphelion.core.saveddata.EnvironmentSavedData;
import net.xevianlight.aphelion.network.packet.PartitionPayload; import net.xevianlight.aphelion.network.packet.PartitionPayload;
@@ -139,6 +140,7 @@ public class Aphelion {
@SubscribeEvent @SubscribeEvent
public static void registerBER(EntityRenderersEvent.RegisterRenderers event) { public static void registerBER(EntityRenderersEvent.RegisterRenderers event) {
event.registerBlockEntityRenderer(ModBlockEntities.VAF_MULTIBLOCK_DUMMY_ENTITY.get(), MultiblockDummyRenderer::new); event.registerBlockEntityRenderer(ModBlockEntities.VAF_MULTIBLOCK_DUMMY_ENTITY.get(), MultiblockDummyRenderer::new);
event.registerBlockEntityRenderer(ModBlockEntities.ROCKET_ASSEMBLER_BLOCK_ENTITY.get(), RocketAssemblerBlockEntityRenderer::new);
// event.registerBlockEntityRenderer(ModBlockEntities.OXYGEN_TEST_BLOCK_ENTITY.get(), OxygenTestRenderer::new); // event.registerBlockEntityRenderer(ModBlockEntities.OXYGEN_TEST_BLOCK_ENTITY.get(), OxygenTestRenderer::new);
} }

View File

@@ -25,6 +25,8 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.items.ItemStackHandler;
import net.xevianlight.aphelion.block.custom.base.BasicEntityBlock;
import net.xevianlight.aphelion.block.custom.base.BasicHorizontalEntityBlock;
import net.xevianlight.aphelion.block.entity.custom.ElectricArcFurnaceEntity; import net.xevianlight.aphelion.block.entity.custom.ElectricArcFurnaceEntity;
import net.xevianlight.aphelion.core.init.ModBlockEntities; import net.xevianlight.aphelion.core.init.ModBlockEntities;
import net.xevianlight.aphelion.util.AphelionBlockStateProperties; import net.xevianlight.aphelion.util.AphelionBlockStateProperties;
@@ -34,14 +36,14 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ElectricArcFurnace extends BaseEntityBlock { public class ElectricArcFurnace extends BasicHorizontalEntityBlock {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final BooleanProperty LIT = BlockStateProperties.LIT; public static final BooleanProperty LIT = BlockStateProperties.LIT;
public static final BooleanProperty FORMED = AphelionBlockStateProperties.FORMED; public static final BooleanProperty FORMED = AphelionBlockStateProperties.FORMED;
public ElectricArcFurnace(Properties properties) { public ElectricArcFurnace(Properties properties) {
super(properties); super(properties, true);
this.registerDefaultState(this.getStateDefinition().any() this.registerDefaultState(this.getStateDefinition().any()
.setValue(FORMED, false)); .setValue(FORMED, false));
} }
@@ -164,25 +166,6 @@ public class ElectricArcFurnace extends BaseEntityBlock {
return 0; return 0;
} }
@Override
public @Nullable <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> blockEntityType) {
if (level.isClientSide) {
return null;
}
return createTickerHelper(blockEntityType, ModBlockEntities.ELECTRIC_ARC_FURNACE_ENTITY.get(), (level1, blockPos, blockState, electricArcFurnaceEntity) -> electricArcFurnaceEntity.tick(level1, blockPos, blockState));
}
@Override
protected BlockState rotate(BlockState state, Rotation rotation) {
return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
}
@Override
protected BlockState mirror(BlockState state, Mirror mirror) {
return state.rotate(mirror.getRotation(state.getValue(FACING)));
}
@Override @Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) { public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(LIT, false).setValue(FORMED, false); return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(LIT, false).setValue(FORMED, false);

View File

@@ -0,0 +1,205 @@
package net.xevianlight.aphelion.block.custom;
import com.mojang.datafixers.kinds.Const;
import com.mojang.math.Constants;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
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.BooleanProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.xevianlight.aphelion.block.custom.base.BasicEntityBlock;
import net.xevianlight.aphelion.block.entity.custom.PipeTestBlockEntity;
import net.xevianlight.aphelion.core.init.ModBlocks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
// a lot of this is ai slop so take it with a grainlet of salt
public class PipeTestBlock extends BasicEntityBlock {
// shortcuts for each directional property because they're pretty verbose
// t/f here means is/isn't connected outgoing in that direction
public static final BooleanProperty NORTH = BlockStateProperties.NORTH;
public static final BooleanProperty SOUTH = BlockStateProperties.SOUTH;
public static final BooleanProperty EAST = BlockStateProperties.EAST;
public static final BooleanProperty WEST = BlockStateProperties.WEST;
public static final BooleanProperty UP = BlockStateProperties.UP;
public static final BooleanProperty DOWN = BlockStateProperties.DOWN;
// Voxel shape pieces to make the actual pipe model
private static final VoxelShape CORE = Block.box(6, 6, 6, 10, 10, 10);
private static final VoxelShape NORTH_SHAPE = Block.box(6, 6, 0, 10, 10, 6);
private static final VoxelShape SOUTH_SHAPE = Block.box(6, 6, 10, 10, 10, 16);
private static final VoxelShape EAST_SHAPE = Block.box(10, 6, 6, 16, 10, 10);
private static final VoxelShape WEST_SHAPE = Block.box(0, 6, 6, 6, 10, 10);
private static final VoxelShape UP_SHAPE = Block.box(6, 10, 6, 10, 16, 10);
private static final VoxelShape DOWN_SHAPE = Block.box(6, 0, 6, 10, 6, 10);
// Assembles the "VoxelShape" of the block which i assume is just the collision/place/mine hitbox
// later this should be cached for each different shape that we need
@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
VoxelShape shape = CORE;
if (state.getValue(NORTH)) shape = Shapes.join(shape, NORTH_SHAPE, BooleanOp.OR);
if (state.getValue(SOUTH)) shape = Shapes.join(shape, SOUTH_SHAPE, BooleanOp.OR);
if (state.getValue(EAST)) shape = Shapes.join(shape, EAST_SHAPE, BooleanOp.OR);
if (state.getValue(WEST)) shape = Shapes.join(shape, WEST_SHAPE, BooleanOp.OR);
if (state.getValue(UP)) shape = Shapes.join(shape, UP_SHAPE, BooleanOp.OR);
if (state.getValue(DOWN)) shape = Shapes.join(shape, DOWN_SHAPE, BooleanOp.OR);
return shape;
}
public PipeTestBlock(Properties properties) {
super(properties, true);
this.registerDefaultState(this.stateDefinition.any()
.setValue(NORTH, false).setValue(SOUTH, false)
.setValue(EAST, false).setValue(WEST, false)
.setValue(UP, false).setValue(DOWN, false));
}
@Override
protected MapCodec<? extends BaseEntityBlock> codec() {
return null;
}
// This method determines the state; called when first placed
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return makeConnections(context.getLevel(), context.getClickedPos());
}
// Updates the block; called when a neighbor changes
@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos currentPos, BlockPos neighborPos) {
return makeConnections(level, currentPos);
}
public static Properties getProperties() {
return Properties.of().noOcclusion();
}
private boolean hasAttachment(@Nullable PipeTestBlockEntity BE, Direction direction) {
return (BE != null && BE.hasAttachment(direction));
}
private BlockState makeConnections(LevelAccessor level, BlockPos pos) {
BlockEntity BE = level.getBlockEntity(pos);
PipeTestBlockEntity PTBE = null;
if (BE instanceof PipeTestBlockEntity found) {
PTBE = found;
}
return this.defaultBlockState()
.setValue(NORTH, canConnect(level, pos.north(), Direction.SOUTH) || hasAttachment(PTBE, Direction.NORTH))
.setValue(SOUTH, canConnect(level, pos.south(), Direction.NORTH) || hasAttachment(PTBE, Direction.SOUTH))
.setValue(EAST, canConnect(level, pos.east(), Direction.WEST) || hasAttachment(PTBE, Direction.EAST))
.setValue(WEST, canConnect(level, pos.west(), Direction.EAST) || hasAttachment(PTBE, Direction.WEST))
.setValue(UP, canConnect(level, pos.above(), Direction.DOWN) || hasAttachment(PTBE, Direction.UP))
.setValue(DOWN, canConnect(level, pos.below(), Direction.UP) || hasAttachment(PTBE, Direction.DOWN));
}
/// If a PipeTestBlock can connect to this position from the given direction.
/// If you're going to the NORTH of yourself, you should be accessing the SOUTH side.
public static boolean canConnect(LevelAccessor levelA, BlockPos neighborPos, Direction accessSide) {
// Methinks this is not the best way to test this.
boolean isPipe = levelA.getBlockState(neighborPos).is(ModBlocks.PIPE_TEST_BLOCK.get());
/// This code is AI, but I think it works? I think the reason it's a levelAccessor instead of a level
/// is that we're not sure if we're in, for example, an inventory slot or not.
/// Either way, this should only trigger when it makes sense (assuming this is correct in the first place)
boolean isInventory;
if (levelA instanceof Level level) {
isInventory = level.getCapability(Capabilities.ItemHandler.BLOCK, neighborPos, accessSide) != null;
} else {
isInventory = false;
}
return isPipe || isInventory;
}
@Override
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
BlockEntity BE = level.getBlockEntity(pos);
if (BE instanceof PipeTestBlockEntity pipe) {
// force everything connected to this pipe to reevaluate
if (pipe.graph != null) pipe.graph.invalidate();
}
super.onRemove(state, level, pos, newState, isMoving);
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(NORTH, SOUTH, EAST, WEST, UP, DOWN);
}
@Override
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
BlockEntity BE = level.getBlockEntity(pos);
if (BE instanceof PipeTestBlockEntity PTBE) {
ItemInteractionResult r = PTBE.useItemOn(stack, state, level, pos, player, hand, hitResult, this);
BlockState newState = makeConnections(level, pos);
level.setBlock(pos, newState, 3);
return r;
} else {
return super.useItemOn(stack, state, level, pos, player, hand, hitResult);
}
}
// Doesn't block sunlight
// @Override
// public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) {
// return true;
// }
/// This function doesn't do what the AI says it does. I have no idea what it actually does, though
// 2. Prevents the "black shadows" inside or around the pipe
// @Override
// public int getLightBlock(BlockState state, BlockGetter worldIn, BlockPos pos) {
// return 0;
// }
/// I don't know what this does, because Properties.noOcclusion() is the part that made the leaves keep
/// rendering their faces.
// 3. Tells adjacent blocks (like leaves) to keep rendering their faces
// @Override
// public boolean isOcclusionShapeFullBlock(BlockState state, BlockGetter worldIn, BlockPos pos) {
// return false;
// }
// This bit affects how strong the ambient occlusion effect is
@Override
public float getShadeBrightness(BlockState state, BlockGetter world, BlockPos pos) {
return 1.0F; // Maintains full brightness
}
@Override
public @Nullable BlockEntity newBlockEntity(@NotNull BlockPos blockPos, @NotNull BlockState blockState) {
return new PipeTestBlockEntity(blockPos, blockState);
}
}

View File

@@ -2,21 +2,22 @@ package net.xevianlight.aphelion.block.custom;
import com.mojang.serialization.MapCodec; import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; 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.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.xevianlight.aphelion.block.custom.base.BasicHorizontalEntityBlock; import net.xevianlight.aphelion.block.custom.base.BasicHorizontalEntityBlock;
import net.xevianlight.aphelion.block.entity.custom.RocketAssemblerBlockEntity; import net.xevianlight.aphelion.block.entity.custom.RocketAssemblerBlockEntity;
import net.xevianlight.aphelion.util.AphelionBlockStateProperties;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class RocketAssemblerBlock extends BasicHorizontalEntityBlock { public class RocketAssemblerBlock extends BasicHorizontalEntityBlock {
public static final BooleanProperty FORMED = AphelionBlockStateProperties.FORMED;
public RocketAssemblerBlock(Properties properties) { public RocketAssemblerBlock(Properties properties) {
super(properties, true); super(properties, true);
} }
@@ -24,7 +25,7 @@ public class RocketAssemblerBlock extends BasicHorizontalEntityBlock {
public static final MapCodec<RocketAssemblerBlock> CODEC = simpleCodec(RocketAssemblerBlock::new); public static final MapCodec<RocketAssemblerBlock> CODEC = simpleCodec(RocketAssemblerBlock::new);
@Override @Override
protected MapCodec<? extends BaseEntityBlock> codec() { protected @NotNull MapCodec<? extends BaseEntityBlock> codec() {
return CODEC; return CODEC;
} }
@@ -38,7 +39,18 @@ public class RocketAssemblerBlock extends BasicHorizontalEntityBlock {
} }
@Override @Override
public @Nullable BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { public @Nullable BlockEntity newBlockEntity(@NotNull BlockPos blockPos, @NotNull BlockState blockState) {
return new RocketAssemblerBlockEntity(blockPos, blockState); return new RocketAssemblerBlockEntity(blockPos, blockState);
} }
@Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(FORMED, false);
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FORMED);
super.createBlockStateDefinition(builder);
}
} }

View File

@@ -14,10 +14,10 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity; 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.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; 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.BlockStateProperties;
@@ -25,25 +25,25 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.items.ItemStackHandler;
import net.xevianlight.aphelion.block.entity.custom.ElectricArcFurnaceEntity; import net.xevianlight.aphelion.block.custom.base.BasicHorizontalEntityBlock;
import net.xevianlight.aphelion.block.entity.custom.VacuumArcFurnaceControllerEntity; import net.xevianlight.aphelion.block.entity.custom.VacuumArcFurnaceControllerEntity;
import net.xevianlight.aphelion.core.init.ModBlockEntities;
import net.xevianlight.aphelion.util.AphelionBlockStateProperties; import net.xevianlight.aphelion.util.AphelionBlockStateProperties;
import net.xevianlight.aphelion.util.IMultiblockController; import net.xevianlight.aphelion.util.IMultiblockController;
import net.xevianlight.aphelion.util.MultiblockHelper; import net.xevianlight.aphelion.util.MultiblockHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class VacuumArcFurnaceController extends BaseEntityBlock { public class VacuumArcFurnaceController extends BasicHorizontalEntityBlock {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final BooleanProperty LIT = BlockStateProperties.LIT; public static final BooleanProperty LIT = BlockStateProperties.LIT;
public static final BooleanProperty FORMED = AphelionBlockStateProperties.FORMED; public static final BooleanProperty FORMED = AphelionBlockStateProperties.FORMED;
public VacuumArcFurnaceController(Properties properties) { public VacuumArcFurnaceController(Properties properties) {
super(properties); super(properties, true);
this.registerDefaultState(this.getStateDefinition().any() this.registerDefaultState(this.getStateDefinition().any()
.setValue(FACING, Direction.NORTH) .setValue(FACING, Direction.NORTH)
.setValue(LIT, false) .setValue(LIT, false)
@@ -77,7 +77,7 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
} }
@Override @Override
public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult result) { public @NotNull InteractionResult useWithoutItem(@NotNull BlockState state, Level level, @NotNull BlockPos pos, @NotNull Player player, @NotNull BlockHitResult result) {
if (!level.isClientSide && player instanceof ServerPlayer serverPlayer && level.getBlockEntity(pos) instanceof VacuumArcFurnaceControllerEntity vacuumArcFurnaceEntity) { if (!level.isClientSide && player instanceof ServerPlayer serverPlayer && level.getBlockEntity(pos) instanceof VacuumArcFurnaceControllerEntity vacuumArcFurnaceEntity) {
if (vacuumArcFurnaceEntity.isFormed()) if (vacuumArcFurnaceEntity.isFormed())
serverPlayer.openMenu(new SimpleMenuProvider(vacuumArcFurnaceEntity, Component.literal("Vacuum Arc Furnace")), pos); serverPlayer.openMenu(new SimpleMenuProvider(vacuumArcFurnaceEntity, Component.literal("Vacuum Arc Furnace")), pos);
@@ -88,21 +88,16 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
@Override @Override
public @Nullable BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { public @Nullable BlockEntity newBlockEntity(@NotNull BlockPos blockPos, @NotNull BlockState blockState) {
return new VacuumArcFurnaceControllerEntity(blockPos, blockState); return new VacuumArcFurnaceControllerEntity(blockPos, blockState);
} }
@Override @Override
public RenderShape getRenderShape(BlockState pState) { protected void onRemove(BlockState state, Level level, @NotNull BlockPos pos, BlockState newState, boolean movedByPiston) {
return RenderShape.MODEL;
}
@Override
protected void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
if (!level.isClientSide && state.getBlock() != newState.getBlock()) { if (!level.isClientSide && state.getBlock() != newState.getBlock()) {
BlockEntity blockEntity= level.getBlockEntity(pos); BlockEntity blockEntity= level.getBlockEntity(pos);
if (blockEntity instanceof VacuumArcFurnaceControllerEntity vacuumArcFurnaceEntity) { if (blockEntity instanceof VacuumArcFurnaceControllerEntity vacuumArcFurnaceEntity) {
if(state.getValue(FORMED)) MultiblockHelper.unformForRemoval(level, state, pos, vacuumArcFurnaceEntity.SHAPE, AphelionBlockStateProperties.FORMED); if(state.getValue(FORMED)) MultiblockHelper.unformForRemoval(level, state, pos, VacuumArcFurnaceControllerEntity.SHAPE, AphelionBlockStateProperties.FORMED);
vacuumArcFurnaceEntity.drops(); vacuumArcFurnaceEntity.drops();
} }
} }
@@ -110,7 +105,7 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
} }
@Override @Override
protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) { protected void onPlace(BlockState state, Level level, @NotNull BlockPos pos, @NotNull BlockState oldState, boolean movedByPiston) {
super.onPlace(state, level, pos, oldState, movedByPiston); super.onPlace(state, level, pos, oldState, movedByPiston);
if (!level.isClientSide() && oldState.getBlock() != state.getBlock()) { if (!level.isClientSide() && oldState.getBlock() != state.getBlock()) {
BlockEntity blockEntity= level.getBlockEntity(pos); BlockEntity blockEntity= level.getBlockEntity(pos);
@@ -120,7 +115,7 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
} }
} }
public static int getRedstoneSignalFromItemHandler(@javax.annotation.Nullable ItemStackHandler itemStackHandler, List<Integer> slots) { public static int getRedstoneSignalFromItemHandler(@Nullable ItemStackHandler itemStackHandler, List<Integer> slots) {
if (itemStackHandler == null) { if (itemStackHandler == null) {
return 0; return 0;
} else { } else {
@@ -141,22 +136,22 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
} }
@Override @Override
protected boolean isSignalSource(BlockState state) { protected boolean isSignalSource(@NotNull BlockState state) {
return true; return true;
} }
@Override @Override
protected int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { protected int getSignal(@NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull Direction direction) {
return super.getSignal(state, level, pos, direction); return super.getSignal(state, level, pos, direction);
} }
@Override @Override
protected boolean hasAnalogOutputSignal(BlockState state) { protected boolean hasAnalogOutputSignal(@NotNull BlockState state) {
return true; return true;
} }
@Override @Override
protected int getAnalogOutputSignal(BlockState blockState, Level level, BlockPos pos) { protected int getAnalogOutputSignal(@NotNull BlockState blockState, Level level, @NotNull BlockPos pos) {
List<Integer> slots = new ArrayList<>(); List<Integer> slots = new ArrayList<>();
slots.add(VacuumArcFurnaceControllerEntity.INPUT_SLOT); slots.add(VacuumArcFurnaceControllerEntity.INPUT_SLOT);
slots.add(VacuumArcFurnaceControllerEntity.SECONDARY_INPUT_SLOT); slots.add(VacuumArcFurnaceControllerEntity.SECONDARY_INPUT_SLOT);
@@ -169,25 +164,6 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
return 0; return 0;
} }
@Override
public @Nullable <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> blockEntityType) {
if (level.isClientSide) {
return null;
}
return createTickerHelper(blockEntityType, ModBlockEntities.VACUUM_ARC_FURNACE_ENTITY.get(), (level1, blockPos, blockState, vacuumArcFurnaceEntity) -> vacuumArcFurnaceEntity.tick(level1, blockPos, blockState));
}
@Override
protected BlockState rotate(BlockState state, Rotation rotation) {
return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
}
@Override
protected BlockState mirror(BlockState state, Mirror mirror) {
return state.rotate(mirror.getRotation(state.getValue(FACING)));
}
@Override @Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) { public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(LIT, false).setValue(FORMED, false); return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(LIT, false).setValue(FORMED, false);

View File

@@ -7,16 +7,44 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
public interface TickableBlockEntity { public interface TickableBlockEntity {
void tick(Level entityLevel, long time, BlockState blockState, BlockPos pos);
/**
* Runs on both the client AND server.
* @param level
* @param time
* @param state
* @param pos
*/
default void tick (Level level, long time, BlockState state, BlockPos pos) {};
/**
* Runs on the client only
* @param level
* @param time
* @param state
* @param pos
*/
void clientTick(ClientLevel level, long time, BlockState state, BlockPos pos); void clientTick(ClientLevel level, long time, BlockState state, BlockPos pos);
/**
* Runs on the server only
* @param level
* @param time
* @param state
* @param pos
*/
void serverTick(ServerLevel level, long time, BlockState state, BlockPos pos); void serverTick(ServerLevel level, long time, BlockState state, BlockPos pos);
default boolean isInitialized() { default boolean isInitialized() {
return true; return true;
}; };
/**
* Runs on client AND server, once only.
* @param level
* @param state
* @param pos
*/
void firstTick(Level level, BlockState state, BlockPos pos); void firstTick(Level level, BlockState state, BlockPos pos);
default void onRemoved() {} default void onRemoved() {}

View File

@@ -1,5 +1,6 @@
package net.xevianlight.aphelion.block.entity.custom; package net.xevianlight.aphelion.block.entity.custom;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
@@ -8,6 +9,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Containers; import net.minecraft.world.Containers;
import net.minecraft.world.MenuProvider; import net.minecraft.world.MenuProvider;
import net.minecraft.world.SimpleContainer; import net.minecraft.world.SimpleContainer;
@@ -25,6 +27,7 @@ import net.neoforged.neoforge.energy.IEnergyStorage;
import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.items.ItemStackHandler;
import net.xevianlight.aphelion.block.custom.ElectricArcFurnace; import net.xevianlight.aphelion.block.custom.ElectricArcFurnace;
import net.xevianlight.aphelion.block.custom.base.TickableBlockEntity;
import net.xevianlight.aphelion.block.entity.energy.ModEnergyStorage; import net.xevianlight.aphelion.block.entity.energy.ModEnergyStorage;
import net.xevianlight.aphelion.core.init.ModBlockEntities; import net.xevianlight.aphelion.core.init.ModBlockEntities;
import net.xevianlight.aphelion.core.init.ModBlocks; import net.xevianlight.aphelion.core.init.ModBlocks;
@@ -39,7 +42,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
public class ElectricArcFurnaceEntity extends BlockEntity implements MenuProvider { public class ElectricArcFurnaceEntity extends BlockEntity implements MenuProvider, TickableBlockEntity {
private final int SIZE = 4; private final int SIZE = 4;
private int ENERGY_CAPACITY = 64000; private int ENERGY_CAPACITY = 64000;
@@ -101,10 +104,8 @@ public class ElectricArcFurnaceEntity extends BlockEntity implements MenuProvide
// } // }
}; };
public void tick(Level level, BlockPos pos, BlockState blockState) { @Override
public void serverTick(ServerLevel level, long time, BlockState state, BlockPos pos) {
if (!blockState.getValue(AphelionBlockStateProperties.FORMED))
return;
chargeFromItem(); chargeFromItem();
@@ -114,8 +115,8 @@ public class ElectricArcFurnaceEntity extends BlockEntity implements MenuProvide
// Recipe detected! We have enough energy to process // Recipe detected! We have enough energy to process
progress++; progress++;
useEnergy(); useEnergy();
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, true)); level.setBlockAndUpdate(pos, state.setValue(ElectricArcFurnace.LIT, true));
setChanged(level, pos, blockState); setChanged(level, pos, state);
if (hasCraftingFinished()) { if (hasCraftingFinished()) {
outputBlastingResult(INPUT_SLOT, OUTPUT_SLOT); outputBlastingResult(INPUT_SLOT, OUTPUT_SLOT);
@@ -123,14 +124,14 @@ public class ElectricArcFurnaceEntity extends BlockEntity implements MenuProvide
} }
} else if (hasFurnaceRecipe(INPUT_SLOT) && !hasEnoughEnergyToCraft(MACHINE_ENERGY_COST)) { } else if (hasFurnaceRecipe(INPUT_SLOT) && !hasEnoughEnergyToCraft(MACHINE_ENERGY_COST)) {
// Recipe detected but we ran out of power // Recipe detected but we ran out of power
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, false)); level.setBlockAndUpdate(pos, state.setValue(ElectricArcFurnace.LIT, false));
setChanged(level, pos, blockState); setChanged(level, pos, state);
progress = progress > 0 ? progress - 1 : 0; progress = progress > 0 ? progress - 1 : 0;
} else { } else {
// Invalid recipe // Invalid recipe
resetProgress(); resetProgress();
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, false)); level.setBlockAndUpdate(pos, state.setValue(ElectricArcFurnace.LIT, false));
setChanged(level, pos, blockState); setChanged(level, pos, state);
} }
} else { } else {
// Secondary slot is NOT empty, try alloying recipes // Secondary slot is NOT empty, try alloying recipes
@@ -139,8 +140,8 @@ public class ElectricArcFurnaceEntity extends BlockEntity implements MenuProvide
// Alloy recipe detected! We have enough energy to process // Alloy recipe detected! We have enough energy to process
progress++; progress++;
useEnergy(); useEnergy();
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, true)); level.setBlockAndUpdate(pos, state.setValue(ElectricArcFurnace.LIT, true));
setChanged(level, pos, blockState); setChanged(level, pos, state);
if (hasCraftingFinished()) { if (hasCraftingFinished()) {
outputAlloyingResult(INPUT_SLOT, SECONDARY_INPUT_SLOT, OUTPUT_SLOT); outputAlloyingResult(INPUT_SLOT, SECONDARY_INPUT_SLOT, OUTPUT_SLOT);
@@ -148,19 +149,17 @@ public class ElectricArcFurnaceEntity extends BlockEntity implements MenuProvide
} }
} else { } else {
// Recipe detected but we ran out of power // Recipe detected but we ran out of power
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, false)); level.setBlockAndUpdate(pos, state.setValue(ElectricArcFurnace.LIT, false));
setChanged(level, pos, blockState); setChanged(level, pos, state);
progress = progress > 0 ? progress - 1 : 0; progress = progress > 0 ? progress - 1 : 0;
} }
} else { } else {
// Invalid recipe // Invalid recipe
resetProgress(); resetProgress();
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, false)); level.setBlockAndUpdate(pos, state.setValue(ElectricArcFurnace.LIT, false));
setChanged(level, pos, blockState); setChanged(level, pos, state);
} }
} }
} }
private void chargeFromItem() { private void chargeFromItem() {
@@ -408,4 +407,14 @@ public class ElectricArcFurnaceEntity extends BlockEntity implements MenuProvide
new MultiblockHelper.ShapePart(new BlockPos(3,0,3), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)), new MultiblockHelper.ShapePart(new BlockPos(3,0,3), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
// new MultiblockHelper.ShapePart(new BlockPos(-1,0,0), s -> s.is(Blocks.AMETHYST_BLOCK)) // new MultiblockHelper.ShapePart(new BlockPos(-1,0,0), s -> s.is(Blocks.AMETHYST_BLOCK))
}; };
@Override
public void clientTick(ClientLevel level, long time, BlockState state, BlockPos pos) {
}
@Override
public void firstTick(Level level, BlockState state, BlockPos pos) {
}
} }

View File

@@ -0,0 +1,155 @@
package net.xevianlight.aphelion.block.entity.custom;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.xevianlight.aphelion.Aphelion;
import net.xevianlight.aphelion.block.custom.PipeTestBlock;
import net.xevianlight.aphelion.block.custom.base.TickableBlockEntity;
import net.xevianlight.aphelion.core.init.ModBlockEntities;
import net.xevianlight.aphelion.core.init.ModBlocks;
import net.xevianlight.aphelion.systems.conveyor.*;
import net.xevianlight.aphelion.util.FloodFill3D;
import org.jetbrains.annotations.Nullable;
import java.util.*;
public class PipeTestBlockEntity extends BlockEntity implements TickableBlockEntity {
public @Nullable ConveyorNetwork graph = null;
public final Map<Direction, @Nullable ConveyorAttachment> attachments = new HashMap<>();
public final Map<Direction, @Nullable ConveyorOutput> outputs = new HashMap<>();
public PipeTestBlockEntity(BlockPos pos, BlockState blockState) {
super(ModBlockEntities.PIPE_TEST_BLOCK_ENTITY.get(), pos, blockState);
}
@Override
public void clientTick(ClientLevel level, long time, BlockState state, BlockPos pos) {
}
@Override
public void serverTick(ServerLevel level, long time, BlockState state, BlockPos pos) {
if (this.graph == null) initGraph(level, pos);
// TODO: Call this as little as necessary
makeOutputs(level, state, pos);
for (Direction dir : Direction.values()) {
ConveyorAttachment attachment = attachments.get(dir);
if (attachment != null) {
attachment.tick(level, state, pos, dir, graph);
}
}
}
@Override
public void firstTick(Level level, BlockState state, BlockPos pos) {
}
private void addOutput(Direction dir, ConveyorOutput output) {
outputs.put(dir, output);
if (graph != null) graph.outputs.add(output);
}
private void removeOutput(Direction dir) {
ConveyorOutput old = outputs.get(dir);
if (graph != null) graph.outputs.remove(old);
outputs.remove(dir);
}
private boolean canOutputTo(Level level, BlockPos pos, Direction accessSide) {
return level.getCapability(Capabilities.ItemHandler.BLOCK, pos, accessSide) != null;
}
protected void makeOutputs(ServerLevel level, BlockState state, BlockPos pos) {
BlockPos.MutableBlockPos neighbor = new BlockPos.MutableBlockPos();
for (Direction dir : Direction.values()) {
neighbor.setWithOffset(pos, dir);
if (canOutputTo(level, neighbor, dir.getOpposite()) && attachments.get(dir) == null && outputs.get(dir) == null) {
addOutput(dir, new BasicItemOutput(level, pos, dir));
}
if (!(canOutputTo(level, neighbor, dir.getOpposite()) && attachments.get(dir) == null) && outputs.get(dir) != null) {
removeOutput(dir);
}
}
}
public boolean hasAttachment(Direction direction) {
return attachments.get(direction) != null;
}
// Simplest implementation I can think of
public static void initGraph(Level level, BlockPos pos) {
Aphelion.LOGGER.info("Init graph from {}", pos);
if (!level.getBlockState(pos).is(ModBlocks.PIPE_TEST_BLOCK.get())) return;
Set<BlockPos> pipes = FloodFill3D.run(
level, pos, 1000,
(var v1, var v2, var state, var v4, var v5, var v6) -> state.is(ModBlocks.PIPE_TEST_BLOCK.get()),
false);
Aphelion.LOGGER.info("Got {} pipes", pipes.size());
ConveyorNetwork graph = new ConveyorNetwork();
for (BlockPos pipePos : pipes) {
BlockEntity BE = level.getBlockEntity(pipePos);
if (BE instanceof PipeTestBlockEntity pipe) {
// Invalidate any old graphs
if (pipe.graph != null) {
pipe.graph.invalidate();
}
graph.addPipe(pipe);
}
}
}
public void setAttachment(Direction side, ConveyorAttachment attachment) {
attachments.put(side, attachment);
}
public boolean trySetAttachment(Direction side, ConveyorAttachment attachment) {
if (hasAttachment(side)) return false;
setAttachment(side, attachment);
return true;
}
public static boolean isAttachmentItem(ItemStack stack) {
//TODO: add actual attachment items instead of just stone
return stack.is(Item.byId(1));
}
// Server only
public ConveyorAttachment getAttachmentForItem(ItemStack stack, Direction side) {
if (level.isClientSide()) throw new RuntimeException("Cannot get attachment item on client side!");
return new BasicItemExtractAttachment((ServerLevel) level, getBlockPos(), side);
}
/// Called from pipe test block's useItemOn
public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult, PipeTestBlock block) {
if (level.isClientSide) return ItemInteractionResult.SUCCESS;
Vec3 relativePos = hitResult.getLocation().subtract(pos.getCenter());
Direction pipeSide = Direction.getNearest(relativePos);
if (isAttachmentItem(stack)) {
boolean success = trySetAttachment(pipeSide, getAttachmentForItem(stack, pipeSide));
return success ? ItemInteractionResult.SUCCESS : ItemInteractionResult.FAIL;
} else {
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; // goes through with whatever other interaction (placing a block, etc)
}
}
}

View File

@@ -1,19 +1,44 @@
package net.xevianlight.aphelion.block.entity.custom; package net.xevianlight.aphelion.block.entity.custom;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.xevianlight.aphelion.Aphelion;
import net.xevianlight.aphelion.block.custom.base.TickableBlockEntity; import net.xevianlight.aphelion.block.custom.base.TickableBlockEntity;
import net.xevianlight.aphelion.core.init.ModBlockEntities; import net.xevianlight.aphelion.core.init.ModBlockEntities;
import net.xevianlight.aphelion.core.init.ModBlocks;
import net.xevianlight.aphelion.util.AphelionBlockStateProperties;
import net.xevianlight.aphelion.util.ModTags;
import net.xevianlight.aphelion.util.RocketStructure; import net.xevianlight.aphelion.util.RocketStructure;
import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayDeque;
public class RocketAssemblerBlockEntity extends BlockEntity implements TickableBlockEntity { public class RocketAssemblerBlockEntity extends BlockEntity implements TickableBlockEntity {
Direction facing;
BlockPos padScanStart = BlockPos.ZERO;
private PadInfo padBounds;
public @Nullable PadInfo getPadBounds() {
return padBounds;
}
public boolean isInitialized; public boolean isInitialized;
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
@@ -24,13 +49,156 @@ public class RocketAssemblerBlockEntity extends BlockEntity implements TickableB
super(ModBlockEntities.ROCKET_ASSEMBLER_BLOCK_ENTITY.get(), pos, blockState); super(ModBlockEntities.ROCKET_ASSEMBLER_BLOCK_ENTITY.get(), pos, blockState);
} }
public void tick(Level level1, BlockPos blockPos, BlockState blockState) { public record PadInfo(BlockPos min, BlockPos max) {
public int getVolume() {
int dx = max.getX() - min.getX() + 1;
int dy = max.getY() - min.getY() + 1;
int dz = max.getZ() - min.getZ() + 1;
return dx * dy * dz;
}
} }
public boolean getPlatform() { private final Block TOWER_BLOCK = ModBlocks.BLOCK_STEEL.get();
public BlockPos towerBasePos;
public @Nullable PadInfo getPlatform() {
// TODO // TODO
throw new NotImplementedException(); int y = this.padScanStart.getY();
BlockPos start = this.padScanStart;
if (level == null) return null;
if (!isPad(level.getBlockState(start))) return null;
int minX = start.getX();
while (isPad(level.getBlockState(new BlockPos(minX - 1, y, start.getZ())))) minX--;
// Find maxX by walking east
int maxX = start.getX();
while (isPad(level.getBlockState(new BlockPos(maxX + 1, y, start.getZ())))) maxX++;
// Find minZ by walking north
int minZ = start.getZ();
while (isPad(level.getBlockState(new BlockPos(start.getX(), y, minZ - 1)))) minZ--;
// Find maxZ by walking south
int maxZ = start.getZ();
while (isPad(level.getBlockState(new BlockPos(start.getX(), y, maxZ + 1)))) maxZ++;
int width = (maxX - minX) + 1;
int length = (maxZ - minZ) + 1;
// Must be square
if (width != length) return null;
// Verify the entire rectangle is filled with pad blocks
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
if (!isPad(level.getBlockState(new BlockPos(x, y, z)))) return null;
}
}
return new PadInfo(new BlockPos(minX, y, minZ), new BlockPos(maxX, y, maxZ));
}
private boolean connected(BlockState state, Direction dir) {
return switch (dir) {
case NORTH -> state.getValue(BlockStateProperties.NORTH);
case SOUTH -> state.getValue(BlockStateProperties.SOUTH);
case EAST -> state.getValue(BlockStateProperties.EAST);
case WEST -> state.getValue(BlockStateProperties.WEST);
default -> false;
};
}
public @Nullable PadInfo getPlatformFill() {
if (level == null) return null;
BlockPos start = this.padScanStart;
if (!isPad(level.getBlockState(start))) return null;
final int y = start.getY();
int towerHeight = 0;
ArrayDeque<BlockPos> queue = new ArrayDeque<>();
LongOpenHashSet visited = new LongOpenHashSet();
queue.add(start);
visited.add(start.asLong());
final Direction[] CARDINALS = {Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST};
// When the $#$# are we going to have a rocket larger than 64x64... don't...
final int MAX_PAD_BLOCKS = 4096;
boolean towerFound = false;
while (!queue.isEmpty()) {
BlockPos p = queue.removeFirst();
BlockState s = level.getBlockState(p);
// We trust block states entirely. If a block state says it has a pad in a direction and is wrong, something else has failed. To minimize level checks and have this run as fast as possible, I won't compare the block
// if (!isPad(s)) continue;
for (Direction d : CARDINALS) {
// Only keep going if the block claims to have a neighbor in that direction
BlockPos n = p.relative(d);
if (!connected(s, d)) {
if (level.getBlockState(n).is(TOWER_BLOCK)) {
if (!towerFound) {
towerBasePos = n;
towerFound = true;
} else if (!n.equals(towerBasePos)) {
Aphelion.LOGGER.warn("Multiple towers found, rocket pad invalid");
return null;
}
}
continue;
}
if (visited.contains(n.asLong())) continue; // skip if we've already seen this block
visited.add(n.asLong());
queue.addLast(n);
if (visited.size() > MAX_PAD_BLOCKS) return null;
}
}
// Pads missing a tower should be invalid
if (!towerFound || towerBasePos == null) return null;
towerHeight = getTowerHeight(level, towerBasePos);
if (towerHeight <= 0) return null;
int minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE;
int minZ = Integer.MAX_VALUE, maxZ = Integer.MIN_VALUE;
for (Long p : visited) {
minX = Math.min(minX, BlockPos.of(p).getX());
maxX = Math.max(maxX, BlockPos.of(p).getX());
minZ = Math.min(minZ, BlockPos.of(p).getZ());
maxZ = Math.max(maxZ, BlockPos.of(p).getZ());
}
int width = (maxX - minX) + 1;
int length = (maxZ - minZ) + 1;
// SQUARE AND SOLID??? The math works out here that this will only be true if the number of blocks found matches the side lengths squared. We don't need to check for holes manually!
if (visited.size() != length * width || length != width) return null;
return new PadInfo(new BlockPos(minX, y + 1, minZ), new BlockPos(maxX, y + towerHeight, maxZ));
}
private int getTowerHeight(@NotNull Level level, @NotNull BlockPos base) {
int h = 0;
BlockPos p = base.above();
while (level.getBlockState(p).is(TOWER_BLOCK)) {
h++;
p = p.above();
}
return h;
} }
public RocketStructure scan() { public RocketStructure scan() {
@@ -38,11 +206,6 @@ public class RocketAssemblerBlockEntity extends BlockEntity implements TickableB
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override
public void tick(Level entityLevel, long time, BlockState blockState, BlockPos pos) {
}
@Override @Override
public void clientTick(ClientLevel level, long time, BlockState state, BlockPos pos) { public void clientTick(ClientLevel level, long time, BlockState state, BlockPos pos) {
@@ -50,11 +213,87 @@ public class RocketAssemblerBlockEntity extends BlockEntity implements TickableB
@Override @Override
public void serverTick(ServerLevel level, long time, BlockState state, BlockPos pos) { public void serverTick(ServerLevel level, long time, BlockState state, BlockPos pos) {
PadInfo newBounds = getPlatformFill();
setPadBoundsAndSync(newBounds);
boolean formed = newBounds != null;
if (state.getValue(AphelionBlockStateProperties.FORMED) != formed) {
level.setBlockAndUpdate(pos, state.setValue(AphelionBlockStateProperties.FORMED, formed));
}
} }
@Override @Override
public void firstTick(Level level, BlockState state, BlockPos pos) { public void firstTick(Level level, BlockState state, BlockPos pos) {
facing = getBlockState().getValue(BlockStateProperties.HORIZONTAL_FACING);
padScanStart = getBlockPos().mutable().below().relative(facing.getOpposite());
this.isInitialized = true; this.isInitialized = true;
} }
private static boolean isPad(BlockState s) {
return s.is(ModTags.Blocks.LAUNCH_PAD); // or s.getBlock() == ModBlocks.PAD.get()
}
@Override
protected void saveAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
super.saveAdditional(tag, registries);
PadInfo pad = this.padBounds;
if (pad != null) {
tag.putLong("PadMin", padBounds.min().asLong());
tag.putLong("PadMax", padBounds.max().asLong());
}
}
@Override
protected void loadAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
super.loadAdditional(tag, registries);
if (tag.contains("PadMin") && tag.contains("PadMax")) {
BlockPos min = BlockPos.of(tag.getLong("PadMin"));
BlockPos max = BlockPos.of(tag.getLong("PadMax"));
this.padBounds = new PadInfo(min, max);
} else {
this.padBounds = null;
}
}
@Override
public @NotNull CompoundTag getUpdateTag(HolderLookup.@NotNull Provider registries) {
CompoundTag tag = super.getUpdateTag(registries);
saveAdditional(tag, registries);
return tag;
}
@Override
public void handleUpdateTag(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
loadAdditional(tag, registries);
}
private void setPadBoundsAndSync(@Nullable PadInfo newBounds) {
if (java.util.Objects.equals(this.padBounds, newBounds)) return;
this.padBounds = newBounds;
setChanged(); // marks BE dirty for saving
if (level instanceof ServerLevel server) {
BlockState state = getBlockState();
server.sendBlockUpdated(worldPosition, state, state, 3);
}
}
@Override
public Packet<ClientGamePacketListener> getUpdatePacket() {
// sends the tag from getUpdateTag()
return ClientboundBlockEntityDataPacket.create(this);
}
@Override
public void onDataPacket(@NotNull Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.@NotNull Provider registries) {
// apply the received tag on client
CompoundTag tag = pkt.getTag();
if (tag != null) {
this.loadAdditional(tag, registries);
}
}
} }

View File

@@ -1,5 +1,6 @@
package net.xevianlight.aphelion.block.entity.custom; package net.xevianlight.aphelion.block.entity.custom;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
@@ -8,6 +9,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Containers; import net.minecraft.world.Containers;
import net.minecraft.world.MenuProvider; import net.minecraft.world.MenuProvider;
import net.minecraft.world.SimpleContainer; import net.minecraft.world.SimpleContainer;
@@ -28,14 +30,14 @@ import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.energy.IEnergyStorage; import net.neoforged.neoforge.energy.IEnergyStorage;
import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.items.ItemStackHandler;
import net.xevianlight.aphelion.block.custom.ElectricArcFurnace; import net.xevianlight.aphelion.block.custom.VacuumArcFurnaceController;
import net.xevianlight.aphelion.block.custom.base.TickableBlockEntity;
import net.xevianlight.aphelion.block.entity.energy.ModEnergyStorage; import net.xevianlight.aphelion.block.entity.energy.ModEnergyStorage;
import net.xevianlight.aphelion.core.init.ModBlockEntities; import net.xevianlight.aphelion.core.init.ModBlockEntities;
import net.xevianlight.aphelion.core.init.ModBlocks; import net.xevianlight.aphelion.core.init.ModBlocks;
import net.xevianlight.aphelion.recipe.ElectricArcFurnaceRecipe; import net.xevianlight.aphelion.recipe.ElectricArcFurnaceRecipe;
import net.xevianlight.aphelion.recipe.ElectricArcFurnaceRecipeInput; import net.xevianlight.aphelion.recipe.ElectricArcFurnaceRecipeInput;
import net.xevianlight.aphelion.recipe.ModRecipes; import net.xevianlight.aphelion.recipe.ModRecipes;
import net.xevianlight.aphelion.screen.VacuumArcFurnaceMenu;
import net.xevianlight.aphelion.screen.ElectricArcFurnaceMenu; import net.xevianlight.aphelion.screen.ElectricArcFurnaceMenu;
import net.xevianlight.aphelion.util.AphelionBlockStateProperties; import net.xevianlight.aphelion.util.AphelionBlockStateProperties;
import net.xevianlight.aphelion.util.IMultiblockController; import net.xevianlight.aphelion.util.IMultiblockController;
@@ -45,16 +47,16 @@ import org.jetbrains.annotations.Nullable;
import java.util.Optional; import java.util.Optional;
public class VacuumArcFurnaceControllerEntity extends BlockEntity implements MenuProvider, IMultiblockController { public class VacuumArcFurnaceControllerEntity extends BlockEntity implements MenuProvider, IMultiblockController, TickableBlockEntity {
private final int SIZE = 4; private final int SIZE = 4;
private int ENERGY_CAPACITY = 64000; private final int ENERGY_CAPACITY = 64000;
private int MAX_TRANSFER = 320; private final int MAX_TRANSFER = 320;
private int progress = 0; private int progress = 0;
private int maxProgress = 100; private int maxProgress = 100;
private final int DEFAULT_MAX_PROGRESS = 100; private final int DEFAULT_MAX_PROGRESS = 100;
private final ContainerData data; private final ContainerData data;
private int MACHINE_ENERGY_COST = 20; private final int MACHINE_ENERGY_COST = 20;
public static final int INPUT_SLOT = 0; public static final int INPUT_SLOT = 0;
public static final int SECONDARY_INPUT_SLOT = 1; public static final int SECONDARY_INPUT_SLOT = 1;
@@ -99,7 +101,7 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
@Override @Override
protected void onContentsChanged(int slot) { protected void onContentsChanged(int slot) {
setChanged(); setChanged();
if(!level.isClientSide()) { if (level != null && !level.isClientSide()) {
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3); level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3);
} }
} }
@@ -114,7 +116,8 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
// } // }
}; };
public void tick(Level level, BlockPos pos, BlockState blockState) { @Override
public void serverTick(ServerLevel level, long time, BlockState state, BlockPos pos) {
if (dirty) { if (dirty) {
dirty = false; dirty = false;
@@ -124,7 +127,7 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
BlockState newBlockState = level.getBlockState(pos); BlockState newBlockState = level.getBlockState(pos);
if (!blockState.getValue(AphelionBlockStateProperties.FORMED)) if (!state.getValue(AphelionBlockStateProperties.FORMED))
return; return;
chargeFromItem(); chargeFromItem();
@@ -135,7 +138,7 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
// Recipe detected! We have enough energy to process // Recipe detected! We have enough energy to process
progress++; progress++;
useEnergy(); useEnergy();
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, true)); level.setBlockAndUpdate(pos, newBlockState.setValue(VacuumArcFurnaceController.LIT, true));
setChanged(level, pos, newBlockState); setChanged(level, pos, newBlockState);
if (hasCraftingFinished()) { if (hasCraftingFinished()) {
@@ -144,13 +147,13 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
} }
} else if (hasFurnaceRecipe(INPUT_SLOT) && !hasEnoughEnergyToCraft(MACHINE_ENERGY_COST)) { } else if (hasFurnaceRecipe(INPUT_SLOT) && !hasEnoughEnergyToCraft(MACHINE_ENERGY_COST)) {
// Recipe detected but we ran out of power // Recipe detected but we ran out of power
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, false)); level.setBlockAndUpdate(pos, newBlockState.setValue(VacuumArcFurnaceController.LIT, false));
setChanged(level, pos, newBlockState); setChanged(level, pos, newBlockState);
progress = progress > 0 ? progress - 1 : 0; progress = progress > 0 ? progress - 1 : 0;
} else { } else {
// Invalid recipe // Invalid recipe
resetProgress(); resetProgress();
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, false)); level.setBlockAndUpdate(pos, newBlockState.setValue(VacuumArcFurnaceController.LIT, false));
setChanged(level, pos, newBlockState); setChanged(level, pos, newBlockState);
} }
} else { } else {
@@ -160,7 +163,7 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
// Alloy recipe detected! We have enough energy to process // Alloy recipe detected! We have enough energy to process
progress++; progress++;
useEnergy(); useEnergy();
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, true)); level.setBlockAndUpdate(pos, newBlockState.setValue(VacuumArcFurnaceController.LIT, true));
setChanged(level, pos, newBlockState); setChanged(level, pos, newBlockState);
if (hasCraftingFinished()) { if (hasCraftingFinished()) {
@@ -169,14 +172,14 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
} }
} else { } else {
// Recipe detected but we ran out of power // Recipe detected but we ran out of power
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, false)); level.setBlockAndUpdate(pos, newBlockState.setValue(VacuumArcFurnaceController.LIT, false));
setChanged(level, pos, newBlockState); setChanged(level, pos, newBlockState);
progress = progress > 0 ? progress - 1 : 0; progress = progress > 0 ? progress - 1 : 0;
} }
} else { } else {
// Invalid recipe // Invalid recipe
resetProgress(); resetProgress();
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, false)); level.setBlockAndUpdate(pos, newBlockState.setValue(VacuumArcFurnaceController.LIT, false));
setChanged(level, pos, newBlockState); setChanged(level, pos, newBlockState);
} }
} }
@@ -411,7 +414,7 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
@Override @Override
public @Nullable AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) { public @Nullable AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
if (isFormed()) if (isFormed())
return new VacuumArcFurnaceMenu(i, inventory, this, this.data); return new ElectricArcFurnaceMenu(i, inventory, this, this.data);
return new ElectricArcFurnaceMenu(i, inventory, this, this.data); return new ElectricArcFurnaceMenu(i, inventory, this, this.data);
} }
@@ -527,4 +530,14 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
public void markDirty() { public void markDirty() {
dirty = true; dirty = true;
} }
@Override
public void clientTick(ClientLevel level, long time, BlockState state, BlockPos pos) {
}
@Override
public void firstTick(Level level, BlockState state, BlockPos pos) {
}
} }

View File

@@ -0,0 +1,44 @@
package net.xevianlight.aphelion.block.entity.custom.renderer;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.AABB;
import net.xevianlight.aphelion.block.entity.custom.RocketAssemblerBlockEntity;
import org.jetbrains.annotations.NotNull;
public class RocketAssemblerBlockEntityRenderer implements BlockEntityRenderer<RocketAssemblerBlockEntity> {
public RocketAssemblerBlockEntityRenderer (BlockEntityRendererProvider.Context context) {
}
@Override
public void render(@NotNull RocketAssemblerBlockEntity be, float v, @NotNull PoseStack poseStack, @NotNull MultiBufferSource multiBufferSource, int i, int i1) {
if (!Minecraft.getInstance().gui.getDebugOverlay().showDebugScreen()) return;
if (be.getPadBounds() == null) return;
BlockPos min = be.getPadBounds().min();
BlockPos max = be.getPadBounds().max();
AABB box = new AABB(
min.getX(), min.getY(), min.getZ(),
max.getX() + 1, max.getY() + 1, max.getZ() + 1
);
poseStack.pushPose();
poseStack.translate(-be.getBlockPos().getX(), -be.getBlockPos().getY(), -be.getBlockPos().getZ());
VertexConsumer vc = multiBufferSource.getBuffer(RenderType.lines());
LevelRenderer.renderLineBox(poseStack, vc, box, 0.0f, 1.0f, 0.0f, 1.0f);
poseStack.popPose();
}
}

View File

@@ -51,4 +51,9 @@ public class ModBlockEntities {
BLOCK_ENTITIES.register("rocket_assembler_block_entity", () -> BlockEntityType.Builder.of( BLOCK_ENTITIES.register("rocket_assembler_block_entity", () -> BlockEntityType.Builder.of(
RocketAssemblerBlockEntity::new, ModBlocks.ROCKET_ASSEMBLER_BLOCK.get()).build(null) RocketAssemblerBlockEntity::new, ModBlocks.ROCKET_ASSEMBLER_BLOCK.get()).build(null)
); );
public static final Supplier<BlockEntityType<PipeTestBlockEntity>> PIPE_TEST_BLOCK_ENTITY =
BLOCK_ENTITIES.register("pipe_test_block_entity", () -> BlockEntityType.Builder.of(
PipeTestBlockEntity::new, ModBlocks.PIPE_TEST_BLOCK.get()).build(null)
);
} }

View File

@@ -19,5 +19,6 @@ public class ModBlocks {
public static final DeferredBlock<Block> VACUUM_ARC_FURNACE_CONTROLLER = BLOCKS.register("vacuum_arc_furnace_controller", () -> new VacuumArcFurnaceController(VacuumArcFurnaceController.getProperties())); public static final DeferredBlock<Block> VACUUM_ARC_FURNACE_CONTROLLER = BLOCKS.register("vacuum_arc_furnace_controller", () -> new VacuumArcFurnaceController(VacuumArcFurnaceController.getProperties()));
public static final DeferredBlock<Block> VAF_MULTIBLOCK_DUMMY_BLOCK = BLOCKS.register("vaf_dummy_block", () -> new VAFMultiblockDummyBlock(VAFMultiblockDummyBlock.getProperties())); public static final DeferredBlock<Block> VAF_MULTIBLOCK_DUMMY_BLOCK = BLOCKS.register("vaf_dummy_block", () -> new VAFMultiblockDummyBlock(VAFMultiblockDummyBlock.getProperties()));
public static final DeferredBlock<Block> OXYGEN_TEST_BLOCK = BLOCKS.register("oxygen_test_block", () -> new OxygenTestBlock(OxygenTestBlock.getProperties())); public static final DeferredBlock<Block> OXYGEN_TEST_BLOCK = BLOCKS.register("oxygen_test_block", () -> new OxygenTestBlock(OxygenTestBlock.getProperties()));
public static final DeferredBlock<Block> ROCKET_ASSEMBLER_BLOCK = BLOCKS.register("rocket_assemblerblock", () -> new RocketAssemblerBlock(RocketAssemblerBlock.getProperties())); public static final DeferredBlock<Block> ROCKET_ASSEMBLER_BLOCK = BLOCKS.register("rocket_assembler_block", () -> new RocketAssemblerBlock(RocketAssemblerBlock.getProperties()));
public static final DeferredBlock<Block> PIPE_TEST_BLOCK = BLOCKS.register("pipe", () -> new PipeTestBlock(PipeTestBlock.getProperties()));
} }

View File

@@ -42,5 +42,6 @@ public class ModCreativeTabs {
output.accept(ModItems.ARC_FURNACE_CASING_BLOCK); output.accept(ModItems.ARC_FURNACE_CASING_BLOCK);
output.accept(ModItems.VACUUM_ARC_FURNACE_CONTROLLER); output.accept(ModItems.VACUUM_ARC_FURNACE_CONTROLLER);
output.accept(ModItems.LAUNCH_PAD); output.accept(ModItems.LAUNCH_PAD);
output.accept(ModItems.ROCKET_ASSEMBLER_BLOCK);
}).build()); }).build());
} }

View File

@@ -36,6 +36,8 @@ public static final DeferredItem<Item> MUSIC_DISC_BIT_SHIFT = ITEMS.register("mu
public static final DeferredItem<BlockItem> ARC_FURNACE_CASING_BLOCK = ITEMS.register("arc_furnace_casing", () -> new BlockItem(ModBlocks.ARC_FURNACE_CASING_BLOCK.get(), ArcFurnaceCasingBlock.getItemProperties())); public static final DeferredItem<BlockItem> ARC_FURNACE_CASING_BLOCK = ITEMS.register("arc_furnace_casing", () -> new BlockItem(ModBlocks.ARC_FURNACE_CASING_BLOCK.get(), ArcFurnaceCasingBlock.getItemProperties()));
public static final DeferredItem<BlockItem> VACUUM_ARC_FURNACE_CONTROLLER = ITEMS.register("vacuum_arc_furnace_controller", () -> new BlockItem(ModBlocks.VACUUM_ARC_FURNACE_CONTROLLER.get(), VacuumArcFurnaceController.getItemProperties())); public static final DeferredItem<BlockItem> VACUUM_ARC_FURNACE_CONTROLLER = ITEMS.register("vacuum_arc_furnace_controller", () -> new BlockItem(ModBlocks.VACUUM_ARC_FURNACE_CONTROLLER.get(), VacuumArcFurnaceController.getItemProperties()));
public static final DeferredItem<BlockItem> OXYGEN_TEST_BLOCK = ITEMS.register("oxygen_test_block", () -> new BlockItem(ModBlocks.OXYGEN_TEST_BLOCK.get(), new Item.Properties())); public static final DeferredItem<BlockItem> OXYGEN_TEST_BLOCK = ITEMS.register("oxygen_test_block", () -> new BlockItem(ModBlocks.OXYGEN_TEST_BLOCK.get(), new Item.Properties()));
public static final DeferredItem<BlockItem> PIPE_TEST_BLOCK = ITEMS.register("pipe", () -> new BlockItem(ModBlocks.PIPE_TEST_BLOCK.get(), new Item.Properties()));
public static final DeferredItem<BlockItem> LAUNCH_PAD = ITEMS.register("launch_pad", () -> new BlockItem(ModBlocks.LAUNCH_PAD.get(), LaunchPad.getItemProperties())); public static final DeferredItem<BlockItem> LAUNCH_PAD = ITEMS.register("launch_pad", () -> new BlockItem(ModBlocks.LAUNCH_PAD.get(), LaunchPad.getItemProperties()));
public static final DeferredItem<BlockItem> ROCKET_ASSEMBLER_BLOCK = ITEMS.register("rocket_assembler_block", () -> new BlockItem(ModBlocks.ROCKET_ASSEMBLER_BLOCK.get(), RocketAssemblerBlock.getItemProperties()));
// public static final DeferredItem<BlockItem> VAF_MULTIBLOCK_DUMMY_BLOCK = ITEMS.register("vaf_multiblock_dummy_block", () -> new BlockItem(ModBlocks.VAF_MULTIBLOCK_DUMMY_BLOCK.get(), VAFMultiblockDummyBlock.getItemProperties())); // public static final DeferredItem<BlockItem> VAF_MULTIBLOCK_DUMMY_BLOCK = ITEMS.register("vaf_multiblock_dummy_block", () -> new BlockItem(ModBlocks.VAF_MULTIBLOCK_DUMMY_BLOCK.get(), VAFMultiblockDummyBlock.getItemProperties()));
} }

View File

@@ -103,9 +103,8 @@ public class EnvironmentSavedData extends SavedData {
public void setOxygen(Level level, BlockPos pos, boolean value) { public void setOxygen(Level level, BlockPos pos, boolean value) {
var data = getDataForPosition(level, pos); var data = getDataForPosition(level, pos);
data.setOxygen(value);
// Aphelion.LOGGER.info("Set oxygen for {} to {}", pos, value); // Aphelion.LOGGER.info("Set oxygen for {} to {}", pos, value);
putOrRemove(level, pos.asLong(), data.pack()); putOrRemove(level, pos.asLong(), data.withOxygen(value).pack());
} }
public void setOxygen(Level level, Collection<BlockPos> positions, boolean value) { public void setOxygen(Level level, Collection<BlockPos> positions, boolean value) {
@@ -116,8 +115,7 @@ public class EnvironmentSavedData extends SavedData {
public void resetOxygen(Level level, BlockPos pos) { public void resetOxygen(Level level, BlockPos pos) {
var data = getDataForPosition(level, pos); var data = getDataForPosition(level, pos);
data.setOxygen(defaultData(level).hasOxygen()); putOrRemove(level, pos.asLong(), data.withOxygen(defaultData(level).hasOxygen()).pack());
putOrRemove(level, pos.asLong(), data.pack());
} }
public void resetOxygen(Level level, Collection<BlockPos> positions) { public void resetOxygen(Level level, Collection<BlockPos> positions) {
@@ -133,8 +131,7 @@ public class EnvironmentSavedData extends SavedData {
public void setGravity(Level level, BlockPos pos, float value) { public void setGravity(Level level, BlockPos pos, float value) {
var data = getDataForPosition(level, pos); var data = getDataForPosition(level, pos);
data.setGravity(value); putOrRemove(level, pos.asLong(), data.withGravity(value).pack());
putOrRemove(level, pos.asLong(), data.pack());
} }
public void setGravity(Level level, Collection<BlockPos> positions, float value) { public void setGravity(Level level, Collection<BlockPos> positions, float value) {
@@ -145,8 +142,7 @@ public class EnvironmentSavedData extends SavedData {
public void resetGravity(Level level, BlockPos pos) { public void resetGravity(Level level, BlockPos pos) {
var data = getDataForPosition(level, pos); var data = getDataForPosition(level, pos);
data.setGravity(defaultData(level).getGravity()); putOrRemove(level, pos.asLong(), data.withGravity(defaultData(level).getGravity()).pack());
putOrRemove(level, pos.asLong(), data.pack());
} }
public short getTemperature(Level level, BlockPos pos) { public short getTemperature(Level level, BlockPos pos) {
@@ -156,8 +152,7 @@ public class EnvironmentSavedData extends SavedData {
public void setTemperature(Level level, BlockPos pos, short value) { public void setTemperature(Level level, BlockPos pos, short value) {
var data = getDataForPosition(level, pos); var data = getDataForPosition(level, pos);
data.setTemperature(value); putOrRemove(level, pos.asLong(), data.withTemperature(value).pack());
putOrRemove(level, pos.asLong(), data.pack());
} }
public void setTemperature(Level level, Collection<BlockPos> positions, short value) { public void setTemperature(Level level, Collection<BlockPos> positions, short value) {
@@ -168,8 +163,7 @@ public class EnvironmentSavedData extends SavedData {
public void resetTemperature(Level level, BlockPos pos) { public void resetTemperature(Level level, BlockPos pos) {
var data = getDataForPosition(level, pos); var data = getDataForPosition(level, pos);
data.setTemperature(defaultData(level).getTemperature()); putOrRemove(level, pos.asLong(), data.withTemperature((defaultData(level).getTemperature())).pack());
putOrRemove(level, pos.asLong(), data.pack());
} }
private void putOrRemove(Level level, long key, int packed) { private void putOrRemove(Level level, long key, int packed) {

View File

@@ -1,8 +1,6 @@
package net.xevianlight.aphelion.core.saveddata; package net.xevianlight.aphelion.core.saveddata;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@@ -10,8 +8,6 @@ import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.saveddata.SavedData; import net.minecraft.world.level.saveddata.SavedData;
import net.xevianlight.aphelion.client.ClientOxygenCache;
import net.xevianlight.aphelion.core.saveddata.types.EnvironmentData;
import net.xevianlight.aphelion.core.saveddata.types.GravityData; import net.xevianlight.aphelion.core.saveddata.types.GravityData;
import net.xevianlight.aphelion.planet.Planet; import net.xevianlight.aphelion.planet.Planet;
import net.xevianlight.aphelion.planet.PlanetCache; import net.xevianlight.aphelion.planet.PlanetCache;
@@ -19,7 +15,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@@ -105,7 +100,7 @@ public class GravitySavedData extends SavedData {
List<GravityData> regions = getGravityRegions(pos); List<GravityData> regions = getGravityRegions(pos);
for (var e : regions) { for (var e : regions) {
sum += e.getAccel(); sum += e.getGravity();
} }
return sum; return sum;
@@ -120,7 +115,7 @@ public class GravitySavedData extends SavedData {
List<GravityData> regions = getGravityRegions(pos); List<GravityData> regions = getGravityRegions(pos);
for (var e : regions) { for (var e : regions) {
var accel = e.getAccel(); var accel = e.getGravity();
if (accel > max) max = accel; if (accel > max) max = accel;
} }

View File

@@ -1,6 +1,6 @@
package net.xevianlight.aphelion.core.saveddata.types; package net.xevianlight.aphelion.core.saveddata.types;
public final class EnvironmentData { public record EnvironmentData (boolean oxygen, short temperature, float gravity){
@@ -26,9 +26,6 @@ public final class EnvironmentData {
private static final int TEMPERATURE_BIT = OXYGEN_BIT + OXYGEN_BITS; // next 16 bits private static final int TEMPERATURE_BIT = OXYGEN_BIT + OXYGEN_BITS; // next 16 bits
private static final int GRAVITY_BIT = TEMPERATURE_BIT + TEMPERATURE_BITS; // next 15 bits private static final int GRAVITY_BIT = TEMPERATURE_BIT + TEMPERATURE_BITS; // next 15 bits
private boolean oxygen;
private short temperature;
private float gravity;
public EnvironmentData(boolean oxygen, short temperature, float gravity) { public EnvironmentData(boolean oxygen, short temperature, float gravity) {
this.oxygen = oxygen; this.oxygen = oxygen;
@@ -36,6 +33,19 @@ public final class EnvironmentData {
this.gravity = gravity; this.gravity = gravity;
} }
public EnvironmentData withOxygen(boolean newOxygen) {
return new EnvironmentData(newOxygen, this.temperature, this.gravity);
}
public EnvironmentData withTemperature(short newTemperature) {
return new EnvironmentData(this.oxygen, newTemperature, this.gravity);
}
@Deprecated
public EnvironmentData withGravity(float newGravity) {
return new EnvironmentData(this.oxygen, this.temperature, newGravity);
}
public int pack() { public int pack() {
int packedData = 0; int packedData = 0;
@@ -76,23 +86,12 @@ public final class EnvironmentData {
return oxygen; return oxygen;
} }
public void setOxygen(boolean oxygen) {
this.oxygen = oxygen;
}
public short getTemperature() { public short getTemperature() {
return temperature; return temperature;
} }
public void setTemperature(short temperature) {
this.temperature = temperature;
}
public float getGravity() { public float getGravity() {
return gravity; return gravity;
} }
public void setGravity(float gravity) {
this.gravity = gravity;
}
} }

View File

@@ -1,49 +1,39 @@
package net.xevianlight.aphelion.core.saveddata.types; package net.xevianlight.aphelion.core.saveddata.types;
public class GravityData { // A record seems more useful here since this class is really only to help us interpret these values as they are written to the disk as an integer.
private float accel; // We never store GravityData for any reason other than to test its values or to pack it into an integer.
private float radius; public record GravityData (float gravity, float radius) {
public static final float DEFAULT_GRAVITY = 9.80665f; // 1G public static final float DEFAULT_GRAVITY = 32.00f; // Vanilla acceleration
public static final float GRAVITY_PRECISION = 100.0f; public static final float GRAVITY_PRECISION = 100.0f;
public static final float RADIUS_PRECISION = 100.0f; public static final float RADIUS_PRECISION = 100.0f;
public static final float MAX_RADIUS = Short.MAX_VALUE / RADIUS_PRECISION; public static final float MAX_RADIUS = Short.MAX_VALUE / RADIUS_PRECISION;
public static final float MAX_GRAVITY = Short.MAX_VALUE / GRAVITY_PRECISION; public static final float MAX_GRAVITY = Short.MAX_VALUE / GRAVITY_PRECISION;
public GravityData(float accel, float radius) { public GravityData {
this.accel = accel; gravity = Math.clamp(gravity, 0f, MAX_GRAVITY);
this.radius = radius; radius = Math.clamp(radius, 0f, MAX_RADIUS);
} }
public int pack() { public int pack() {
int packed = 0; int g = Math.round(gravity * GRAVITY_PRECISION) & 0xFFFF;
int r = Math.round(radius * RADIUS_PRECISION) & 0xFFFF;
packed |= (int) (this.accel * GRAVITY_PRECISION); return g | (r << 16);
packed |= (int) (this.radius * RADIUS_PRECISION) << 16;
return packed;
} }
public float getAccel() { public float getGravity() {
return accel; return gravity;
}
public void setAccel(float accel) {
this.accel = accel;
} }
public float getRadius() { public float getRadius() {
return radius; return radius;
} }
public void setRadius(short radius) {
this.radius = radius;
}
public static GravityData unpack(int packed) { public static GravityData unpack(int packed) {
float accel = (packed & 0xFFFF) / GRAVITY_PRECISION; float gravity = (packed & 0xFFFF) / GRAVITY_PRECISION;
float radius = (packed >> 16) / RADIUS_PRECISION; float radius = ((packed >>> 16) & 0xFFFF) / RADIUS_PRECISION;
return new GravityData(accel, radius); return new GravityData(gravity, radius);
} }
} }

View File

@@ -26,6 +26,7 @@ public class ModBlockLootTableProvider extends BlockLootSubProvider {
dropSelf(ModBlocks.OXYGEN_TEST_BLOCK.get()); dropSelf(ModBlocks.OXYGEN_TEST_BLOCK.get());
dropOther(ModBlocks.VAF_MULTIBLOCK_DUMMY_BLOCK.get(), ItemStack.EMPTY.getItem()); dropOther(ModBlocks.VAF_MULTIBLOCK_DUMMY_BLOCK.get(), ItemStack.EMPTY.getItem());
dropSelf(ModBlocks.LAUNCH_PAD.get()); dropSelf(ModBlocks.LAUNCH_PAD.get());
dropSelf(ModBlocks.ROCKET_ASSEMBLER_BLOCK.get());
} }
@Override @Override

View File

@@ -25,6 +25,12 @@ public class ModBlockStateProvider extends BlockStateProvider {
blockItem(ModBlocks.ELECTRIC_ARC_FURNACE); blockItem(ModBlocks.ELECTRIC_ARC_FURNACE);
blockItem(ModBlocks.VACUUM_ARC_FURNACE_CONTROLLER); blockItem(ModBlocks.VACUUM_ARC_FURNACE_CONTROLLER);
// horizontalBlock(ModBlocks.ROCKET_ASSEMBLER_BLOCK.get(), models().orientable("aphelion:rocket_assembler_block",
// modLoc("block/test_block"),
// mcLoc("block/furnace_front"),
// modLoc("block/test_block")));
blockItem(ModBlocks.ROCKET_ASSEMBLER_BLOCK);
blockWithItem(ModBlocks.BLOCK_STEEL); blockWithItem(ModBlocks.BLOCK_STEEL);
blockWithItem(ModBlocks.DIMENSION_CHANGER); blockWithItem(ModBlocks.DIMENSION_CHANGER);

View File

@@ -0,0 +1,61 @@
package net.xevianlight.aphelion.systems.conveyor;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.capabilities.BlockCapabilityCache;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandler;
import net.xevianlight.aphelion.block.entity.custom.PipeTestBlockEntity;
import org.jetbrains.annotations.Nullable;
public class BasicItemExtractAttachment extends ConveyorAttachment implements ConveyorInput {
BlockCapabilityCache<IItemHandler, @Nullable Direction> capabilityCache;
public BasicItemExtractAttachment(ServerLevel level, BlockPos pos, Direction facingDirection) {
super(level, pos, facingDirection);
capabilityCache = BlockCapabilityCache.create(
Capabilities.ItemHandler.BLOCK,
level,
pos.relative(facingDirection),
facingDirection.getOpposite()
);
}
@Override
public void render() {
}
@Override
public void tick(ServerLevel level, BlockState state, BlockPos pos, Direction facingDirection, ConveyorNetwork network) {
// do an extract and distribute
IItemHandler container = capabilityCache.getCapability();
if (container == null) return;
final int EXTRACT_PER_TICK = 4;
int to_extract = EXTRACT_PER_TICK;
int extract_slot_id = container.getSlots() - 1;
while (extract_slot_id >= 0 && container.getStackInSlot(extract_slot_id).isEmpty()) extract_slot_id--;
if (extract_slot_id == -1) return;
// Do a simulated extract, then run through every output side on the graph and do real inserts.
// By the end, remove as many items as we successfully inserted with a real extract
ItemStack to_distribute = container.extractItem(extract_slot_id, to_extract, true);
int extracted_amount = to_distribute.getCount();
to_distribute = network.insertItem(to_distribute, false);
int distributed_amount = extracted_amount;
if (!to_distribute.isEmpty()) {
distributed_amount = extracted_amount - to_distribute.getCount();
}
container.extractItem(extract_slot_id, distributed_amount, false);
}
}

View File

@@ -0,0 +1,39 @@
package net.xevianlight.aphelion.systems.conveyor;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.capabilities.BlockCapabilityCache;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandler;
import org.jetbrains.annotations.Nullable;
public class BasicItemOutput implements ConveyorOutput {
BlockCapabilityCache<IItemHandler, @Nullable Direction> capabilityCache;
public BasicItemOutput(ServerLevel level, BlockPos pos, Direction facingDirection) {
capabilityCache = BlockCapabilityCache.create(
Capabilities.ItemHandler.BLOCK,
level,
pos.relative(facingDirection),
facingDirection.getOpposite()
);
}
@Override
public ItemStack insertItem(ItemStack stack, boolean simulate) {
ItemStack toInsert = stack.copy();
IItemHandler container = capabilityCache.getCapability();
if (container == null) return toInsert;
for (int insertIndex = 0; insertIndex < container.getSlots(); insertIndex++) {
if (toInsert.isEmpty()) break;
toInsert = container.insertItem(insertIndex, toInsert, simulate);
}
return toInsert;
}
}

View File

@@ -0,0 +1,16 @@
package net.xevianlight.aphelion.systems.conveyor;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.state.BlockState;
import net.xevianlight.aphelion.block.entity.custom.PipeTestBlockEntity;
public class ConveyorAttachment {
ConveyorAttachment(ServerLevel level, BlockPos pos, Direction facingDirection) {}
//TODO: put in the right interface for a render function
void render() {};
public void tick(ServerLevel level, BlockState state, BlockPos pos, Direction facingDirection, ConveyorNetwork network) {}
}

View File

@@ -0,0 +1,10 @@
package net.xevianlight.aphelion.systems.conveyor;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.state.BlockState;
public interface ConveyorInput {
void tick(ServerLevel level, BlockState state, BlockPos pos, Direction facingDirection, ConveyorNetwork graph);
}

View File

@@ -0,0 +1,46 @@
package net.xevianlight.aphelion.systems.conveyor;
import net.minecraft.world.item.ItemStack;
import net.xevianlight.aphelion.block.entity.custom.PipeTestBlockEntity;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
// I'm naming and structuring the conveyor stuff like this bc i kinda wanna try making a space-engineers
// style request system later... though it might not be necessary, given that the reason it needs to be like that
// in space engineers is mostly space constraints if i had to guess
public class ConveyorNetwork {
boolean isInvalid = false;
public List<PipeTestBlockEntity> pipes = new ArrayList<>();
public Set<ConveyorOutput> outputs = new HashSet<>();
public ItemStack insertItem(ItemStack stack, boolean simulate) {
if (isInvalid) return stack;
for (ConveyorOutput output : outputs) {
stack = output.insertItem(stack, simulate);
if (stack.isEmpty()) break;
}
return stack;
}
public void addPipe(PipeTestBlockEntity pipe) {
pipes.add(pipe);
pipe.graph = this;
for (ConveyorOutput output : pipe.outputs.values()) {
if (output != null) this.outputs.add(output);
}
}
/// Called whenever a pipe is removed from a graph, or when a new graph comes across an old one.
public void invalidate() {
for (PipeTestBlockEntity pipe : pipes) {
pipe.graph = null;
for (ConveyorOutput output : pipe.outputs.values()) {
if (output != null) this.outputs.remove(output);
}
}
this.isInvalid = true;
}
}

View File

@@ -0,0 +1,8 @@
package net.xevianlight.aphelion.systems.conveyor;
import net.minecraft.world.item.ItemStack;
public interface ConveyorOutput {
/// @return Rejected items
ItemStack insertItem(ItemStack stack, boolean simulate);
}

View File

@@ -0,0 +1,11 @@
{
"multipart": [
{ "apply": { "model": "aphelion:block/pipe_core" }},
{ "when": { "north": "true" }, "apply": { "model": "aphelion:block/pipe_side" }},
{ "when": { "east": "true" }, "apply": { "model": "aphelion:block/pipe_side", "y": 90 }},
{ "when": { "south": "true" }, "apply": { "model": "aphelion:block/pipe_side", "y": 180 }},
{ "when": { "west": "true" }, "apply": { "model": "aphelion:block/pipe_side", "y": 270 }},
{ "when": { "up": "true" }, "apply": { "model": "aphelion:block/pipe_side", "x": 270 }},
{ "when": { "down": "true" }, "apply": { "model": "aphelion:block/pipe_side", "x": 90 }}
]
}

View File

@@ -0,0 +1,34 @@
{
"variants": {
"facing=east,formed=false": {
"model": "aphelion:block/rocket_assembler_block",
"y": 90
},
"facing=north,formed=false": {
"model": "aphelion:block/rocket_assembler_block"
},
"facing=south,formed=false": {
"model": "aphelion:block/rocket_assembler_block",
"y": 180
},
"facing=west,formed=false": {
"model": "aphelion:block/rocket_assembler_block",
"y": 270
},
"facing=east,formed=true": {
"model": "aphelion:block/rocket_assembler_block_formed",
"y": 90
},
"facing=north,formed=true": {
"model": "aphelion:block/rocket_assembler_block_formed"
},
"facing=south,formed=true": {
"model": "aphelion:block/rocket_assembler_block_formed",
"y": 180
},
"facing=west,formed=true": {
"model": "aphelion:block/rocket_assembler_block_formed",
"y": 270
}
}
}

View File

@@ -0,0 +1,20 @@
{
"ambientocclusion": false,
"textures": {
"texture": "aphelion:block/pipe_texture"
},
"elements": [
{
"from": [ 6, 6, 6 ],
"to": [ 10, 10, 10 ],
"faces": {
"down": { "texture": "#texture", "uv": [ 6, 6, 10, 10 ] },
"up": { "texture": "#texture", "uv": [ 6, 6, 10, 10 ] },
"north": { "texture": "#texture", "uv": [ 6, 6, 10, 10 ] },
"south": { "texture": "#texture", "uv": [ 6, 6, 10, 10 ] },
"west": { "texture": "#texture", "uv": [ 6, 6, 10, 10 ] },
"east": { "texture": "#texture", "uv": [ 6, 6, 10, 10 ] }
}
}
]
}

View File

@@ -0,0 +1,18 @@
{
"textures": {
"texture": "aphelion:block/pipe_texture"
},
"elements": [
{
"from": [ 6, 6, 0 ],
"to": [ 10, 10, 6 ],
"faces": {
"down": { "texture": "#texture", "uv": [ 6, 0, 10, 6 ] },
"up": { "texture": "#texture", "uv": [ 6, 0, 10, 6 ] },
"north": { "texture": "#texture", "uv": [ 6, 6, 10, 10 ] },
"west": { "texture": "#texture", "uv": [ 0, 6, 6, 10 ] },
"east": { "texture": "#texture", "uv": [ 0, 6, 6, 10 ] }
}
}
]
}

View File

@@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"front": "minecraft:block/furnace_front",
"side": "aphelion:block/test_block",
"top": "aphelion:block/test_block"
}
}

View File

@@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"front": "minecraft:block/furnace_front",
"side": "aphelion:block/arc_furnace_casing_formed",
"top": "aphelion:block/arc_furnace_casing_formed"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B

1
test.txt Normal file
View File

@@ -0,0 +1 @@
hello world!