Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
screret committed Oct 22, 2023
1 parent cadd9ce commit 77ec521
Show file tree
Hide file tree
Showing 31 changed files with 331 additions and 302 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

0.0.2.a:
- fix fabric
- make dyson sphere able to collapse if left without maintenance
- add dyson sphe
- remove rocket launch keybind


0.0.2:
Expand Down
27 changes: 27 additions & 0 deletions common/src/main/java/argent_matter/gcys/GCyS.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package argent_matter.gcys;

import argent_matter.gcys.api.capability.GcysCapabilityHelper;
import argent_matter.gcys.api.capability.IDysonSystem;
import argent_matter.gcys.api.gui.factory.EntityUIFactory;
import argent_matter.gcys.api.registries.GcysRegistries;
import argent_matter.gcys.api.space.dyson.DysonSystemSavedData;
import argent_matter.gcys.common.data.*;
import argent_matter.gcys.config.GcysConfig;
import argent_matter.gcys.data.GCySDatagen;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.lowdragmc.lowdraglib.gui.factory.UIFactory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Set;

public class GCyS {
public static final String
MOD_ID = "gcys",
Expand Down Expand Up @@ -52,4 +60,23 @@ public static void onKeyPressed(int key, int action, int modifiers) {
}
*/
}

private static final ThreadLocal<Set<IDysonSystem>> TICKED_SYSTEMS = ThreadLocal.withInitial(HashSet::new);

public static void onLevelTick(Level ticked, boolean isStart) {
if (!(ticked instanceof ServerLevel level)) return;

if (isStart) {
if (!level.dimensionType().hasCeiling()) {
var sat = GcysCapabilityHelper.getSatellites(level);
if (sat != null) sat.tickSatellites();
}

IDysonSystem system = DysonSystemSavedData.getOrCreate(level);
if (system == null || TICKED_SYSTEMS.get().contains(system)) return;
system.tick();
} else {
TICKED_SYSTEMS.get().clear();
}
}
}
4 changes: 2 additions & 2 deletions common/src/main/java/argent_matter/gcys/GCySClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class GCySClient {

public static boolean isDysonSphereActive;
public static boolean isDysonSphereActive = false;

public static boolean hasUpdatedPlanets = false;
public static List<PlanetSkyRenderer> skyRenderers = new ArrayList<>();
Expand All @@ -20,6 +20,6 @@ public class GCySClient {
public static List<Galaxy> galaxies = new ArrayList<>();

public static void init() {
GCySKeyMappings.init();
//GCySKeyMappings.init();
}
}
12 changes: 1 addition & 11 deletions common/src/main/java/argent_matter/gcys/GCySGTAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ public void registerCovers() {
IGTAddon.super.registerCovers();
}

@Override
public void registerRecipeTypes() {

}

@Override
public void registerMachines() {

}

@Override
public void registerWorldgenLayers() {
IGTAddon.super.registerWorldgenLayers();
Expand All @@ -71,7 +61,7 @@ public void collectMaterialCasings(MaterialCasingCollectionEvent event) {
}

@Override
public void initializeRecipes(Consumer<FinishedRecipe> provider) {
public void addRecipes(Consumer<FinishedRecipe> provider) {
GCySRecipes.init(provider);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package argent_matter.gcys.api.capability;


import argent_matter.gcys.api.space.dyson.DysonSphere;
import argent_matter.gcys.common.satellite.DysonSwarmSatellite;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public interface IDysonSystem {
/**
* @return if a dyson sphere active in this dimension.
* @return this solar system's active dyson sphere, or null if none
*/
@Nullable
DysonSphere activeDysonSphere();

boolean isDysonSphereActive();

/**
Expand All @@ -27,4 +32,8 @@ public interface IDysonSystem {
void addDysonSatellite(BlockPos controllerPos, DysonSwarmSatellite satellite);

void disableAllDysonSatellites(BlockPos controllerPos);

void tick();

void setDirty();
}

This file was deleted.

127 changes: 102 additions & 25 deletions common/src/main/java/argent_matter/gcys/api/space/dyson/DysonSphere.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,117 @@
package argent_matter.gcys.api.space.dyson;

import com.gregtechceu.gtceu.api.gui.widget.EnumSelectorWidget;
import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture;
import argent_matter.gcys.api.capability.IDysonSystem;
import com.gregtechceu.gtceu.api.GTValues;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.core.BlockPos;
import net.minecraft.util.StringRepresentable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerLevel;

public record DysonSphere(
BlockPos controllerPos) {
public class DysonSphere {

public enum Component implements StringRepresentable, EnumSelectorWidget.SelectableEnum {
FRAME("frame", "gcys.dyson_component.frame"),
CELL("cell", "gcys.dyson_component.cell"),
PANEL("panel", "gcys.dyson_component.panel"),
PORT("port", "gcys.dyson_component.port")
;
private final int MINIMUM_MAINTENANCE_TIME = 3456000; // 48 real-life hours = 3456000 ticks
private final float BASE_COLLAPSE_CHANCE = 0.00005f;

private final String id, tooltipKey;
private final IDysonSystem system;

Component(String id, String tooltipKey) {
this.id = id;
this.tooltipKey = tooltipKey;
}
@Getter
private BlockPos controllerPos;
@Getter @Setter
private int timeActive = 0, timeNeededMaintenance = 0;
@Getter
private boolean needsMaintenance;
@Getter @Setter
private boolean collapsed;

public DysonSphere(BlockPos controllerPos, IDysonSystem system) {
this.controllerPos = controllerPos;
this.system = system;
}

@Override
public String getSerializedName() {
return id;
public void tick(ServerLevel level) {
if (level.getGameTime() % 20 == 0) {
if (this.isCollapsed()) return;
if (this.isNeedsMaintenance()) {
if (GTValues.RNG.nextFloat() <= BASE_COLLAPSE_CHANCE * timeNeededMaintenance) {
this.setCollapsed();
}

timeNeededMaintenance++;
this.system.setDirty();
return;
}

if (calculateTime(20)) {
if (GTValues.RNG.nextFloat() - 0.75f >= 0) {
this.needsMaintenance();
}
}
}
}

@Override
public String getTooltip() {
return tooltipKey;
public float getCollapseChance() {
return BASE_COLLAPSE_CHANCE * timeNeededMaintenance;
}

public void needsMaintenance() {
this.needsMaintenance = true;
this.timeNeededMaintenance++;
this.system.setDirty();
}

public void fixMaintenance() {
this.needsMaintenance = false;
this.timeNeededMaintenance = 0;
this.system.setDirty();
}

public void setCollapsed() {
this.setCollapsed(true);
this.system.disableDysonSphere(this.controllerPos);
}

private boolean calculateTime(int timeSinceLastTick) {
setTimeActive(timeSinceLastTick + getTimeActive());
this.system.setDirty();
var value = getTimeActive() - MINIMUM_MAINTENANCE_TIME;
if (value > 0) {
setTimeActive(value);
return true;
}
return false;
}

public void setControllerPos(BlockPos controllerPos) {
this.controllerPos = controllerPos;
this.system.setDirty();
}

@Override
public IGuiTexture getIcon() {
return null;
public void save(CompoundTag tag) {
if (controllerPos != null) {
tag.put("controllerPos", NbtUtils.writeBlockPos(controllerPos));
}
tag.putBoolean("needsMaintenance", this.isNeedsMaintenance());
tag.putBoolean("collapsed", this.isCollapsed());
tag.putInt("timeActive", this.timeActive);
tag.putInt("timeNeededMaintenance", this.timeNeededMaintenance);
}

public static DysonSphere load(CompoundTag tag, IDysonSystem system) {
BlockPos controllerPos = tag.contains("controllerPos", Tag.TAG_COMPOUND) ? NbtUtils.readBlockPos(tag.getCompound("controllerPos")) : null;
boolean needsMaintenance = tag.getBoolean("needsMaintenance");
boolean collapsed = tag.getBoolean("collapsed");
int timeActive = tag.getInt("timeActive");
int timeNeededMaintenance = tag.getInt("timeNeededMaintenance");

DysonSphere sphere = new DysonSphere(controllerPos, system);
sphere.needsMaintenance = needsMaintenance;
sphere.setCollapsed(collapsed);
sphere.setTimeActive(timeActive);
sphere.setTimeNeededMaintenance(timeNeededMaintenance);

return sphere;
}
}
Loading

0 comments on commit 77ec521

Please sign in to comment.