mirror of
https://github.com/XevianLight/Aphelion.git
synced 2026-05-11 01:50:56 +01:00
More EnvironmentSavedData stuff
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
package net.xevianlight.aphelion.core;
|
||||
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class KeyVariables {
|
||||
|
||||
public static final Map<UUID, Boolean> KEY_UP = new HashMap<>();
|
||||
public static final Map<UUID, Boolean> KEY_DOWN = new HashMap<>();
|
||||
public static final Map<UUID, Boolean> KEY_RIGHT = new HashMap<>();
|
||||
public static final Map<UUID, Boolean> KEY_LEFT = new HashMap<>();
|
||||
public static final Map<UUID, Boolean> KEY_JUMP = new HashMap<>();
|
||||
public static final Map<UUID, Boolean> KEY_TABLET = new HashMap<>();
|
||||
|
||||
public static boolean isHoldingUp(Player player) {
|
||||
return player != null && KEY_UP.getOrDefault(player.getUUID(), false);
|
||||
}
|
||||
|
||||
public static boolean isHoldingDown(Player player) {
|
||||
return player != null && KEY_DOWN.getOrDefault(player.getUUID(), false);
|
||||
}
|
||||
|
||||
public static boolean isHoldingRight(Player player) {
|
||||
return player != null && KEY_RIGHT.getOrDefault(player.getUUID(), false);
|
||||
}
|
||||
|
||||
public static boolean isHoldingLeft(Player player) {
|
||||
return player != null && KEY_LEFT.getOrDefault(player.getUUID(), false);
|
||||
}
|
||||
|
||||
public static boolean isHoldingJump(Player player) {
|
||||
return player != null && KEY_JUMP.getOrDefault(player.getUUID(), false);
|
||||
}
|
||||
|
||||
public static boolean getHoldingTabletPress(Player player) {
|
||||
return player != null && KEY_TABLET.getOrDefault(player.getUUID(), false);
|
||||
}
|
||||
|
||||
|
||||
public static Map<KeyMapping, String> getKey(Minecraft minecraft) {
|
||||
Map<KeyMapping, String> key = new HashMap<>();
|
||||
key.put(minecraft.options.keyUp, "key_up");
|
||||
key.put(minecraft.options.keyDown, "key_down");
|
||||
key.put(minecraft.options.keyRight, "key_right");
|
||||
key.put(minecraft.options.keyLeft, "key_left");
|
||||
key.put(minecraft.options.keyJump, "key_jump");
|
||||
return key;
|
||||
}
|
||||
|
||||
public static void setKeyVariable(String key, UUID uuid, Boolean bool) {
|
||||
switch (key) {
|
||||
case "key_up":
|
||||
KEY_UP.put(uuid, bool);
|
||||
case "key_down":
|
||||
KEY_DOWN.put(uuid, bool);
|
||||
case "key_right":
|
||||
KEY_RIGHT.put(uuid, bool);
|
||||
case "key_left":
|
||||
KEY_LEFT.put(uuid, bool);
|
||||
case "key_jump":
|
||||
KEY_JUMP.put(uuid, bool);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,15 @@ import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.saveddata.SavedData;
|
||||
import net.xevianlight.aphelion.Aphelion;
|
||||
import net.xevianlight.aphelion.core.saveddata.types.EnvironmentData;
|
||||
import net.xevianlight.aphelion.planet.Planet;
|
||||
import net.xevianlight.aphelion.planet.PlanetCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -69,48 +74,82 @@ public class EnvironmentSavedData extends SavedData {
|
||||
return data;
|
||||
}
|
||||
|
||||
public EnvironmentData getDataForPosition(BlockPos pos) {
|
||||
int packed = envData.getOrDefault(pos.asLong(), EnvironmentData.DEFAULT_PACKED);
|
||||
public EnvironmentData getDataForPosition(Level level, BlockPos pos) {
|
||||
Planet planet = PlanetCache.getByDimensionOrNull(level.dimension());
|
||||
int packedDefault;
|
||||
|
||||
if (planet == null) {
|
||||
packedDefault = EnvironmentData.DEFAULT_PACKED;
|
||||
} else {
|
||||
EnvironmentData planetData = new EnvironmentData(planet.oxygen(), EnvironmentData.DEFAULT_TEMPERATURE, (short) planet.gravity());
|
||||
packedDefault = planetData.pack();
|
||||
}
|
||||
int packed = envData.getOrDefault(pos.asLong(),packedDefault);
|
||||
return EnvironmentData.unpack(packed);
|
||||
}
|
||||
|
||||
public void setDataForPosition(BlockPos pos, EnvironmentData data) {
|
||||
public void setDataForPosition(Level level, BlockPos pos, EnvironmentData data) {
|
||||
putOrRemove(pos.asLong(), data.pack());
|
||||
}
|
||||
|
||||
public boolean hasOxygen(BlockPos pos) {
|
||||
var data = getDataForPosition(pos);
|
||||
public boolean hasOxygen(Level level, BlockPos pos) {
|
||||
var data = getDataForPosition(level, pos);
|
||||
return data.hasOxygen();
|
||||
}
|
||||
|
||||
public void setOxygen(BlockPos pos, boolean value) {
|
||||
var data = getDataForPosition(pos);
|
||||
public void setOxygen(Level level, BlockPos pos, boolean value) {
|
||||
var data = getDataForPosition(level, pos);
|
||||
data.setOxygen(value);
|
||||
Aphelion.LOGGER.info("Set oxygen for {} to {}", pos, value);
|
||||
putOrRemove(pos.asLong(), data.pack());
|
||||
}
|
||||
|
||||
public float getGravity(BlockPos pos) {
|
||||
var data = getDataForPosition(pos);
|
||||
public void setOxygen(Level level, Collection<BlockPos> positions, boolean value) {
|
||||
for (BlockPos pos : positions) {
|
||||
setOxygen(level, pos, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void resetOxygen(Level level, BlockPos pos) {
|
||||
var data = getDataForPosition(level, pos);
|
||||
data.setOxygen(EnvironmentData.DEFAULT_OXYGEN);
|
||||
putOrRemove(pos.asLong(), data.pack());
|
||||
}
|
||||
|
||||
public float getGravity(Level level, BlockPos pos) {
|
||||
var data = getDataForPosition(level, pos);
|
||||
return data.getGravity();
|
||||
}
|
||||
|
||||
public void setGravity(BlockPos pos, float value) {
|
||||
var data = getDataForPosition(pos);
|
||||
public void setGravity(Level level, BlockPos pos, float value) {
|
||||
var data = getDataForPosition(level, pos);
|
||||
data.setGravity(value);
|
||||
putOrRemove(pos.asLong(), data.pack());
|
||||
}
|
||||
|
||||
public short getTemperature(BlockPos pos) {
|
||||
var data = getDataForPosition(pos);
|
||||
public void setGravity(Level level, Collection<BlockPos> positions, float value) {
|
||||
for (BlockPos pos : positions) {
|
||||
setGravity(level, pos, value);
|
||||
}
|
||||
}
|
||||
|
||||
public short getTemperature(Level level, BlockPos pos) {
|
||||
var data = getDataForPosition(level, pos);
|
||||
return data.getTemperature();
|
||||
}
|
||||
|
||||
public void setTemperature(BlockPos pos, short value) {
|
||||
var data = getDataForPosition(pos);
|
||||
public void setTemperature(Level level, BlockPos pos, short value) {
|
||||
var data = getDataForPosition(level, pos);
|
||||
data.setTemperature(value);
|
||||
putOrRemove(pos.asLong(), data.pack());
|
||||
}
|
||||
|
||||
public void setTemperature(Level level, Collection<BlockPos> positions, short value) {
|
||||
for (BlockPos pos : positions) {
|
||||
setTemperature(level, pos, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void putOrRemove(long key, int packed) {
|
||||
if (packed == EnvironmentData.DEFAULT_PACKED) {
|
||||
envData.remove(key);
|
||||
@@ -126,4 +165,4 @@ public class EnvironmentSavedData extends SavedData {
|
||||
NAME
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,6 @@ public record StarSystem(
|
||||
int temp
|
||||
) {
|
||||
public static final Codec<StarSystem> CODEC = RecordCodecBuilder.create(inst -> inst.group(
|
||||
Codec.INT.fieldOf("dimension").forGetter(StarSystem::temp)
|
||||
Codec.INT.fieldOf("temp").forGetter(StarSystem::temp)
|
||||
).apply(inst, StarSystem::new));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user