Skip to content

Commit

Permalink
fix crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
screret committed Sep 26, 2024
1 parent f151aa6 commit 2110408
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### ADDITIONS:

### FIXES:
- fixed server crash

### CHANGES:
- updated to GT 1.4.4
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencyResolutionManagement {
def parchmentVersion = "2024.07.28" // https://parchmentmc.org/docs/getting-started
def configurationVersion = "5573796"
def gtCeuVersion = "1.4.4"
def ldLibVersion = "1.0.28.c"
def ldLibVersion = "1.0.28.d"
def moddevgradleVersion = "2.0.15-beta"

forge {
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/argent_matter/gcyr/GCYR.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ public static ResourceLocation id(String path) {
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
}

@SubscribeEvent
public void registerGuiOverlays(RegisterGuiLayersEvent event) {
event.registerBelowAll(GCYR.id("oxygen_tank"), new EntityOxygenHUD());
}


@SubscribeEvent
public void registerClientReloadListeners(RegisterClientReloadListenersEvent event) {
// insert the resource loader into the first index forcefully, so we can load our data before shaders are loaded.
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/argent_matter/gcyr/GCYRClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
import argent_matter.gcyr.api.space.planet.PlanetRing;
import argent_matter.gcyr.api.space.planet.PlanetSkyRenderer;
import argent_matter.gcyr.api.space.planet.SolarSystem;
import argent_matter.gcyr.common.gui.EntityOxygenHUD;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings("unused")
@EventBusSubscriber(modid = GCYR.MOD_ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class GCYRClient {

public static VertexFormat.Mode MODE_QUAD_STRIP = null;
Expand All @@ -29,4 +36,9 @@ public class GCYRClient {
public static void init() {
//GCYRKeyMappings.init();
}

@SubscribeEvent
public static void registerGuiOverlays(RegisterGuiLayersEvent event) {
event.registerBelowAll(GCYR.id("oxygen_tank"), new EntityOxygenHUD());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public class KeyCardBehaviour implements IAddInformation {
Expand All @@ -34,7 +35,7 @@ public static void setOwner(ItemStack stack, LivingEntity entity) {
public static void setSavedStation(ItemStack stack, @Nullable Integer stationId, Planet planet) {
if (!GCYRItems.KEYCARD.isIn(stack)) return;
if (stationId == null) return;
stack.set(GCYRDataComponents.ID_CHIP, new IdChip(stationId, planet.orbitWorld().location(), null));
stack.set(GCYRDataComponents.ID_CHIP, new IdChip(stationId, Optional.of(planet.orbitWorld().location()), Optional.empty()));
}

@Nullable
Expand All @@ -52,7 +53,7 @@ public static Planet getSavedPlanet(ItemStack stack) {
if (idChip == null) {
return null;
}
return PlanetData.getPlanet(idChip.currentPlanet());
return PlanetData.getPlanet(idChip.currentPlanet().orElse(null));
}

//@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public static Planet getPlanetFromStack(ItemStack stack) {
if (!stack.has(GCYRDataComponents.ID_CHIP)) {
return null;
}
return PlanetData.getPlanetFromLevelOrOrbit(ResourceKey.create(Registries.DIMENSION, stack.get(GCYRDataComponents.ID_CHIP).currentPlanet())).orElse(null);
return PlanetData.getPlanetFromLevelOrOrbit(ResourceKey.create(Registries.DIMENSION,
stack.get(GCYRDataComponents.ID_CHIP).currentPlanet().orElse(null)))
.orElse(null);
}

public static void setSavedPosition(ItemStack stack, ResourceKey<Level> level, BlockPos pos) {
Expand All @@ -68,8 +70,9 @@ public static void setSavedPosition(ItemStack stack, ResourceKey<Level> level, B
public static GlobalPos getSavedPosition(ItemStack stack) {
if (!stack.has(GCYRDataComponents.ID_CHIP)) return null;
IdChip idChip = stack.get(GCYRDataComponents.ID_CHIP);
ResourceLocation currentLevel = idChip.currentPlanet();
return GlobalPos.of(ResourceKey.create(Registries.DIMENSION, currentLevel), idChip.currentPos());
if (idChip.currentPos().isEmpty()) return null;
ResourceLocation currentLevel = idChip.currentPlanet().orElse(null);
return GlobalPos.of(ResourceKey.create(Registries.DIMENSION, currentLevel), idChip.currentPos().get());
}

@Override
Expand All @@ -82,7 +85,7 @@ public void appendHoverText(ItemStack stack, @Nullable Item.TooltipContext level
if (currentStationId != null) {
tooltipComponents.add(Component.translatable("metaitem.planet_id_circuit.station", currentStationId));
}
BlockPos currentTargetPos = !stack.has(GCYRDataComponents.ID_CHIP) ? null : stack.get(GCYRDataComponents.ID_CHIP).currentPos();
BlockPos currentTargetPos = !stack.has(GCYRDataComponents.ID_CHIP) ? null : stack.get(GCYRDataComponents.ID_CHIP).currentPos().orElse(null);
if (currentTargetPos != null) {
tooltipComponents.add(Component.translatable("metaitem.planet_id_circuit.pos",
currentTargetPos.getX(), currentTargetPos.getY(), currentTargetPos.getZ()));
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/argent_matter/gcyr/common/item/component/IdChip.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package argent_matter.gcyr.common.item.component;

import argent_matter.gcyr.api.space.planet.Planet;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.latvian.mods.kubejs.util.ID;
import io.netty.buffer.ByteBuf;
import net.minecraft.core.BlockPos;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;

public record IdChip(int currentStation, ResourceLocation currentPlanet, BlockPos currentPos) {
import java.util.Optional;

public static final IdChip EMPTY = new IdChip(Integer.MIN_VALUE, null, null);
public record IdChip(int currentStation, @NotNull Optional<ResourceLocation> currentPlanet, @NotNull Optional<BlockPos> currentPos) {

public static final IdChip EMPTY = new IdChip(Integer.MIN_VALUE, Optional.empty(), Optional.empty());

public static final Codec<IdChip> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.optionalFieldOf("current_station", -1).forGetter(IdChip::currentStation),
ResourceLocation.CODEC.fieldOf("current_planet").forGetter(IdChip::currentPlanet),
BlockPos.CODEC.fieldOf("current_pos").forGetter(IdChip::currentPos)
ResourceLocation.CODEC.optionalFieldOf("current_planet").forGetter(IdChip::currentPlanet),
BlockPos.CODEC.optionalFieldOf("current_pos").forGetter(IdChip::currentPos)
).apply(instance, IdChip::new));

public static final StreamCodec<ByteBuf, IdChip> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.INT, IdChip::currentStation,
ResourceLocation.STREAM_CODEC, IdChip::currentPlanet,
BlockPos.STREAM_CODEC, IdChip::currentPos,
ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC), IdChip::currentPlanet,
ByteBufCodecs.optional(BlockPos.STREAM_CODEC), IdChip::currentPos,
IdChip::new);

public boolean hasStation() {
Expand All @@ -34,10 +34,12 @@ public boolean hasStation() {
public IdChip updateStation(int currentStation) {
return new IdChip(currentStation, currentPlanet, currentPos);
}

public IdChip updatePlanet(ResourceLocation currentPlanet) {
return new IdChip(currentStation, currentPlanet, currentPos);
return new IdChip(currentStation, Optional.ofNullable(currentPlanet), currentPos);
}

public IdChip updatePos(BlockPos currentPos) {
return new IdChip(currentStation, currentPlanet, currentPos);
return new IdChip(currentStation, currentPlanet, Optional.ofNullable(currentPos));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import argent_matter.gcyr.common.data.GCYRDataComponents;
import argent_matter.gcyr.common.data.GCYRItems;
import argent_matter.gcyr.common.entity.RocketEntity;
import argent_matter.gcyr.common.item.behaviour.PlanetIdChipBehaviour;
import argent_matter.gcyr.common.item.component.IdChip;
import argent_matter.gcyr.data.loader.PlanetData;
import lombok.AllArgsConstructor;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
Expand All @@ -15,6 +13,8 @@
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.network.handling.IPayloadContext;

import java.util.Optional;

@AllArgsConstructor
public class PacketSendSelectedDimension implements CustomPacketPayload {

Expand Down Expand Up @@ -47,7 +47,7 @@ public static void execute(PacketSendSelectedDimension packet, IPayloadContext h
if (packet.dimensionId != null) {
ItemStack handItem = handler.player().getItemInHand(handler.player().getUsedItemHand());
if (handItem.is(GCYRItems.ID_CHIP.get())) {
handItem.set(GCYRDataComponents.ID_CHIP, new IdChip(Integer.MIN_VALUE, packet.dimensionId, null));
handItem.set(GCYRDataComponents.ID_CHIP, new IdChip(Integer.MIN_VALUE, Optional.of(packet.dimensionId), Optional.empty()));
}
}
}
Expand Down

0 comments on commit 2110408

Please sign in to comment.