Skip to content

Commit e66f898

Browse files
committed
Add scan module & pointer block.
1 parent 379b171 commit e66f898

File tree

18 files changed

+149
-1
lines changed

18 files changed

+149
-1
lines changed

src/main/java/net/automotons/AutomotonsRegistry.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.automotons.blocks.AutomotonBlock;
44
import net.automotons.blocks.AutomotonBlockEntity;
5+
import net.automotons.blocks.PointerBlock;
56
import net.automotons.items.HeadItem;
67
import net.automotons.items.ModuleItem;
78
import net.automotons.items.RoboticsBookItem;
@@ -10,13 +11,17 @@
1011
import net.automotons.screens.AutomotonScreenHandler;
1112
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
1213
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
14+
import net.fabricmc.fabric.api.tag.TagRegistry;
1315
import net.minecraft.block.Block;
16+
import net.minecraft.block.BlockState;
17+
import net.minecraft.block.HorizontalFacingBlock;
1418
import net.minecraft.block.Material;
1519
import net.minecraft.block.entity.BlockEntityType;
1620
import net.minecraft.item.BlockItem;
1721
import net.minecraft.item.Item;
1822
import net.minecraft.loot.entry.LootPoolEntryType;
1923
import net.minecraft.screen.ScreenHandlerType;
24+
import net.minecraft.tag.Tag;
2025
import net.minecraft.util.Identifier;
2126
import net.minecraft.util.Pair;
2227
import net.minecraft.util.registry.Registry;
@@ -32,9 +37,12 @@ public class AutomotonsRegistry{
3237

3338
// For BlockItems
3439
private static final List<Pair<Identifier, Block>> WITH_ITEMS = new ArrayList<>();
40+
// For scanning module
41+
private static final Tag<Block> SCANNABLE = TagRegistry.block(autoId("automoton_scannable"));
3542

3643
// Blocks
3744
public static Block AUTOMOTON = new AutomotonBlock(FabricBlockSettings.of(Material.METAL).breakByHand(true).strength(6f).nonOpaque().solidBlock((state, world, pos) -> false));
45+
public static Block POINTER = new PointerBlock(FabricBlockSettings.of(Material.METAL).breakByHand(true).breakInstantly());
3846

3947
// Item Settings
4048
private static final Item.Settings TABBED = new Item.Settings().group(Automotons.ITEMS);
@@ -95,6 +103,12 @@ public class AutomotonsRegistry{
95103
public static Item MOVE_LEFT_MODULE = new ModuleItem(TABBED, AutomotonBlockEntity::moveLeft);
96104
public static Item MOVE_RIGHT_MODULE = new ModuleItem(TABBED, AutomotonBlockEntity::moveRight);
97105
public static Item MOVE_BACK_MODULE = new ModuleItem(TABBED, AutomotonBlockEntity::moveBack);
106+
public static Item SCAN_MODULE = new ModuleItem(TABBED, entity -> {
107+
BlockState below = entity.getWorld().getBlockState(entity.getPos().down());
108+
if(below.isIn(SCANNABLE) && below.getProperties().contains(HorizontalFacingBlock.FACING))
109+
return entity.move(below.get(HorizontalFacingBlock.FACING));
110+
return false;
111+
});
98112

99113
// Block Entity Types
100114
public static BlockEntityType<AutomotonBlockEntity> AUTOMOTON_BE = BlockEntityType.Builder
@@ -111,6 +125,7 @@ public class AutomotonsRegistry{
111125
public static void registerObjects(){
112126
// Blocks
113127
WITH_ITEMS.add(new Pair<>(autoId("automoton"), AUTOMOTON));
128+
WITH_ITEMS.add(new Pair<>(autoId("pointer"), POINTER));
114129

115130
for(Pair<Identifier, Block> item : WITH_ITEMS){
116131
register(Registry.BLOCK, item.getLeft(), item.getRight());
@@ -146,6 +161,7 @@ public static void registerObjects(){
146161
register(Registry.ITEM, autoId("move_left_module"), MOVE_LEFT_MODULE);
147162
register(Registry.ITEM, autoId("move_right_module"), MOVE_RIGHT_MODULE);
148163
register(Registry.ITEM, autoId("move_back_module"), MOVE_BACK_MODULE);
164+
register(Registry.ITEM, autoId("scan_module"), SCAN_MODULE);
149165

150166
// Block Entity Types
151167
register(Registry.BLOCK_ENTITY_TYPE, autoId("automoton"), AUTOMOTON_BE);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package net.automotons.blocks;
2+
3+
import net.minecraft.block.Block;
4+
import net.minecraft.block.BlockState;
5+
import net.minecraft.block.HorizontalFacingBlock;
6+
import net.minecraft.item.ItemPlacementContext;
7+
import net.minecraft.state.StateManager;
8+
9+
public class PointerBlock extends HorizontalFacingBlock{
10+
11+
public PointerBlock(Settings settings){
12+
super(settings);
13+
}
14+
15+
protected void appendProperties(StateManager.Builder<Block, BlockState> builder){
16+
builder.add(FACING);
17+
}
18+
19+
public BlockState getPlacementState(ItemPlacementContext ctx){
20+
return this.getDefaultState().with(FACING, ctx.getPlayerFacing());
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"variants": {
3+
"facing=east": {
4+
"model": "automotons:block/pointer",
5+
"y": 90
6+
},
7+
"facing=north": {
8+
"model": "automotons:block/pointer"
9+
},
10+
"facing=south": {
11+
"model": "automotons:block/pointer",
12+
"y": 180
13+
},
14+
"facing=west": {
15+
"model": "automotons:block/pointer",
16+
"y": 270
17+
}
18+
}
19+
}

src/main/resources/assets/automotons/lang/en_us.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
"item.automotons.move_left_module": "Move Left Module",
3030
"item.automotons.move_right_module": "Move Right Module",
3131
"item.automotons.move_back_module": "Move Back Module",
32+
"item.automotons.scan_module": "Scan Module",
3233

3334
"block.automotons.automoton": "Automoton",
35+
"block.automotons.pointer": "Pointer",
3436

3537
"container.automoton": "Automoton",
3638
"gui.automoton.engaged": "Engaged",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"parent": "block/cube",
3+
"textures": {
4+
"up": "automotons:blocks/pointer_top",
5+
"down": "automotons:blocks/pointer_bottom",
6+
"east": "automotons:blocks/pointer_side",
7+
"west": "automotons:blocks/pointer_side",
8+
"north": "automotons:blocks/pointer_point",
9+
"south": "automotons:blocks/pointer_back",
10+
"particle": "automotons:blocks/pointer_back"
11+
}
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"parent": "automotons:block/pointer"
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "minecraft:item/generated",
3+
"textures": {
4+
"layer0": "automotons:item/scan_module"
5+
}
6+
}
153 Bytes
Loading
269 Bytes
Loading
214 Bytes
Loading

0 commit comments

Comments
 (0)