mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-23 17:09:21 +00:00
change name to BlockPos
This commit is contained in:
@@ -19,20 +19,20 @@ package net.momirealms.customcrops.api.mechanic.world;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ChunkPos {
|
public class BlockPos {
|
||||||
|
|
||||||
private final int position;
|
private final int position;
|
||||||
|
|
||||||
public ChunkPos(int position) {
|
public BlockPos(int position) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChunkPos(int x, int y, int z) {
|
public BlockPos(int x, int y, int z) {
|
||||||
this.position = ((x & 0xF) << 28) | ((z & 0xF) << 24) | (y & 0xFFFFFF);
|
this.position = ((x & 0xF) << 28) | ((z & 0xF) << 24) | (y & 0xFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChunkPos getByLocation(SimpleLocation location) {
|
public static BlockPos getByLocation(SimpleLocation location) {
|
||||||
return new ChunkPos(location.getX() % 16, location.getY(), location.getZ() % 16);
|
return new BlockPos(location.getX() % 16, location.getY(), location.getZ() % 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleLocation getLocation(String world, ChunkCoordinate coordinate) {
|
public SimpleLocation getLocation(String world, ChunkCoordinate coordinate) {
|
||||||
@@ -67,8 +67,8 @@ public class ChunkPos {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
ChunkPos chunkPos = (ChunkPos) o;
|
BlockPos blockPos = (BlockPos) o;
|
||||||
return position == chunkPos.position;
|
return position == blockPos.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customcrops.api.mechanic.world.level;
|
package net.momirealms.customcrops.api.mechanic.world.level;
|
||||||
|
|
||||||
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
|
import net.momirealms.customcrops.api.mechanic.world.BlockPos;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -26,15 +26,15 @@ public interface CustomCropsSection {
|
|||||||
|
|
||||||
int getSectionID();
|
int getSectionID();
|
||||||
|
|
||||||
CustomCropsBlock getBlockAt(ChunkPos pos);
|
CustomCropsBlock getBlockAt(BlockPos pos);
|
||||||
|
|
||||||
CustomCropsBlock removeBlockAt(ChunkPos pos);
|
CustomCropsBlock removeBlockAt(BlockPos pos);
|
||||||
|
|
||||||
CustomCropsBlock addBlockAt(ChunkPos pos, CustomCropsBlock block);
|
CustomCropsBlock addBlockAt(BlockPos pos, CustomCropsBlock block);
|
||||||
|
|
||||||
boolean canPrune();
|
boolean canPrune();
|
||||||
|
|
||||||
CustomCropsBlock[] getBlocks();
|
CustomCropsBlock[] getBlocks();
|
||||||
|
|
||||||
Map<ChunkPos, CustomCropsBlock> getBlockMap();
|
Map<BlockPos, CustomCropsBlock> getBlockMap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import net.momirealms.customcrops.api.mechanic.item.Sprinkler;
|
|||||||
import net.momirealms.customcrops.api.mechanic.misc.CRotation;
|
import net.momirealms.customcrops.api.mechanic.misc.CRotation;
|
||||||
import net.momirealms.customcrops.api.mechanic.requirement.State;
|
import net.momirealms.customcrops.api.mechanic.requirement.State;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.ChunkCoordinate;
|
import net.momirealms.customcrops.api.mechanic.world.ChunkCoordinate;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
|
import net.momirealms.customcrops.api.mechanic.world.BlockPos;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.SimpleLocation;
|
import net.momirealms.customcrops.api.mechanic.world.SimpleLocation;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.level.*;
|
import net.momirealms.customcrops.api.mechanic.world.level.*;
|
||||||
@@ -47,7 +47,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
private final ChunkCoordinate chunkCoordinate;
|
private final ChunkCoordinate chunkCoordinate;
|
||||||
private final ConcurrentHashMap<Integer, CSection> loadedSections;
|
private final ConcurrentHashMap<Integer, CSection> loadedSections;
|
||||||
private final PriorityQueue<TickTask> queue;
|
private final PriorityQueue<TickTask> queue;
|
||||||
private final Set<ChunkPos> tickedBlocks;
|
private final Set<BlockPos> tickedBlocks;
|
||||||
private long lastLoadedTime;
|
private long lastLoadedTime;
|
||||||
private int loadedSeconds;
|
private int loadedSeconds;
|
||||||
private int unloadedSeconds;
|
private int unloadedSeconds;
|
||||||
@@ -69,7 +69,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
long lastLoadedTime,
|
long lastLoadedTime,
|
||||||
ConcurrentHashMap<Integer, CSection> loadedSections,
|
ConcurrentHashMap<Integer, CSection> loadedSections,
|
||||||
PriorityQueue<TickTask> queue,
|
PriorityQueue<TickTask> queue,
|
||||||
HashSet<ChunkPos> tickedBlocks
|
HashSet<BlockPos> tickedBlocks
|
||||||
) {
|
) {
|
||||||
this.cWorld = cWorld;
|
this.cWorld = cWorld;
|
||||||
this.chunkCoordinate = chunkCoordinate;
|
this.chunkCoordinate = chunkCoordinate;
|
||||||
@@ -124,7 +124,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
while (!queue.isEmpty() && queue.peek().getTime() <= loadedSeconds) {
|
while (!queue.isEmpty() && queue.peek().getTime() <= loadedSeconds) {
|
||||||
TickTask task = queue.poll();
|
TickTask task = queue.poll();
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
ChunkPos pos = task.getChunkPos();
|
BlockPos pos = task.getChunkPos();
|
||||||
CSection section = loadedSections.get(pos.getSectionID());
|
CSection section = loadedSections.get(pos.getSectionID());
|
||||||
if (section != null) {
|
if (section != null) {
|
||||||
CustomCropsBlock block = section.getBlockAt(pos);
|
CustomCropsBlock block = section.getBlockAt(pos);
|
||||||
@@ -161,7 +161,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
int x = random.nextInt(16);
|
int x = random.nextInt(16);
|
||||||
int y = random.nextInt(16) + baseY;
|
int y = random.nextInt(16) + baseY;
|
||||||
int z = random.nextInt(16);
|
int z = random.nextInt(16);
|
||||||
CustomCropsBlock block = section.getBlockAt(new ChunkPos(x,y,z));
|
CustomCropsBlock block = section.getBlockAt(new BlockPos(x,y,z));
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
switch (block.getType()) {
|
switch (block.getType()) {
|
||||||
case CROP -> {
|
case CROP -> {
|
||||||
@@ -199,7 +199,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
public void arrangeTasks(int unit) {
|
public void arrangeTasks(int unit) {
|
||||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||||
for (CustomCropsSection section : getSections()) {
|
for (CustomCropsSection section : getSections()) {
|
||||||
for (Map.Entry<ChunkPos, CustomCropsBlock> entry : section.getBlockMap().entrySet()) {
|
for (Map.Entry<BlockPos, CustomCropsBlock> entry : section.getBlockMap().entrySet()) {
|
||||||
this.queue.add(new TickTask(
|
this.queue.add(new TickTask(
|
||||||
random.nextInt(0, unit),
|
random.nextInt(0, unit),
|
||||||
entry.getKey()
|
entry.getKey()
|
||||||
@@ -209,7 +209,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tryCreatingTaskForNewBlock(ChunkPos pos) {
|
public void tryCreatingTaskForNewBlock(BlockPos pos) {
|
||||||
WorldSetting setting = cWorld.getWorldSetting();
|
WorldSetting setting = cWorld.getWorldSetting();
|
||||||
if (setting.isScheduledTick() && !tickedBlocks.contains(pos)) {
|
if (setting.isScheduledTick() && !tickedBlocks.contains(pos)) {
|
||||||
tickedBlocks.add(pos);
|
tickedBlocks.add(pos);
|
||||||
@@ -433,7 +433,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CustomCropsBlock removeBlockAt(SimpleLocation location) {
|
public CustomCropsBlock removeBlockAt(SimpleLocation location) {
|
||||||
ChunkPos pos = ChunkPos.getByLocation(location);
|
BlockPos pos = BlockPos.getByLocation(location);
|
||||||
CSection section = loadedSections.get(pos.getSectionID());
|
CSection section = loadedSections.get(pos.getSectionID());
|
||||||
if (section == null) return null;
|
if (section == null) return null;
|
||||||
return section.removeBlockAt(pos);
|
return section.removeBlockAt(pos);
|
||||||
@@ -441,7 +441,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CustomCropsBlock addBlockAt(CustomCropsBlock block, SimpleLocation location) {
|
public CustomCropsBlock addBlockAt(CustomCropsBlock block, SimpleLocation location) {
|
||||||
ChunkPos pos = ChunkPos.getByLocation(location);
|
BlockPos pos = BlockPos.getByLocation(location);
|
||||||
CSection section = loadedSections.get(pos.getSectionID());
|
CSection section = loadedSections.get(pos.getSectionID());
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
section = new CSection(pos.getSectionID());
|
section = new CSection(pos.getSectionID());
|
||||||
@@ -453,7 +453,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<CustomCropsBlock> getBlockAt(SimpleLocation location) {
|
public Optional<CustomCropsBlock> getBlockAt(SimpleLocation location) {
|
||||||
ChunkPos pos = ChunkPos.getByLocation(location);
|
BlockPos pos = BlockPos.getByLocation(location);
|
||||||
CSection section = loadedSections.get(pos.getSectionID());
|
CSection section = loadedSections.get(pos.getSectionID());
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@@ -539,7 +539,7 @@ public class CChunk implements CustomCropsChunk {
|
|||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ChunkPos> getTickedBlocks() {
|
public Set<BlockPos> getTickedBlocks() {
|
||||||
return tickedBlocks;
|
return tickedBlocks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customcrops.mechanic.world;
|
package net.momirealms.customcrops.mechanic.world;
|
||||||
|
|
||||||
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
|
import net.momirealms.customcrops.api.mechanic.world.BlockPos;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsSection;
|
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsSection;
|
||||||
|
|
||||||
@@ -27,14 +27,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
public class CSection implements CustomCropsSection {
|
public class CSection implements CustomCropsSection {
|
||||||
|
|
||||||
private final int sectionID;
|
private final int sectionID;
|
||||||
private final ConcurrentHashMap<ChunkPos, CustomCropsBlock> blocks;
|
private final ConcurrentHashMap<BlockPos, CustomCropsBlock> blocks;
|
||||||
|
|
||||||
public CSection(int sectionID) {
|
public CSection(int sectionID) {
|
||||||
this.sectionID = sectionID;
|
this.sectionID = sectionID;
|
||||||
this.blocks = new ConcurrentHashMap<>();
|
this.blocks = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CSection(int sectionID, ConcurrentHashMap<ChunkPos, CustomCropsBlock> blocks) {
|
public CSection(int sectionID, ConcurrentHashMap<BlockPos, CustomCropsBlock> blocks) {
|
||||||
this.blocks = blocks;
|
this.blocks = blocks;
|
||||||
this.sectionID = sectionID;
|
this.sectionID = sectionID;
|
||||||
}
|
}
|
||||||
@@ -45,17 +45,17 @@ public class CSection implements CustomCropsSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CustomCropsBlock getBlockAt(ChunkPos pos) {
|
public CustomCropsBlock getBlockAt(BlockPos pos) {
|
||||||
return blocks.get(pos);
|
return blocks.get(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CustomCropsBlock removeBlockAt(ChunkPos pos) {
|
public CustomCropsBlock removeBlockAt(BlockPos pos) {
|
||||||
return blocks.remove(pos);
|
return blocks.remove(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CustomCropsBlock addBlockAt(ChunkPos pos, CustomCropsBlock block) {
|
public CustomCropsBlock addBlockAt(BlockPos pos, CustomCropsBlock block) {
|
||||||
return blocks.put(pos, block);
|
return blocks.put(pos, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public class CSection implements CustomCropsSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ChunkPos, CustomCropsBlock> getBlockMap() {
|
public Map<BlockPos, CustomCropsBlock> getBlockMap() {
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import com.google.gson.Gson;
|
|||||||
import net.momirealms.customcrops.api.CustomCropsPlugin;
|
import net.momirealms.customcrops.api.CustomCropsPlugin;
|
||||||
import net.momirealms.customcrops.api.manager.ConfigManager;
|
import net.momirealms.customcrops.api.manager.ConfigManager;
|
||||||
import net.momirealms.customcrops.api.manager.WorldManager;
|
import net.momirealms.customcrops.api.manager.WorldManager;
|
||||||
import net.momirealms.customcrops.api.mechanic.item.ItemType;
|
|
||||||
import net.momirealms.customcrops.api.mechanic.world.*;
|
import net.momirealms.customcrops.api.mechanic.world.*;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsChunk;
|
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsChunk;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsWorld;
|
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsWorld;
|
||||||
@@ -241,21 +240,21 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
|||||||
PriorityQueue<TickTask> queue = new PriorityQueue<>(Math.max(11, tasksSize));
|
PriorityQueue<TickTask> queue = new PriorityQueue<>(Math.max(11, tasksSize));
|
||||||
for (int i = 0; i < tasksSize; i++) {
|
for (int i = 0; i < tasksSize; i++) {
|
||||||
int time = chunkData.readInt();
|
int time = chunkData.readInt();
|
||||||
ChunkPos pos = new ChunkPos(chunkData.readInt());
|
BlockPos pos = new BlockPos(chunkData.readInt());
|
||||||
queue.add(new TickTask(time, pos));
|
queue.add(new TickTask(time, pos));
|
||||||
}
|
}
|
||||||
// read ticked blocks
|
// read ticked blocks
|
||||||
int tickedSize = chunkData.readInt();
|
int tickedSize = chunkData.readInt();
|
||||||
HashSet<ChunkPos> tickedSet = new HashSet<>(Math.max(11, tickedSize));
|
HashSet<BlockPos> tickedSet = new HashSet<>(Math.max(11, tickedSize));
|
||||||
for (int i = 0; i < tickedSize; i++) {
|
for (int i = 0; i < tickedSize; i++) {
|
||||||
tickedSet.add(new ChunkPos(chunkData.readInt()));
|
tickedSet.add(new BlockPos(chunkData.readInt()));
|
||||||
}
|
}
|
||||||
// read block data
|
// read block data
|
||||||
ConcurrentHashMap<Integer, CSection> sectionMap = new ConcurrentHashMap<>();
|
ConcurrentHashMap<Integer, CSection> sectionMap = new ConcurrentHashMap<>();
|
||||||
int sections = chunkData.readInt();
|
int sections = chunkData.readInt();
|
||||||
// read sections
|
// read sections
|
||||||
for (int i = 0; i < sections; i++) {
|
for (int i = 0; i < sections; i++) {
|
||||||
ConcurrentHashMap<ChunkPos, CustomCropsBlock> blockMap = new ConcurrentHashMap<>();
|
ConcurrentHashMap<BlockPos, CustomCropsBlock> blockMap = new ConcurrentHashMap<>();
|
||||||
int sectionID = chunkData.readInt();
|
int sectionID = chunkData.readInt();
|
||||||
byte[] sectionBytes = new byte[chunkData.readInt()];
|
byte[] sectionBytes = new byte[chunkData.readInt()];
|
||||||
chunkData.read(sectionBytes);
|
chunkData.read(sectionBytes);
|
||||||
@@ -271,32 +270,32 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case "CROP" -> {
|
case "CROP" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemoryCrop(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemoryCrop(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "POT" -> {
|
case "POT" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemoryPot(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemoryPot(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "SPRINKLER" -> {
|
case "SPRINKLER" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemorySprinkler(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemorySprinkler(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "SCARECROW" -> {
|
case "SCARECROW" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemoryScarecrow(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemoryScarecrow(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "GREENHOUSE" -> {
|
case "GREENHOUSE" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemoryGlass(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemoryGlass(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -375,10 +374,10 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] tickedBlocksToArray(Set<ChunkPos> set) {
|
private int[] tickedBlocksToArray(Set<BlockPos> set) {
|
||||||
int[] ticked = new int[set.size()];
|
int[] ticked = new int[set.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (ChunkPos pos : set) {
|
for (BlockPos pos : set) {
|
||||||
ticked[i] = pos.getPosition();
|
ticked[i] = pos.getPosition();
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -401,11 +400,11 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
|||||||
return new SerializableSection(section.getSectionID(), toCompoundTags(section.getBlockMap()));
|
return new SerializableSection(section.getSectionID(), toCompoundTags(section.getBlockMap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CompoundTag> toCompoundTags(Map<ChunkPos, CustomCropsBlock> blocks) {
|
private List<CompoundTag> toCompoundTags(Map<BlockPos, CustomCropsBlock> blocks) {
|
||||||
ArrayList<CompoundTag> tags = new ArrayList<>(blocks.size());
|
ArrayList<CompoundTag> tags = new ArrayList<>(blocks.size());
|
||||||
Map<CustomCropsBlock, List<Integer>> blockToPosMap = new HashMap<>();
|
Map<CustomCropsBlock, List<Integer>> blockToPosMap = new HashMap<>();
|
||||||
for (Map.Entry<ChunkPos, CustomCropsBlock> entry : blocks.entrySet()) {
|
for (Map.Entry<BlockPos, CustomCropsBlock> entry : blocks.entrySet()) {
|
||||||
ChunkPos coordinate = entry.getKey();
|
BlockPos coordinate = entry.getKey();
|
||||||
CustomCropsBlock block = entry.getValue();
|
CustomCropsBlock block = entry.getValue();
|
||||||
List<Integer> coordinates = blockToPosMap.computeIfAbsent(block, k -> new ArrayList<>());
|
List<Integer> coordinates = blockToPosMap.computeIfAbsent(block, k -> new ArrayList<>());
|
||||||
coordinates.add(coordinate.getPosition());
|
coordinates.add(coordinate.getPosition());
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import com.infernalsuite.aswm.api.world.SlimeWorld;
|
|||||||
import net.momirealms.customcrops.api.CustomCropsPlugin;
|
import net.momirealms.customcrops.api.CustomCropsPlugin;
|
||||||
import net.momirealms.customcrops.api.manager.WorldManager;
|
import net.momirealms.customcrops.api.manager.WorldManager;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.ChunkCoordinate;
|
import net.momirealms.customcrops.api.mechanic.world.ChunkCoordinate;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
|
import net.momirealms.customcrops.api.mechanic.world.BlockPos;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsChunk;
|
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsChunk;
|
||||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsWorld;
|
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsWorld;
|
||||||
@@ -194,13 +194,13 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor {
|
|||||||
|
|
||||||
PriorityQueue<TickTask> queue = new PriorityQueue<>(Math.max(11, queued.length / 2));
|
PriorityQueue<TickTask> queue = new PriorityQueue<>(Math.max(11, queued.length / 2));
|
||||||
for (int i = 0, size = queued.length / 2; i < size; i++) {
|
for (int i = 0, size = queued.length / 2; i < size; i++) {
|
||||||
ChunkPos pos = new ChunkPos(queued[2*i+1]);
|
BlockPos pos = new BlockPos(queued[2*i+1]);
|
||||||
queue.add(new TickTask(queued[2*i], pos));
|
queue.add(new TickTask(queued[2*i], pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<ChunkPos> tickedSet = new HashSet<>(Math.max(11, ticked.length));
|
HashSet<BlockPos> tickedSet = new HashSet<>(Math.max(11, ticked.length));
|
||||||
for (int tick : ticked) {
|
for (int tick : ticked) {
|
||||||
tickedSet.add(new ChunkPos(tick));
|
tickedSet.add(new BlockPos(tick));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConcurrentHashMap<Integer, CSection> sectionMap = new ConcurrentHashMap<>();
|
ConcurrentHashMap<Integer, CSection> sectionMap = new ConcurrentHashMap<>();
|
||||||
@@ -208,7 +208,7 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor {
|
|||||||
for (Map.Entry<String, Tag<?>> entry : sectionCompoundMap.entrySet()) {
|
for (Map.Entry<String, Tag<?>> entry : sectionCompoundMap.entrySet()) {
|
||||||
if (entry.getValue() instanceof ListTag<?> listTag) {
|
if (entry.getValue() instanceof ListTag<?> listTag) {
|
||||||
int id = Integer.parseInt(entry.getKey());
|
int id = Integer.parseInt(entry.getKey());
|
||||||
ConcurrentHashMap<ChunkPos, CustomCropsBlock> blockMap = new ConcurrentHashMap<>();
|
ConcurrentHashMap<BlockPos, CustomCropsBlock> blockMap = new ConcurrentHashMap<>();
|
||||||
ListTag<CompoundTag> blocks = (ListTag<CompoundTag>) listTag;
|
ListTag<CompoundTag> blocks = (ListTag<CompoundTag>) listTag;
|
||||||
for (CompoundTag blockTag : blocks.getValue()) {
|
for (CompoundTag blockTag : blocks.getValue()) {
|
||||||
CompoundMap block = blockTag.getValue();
|
CompoundMap block = blockTag.getValue();
|
||||||
@@ -217,32 +217,32 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case "CROP" -> {
|
case "CROP" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemoryCrop(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemoryCrop(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "POT" -> {
|
case "POT" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemoryPot(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemoryPot(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "SPRINKLER" -> {
|
case "SPRINKLER" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemorySprinkler(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemorySprinkler(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "SCARECROW" -> {
|
case "SCARECROW" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemoryScarecrow(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemoryScarecrow(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "GLASS" -> {
|
case "GLASS" -> {
|
||||||
for (int pos : (int[]) block.get("pos").getValue()) {
|
for (int pos : (int[]) block.get("pos").getValue()) {
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
BlockPos blockPos = new BlockPos(pos);
|
||||||
blockMap.put(chunkPos, new MemoryGlass(chunkPos.getLocation(world, coordinate), new CompoundMap(data)));
|
blockMap.put(blockPos, new MemoryGlass(blockPos.getLocation(world, coordinate), new CompoundMap(data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,24 +17,24 @@
|
|||||||
|
|
||||||
package net.momirealms.customcrops.scheduler.task;
|
package net.momirealms.customcrops.scheduler.task;
|
||||||
|
|
||||||
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
|
import net.momirealms.customcrops.api.mechanic.world.BlockPos;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class TickTask implements Comparable<TickTask> {
|
public class TickTask implements Comparable<TickTask> {
|
||||||
|
|
||||||
private static int taskID;
|
private static int taskID;
|
||||||
private final int time;
|
private final int time;
|
||||||
private final ChunkPos chunkPos;
|
private final BlockPos blockPos;
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
public TickTask(int time, ChunkPos chunkPos) {
|
public TickTask(int time, BlockPos blockPos) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.chunkPos = chunkPos;
|
this.blockPos = blockPos;
|
||||||
this.id = taskID++;
|
this.id = taskID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChunkPos getChunkPos() {
|
public BlockPos getChunkPos() {
|
||||||
return chunkPos;
|
return blockPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTime() {
|
public int getTime() {
|
||||||
|
|||||||
Reference in New Issue
Block a user