Skip to content

Commit 35d205d

Browse files
committed
Add slim version of Cryptographic Accelerator (data incomplete)
1 parent e34a34d commit 35d205d

29 files changed

Lines changed: 398 additions & 28 deletions

common/src/main/java/me/alexdevs/classicPeripherals/ModRegistry.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import dan200.computercraft.api.ComputerCraftAPI;
55
import dan200.computercraft.api.component.ComputerComponents;
66
import dan200.computercraft.api.upgrades.UpgradeType;
7+
import me.alexdevs.classicPeripherals.peripherals.crypto.slim.CryptographicAcceleratorSlimBlock;
8+
import me.alexdevs.classicPeripherals.peripherals.crypto.slim.CryptographicAcceleratorSlimBlockEntity;
79
import me.alexdevs.classicPeripherals.platform.*;
8-
import me.alexdevs.classicPeripherals.peripherals.crypto.CryptographicAcceleratorBlock;
9-
import me.alexdevs.classicPeripherals.peripherals.crypto.CryptographicAcceleratorBlockEntity;
10+
import me.alexdevs.classicPeripherals.peripherals.crypto.full.CryptographicAcceleratorBlock;
11+
import me.alexdevs.classicPeripherals.peripherals.crypto.full.CryptographicAcceleratorBlockEntity;
1012
import me.alexdevs.classicPeripherals.peripherals.nfc.NfcReaderBlock;
1113
import me.alexdevs.classicPeripherals.peripherals.radio.antenna.RadioAntennaBlockEntity;
1214
import me.alexdevs.classicPeripherals.peripherals.radio.tower.RadioTowerControllerBlockEntity;
@@ -114,6 +116,12 @@ public static class Blocks {
114116
.isValidSpawn(Blocks::never)
115117
.isRedstoneConductor(Blocks::never)
116118
));
119+
public static final RegistrySupplier<CryptographicAcceleratorSlimBlock> CRYPTOGRAPHIC_ACCELERATOR_SLIM = register("cryptographic_accelerator_slim", () -> new CryptographicAcceleratorSlimBlock(BlockBehaviour.Properties.of()
120+
.strength(2.0F)
121+
.mapColor(MapColor.STONE)
122+
.isValidSpawn(Blocks::never)
123+
.isRedstoneConductor(Blocks::never)
124+
));
117125
public static final RegistrySupplier<ScannerBlock> SCANNER = register("scanner", () -> new ScannerBlock(BlockBehaviour.Properties.of()
118126
.strength(2.0F)
119127
.mapColor(MapColor.STONE)
@@ -159,14 +167,22 @@ static void initialize() {
159167
public static class TileEntities {
160168
public static final RegistrySupplier<BlockEntityType<RadioTowerControllerBlockEntity>> TOWER_BASE = register("tower_base",
161169
() -> BlockEntityType.Builder.of(RadioTowerControllerBlockEntity::new, Blocks.TOWER_BASE.get()).build(null));
170+
162171
public static final RegistrySupplier<BlockEntityType<RadioAntennaBlockEntity>> ANTENNA = register("antenna",
163172
() -> BlockEntityType.Builder.of(RadioAntennaBlockEntity::new, Blocks.ANTENNA.get()).build(null));
173+
164174
public static final RegistrySupplier<BlockEntityType<NfcReaderBlockEntity>> NFC_READER = register("nfc_reader",
165175
() -> BlockEntityType.Builder.of(NfcReaderBlockEntity::new, Blocks.NFC_READER.get()).build(null));
176+
166177
public static final RegistrySupplier<BlockEntityType<RfidScannerBlockEntity>> RFID_SCANNER = register("rfid_scanner",
167178
() -> BlockEntityType.Builder.of(RfidScannerBlockEntity::new, Blocks.RFID_SCANNER.get()).build(null));
179+
168180
public static final RegistrySupplier<BlockEntityType<CryptographicAcceleratorBlockEntity>> CRYPTOGRAPHIC_ACCELERATOR = register("cryptographic_accelerator",
169181
() -> BlockEntityType.Builder.of(CryptographicAcceleratorBlockEntity::new, Blocks.CRYPTOGRAPHIC_ACCELERATOR.get()).build(null));
182+
183+
public static final RegistrySupplier<BlockEntityType<CryptographicAcceleratorSlimBlockEntity>> CRYPTOGRAPHIC_ACCELERATOR_SLIM = register("cryptographic_accelerator_slim",
184+
() -> BlockEntityType.Builder.of(CryptographicAcceleratorSlimBlockEntity::new, Blocks.CRYPTOGRAPHIC_ACCELERATOR_SLIM.get()).build(null));
185+
170186
public static final RegistrySupplier<BlockEntityType<ScannerBlockEntity>> SCANNER = register("scanner",
171187
() -> BlockEntityType.Builder.of(ScannerBlockEntity::new, Blocks.SCANNER.get()).build(null));
172188

@@ -185,6 +201,7 @@ public static void register(PeripheralRegistrar registrar) {
185201
registrar.register(TileEntities.NFC_READER.get(), (block, dir) -> block.peripheral());
186202
registrar.register(TileEntities.RFID_SCANNER.get(), RfidScannerBlockEntity::peripheral);
187203
registrar.register(TileEntities.CRYPTOGRAPHIC_ACCELERATOR.get(), (block, dir) -> block.peripheral());
204+
registrar.register(TileEntities.CRYPTOGRAPHIC_ACCELERATOR_SLIM.get(), CryptographicAcceleratorSlimBlockEntity::peripheral);
188205
registrar.register(TileEntities.SCANNER.get(), (block, dir) -> block.peripheral());
189206
}
190207
}

common/src/main/java/me/alexdevs/classicPeripherals/datagen/generators/BlockModelProvider.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dan200.computercraft.api.ComputerCraftAPI;
44
import me.alexdevs.classicPeripherals.ClassicPeripherals;
55
import me.alexdevs.classicPeripherals.ModRegistry;
6+
import me.alexdevs.classicPeripherals.peripherals.crypto.slim.CryptographicAcceleratorSlimBlock;
67
import me.alexdevs.classicPeripherals.peripherals.nfc.NfcReaderBlock;
78
import me.alexdevs.classicPeripherals.peripherals.rfid.RfidScannerBlock;
89
import me.alexdevs.classicPeripherals.peripherals.scanner.ScannerBlock;
@@ -46,6 +47,7 @@ public static void addBlockModels(BlockModelGenerators generators) {
4647
createNfcReaderModel(generators, ModRegistry.Blocks.NFC_READER.get());
4748
createRfidScannerModel(generators, ModRegistry.Blocks.RFID_SCANNER.get());
4849
createScannerModel(generators, ModRegistry.Blocks.SCANNER.get());
50+
createCryptographicAcceleratorSmallModel(generators, ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR_SLIM.get());
4951

5052
generators.createHorizontallyRotatedBlock(ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR.get(), TexturedModel.ORIENTABLE);
5153
generators.delegateItemModel(ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR.get(), getModelLocation(ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR.get()));
@@ -89,6 +91,13 @@ private static void createRfidScannerModel(BlockModelGenerators generators, Rfid
8991
generators.delegateItemModel(block, getModelLocation(block));
9092
}
9193

94+
private static void createCryptographicAcceleratorSmallModel(BlockModelGenerators generators, CryptographicAcceleratorSlimBlock block) {
95+
generators.blockStateOutput.accept(MultiVariantGenerator.multiVariant(block)
96+
.with(BlockModelGenerators.createFacingDispatch())
97+
);
98+
generators.delegateItemModel(block, getModelLocation(block));
99+
}
100+
92101
private static void createScannerModel(BlockModelGenerators generators, ScannerBlock block) {
93102
generators.blockStateOutput.accept(MultiVariantGenerator.multiVariant(block)
94103
.with(BlockModelGenerators.createHorizontalFacingDispatch())

common/src/main/java/me/alexdevs/classicPeripherals/datagen/generators/LanguageGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private void addTranslations() {
3737
add(ModRegistry.Items.RFID_BADGE.get(), "RFID Badge");
3838
add(ModRegistry.Blocks.RFID_SCANNER.get(), "RFID Scanner");
3939
add(ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR.get(), "Cryptographic Accelerator");
40+
add(ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR_SLIM.get(), "Cryptographic Accelerator");
4041
add(ModRegistry.Blocks.SCANNER.get(), "Scanner");
4142

4243
add("upgrade.radio.adjective", "Radio");

common/src/main/java/me/alexdevs/classicPeripherals/datagen/generators/LootTableGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void generate(@NonNull BiConsumer<ResourceKey<net.minecraft.world.level.s
3030
dropSelf(output, ModRegistry.Blocks.NFC_READER);
3131
dropSelf(output, ModRegistry.Blocks.RFID_SCANNER);
3232
dropSelf(output, ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR);
33+
dropSelf(output, ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR_SLIM);
3334
dropSelf(output, ModRegistry.Blocks.SCANNER);
3435
}
3536

common/src/main/java/me/alexdevs/classicPeripherals/datagen/generators/RecipeGenerator.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import dan200.computercraft.api.ComputerCraftTags;
44
import dan200.computercraft.shared.ModRegistry;
5+
import me.alexdevs.classicPeripherals.ClassicPeripherals;
56
import me.alexdevs.classicPeripherals.peripherals.nfc.item.NfcCardRecipe;
67
import me.alexdevs.classicPeripherals.peripherals.rfid.item.RfidBadgeRecipe;
78
import net.minecraft.core.HolderLookup;
89
import net.minecraft.data.PackOutput;
910
import net.minecraft.data.recipes.*;
11+
import net.minecraft.resources.ResourceKey;
12+
import net.minecraft.resources.ResourceLocation;
1013
import net.minecraft.tags.ItemTags;
1114
import net.minecraft.world.item.Items;
1215
import org.jspecify.annotations.NonNull;
@@ -137,5 +140,19 @@ public void buildRecipes(@NonNull RecipeOutput output) {
137140
.define('r', Items.REDSTONE)
138141
.unlockedBy("has_observer", has(Items.OBSERVER))
139142
.save(output);
143+
144+
ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, me.alexdevs.classicPeripherals.ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR_SLIM.get())
145+
.requires(me.alexdevs.classicPeripherals.ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR.get())
146+
.unlockedBy("has_crypto_accelerator", has(me.alexdevs.classicPeripherals.ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR.get()))
147+
.save(output, id("crypto_accelerator_full_to_slim"));
148+
149+
ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, me.alexdevs.classicPeripherals.ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR.get())
150+
.requires(me.alexdevs.classicPeripherals.ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR_SLIM.get())
151+
.unlockedBy("has_crypto_accelerator_slim", has(me.alexdevs.classicPeripherals.ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR.get()))
152+
.save(output, id("crypto_accelerator_slim_to_full"));
153+
}
154+
155+
private static ResourceLocation id(String path) {
156+
return ResourceLocation.fromNamespaceAndPath(ClassicPeripherals.MOD_ID, path);
140157
}
141158
}

common/src/main/java/me/alexdevs/classicPeripherals/datagen/generators/TagGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public TagGenerator(PackOutput output, CompletableFuture<HolderLookup.Provider>
2222
protected void addTags(HolderLookup.@NonNull Provider provider) {
2323
tag(BlockTags.MINEABLE_WITH_PICKAXE)
2424
.add(key(ModRegistry.Blocks.TOWER_BASE), key(ModRegistry.Blocks.TOWER_SEGMENT), key(ModRegistry.Blocks.TOWER_HEAD), key(ModRegistry.Blocks.ANTENNA))
25-
.add(key(ModRegistry.Blocks.NFC_READER), key(ModRegistry.Blocks.RFID_SCANNER), key(ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR), key(ModRegistry.Blocks.SCANNER));
25+
.add(key(ModRegistry.Blocks.NFC_READER), key(ModRegistry.Blocks.RFID_SCANNER), key(ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR), key(ModRegistry.Blocks.CRYPTOGRAPHIC_ACCELERATOR_SLIM), key(ModRegistry.Blocks.SCANNER));
2626
}
2727

2828
private static ResourceKey<Block> key(RegistrySupplier<? extends Block> supplier) {

common/src/main/java/me/alexdevs/classicPeripherals/peripherals/crypto/CryptographicAcceleratorBlockEntity.java renamed to common/src/main/java/me/alexdevs/classicPeripherals/peripherals/crypto/AbstractCryptographicAcceleratorBlockEntity.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package me.alexdevs.classicPeripherals.peripherals.crypto;
22

33
import dan200.computercraft.api.peripheral.IPeripheral;
4-
import me.alexdevs.classicPeripherals.ModRegistry;
54
import net.minecraft.core.BlockPos;
65
import net.minecraft.world.level.block.entity.BlockEntity;
6+
import net.minecraft.world.level.block.entity.BlockEntityType;
77
import net.minecraft.world.level.block.state.BlockState;
88
import org.jspecify.annotations.Nullable;
99

10-
public class CryptographicAcceleratorBlockEntity extends BlockEntity {
10+
public abstract class AbstractCryptographicAcceleratorBlockEntity extends BlockEntity {
1111
public static class CryptographicAcceleratorPeripheral extends AbstractCryptographicAcceleratorPeripheral {
12-
private final CryptographicAcceleratorBlockEntity cryptographicAccelerator;
12+
protected final AbstractCryptographicAcceleratorBlockEntity cryptographicAccelerator;
1313

14-
public CryptographicAcceleratorPeripheral(CryptographicAcceleratorBlockEntity blockEntity) {
14+
public CryptographicAcceleratorPeripheral(AbstractCryptographicAcceleratorBlockEntity blockEntity) {
1515
this.cryptographicAccelerator = blockEntity;
1616
}
1717

@@ -21,13 +21,9 @@ public boolean equals(@Nullable IPeripheral other) {
2121
}
2222
}
2323

24-
private final CryptographicAcceleratorPeripheral peripheral = new CryptographicAcceleratorPeripheral(this);
24+
protected final CryptographicAcceleratorPeripheral peripheral = new CryptographicAcceleratorPeripheral(this);
2525

26-
public CryptographicAcceleratorBlockEntity(BlockPos pos, BlockState blockState) {
27-
super(ModRegistry.TileEntities.CRYPTOGRAPHIC_ACCELERATOR.get(), pos, blockState);
28-
}
29-
30-
public AbstractCryptographicAcceleratorPeripheral peripheral() {
31-
return peripheral;
26+
public AbstractCryptographicAcceleratorBlockEntity(BlockEntityType<?> entityType, BlockPos pos, BlockState blockState) {
27+
super(entityType, pos, blockState);
3228
}
3329
}

common/src/main/java/me/alexdevs/classicPeripherals/peripherals/crypto/CryptographicAcceleratorBlock.java renamed to common/src/main/java/me/alexdevs/classicPeripherals/peripherals/crypto/full/CryptographicAcceleratorBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.alexdevs.classicPeripherals.peripherals.crypto;
1+
package me.alexdevs.classicPeripherals.peripherals.crypto.full;
22

33
import com.mojang.serialization.MapCodec;
44
import net.minecraft.core.BlockPos;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package me.alexdevs.classicPeripherals.peripherals.crypto.full;
2+
3+
import me.alexdevs.classicPeripherals.ModRegistry;
4+
import me.alexdevs.classicPeripherals.peripherals.crypto.AbstractCryptographicAcceleratorBlockEntity;
5+
import me.alexdevs.classicPeripherals.peripherals.crypto.AbstractCryptographicAcceleratorPeripheral;
6+
import net.minecraft.core.BlockPos;
7+
import net.minecraft.world.level.block.state.BlockState;
8+
9+
public class CryptographicAcceleratorBlockEntity extends AbstractCryptographicAcceleratorBlockEntity {
10+
public CryptographicAcceleratorBlockEntity(BlockPos pos, BlockState blockState) {
11+
super(ModRegistry.TileEntities.CRYPTOGRAPHIC_ACCELERATOR.get(), pos, blockState);
12+
}
13+
14+
public AbstractCryptographicAcceleratorPeripheral peripheral() {
15+
return peripheral;
16+
}
17+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package me.alexdevs.classicPeripherals.peripherals.crypto.slim;
2+
3+
import com.mojang.serialization.MapCodec;
4+
import dan200.computercraft.shared.peripheral.modem.ModemShapes;
5+
import me.alexdevs.classicPeripherals.peripherals.crypto.full.CryptographicAcceleratorBlockEntity;
6+
import net.minecraft.core.BlockPos;
7+
import net.minecraft.core.Direction;
8+
import net.minecraft.world.item.context.BlockPlaceContext;
9+
import net.minecraft.world.level.BlockGetter;
10+
import net.minecraft.world.level.LevelAccessor;
11+
import net.minecraft.world.level.LevelReader;
12+
import net.minecraft.world.level.block.*;
13+
import net.minecraft.world.level.block.entity.BlockEntity;
14+
import net.minecraft.world.level.block.state.BlockState;
15+
import net.minecraft.world.level.block.state.StateDefinition;
16+
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
17+
import net.minecraft.world.level.block.state.properties.BooleanProperty;
18+
import net.minecraft.world.level.material.FluidState;
19+
import net.minecraft.world.level.material.Fluids;
20+
import net.minecraft.world.phys.shapes.CollisionContext;
21+
import net.minecraft.world.phys.shapes.VoxelShape;
22+
import org.jetbrains.annotations.Nullable;
23+
import org.jspecify.annotations.NonNull;
24+
25+
public class CryptographicAcceleratorSlimBlock extends DirectionalBlock implements EntityBlock, SimpleWaterloggedBlock {
26+
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
27+
28+
public CryptographicAcceleratorSlimBlock(Properties properties) {
29+
super(properties);
30+
31+
registerDefaultState(defaultBlockState()
32+
.setValue(DirectionalBlock.FACING, Direction.NORTH)
33+
.setValue(WATERLOGGED, false)
34+
);
35+
}
36+
37+
@Override
38+
protected @NonNull MapCodec<? extends DirectionalBlock> codec() {
39+
return simpleCodec(CryptographicAcceleratorSlimBlock::new);
40+
}
41+
42+
@Override
43+
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
44+
builder.add(DirectionalBlock.FACING, WATERLOGGED);
45+
}
46+
47+
@Override
48+
public @NonNull VoxelShape getShape(BlockState state, @NonNull BlockGetter level, @NonNull BlockPos pos, @NonNull CollisionContext context) {
49+
return ModemShapes.getBounds(state.getValue(FACING));
50+
}
51+
52+
@Override
53+
public @NonNull BlockState updateShape(BlockState state, @NonNull Direction direction, @NonNull BlockState neighborState, @NonNull LevelAccessor level, @NonNull BlockPos pos, @NonNull BlockPos neighborPos) {
54+
if (state.getValue(WATERLOGGED)) {
55+
level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
56+
}
57+
58+
return super.updateShape(state, direction, neighborState, level, pos, neighborPos);
59+
}
60+
61+
public @NonNull FluidState getFluidState(BlockState state) {
62+
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState();
63+
}
64+
65+
@Override
66+
public boolean canSurvive(BlockState state, @NonNull LevelReader level, BlockPos pos) {
67+
var facing = state.getValue(FACING);
68+
return ModemShapes.canSupport(level, pos.relative(facing), facing.getOpposite());
69+
}
70+
71+
@Override
72+
public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) {
73+
var waterlogged = context.getLevel().getFluidState(context.getClickedPos()).getType() == Fluids.WATER;
74+
return defaultBlockState()
75+
.setValue(FACING, context.getClickedFace().getOpposite())
76+
.setValue(WATERLOGGED, waterlogged);
77+
}
78+
79+
@Override
80+
@Deprecated
81+
public @NonNull BlockState mirror(BlockState state, Mirror mirrorIn) {
82+
return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
83+
}
84+
85+
@Override
86+
@Deprecated
87+
public @NonNull BlockState rotate(BlockState state, Rotation rot) {
88+
return state.setValue(FACING, rot.rotate(state.getValue(FACING)));
89+
}
90+
91+
@Override
92+
public @Nullable BlockEntity newBlockEntity(@NonNull BlockPos pos, @NonNull BlockState state) {
93+
return new CryptographicAcceleratorBlockEntity(pos, state);
94+
}
95+
}

0 commit comments

Comments
 (0)