Skip to content

Commit

Permalink
Merge pull request #93 from Cjsah/1.18
Browse files Browse the repository at this point in the history
更新一丢丢
  • Loading branch information
Cjsah authored Feb 5, 2022
2 parents f3da7f6 + 12eb708 commit 82189f6
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
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.

0 comments on commit 82189f6

Please sign in to comment.