Finish wireless terminals

This commit is contained in:
2024-08-16 19:57:52 +02:00
parent f63a5a36d7
commit 2c40d3ae3f
62 changed files with 408 additions and 308 deletions

View File

@@ -28,7 +28,7 @@ import java.util.HashMap;
import java.util.List;
public class ServerStorage implements ModInitializer {
public static final List<String> moduleList = Arrays.asList("bus", "configuration", "container", "display", "drive", "filtering", "inventory", "pagination", "pcb", "transport", "netherite_upgrade");
public static final List<String> moduleList = Arrays.asList("bus", "configuration", "container", "display", "drive", "filtering", "inventory", "pagination", "pcb", "transport", "antenna", "radio", "antenna_connector", "modem", "netherite_upgrade");
public static final List<String> tiers = Arrays.asList("iron", "golden", "diamond", "netherite");
public static final List<String> materialList = Arrays.asList("pcb", "pcb_substrate", "cpu", "cpu_substrate", "drive_controller", "drive_casing");

View File

@@ -1,5 +1,8 @@
package systems.brn.serverstorage.blocks;
import eu.pb4.polymer.blocks.api.BlockModelType;
import eu.pb4.polymer.blocks.api.PolymerBlockModel;
import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils;
import eu.pb4.polymer.core.api.block.SimplePolymerBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@@ -9,11 +12,14 @@ import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import systems.brn.serverstorage.lib.ConnectionType;
import java.util.HashMap;
public class ConnectedBlock extends SimplePolymerBlock {
public static final EnumProperty<ConnectionType> NORTH = EnumProperty.of("north", ConnectionType.class);
@@ -23,6 +29,39 @@ public class ConnectedBlock extends SimplePolymerBlock {
public static final EnumProperty<ConnectionType> UP = EnumProperty.of("up", ConnectionType.class);
public static final EnumProperty<ConnectionType> DOWN = EnumProperty.of("down", ConnectionType.class);
// Function to get Y-axis rotation for North, South, East, and West directions
public static int getRotationFromDirection(Direction direction) {
if (direction == Direction.EAST) {
return 90;
} else if (direction == Direction.SOUTH) {
return 180;
} else if (direction == Direction.WEST) {
return 270;
} else {
return 0;
}
}
// Function to get X-axis rotation for Up and Down directions
public static int getXRotationFromDirection(Direction direction) {
if (direction == Direction.UP) {
return 270;
} else if (direction == Direction.DOWN) {
return 90;
} else {
return 0;
}
}
public static HashMap<Direction, BlockState> generateRotations(Identifier identifier) {
Identifier modelIdentifier = identifier.withPath("block/" + identifier.getPath());
HashMap<Direction, BlockState> rotations = new HashMap<>();
for (Direction direction : Direction.values()) {
rotations.put(direction, PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(modelIdentifier, getXRotationFromDirection(direction), getRotationFromDirection(direction))));
}
return rotations;
}
public void setDefaultState() {
setDefaultState(getStateManager().getDefaultState()
.with(NORTH, ConnectionType.NONE)
@@ -66,9 +105,9 @@ public class ConnectedBlock extends SimplePolymerBlock {
BlockEntity blockEntity = world.getBlockEntity(neighborPos);
boolean isConnectedToInventory = blockEntity instanceof Inventory;
ConnectionType connectionType = ConnectionType.NONE;
if (isConnectedToBus){
if (isConnectedToBus) {
connectionType = ConnectionType.BUS;
} else if (isConnectedToInventory){
} else if (isConnectedToInventory) {
connectionType = ConnectionType.INVENTORY;
}

View File

@@ -1,8 +1,5 @@
package systems.brn.serverstorage.blocks;
import eu.pb4.polymer.blocks.api.BlockModelType;
import eu.pb4.polymer.blocks.api.PolymerBlockModel;
import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils;
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
@@ -27,24 +24,26 @@ import org.jetbrains.annotations.Nullable;
import systems.brn.serverstorage.blockentities.HardDriveContainerBlockEntity;
import systems.brn.serverstorage.lib.StorageNetwork;
import java.util.HashMap;
import static systems.brn.serverstorage.ServerStorage.*;
public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTexturedBlock, BlockEntityProvider {
final Identifier identifier;
public static final DirectionProperty FACING = FacingBlock.FACING;
private final BlockState polymerBlockState;
private final HashMap<Direction, BlockState> rotations;
public HardDriveContainerBlock(AbstractBlock.Settings settings, Identifier identifier) {
super(settings, Blocks.NOTE_BLOCK);
this.identifier = identifier;
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(identifier.withPath("block/" + identifier.getPath())));
this.rotations = generateRotations(identifier);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
}
@Override
@@ -55,7 +54,8 @@ public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTe
@Override
public BlockState getPolymerBlockState(BlockState state) {
return this.polymerBlockState;
Direction direction = state.get(FACING);
return rotations.get(direction);
}
public static void register() {

View File

@@ -1,8 +1,5 @@
package systems.brn.serverstorage.blocks;
import eu.pb4.polymer.blocks.api.BlockModelType;
import eu.pb4.polymer.blocks.api.PolymerBlockModel;
import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils;
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
@@ -35,24 +32,26 @@ import systems.brn.serverstorage.lib.PagedGui;
import systems.brn.serverstorage.screens.SearchScreen;
import systems.brn.serverstorage.screens.SettingsScreen;
import java.util.HashMap;
import static systems.brn.serverstorage.ServerStorage.*;
import static systems.brn.serverstorage.lib.PagedGui.*;
public class InventoryInterfaceBlock extends ConnectedBlock implements PolymerTexturedBlock, BlockEntityProvider {
final Identifier identifier;
public static final DirectionProperty FACING = FacingBlock.FACING;
private final BlockState polymerBlockState;
private final HashMap<Direction, BlockState> rotations;
public InventoryInterfaceBlock(Settings settings, Identifier identifier) {
super(settings, Blocks.NOTE_BLOCK);
this.identifier = identifier;
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(identifier.withPath("block/" + identifier.getPath())));
this.rotations = generateRotations(identifier);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
}
@Override
@@ -63,7 +62,8 @@ public class InventoryInterfaceBlock extends ConnectedBlock implements PolymerTe
@Override
public BlockState getPolymerBlockState(BlockState state) {
return this.polymerBlockState;
Direction direction = state.get(FACING);
return rotations.get(direction);
}
public static void register() {
@@ -150,7 +150,7 @@ public class InventoryInterfaceBlock extends ConnectedBlock implements PolymerTe
Block block = state.getBlock();
if (block instanceof InventoryInterfaceBlock) {
if (!world.getGameRules().getBoolean(ServerStorage_Interface_Enable)){
if (!world.getGameRules().getBoolean(ServerStorage_Interface_Enable)) {
playerEntity.sendMessage(Text.translatable("message.serverstorage.block_disabled"), true);
return ActionResult.PASS;
}

View File

@@ -1,8 +1,5 @@
package systems.brn.serverstorage.blocks;
import eu.pb4.polymer.blocks.api.BlockModelType;
import eu.pb4.polymer.blocks.api.PolymerBlockModel;
import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils;
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
@@ -34,6 +31,7 @@ import systems.brn.serverstorage.lib.WirelessTerminalComponents;
import systems.brn.serverstorage.screens.RadioBlockPlayerMangementScreen;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
@@ -43,18 +41,19 @@ import static systems.brn.serverstorage.lib.Util.removePosition;
public class RadioInterfaceBlock extends ConnectedBlock implements PolymerTexturedBlock, BlockEntityProvider {
final Identifier identifier;
public static final DirectionProperty FACING = FacingBlock.FACING;
private final BlockState polymerBlockState;
private final HashMap<Direction, BlockState> rotations;
public RadioInterfaceBlock(Settings settings, Identifier identifier) {
super(settings, Blocks.NOTE_BLOCK);
this.identifier = identifier;
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(identifier.withPath("block/" + identifier.getPath())));
this.rotations = generateRotations(identifier);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
}
@Override
@@ -65,7 +64,8 @@ public class RadioInterfaceBlock extends ConnectedBlock implements PolymerTextur
@Override
public BlockState getPolymerBlockState(BlockState state) {
return this.polymerBlockState;
Direction direction = state.get(FACING);
return rotations.get(direction);
}
public static void register() {

View File

@@ -1,8 +1,5 @@
package systems.brn.serverstorage.blocks;
import eu.pb4.polymer.blocks.api.BlockModelType;
import eu.pb4.polymer.blocks.api.PolymerBlockModel;
import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils;
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
@@ -33,6 +30,7 @@ import org.jetbrains.annotations.Nullable;
import systems.brn.serverstorage.blockentities.StorageInterfaceBlockEntity;
import systems.brn.serverstorage.screens.StorageScreen;
import java.util.HashMap;
import java.util.List;
import static systems.brn.serverstorage.ServerStorage.*;
@@ -41,18 +39,18 @@ import static systems.brn.serverstorage.lib.Util.generateBookContent;
public class StorageInterfaceBlock extends ConnectedBlock implements PolymerTexturedBlock, BlockEntityProvider {
final Identifier identifier;
public static final DirectionProperty FACING = FacingBlock.FACING;
private final BlockState polymerBlockState;
private final HashMap<Direction, BlockState> rotations;
public StorageInterfaceBlock(Settings settings, Identifier identifier) {
super(settings, Blocks.NOTE_BLOCK);
this.identifier = identifier;
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(identifier.withPath("block/" + identifier.getPath())));
this.rotations = generateRotations(identifier);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
}
@Override
@@ -63,7 +61,8 @@ public class StorageInterfaceBlock extends ConnectedBlock implements PolymerText
@Override
public BlockState getPolymerBlockState(BlockState state) {
return this.polymerBlockState;
Direction direction = state.get(FACING);
return rotations.get(direction);
}
public static void register() {