Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

尝试设计电网系统 #270

Merged
merged 24 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# User-specific stuff
.idea/
!.idea/icon.svg

*.iml
*.ipr
Expand Down
47 changes: 47 additions & 0 deletions .idea/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions common/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void init() {
REGISTRATE.registerRegistrate();
}

public static @NotNull ResourceLocation of(String id) {
return new ResourceLocation(MOD_ID, id);
public static @NotNull ResourceLocation of(String path) {
return new ResourceLocation(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dev.dubhe.anvilcraft.api.power;

import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* 电力元件
*/
@SuppressWarnings("unused")
public interface IPowerComponent {
/**
* @return 元件位置
*/
@NotNull
BlockPos getPos();

default VoxelShape getRange() {
return Shapes.block();
}

/**
* 设置电网
*
* @param grid 电网
*/
void setGrid(@Nullable PowerGrid grid);

/**
* 获取电网
*
* @return 电网
*/
@Nullable
PowerGrid getGrid();

/**
* @return 元件类型
*/
@NotNull
PowerComponentType getComponentType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.dubhe.anvilcraft.api.power;

import org.jetbrains.annotations.NotNull;

/**
* 用电
*/
public interface IPowerConsumer extends IPowerComponent {
/**
* @return 输入功率
*/
default int getInputPower() {
return 0;
}

@Override
default @NotNull PowerComponentType getComponentType() {
return PowerComponentType.CONSUMER;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.dubhe.anvilcraft.api.power;

import org.jetbrains.annotations.NotNull;

/**
* 发电
*/
public interface IPowerProducer extends IPowerComponent {
/**
* @return 输出功率
*/
default int getOutputPower() {
return 0;
}

@Override
default @NotNull PowerComponentType getComponentType() {
return PowerComponentType.PRODUCER;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.dubhe.anvilcraft.api.power;

import org.jetbrains.annotations.NotNull;

/**
* 储电
*/
public interface IPowerStorage extends IPowerProducer, IPowerConsumer {
/**
* 输入电量
*
* @param power 输入值
* @return 无法输入的值
*/
int insert(int power);

/**
* 获取电量
*
* @param power 想要获取的值
* @return 实际获取的值
*/
int extract(int power);

@Override
default @NotNull PowerComponentType getComponentType() {
return PowerComponentType.STORAGE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.dubhe.anvilcraft.api.power;

import dev.dubhe.anvilcraft.AnvilCraft;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

/**
* 电力中继器
*/
public interface IPowerTransmitter extends IPowerComponent {
@Override
default VoxelShape getRange() {
int range = AnvilCraft.config.powerTransmitterRange;
return Shapes.box(-range, -range, -range, range + 1, range + 1, range + 1);
}

@Override
default @NotNull PowerComponentType getComponentType() {
return PowerComponentType.TRANSMITTER;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.dubhe.anvilcraft.api.power;

/**
* 电力元件类型
*/
public enum PowerComponentType {
INVALID,
PRODUCER,
CONSUMER,
STORAGE,
TRANSMITTER
}
Loading
Loading