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

更新一丢丢 #93

Merged
merged 1 commit into from
Feb 5, 2022
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
4 changes: 4 additions & 0 deletions src/main/java/com/xekr/ironstars/IronStarsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Random;

public class IronStarsUtil {
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();

public static final Random RANDOM = new Random();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.Level;
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.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Deprecated //TODO 先写着, 写完再去掉
public abstract class AbstractEfficiencyBlockEntity extends BlockEntity {
import java.util.Collections;
import java.util.List;
import java.util.UUID;

public abstract class AbstractEFFBlockEntity extends BlockEntity {
private int lazyTickCounter = 0;

@Nullable private BlockPos source;
@Nullable private UUID netId = null;
private List<BlockPos> sources = Collections.emptyList();

protected AbstractEfficiencyBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
protected AbstractEFFBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}

Expand All @@ -43,7 +49,17 @@ public void load(CompoundTag pTag) {
protected void saveAdditional(CompoundTag pTag) {
}

public abstract int getGeneratedEfficiency();
public UUID getNetwork() {
return this.netId;
}

public boolean hasNetwork() {
return this.netId != null;
}

public abstract boolean isSourceMachine();

public abstract int getMachineEfficiency();

public abstract boolean canOutput(@Nullable Direction side);

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/xekr/ironstars/efficiency/EFFNetwork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.xekr.ironstars.efficiency;

import com.xekr.ironstars.IronStarsUtil;
import com.xekr.ironstars.blocks.entity.AbstractEFFBlockEntity;
import net.minecraft.util.Mth;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

public class EFFNetwork {
private static final Map<UUID, EFFNetwork> NETWORK = new HashMap<>();

private final UUID id;
private final Map<AbstractEFFBlockEntity, Integer> sources = new HashMap<>();
private final Map<AbstractEFFBlockEntity, Integer> members = new LinkedHashMap<>();

private EFFNetwork(AbstractEFFBlockEntity blockEntity) {
this.id = Mth.createInsecureUUID(IronStarsUtil.RANDOM);
this.sources.put(blockEntity, blockEntity.getMachineEfficiency());
}

public static EFFNetwork create(AbstractEFFBlockEntity blockEntity) {
if (blockEntity.hasNetwork() || !blockEntity.isSourceMachine()) return null;
EFFNetwork network = new EFFNetwork(blockEntity);
NETWORK.put(network.id, network);
return network;
}





}

This file was deleted.