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

Feat/linkpowernode #15

Merged
merged 5 commits into from
Dec 10, 2023
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
15 changes: 15 additions & 0 deletions src/main/java/com/hechu/mindustry/MindustryConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ public class MindustryConstants {
public static final String MOD_ID = "mindustry";
public static Path config_folder;
public static CommonConfig commonConfig;

/**
* 用于规范翻译文档
*/
public static final String CHAT = "chat." + MOD_ID + ".";
public static final String CHAT_WARN = CHAT + "warning.";
public static final String CHAT_INFO = CHAT + "info.";
public static final String CHAT_COMMAND = CHAT + "command.";

public static final String DESC = "desc." + MOD_ID + ".";
public static final String DESC_INFO = DESC + "info.";
public static final String DESC_FLAVOUR = DESC + "flavour.";

public static final String GUI = "gui." + MOD_ID + ".";
public static final String GUI_CONFIG = "gui." + MOD_ID + ".config.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PowerNodeRenderer implements BlockEntityRenderer<PowerNodeBlockEnti
public static final ResourceLocation BEAM_LOCATION = new ResourceLocation(MindustryConstants.MOD_ID, "textures/entity/power_node_beam.png");

private static void renderPowerNodeBeam(PoseStack pPoseStack, MultiBufferSource pBufferSource, float pPartialTick, long pGameTime, int pYOffset, int pHeight) {
renderPowerNodeBeam(pPoseStack, pBufferSource, BEAM_LOCATION, pPartialTick, 1.0F, pGameTime, pYOffset, pHeight, 0.07F, 0.06F);
renderPowerNodeBeam(pPoseStack, pBufferSource, BEAM_LOCATION, pPartialTick, 1.0F, pGameTime, pYOffset, 1, 0.07F, 0.06F);
}

public static void renderPowerNodeBeam(PoseStack pPoseStack, MultiBufferSource pBufferSource, ResourceLocation pBeamLocation, float pPartialTick, float pTextureScale, long pGameTime, int pYOffset, int pHeight, float pBeamRadius, float pGlowRadius) {
Expand Down Expand Up @@ -101,7 +101,7 @@ public boolean shouldRenderOffScreen(PowerNodeBlockEntity pBlockEntity) {

@Override
public int getViewDistance() {
return 256;
return 64;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/hechu/mindustry/kiwi/BlockModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.hechu.mindustry.MindustryConstants;
import com.hechu.mindustry.world.level.block.Equipment.PowerNodeBlock;
import com.hechu.mindustry.world.level.block.ore.*;
import com.hechu.mindustry.world.level.block.turrets.SpectreTurretBlock;
import com.hechu.mindustry.world.level.block.turrets.SwarmerTurretBlock;
import net.minecraft.world.level.block.Block;
import snownee.kiwi.AbstractModule;
import snownee.kiwi.KiwiGO;
Expand All @@ -22,6 +20,7 @@
public class BlockModule extends AbstractModule {
@KiwiModule.Category(value = MindustryConstants.MOD_ID + ":tab_main")
public static final KiwiGO<Block> POWER_NODE = go(PowerNodeBlock::new);

@KiwiModule.Name("lead_ore")
public static final KiwiGO<Block> LEAD_ORE_BLOCK = go(LeadOreBlock::new);
@KiwiModule.Name("coal_ore")
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/hechu/mindustry/kiwi/ItemModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hechu.mindustry.kiwi;

import com.hechu.mindustry.MindustryConstants;
import com.hechu.mindustry.world.item.tools.Wrench;
import net.minecraft.world.item.Item;
import snownee.kiwi.AbstractModule;
import snownee.kiwi.KiwiGO;
Expand All @@ -16,6 +17,9 @@
@KiwiModule(value = "item")
@KiwiModule.Category(value = MindustryConstants.MOD_ID + ":tab_materials")
public class ItemModule extends AbstractModule {
@KiwiModule.Category(value = MindustryConstants.MOD_ID + ":tab_main")
public static final KiwiGO<Item> WRENCH = go(() -> new Wrench(new Item.Properties()));

public static final KiwiGO<Item> COPPER = go(() -> new Item(new Item.Properties()));
public static final KiwiGO<Item> COAL = go(() -> new Item(new Item.Properties()));
public static final KiwiGO<Item> LEAD = go(() -> new Item(new Item.Properties()));
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/com/hechu/mindustry/world/item/tools/Wrench.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.hechu.mindustry.world.item.tools;

import com.hechu.mindustry.MindustryConstants;
import com.hechu.mindustry.world.level.block.Equipment.PowerNodeBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import snownee.kiwi.item.ModItem;
import snownee.kiwi.util.NBTHelper;

/**
* @author luobochuanqi
*/
public class Wrench extends ModItem {
public static final String NAME = "wrench";
private static final String NBT_KEY = "PowerNodeData";

public Wrench(Properties builder) {
super(builder);
}

@Override
public InteractionResult useOn(UseOnContext pContext) {
BlockPos clickedPos = pContext.getClickedPos();
BlockEntity blockEntity = pContext.getLevel().getBlockEntity(clickedPos);
ItemStack itemStack = pContext.getItemInHand();
NBTHelper tag = NBTHelper.of(itemStack).get() == null ? NBTHelper.create() : NBTHelper.of(itemStack);
if (!pContext.getLevel().isClientSide() && blockEntity instanceof PowerNodeBlockEntity powerNodeBlockEntity2) {
// 判断当前 nbt 是否已经存储了一个节点的坐标
if (tag.get().contains(NBT_KEY)) {
// powerNodeBlockEntity1 连接 powerNodeBlockEntity2
PowerNodeBlockEntity powerNodeBlockEntity1 = (PowerNodeBlockEntity) pContext.getLevel().getBlockEntity(tag.getPos(NBT_KEY));
if (powerNodeBlockEntity1 != powerNodeBlockEntity2) {
// 如果点击的节点是已经被连接的,那么就取消连接
if (powerNodeBlockEntity1.getConnectedNodes().contains(powerNodeBlockEntity2)
&& powerNodeBlockEntity2.getPassivelyConnectedNodes().contains(powerNodeBlockEntity1)) {
powerNodeBlockEntity1.removeConnectedNode(powerNodeBlockEntity2);
powerNodeBlockEntity2.removePassivelyConnectedNode(powerNodeBlockEntity1);
} else {
powerNodeBlockEntity2.connectFromOtherNode(powerNodeBlockEntity1);
powerNodeBlockEntity1.connectToOtherNode(powerNodeBlockEntity2);
tag.remove(NBT_KEY);
}
} else {
// 否则就可以判断点击的节点是已经存储的节点本身
pContext.getPlayer().sendSystemMessage(Component.translatable(MindustryConstants.CHAT_WARN + "linkSelf"));
return InteractionResult.PASS;
}
} else {
tag.setPos(NBT_KEY, clickedPos);
}
itemStack.setTag(tag.get());
}
return InteractionResult.SUCCESS;
}

@Override
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
Tag tag = pPlayer.getItemInHand(pUsedHand).getTag();
if (tag != null) {
MindustryConstants.logger.debug("yes: " + tag.toString());
} else {
MindustryConstants.logger.debug("no tag");
}
return super.use(pLevel, pPlayer, pUsedHand);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package com.hechu.mindustry.world.level.block.Equipment;

import com.hechu.mindustry.MindustryConstants;
import com.hechu.mindustry.kiwi.BlockEntityModule;
import com.hechu.mindustry.utils.capabilities.MindustryCapabilities;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.RenderShape;
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.phys.BlockHitResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
* @author luobochuanqi
*/
public class PowerNodeBlock extends BaseEntityBlock {

public static final String NAME = "power_node";

public PowerNodeBlock() {
Expand Down Expand Up @@ -45,4 +51,24 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(@NotNull Level pLe
public RenderShape getRenderShape(BlockState pState) {
return RenderShape.MODEL;
}

@Override
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
if (!pLevel.isClientSide()) {
PowerNodeBlockEntity powerNodeBlockEntity = (PowerNodeBlockEntity) pLevel.getBlockEntity(pPos);
MindustryConstants.logger.debug("to:" + powerNodeBlockEntity.getConnectedNodes().toString());
MindustryConstants.logger.debug("from:" + powerNodeBlockEntity.getPassivelyConnectedNodes().toString());
}
return super.use(pState, pLevel, pPos, pPlayer, pHand, pHit);
}

@Override
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
PowerNodeBlockEntity powerNodeBlockEntity = (PowerNodeBlockEntity) pLevel.getBlockEntity(pPos);
List<PowerNodeBlockEntity> passivelyConnectedNodes = powerNodeBlockEntity.getPassivelyConnectedNodes();
for (PowerNodeBlockEntity element : passivelyConnectedNodes) {
element.removeConnectedNode(powerNodeBlockEntity);
}
super.onRemove(pState, pLevel, pPos, pNewState, pIsMoving);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.collect.Lists;
import com.hechu.mindustry.kiwi.BlockEntityModule;
import com.mojang.logging.LogUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand All @@ -18,13 +17,28 @@
*/
public class PowerNodeBlockEntity extends BlockEntity {
public static final String NAME = "power_node";
private static final Logger LOGGER = LogUtils.getLogger();
/**
* A list of beam segments for this PowerNode.
*/
List<PowerNodeBeamSection> beamSections = Lists.newArrayList();
private int lastCheckY;
private List<PowerNodeBeamSection> checkingBeamSections = Lists.newArrayList();
/**
* The maximum number of nodes that can be connected
*/
public static final int MAX_CONNECTIONS = 10;
/**
* Range that can be connected to
*/
public static final int POWER_RANGE = 6;
/**
* Other nodes connected from this node
*/
List<PowerNodeBlockEntity> connectedNodes = org.apache.commons.compress.utils.Lists.newArrayList();
/**
* Other nodes connected to the current node from other nodes
*/
List<PowerNodeBlockEntity> passivelyConnectedNodes = org.apache.commons.compress.utils.Lists.newArrayList();

public PowerNodeBlockEntity(BlockPos pPos, BlockState pBlockState) {
super(BlockEntityModule.POWER_NODE_BLOCK_ENTITY.get(), pPos, pBlockState);
Expand Down Expand Up @@ -76,6 +90,30 @@ public List<PowerNodeBeamSection> getBeamSections() {
return (List<PowerNodeBeamSection>) this.beamSections;
}

public List<PowerNodeBlockEntity> getConnectedNodes() {
return this.connectedNodes;
}

public List<PowerNodeBlockEntity> getPassivelyConnectedNodes() {
return this.passivelyConnectedNodes;
}

public void connectToOtherNode(PowerNodeBlockEntity pBlockEntity) {
this.connectedNodes.add(pBlockEntity);
}

public void connectFromOtherNode(PowerNodeBlockEntity pBlockEntity) {
this.passivelyConnectedNodes.add(pBlockEntity);
}

public boolean removeConnectedNode(PowerNodeBlockEntity pBlockEntity) {
return this.getConnectedNodes().remove(pBlockEntity);
}

public boolean removePassivelyConnectedNode(PowerNodeBlockEntity pBlockEntity) {
return this.getPassivelyConnectedNodes().remove(pBlockEntity);
}

/**
* Return an {@link AABB} that controls the visible scope of a {@link BlockEntityWithoutLevelRenderer} associated with this {@link BlockEntity}
* Defaults to the collision bounding box {@link BlockState#getCollisionShape(BlockGetter, BlockPos)} associated with the block
Expand Down
10 changes: 4 additions & 6 deletions src/main/resources/assets/mindustry/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,27 @@
"item.mindustry.scrap": "Scrap",
"item.mindustry.thorium": "Thorium",
"item.mindustry.titanium": "Titanium",

"item.mindustry.graphite": "Graphite",
"item.mindustry.meta_glass": "Meta Glass",
"item.mindustry.phase_fabric": "Phase Fabric",
"item.mindustry.plastanium": "Plastanium",
"item.mindustry.pyratite": "Pyratite",
"item.mindustry.silicon": "Silicon",
"item.mindustry.surge_alloy": "Surge Alloy",
"item.mindustry.wrench": "Wrench",
"item.mindustry.swarmer_turret": "Swarmer",
"item.mindustry.spectre_turret": "Spectre",

"entity.mindustry.missile_bullet": "Missile",
"entity.mindustry.basic_bullet": "Basic Bullet",

"config.jade.plugin_mindustry.crafting_block": "Show Factory Progress",
"config.jade.plugin_mindustry.drill": "Show Drill Detail",
"config.jade.plugin_mindustry.health_block": "Show Block Health",

"item.mindustry.wrench.tip": "Current: d%",
"itemGroup.mindustry.mindustry": "Mindustry",
"itemGroup.mindustry.materials": "Mindustry - Materials",

"mindustry.block_health": "BlockHealth : %d / %d",
"mindustry.drill_progress": "Progress %d%%",
"mindustry.drill_speed": "Mining Speed : %d items/s",
"mindustry.stored_item": "Item Store : %d / %d"
"mindustry.stored_item": "Item Store : %d / %d",
"chat.mindustry.warning.linkSelf": "! You cannot connect to the node itself"
}
9 changes: 4 additions & 5 deletions src/main/resources/assets/mindustry/lang/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@
"item.mindustry.pyratite": "硫化物",
"item.mindustry.silicon": "硅",
"item.mindustry.surge_alloy": "巨浪合金",
"item.mindustry.wrench": "扳手",
"item.mindustry.swarmer_turret": "蜂群",
"item.mindustry.spectre_turret": "幽灵",

"entity.mindustry.missile_bullet": "导弹",
"entity.mindustry.basic_bullet": "普通子弹",

"config.jade.plugin_mindustry.crafting_block": "显示工厂制作进度",
"config.jade.plugin_mindustry.drill": "显示钻头属性",
"config.jade.plugin_mindustry.health_block": "显示血量",

"item.mindustry.wrench.tip": "当前存储: d%",
"itemGroup.mindustry.mindustry": "Mindustry",
"itemGroup.mindustry.materials": "Mindustry - 材料",

"mindustry.block_health": "生命值 : %d / %d",
"mindustry.drill_progress": "%d%%已挖掘",
"mindustry.drill_speed": "挖掘速度 : %d/秒",
"mindustry.stored_item": "已存储物品 : %d / %d"
"mindustry.stored_item": "已存储物品 : %d / %d",
"chat.mindustry.warning.linkSelf": "你不能连接要连接的节点本身"
}
Loading