mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 18:09:28 +00:00
region file
This commit is contained in:
@@ -133,7 +133,9 @@ public interface WorldManager extends Reloadable {
|
||||
|
||||
void handleChunkUnload(Chunk bukkitChunk);
|
||||
|
||||
void saveChunkToFile(CustomCropsChunk chunk);
|
||||
void saveChunkToCachedRegion(CustomCropsChunk chunk);
|
||||
|
||||
void saveRegionToFile(CustomCropsRegion region);
|
||||
|
||||
void removeGlassAt(@NotNull SimpleLocation location);
|
||||
|
||||
@@ -142,4 +144,6 @@ public interface WorldManager extends Reloadable {
|
||||
CustomCropsBlock removeAnythingAt(SimpleLocation location);
|
||||
|
||||
AbstractWorldAdaptor getWorldAdaptor();
|
||||
|
||||
void saveInfoData(CustomCropsWorld customCropsWorld);
|
||||
}
|
||||
|
||||
@@ -56,4 +56,6 @@ public interface Pot extends KeyItem {
|
||||
String getBlockState(boolean water, FertilizerType type);
|
||||
|
||||
boolean isVanillaBlock();
|
||||
|
||||
boolean isWetPot(String id);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,14 @@ package net.momirealms.customcrops.api.mechanic.world;
|
||||
|
||||
import net.momirealms.customcrops.api.manager.WorldManager;
|
||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsChunk;
|
||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsRegion;
|
||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsWorld;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class AbstractWorldAdaptor implements Listener {
|
||||
|
||||
public static final int version = 1;
|
||||
public static final int chunkVersion = 1;
|
||||
public static final int regionVersion = 1;
|
||||
protected WorldManager worldManager;
|
||||
|
||||
public AbstractWorldAdaptor(WorldManager worldManager) {
|
||||
@@ -35,9 +37,13 @@ public abstract class AbstractWorldAdaptor implements Listener {
|
||||
|
||||
public abstract void init(CustomCropsWorld customCropsWorld);
|
||||
|
||||
public abstract void loadDynamicData(CustomCropsWorld customCropsWorld, ChunkCoordinate chunkCoordinate);
|
||||
public abstract void loadChunkData(CustomCropsWorld customCropsWorld, ChunkPos chunkPos);
|
||||
|
||||
public abstract void unloadDynamicData(CustomCropsWorld customCropsWorld, ChunkCoordinate chunkCoordinate);
|
||||
public abstract void unloadChunkData(CustomCropsWorld customCropsWorld, ChunkPos chunkPos);
|
||||
|
||||
public abstract void saveDynamicData(CustomCropsWorld ccWorld, CustomCropsChunk chunk);
|
||||
public abstract void saveChunkToCachedRegion(CustomCropsChunk customCropsChunk);
|
||||
|
||||
public abstract void saveRegion(CustomCropsRegion customCropsRegion);
|
||||
|
||||
public abstract void saveInfoData(CustomCropsWorld customCropsWorld);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class BlockPos {
|
||||
return new BlockPos(location.getX() % 16, location.getY(), location.getZ() % 16);
|
||||
}
|
||||
|
||||
public SimpleLocation getLocation(String world, ChunkCoordinate coordinate) {
|
||||
public SimpleLocation getLocation(String world, ChunkPos coordinate) {
|
||||
return new SimpleLocation(world, coordinate.x() * 16 + getX(), getY(), coordinate.z() * 16 + getZ());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,20 +20,18 @@ package net.momirealms.customcrops.api.mechanic.world;
|
||||
import org.bukkit.Chunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record ChunkCoordinate(int x, int z) {
|
||||
public record ChunkPos(int x, int z) {
|
||||
|
||||
private static final ChunkCoordinate empty = new ChunkCoordinate(0, 0);
|
||||
|
||||
public static ChunkCoordinate of(int x, int z) {
|
||||
return new ChunkCoordinate(x, z);
|
||||
public static ChunkPos of(int x, int z) {
|
||||
return new ChunkPos(x, z);
|
||||
}
|
||||
|
||||
public static ChunkCoordinate getByString(String coordinate) {
|
||||
public static ChunkPos getByString(String coordinate) {
|
||||
String[] split = coordinate.split(",", 2);
|
||||
try {
|
||||
int x = Integer.parseInt(split[0]);
|
||||
int z = Integer.parseInt(split[1]);
|
||||
return new ChunkCoordinate(x, z);
|
||||
return new ChunkPos(x, z);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
@@ -55,7 +53,7 @@ public record ChunkCoordinate(int x, int z) {
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final ChunkCoordinate other = (ChunkCoordinate) obj;
|
||||
final ChunkPos other = (ChunkPos) obj;
|
||||
if (this.x != other.x) {
|
||||
return false;
|
||||
}
|
||||
@@ -66,13 +64,22 @@ public record ChunkCoordinate(int x, int z) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ChunkCoordinate getByBukkitChunk(@NotNull Chunk chunk) {
|
||||
return new ChunkCoordinate(chunk.getX(), chunk.getZ());
|
||||
public RegionPos getRegionPos() {
|
||||
return RegionPos.getByChunkPos(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ChunkPos getByBukkitChunk(@NotNull Chunk chunk) {
|
||||
return new ChunkPos(chunk.getX(), chunk.getZ());
|
||||
}
|
||||
|
||||
public String getAsString() {
|
||||
return x + "," + z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChunkCoordinate{" +
|
||||
return "ChunkPos{" +
|
||||
"x=" + x +
|
||||
", z=" + z +
|
||||
'}';
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.api.mechanic.world;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record RegionPos(int x, int z) {
|
||||
|
||||
public static RegionPos of(int x, int z) {
|
||||
return new RegionPos(x, z);
|
||||
}
|
||||
|
||||
public static RegionPos getByString(String coordinate) {
|
||||
String[] split = coordinate.split(",", 2);
|
||||
try {
|
||||
int x = Integer.parseInt(split[0]);
|
||||
int z = Integer.parseInt(split[1]);
|
||||
return new RegionPos(x, z);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
long combined = (long) x << 32 | z;
|
||||
return Long.hashCode(combined);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final RegionPos other = (RegionPos) obj;
|
||||
if (this.x != other.x) {
|
||||
return false;
|
||||
}
|
||||
if (this.z != other.z) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static RegionPos getByBukkitChunk(@NotNull Chunk chunk) {
|
||||
int regionX = (int) Math.floor((double) chunk.getX() / 32.0);
|
||||
int regionZ = (int) Math.floor((double) chunk.getZ() / 32.0);
|
||||
return new RegionPos(regionX, regionZ);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static RegionPos getByChunkPos(@NotNull ChunkPos chunk) {
|
||||
int regionX = (int) Math.floor((double) chunk.x() / 32.0);
|
||||
int regionZ = (int) Math.floor((double) chunk.z() / 32.0);
|
||||
return new RegionPos(regionX, regionZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RegionPos{" +
|
||||
"x=" + x +
|
||||
", z=" + z +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -57,8 +57,8 @@ public class SimpleLocation {
|
||||
return worldName;
|
||||
}
|
||||
|
||||
public ChunkCoordinate getChunkCoordinate() {
|
||||
return new ChunkCoordinate(x >> 4, z >> 4);
|
||||
public ChunkPos getChunkCoordinate() {
|
||||
return new ChunkPos(x >> 4, z >> 4);
|
||||
}
|
||||
|
||||
public SimpleLocation add(int x, int y, int z) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import net.momirealms.customcrops.api.mechanic.item.Crop;
|
||||
import net.momirealms.customcrops.api.mechanic.item.Fertilizer;
|
||||
import net.momirealms.customcrops.api.mechanic.item.Pot;
|
||||
import net.momirealms.customcrops.api.mechanic.item.Sprinkler;
|
||||
import net.momirealms.customcrops.api.mechanic.world.ChunkCoordinate;
|
||||
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
|
||||
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
||||
import net.momirealms.customcrops.api.mechanic.world.SimpleLocation;
|
||||
|
||||
@@ -33,7 +33,9 @@ public interface CustomCropsChunk {
|
||||
|
||||
CustomCropsWorld getCustomCropsWorld();
|
||||
|
||||
ChunkCoordinate getChunkCoordinate();
|
||||
CustomCropsRegion getCustomCropsRegion();
|
||||
|
||||
ChunkPos getChunkPos();
|
||||
|
||||
void secondTimer();
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.api.mechanic.world.level;
|
||||
|
||||
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
|
||||
import net.momirealms.customcrops.api.mechanic.world.RegionPos;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface CustomCropsRegion {
|
||||
|
||||
CustomCropsWorld getCustomCropsWorld();
|
||||
|
||||
byte @Nullable [] getChunkBytes(ChunkPos pos);
|
||||
|
||||
RegionPos getRegionPos();
|
||||
|
||||
void removeChunk(ChunkPos pos);
|
||||
|
||||
void saveChunk(ChunkPos pos, byte[] data);
|
||||
|
||||
Map<ChunkPos, byte[]> getRegionDataToSave();
|
||||
|
||||
boolean canPrune();
|
||||
}
|
||||
@@ -21,8 +21,9 @@ import net.momirealms.customcrops.api.mechanic.item.Crop;
|
||||
import net.momirealms.customcrops.api.mechanic.item.Fertilizer;
|
||||
import net.momirealms.customcrops.api.mechanic.item.Pot;
|
||||
import net.momirealms.customcrops.api.mechanic.item.Sprinkler;
|
||||
import net.momirealms.customcrops.api.mechanic.world.ChunkCoordinate;
|
||||
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
|
||||
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
||||
import net.momirealms.customcrops.api.mechanic.world.RegionPos;
|
||||
import net.momirealms.customcrops.api.mechanic.world.SimpleLocation;
|
||||
import net.momirealms.customcrops.api.mechanic.world.season.Season;
|
||||
import org.bukkit.World;
|
||||
@@ -33,11 +34,15 @@ import java.util.Optional;
|
||||
|
||||
public interface CustomCropsWorld {
|
||||
|
||||
void save();
|
||||
|
||||
void startTick();
|
||||
|
||||
void cancelTick();
|
||||
|
||||
CustomCropsChunk removeLazyChunkAt(ChunkCoordinate chunkCoordinate);
|
||||
boolean isRegionLoaded(RegionPos regionPos);
|
||||
|
||||
CustomCropsChunk removeLazyChunkAt(ChunkPos chunkPos);
|
||||
|
||||
WorldSetting getWorldSetting();
|
||||
|
||||
@@ -49,13 +54,17 @@ public interface CustomCropsWorld {
|
||||
|
||||
String getWorldName();
|
||||
|
||||
boolean isChunkLoaded(ChunkCoordinate chunkCoordinate);
|
||||
boolean isChunkLoaded(ChunkPos chunkPos);
|
||||
|
||||
Optional<CustomCropsChunk> getChunkAt(ChunkCoordinate chunkCoordinate);
|
||||
Optional<CustomCropsChunk> getLoadedChunkAt(ChunkPos chunkPos);
|
||||
|
||||
Optional<CustomCropsRegion> getLoadedRegionAt(RegionPos regionPos);
|
||||
|
||||
void loadRegion(CustomCropsRegion region);
|
||||
|
||||
void loadChunk(CustomCropsChunk chunk);
|
||||
|
||||
void unloadChunk(ChunkCoordinate chunkCoordinate);
|
||||
void unloadChunk(ChunkPos chunkPos);
|
||||
|
||||
void setInfoData(WorldInfoData infoData);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user