2026.04.02-51731a32a
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package com.hypixel.hytale.assetstore;
|
||||
|
||||
import com.hypixel.hytale.common.plugin.Mod;
|
||||
import com.hypixel.hytale.common.plugin.PluginManifest;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Path;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class AssetPack {
|
||||
public class AssetPack implements Mod {
|
||||
@Nonnull
|
||||
private final String name;
|
||||
@Nonnull
|
||||
@@ -41,6 +42,7 @@ public class AssetPack {
|
||||
return this.fileSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginManifest getManifest() {
|
||||
return this.manifest;
|
||||
}
|
||||
@@ -53,6 +55,11 @@ public class AssetPack {
|
||||
return this.packLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCoreMod() {
|
||||
return "Hytale:Hytale".equals(this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -315,6 +315,10 @@ public abstract class AssetStore<K, T extends JsonAssetWithMap<K, M>, M extends
|
||||
final ArrayList<Path> files = new ArrayList<>();
|
||||
Set<FileVisitOption> optionsSet = Set.of();
|
||||
Files.walkFileTree(assetsPath, optionsSet, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
|
||||
{
|
||||
Objects.requireNonNull(AssetStore.this);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public FileVisitResult visitFile(@Nonnull Path file, @Nonnull BasicFileAttributes attrs) throws IOException {
|
||||
if (attrs.isRegularFile() && file.toString().endsWith(AssetStore.this.extension)) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.hypixel.hytale.builtin.adventure.farming.interactions.UseCoopInteract
|
||||
import com.hypixel.hytale.builtin.adventure.farming.interactions.UseWateringCanInteraction;
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.CoopBlock;
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.FarmingBlock;
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.FarmingBlockState;
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.TilledSoilBlock;
|
||||
import com.hypixel.hytale.builtin.tagset.config.NPCGroup;
|
||||
import com.hypixel.hytale.component.ComponentRegistryProxy;
|
||||
@@ -51,7 +50,6 @@ public class FarmingPlugin extends JavaPlugin {
|
||||
protected static FarmingPlugin instance;
|
||||
private ComponentType<ChunkStore, TilledSoilBlock> tiledSoilBlockComponentType;
|
||||
private ComponentType<ChunkStore, FarmingBlock> farmingBlockComponentType;
|
||||
private ComponentType<ChunkStore, FarmingBlockState> farmingBlockStateComponentType;
|
||||
private ComponentType<ChunkStore, CoopBlock> coopBlockStateComponentType;
|
||||
private ComponentType<EntityStore, CoopResidentComponent> coopResidentComponentType;
|
||||
|
||||
@@ -106,7 +104,6 @@ public class FarmingPlugin extends JavaPlugin {
|
||||
this.getCodecRegistry(SpreadGrowthBehaviour.CODEC).register("Directional", DirectionalGrowthBehaviour.class, DirectionalGrowthBehaviour.CODEC);
|
||||
this.tiledSoilBlockComponentType = chunkStoreRegistry.registerComponent(TilledSoilBlock.class, "TilledSoil", TilledSoilBlock.CODEC);
|
||||
this.farmingBlockComponentType = chunkStoreRegistry.registerComponent(FarmingBlock.class, "FarmingBlock", FarmingBlock.CODEC);
|
||||
this.farmingBlockStateComponentType = chunkStoreRegistry.registerComponent(FarmingBlockState.class, "Farming", FarmingBlockState.CODEC);
|
||||
this.coopBlockStateComponentType = chunkStoreRegistry.registerComponent(CoopBlock.class, "Coop", CoopBlock.CODEC);
|
||||
this.coopResidentComponentType = entityStoreRegistry.registerComponent(CoopResidentComponent.class, "CoopResident", CoopResidentComponent.CODEC);
|
||||
ComponentType<ChunkStore, BlockModule.BlockStateInfo> blockStateInfoComponentType = BlockModule.BlockStateInfo.getComponentType();
|
||||
@@ -124,7 +121,6 @@ public class FarmingPlugin extends JavaPlugin {
|
||||
this.coopBlockStateComponentType
|
||||
)
|
||||
);
|
||||
chunkStoreRegistry.registerSystem(new FarmingSystems.MigrateFarming());
|
||||
chunkStoreRegistry.registerSystem(new FarmingSystems.OnCoopAdded(blockStateInfoComponentType, this.coopBlockStateComponentType));
|
||||
entityStoreRegistry.registerSystem(new FarmingSystems.CoopResidentEntitySystem(this.coopResidentComponentType, uuidComponentType));
|
||||
entityStoreRegistry.registerSystem(new FarmingSystems.CoopResidentTicking(this.coopResidentComponentType));
|
||||
@@ -154,10 +150,6 @@ public class FarmingPlugin extends JavaPlugin {
|
||||
return this.farmingBlockComponentType;
|
||||
}
|
||||
|
||||
public ComponentType<ChunkStore, FarmingBlockState> getFarmingBlockStateComponentType() {
|
||||
return this.farmingBlockStateComponentType;
|
||||
}
|
||||
|
||||
public ComponentType<ChunkStore, CoopBlock> getCoopBlockStateComponentType() {
|
||||
return this.coopBlockStateComponentType;
|
||||
}
|
||||
|
||||
@@ -6,13 +6,11 @@ import com.hypixel.hytale.builtin.adventure.farming.config.stages.BlockStateFarm
|
||||
import com.hypixel.hytale.builtin.adventure.farming.config.stages.BlockTypeFarmingStageData;
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.CoopBlock;
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.FarmingBlock;
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.FarmingBlockState;
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.TilledSoilBlock;
|
||||
import com.hypixel.hytale.component.AddReason;
|
||||
import com.hypixel.hytale.component.ArchetypeChunk;
|
||||
import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.component.Holder;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.RemoveReason;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
@@ -20,8 +18,7 @@ import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.RefSystem;
|
||||
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Vector3iUtil;
|
||||
import com.hypixel.hytale.protocol.Rangef;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktick.BlockTickStrategy;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
@@ -47,6 +44,8 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class FarmingSystems {
|
||||
private static boolean hasCropAbove(@Nonnull BlockChunk blockChunk, int x, int y, int z) {
|
||||
@@ -202,30 +201,6 @@ public class FarmingSystems {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public static class MigrateFarming extends BlockModule.MigrationSystem {
|
||||
@Override
|
||||
public void onEntityAdd(@Nonnull Holder<ChunkStore> holder, @Nonnull AddReason reason, @Nonnull Store<ChunkStore> store) {
|
||||
FarmingBlockState oldState = holder.getComponent(FarmingPlugin.get().getFarmingBlockStateComponentType());
|
||||
FarmingBlock farming = new FarmingBlock();
|
||||
farming.setGrowthProgress(oldState.getCurrentFarmingStageIndex());
|
||||
farming.setCurrentStageSet(oldState.getCurrentFarmingStageSetName());
|
||||
farming.setSpreadRate(oldState.getSpreadRate());
|
||||
holder.putComponent(FarmingBlock.getComponentType(), farming);
|
||||
holder.removeComponent(FarmingPlugin.get().getFarmingBlockStateComponentType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityRemoved(@Nonnull Holder<ChunkStore> holder, @Nonnull RemoveReason reason, @Nonnull Store<ChunkStore> store) {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Query<ChunkStore> getQuery() {
|
||||
return FarmingPlugin.get().getFarmingBlockStateComponentType();
|
||||
}
|
||||
}
|
||||
|
||||
public static class OnCoopAdded extends RefSystem<ChunkStore> {
|
||||
@Nonnull
|
||||
private final ComponentType<ChunkStore, BlockModule.BlockStateInfo> blockStateInfoComponentType;
|
||||
@@ -519,6 +494,7 @@ public class FarmingSystems {
|
||||
int blockId = blockSection.get(x, y, z);
|
||||
BlockType blockType = BlockType.getAssetMap().getAsset(blockId);
|
||||
FarmingSystems.updateSoilDecayTime(commandBuffer, soilComponent, blockType);
|
||||
decayTime = soilComponent.getDecayTime();
|
||||
}
|
||||
|
||||
if (decayTime == null) {
|
||||
@@ -760,13 +736,13 @@ public class FarmingSystems {
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(worldX, worldZ);
|
||||
WorldChunk chunk = world.getChunkIfInMemory(chunkIndex);
|
||||
double blockRotation = chunk.getRotation(worldX, worldY, worldZ).yaw().getRadians();
|
||||
Vector3d spawnOffset = new Vector3d().assign(coopAsset.getResidentSpawnOffset()).rotateY((float)blockRotation);
|
||||
Vector3d spawnOffset = new Vector3d().set(coopAsset.getResidentSpawnOffset()).rotateY((float)blockRotation);
|
||||
Vector3i coopLocation = new Vector3i(worldX, worldY, worldZ);
|
||||
boolean tryCapture = coopAsset.getCaptureWildNPCsInRange();
|
||||
float captureRange = coopAsset.getWildCaptureRadius();
|
||||
if (tryCapture && captureRange >= 0.0F) {
|
||||
world.execute(() -> {
|
||||
for (Ref<EntityStore> entity : TargetUtil.getAllEntitiesInSphere(coopLocation.toVector3d(), captureRange, store)) {
|
||||
for (Ref<EntityStore> entity : TargetUtil.getAllEntitiesInSphere(Vector3iUtil.toVector3d(coopLocation), captureRange, store)) {
|
||||
coopBlock.tryPutWildResidentFromWild(store, entity, worldTimeResource, coopLocation);
|
||||
}
|
||||
});
|
||||
@@ -776,7 +752,7 @@ public class FarmingSystems {
|
||||
world.execute(() -> coopBlock.ensureNoResidentsInWorld(store));
|
||||
} else {
|
||||
world.execute(() -> {
|
||||
coopBlock.ensureSpawnResidentsInWorld(world, store, coopLocation.toVector3d(), spawnOffset);
|
||||
coopBlock.ensureSpawnResidentsInWorld(world, store, Vector3iUtil.toVector3d(coopLocation), spawnOffset);
|
||||
coopBlock.generateProduceToInventory(worldTimeResource);
|
||||
Vector3i blockPos = new Vector3i(worldX, worldY, worldZ);
|
||||
BlockType currentBlockType = world.getBlockType(blockPos);
|
||||
|
||||
@@ -10,9 +10,8 @@ import com.hypixel.hytale.component.RemoveReason;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.util.HashUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.Rangef;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockGathering;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.HarvestingDropType;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.farming.FarmingData;
|
||||
@@ -38,11 +37,23 @@ import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class FarmingUtil {
|
||||
private static final int MAX_SECONDS_BETWEEN_TICKS = 15;
|
||||
private static final int BETWEEN_RANDOM = 10;
|
||||
|
||||
private static long cappedTickNanos(long desiredNanos, @Nonnull World world, @Nonnull FarmingBlock farmingBlock, int worldX, int worldY, int worldZ) {
|
||||
long maxNanos = (long)(
|
||||
(15.0 + 10.0 * HashUtil.random(farmingBlock.getGeneration() ^ 3405692655L, worldX, worldY, worldZ))
|
||||
* world.getTps()
|
||||
* WorldTimeResource.getSecondsPerTick(world)
|
||||
* 1.0E9
|
||||
);
|
||||
return Math.min(desiredNanos, maxNanos);
|
||||
}
|
||||
|
||||
public static void tickFarming(
|
||||
@Nonnull CommandBuffer<ChunkStore> commandBuffer,
|
||||
@Nonnull BlockChunk blockChunk,
|
||||
@@ -132,24 +143,30 @@ public class FarmingUtil {
|
||||
currentProgress += (float)(remainingTimeSeconds / (baseDuration / growthMultiplier));
|
||||
farmingBlock.setGrowthProgress(currentProgress);
|
||||
long nextGrowthInNanos = (remainingDurationSeconds - remainingTimeSeconds) * 1000000000L;
|
||||
long randCap = (long)(
|
||||
(15.0 + 10.0 * HashUtil.random(farmingBlock.getGeneration() ^ 3405692655L, worldX, worldY, worldZ))
|
||||
* world.getTps()
|
||||
* WorldTimeResource.getSecondsPerTick(world)
|
||||
* 1.0E9
|
||||
blockSection.scheduleTick(
|
||||
ChunkUtil.indexBlock(x, y, z),
|
||||
currentTime.plusNanos(cappedTickNanos(nextGrowthInNanos, world, farmingBlock, worldX, worldY, worldZ))
|
||||
);
|
||||
long cappedNextGrowthInNanos = Math.min(nextGrowthInNanos, randCap);
|
||||
blockSection.scheduleTick(ChunkUtil.indexBlock(x, y, z), currentTime.plusNanos(cappedNextGrowthInNanos));
|
||||
break;
|
||||
}
|
||||
|
||||
remainingTimeSeconds -= remainingDurationSeconds;
|
||||
currentProgress = ++currentStage;
|
||||
int nextStage = currentStage + 1;
|
||||
if (nextStage < stages.length && !stages[nextStage].canApply(commandBuffer, sectionRef, blockRef, x, y, z)) {
|
||||
farmingBlock.setGrowthProgress(currentStage);
|
||||
blockChunk.markNeedsSaving();
|
||||
long regrowNanos = Math.round(baseDuration / growthMultiplier) * 1000000000L;
|
||||
blockSection.scheduleTick(ChunkUtil.indexBlock(x, y, z), currentTime.plusNanos(regrowNanos));
|
||||
break;
|
||||
}
|
||||
|
||||
currentStage = nextStage;
|
||||
currentProgress = nextStage;
|
||||
farmingBlock.setGrowthProgress(currentProgress);
|
||||
blockChunk.markNeedsSaving();
|
||||
farmingBlock.setGeneration(farmingBlock.getGeneration() + 1);
|
||||
if (currentStage >= stages.length) {
|
||||
if (stages[currentStage - 1].implementsShouldStop()) {
|
||||
if (nextStage >= stages.length) {
|
||||
if (stages[nextStage - 1].implementsShouldStop()) {
|
||||
currentStage = stages.length - 1;
|
||||
farmingBlock.setGrowthProgress(currentStage);
|
||||
stages[currentStage].apply(commandBuffer, sectionRef, blockRef, x, y, z, stages[currentStage]);
|
||||
@@ -159,7 +176,7 @@ public class FarmingUtil {
|
||||
}
|
||||
} else {
|
||||
farmingBlock.setExecutions(0);
|
||||
stages[currentStage].apply(commandBuffer, sectionRef, blockRef, x, y, z, stages[currentStage - 1]);
|
||||
stages[nextStage].apply(commandBuffer, sectionRef, blockRef, x, y, z, stages[nextStage - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,115 +228,118 @@ public class FarmingUtil {
|
||||
int rotationIndex,
|
||||
@Nonnull Vector3i blockPosition
|
||||
) {
|
||||
FarmingData farmingConfig = blockType.getFarming();
|
||||
boolean isFarmable = true;
|
||||
if (farmingConfig == null || farmingConfig.getStages() == null) {
|
||||
isFarmable = false;
|
||||
}
|
||||
|
||||
if (blockType.getGathering().getHarvest() == null) {
|
||||
BlockGathering gathering = blockType.getGathering();
|
||||
if (gathering == null) {
|
||||
return false;
|
||||
} else {
|
||||
World world = store.getExternalData().getWorld();
|
||||
Vector3d centerPosition = new Vector3d();
|
||||
blockType.getBlockCenter(rotationIndex, centerPosition);
|
||||
centerPosition.add(blockPosition);
|
||||
if (isFarmable && farmingConfig.getStageSetAfterHarvest() != null) {
|
||||
giveDrops(store, ref, centerPosition, blockType);
|
||||
Map<String, FarmingStageData[]> stageSets = farmingConfig.getStages();
|
||||
FarmingStageData[] stages = stageSets.get(farmingConfig.getStartingStageSet());
|
||||
if (stages == null) {
|
||||
return false;
|
||||
} else {
|
||||
int currentStageIndex = stages.length - 1;
|
||||
FarmingStageData previousStage = stages[currentStageIndex];
|
||||
String newStageSet = farmingConfig.getStageSetAfterHarvest();
|
||||
FarmingStageData[] newStages = stageSets.get(newStageSet);
|
||||
if (newStages != null && newStages.length != 0) {
|
||||
Store<ChunkStore> chunkStore = world.getChunkStore().getStore();
|
||||
Ref<ChunkStore> chunkRef = world.getChunkStore().getChunkReference(ChunkUtil.indexChunkFromBlock(blockPosition.x, blockPosition.z));
|
||||
if (chunkRef == null) {
|
||||
return false;
|
||||
} else {
|
||||
BlockComponentChunk blockComponentChunk = chunkStore.getComponent(chunkRef, BlockComponentChunk.getComponentType());
|
||||
if (blockComponentChunk == null) {
|
||||
HarvestingDropType harvestingDropType = gathering.getHarvest();
|
||||
if (harvestingDropType == null) {
|
||||
return false;
|
||||
} else {
|
||||
World world = store.getExternalData().getWorld();
|
||||
Vector3d centerPosition = new Vector3d();
|
||||
blockType.getBlockCenter(rotationIndex, centerPosition);
|
||||
centerPosition.add(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
FarmingData farmingConfig = blockType.getFarming();
|
||||
boolean isFarmable = farmingConfig != null && farmingConfig.getStages() != null;
|
||||
if (isFarmable && farmingConfig.getStageSetAfterHarvest() != null) {
|
||||
giveDrops(store, ref, centerPosition, blockType, harvestingDropType);
|
||||
Map<String, FarmingStageData[]> stageSets = farmingConfig.getStages();
|
||||
FarmingStageData[] stages = stageSets.get(farmingConfig.getStartingStageSet());
|
||||
if (stages == null) {
|
||||
return false;
|
||||
} else {
|
||||
int currentStageIndex = stages.length - 1;
|
||||
FarmingStageData previousStage = stages[currentStageIndex];
|
||||
String newStageSet = farmingConfig.getStageSetAfterHarvest();
|
||||
FarmingStageData[] newStages = stageSets.get(newStageSet);
|
||||
if (newStages != null && newStages.length != 0) {
|
||||
Store<ChunkStore> chunkStore = world.getChunkStore().getStore();
|
||||
Ref<ChunkStore> chunkRef = world.getChunkStore().getChunkReference(ChunkUtil.indexChunkFromBlock(blockPosition.x, blockPosition.z));
|
||||
if (chunkRef == null) {
|
||||
return false;
|
||||
} else {
|
||||
Instant now = store.getExternalData()
|
||||
.getWorld()
|
||||
.getEntityStore()
|
||||
.getStore()
|
||||
.getResource(WorldTimeResource.getResourceType())
|
||||
.getGameTime();
|
||||
int blockIndexColumn = ChunkUtil.indexBlockInColumn(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
Ref<ChunkStore> blockRef = blockComponentChunk.getEntityReference(blockIndexColumn);
|
||||
FarmingBlock farmingBlock;
|
||||
if (blockRef == null) {
|
||||
Holder<ChunkStore> blockEntity = ChunkStore.REGISTRY.newHolder();
|
||||
blockEntity.putComponent(BlockModule.BlockStateInfo.getComponentType(), new BlockModule.BlockStateInfo(blockIndexColumn, chunkRef));
|
||||
farmingBlock = new FarmingBlock();
|
||||
farmingBlock.setLastTickGameTime(now);
|
||||
farmingBlock.setCurrentStageSet(newStageSet);
|
||||
blockEntity.addComponent(FarmingBlock.getComponentType(), farmingBlock);
|
||||
blockRef = chunkStore.addEntity(blockEntity, AddReason.SPAWN);
|
||||
} else {
|
||||
farmingBlock = chunkStore.ensureAndGetComponent(blockRef, FarmingBlock.getComponentType());
|
||||
}
|
||||
|
||||
farmingBlock.setCurrentStageSet(newStageSet);
|
||||
farmingBlock.setGrowthProgress(0.0F);
|
||||
farmingBlock.setExecutions(0);
|
||||
farmingBlock.setGeneration(farmingBlock.getGeneration() + 1);
|
||||
farmingBlock.setLastTickGameTime(now);
|
||||
Ref<ChunkStore> sectionRef = world.getChunkStore()
|
||||
.getChunkSectionReference(
|
||||
ChunkUtil.chunkCoordinate(blockPosition.x),
|
||||
ChunkUtil.chunkCoordinate(blockPosition.y),
|
||||
ChunkUtil.chunkCoordinate(blockPosition.z)
|
||||
);
|
||||
if (sectionRef == null) {
|
||||
return false;
|
||||
} else if (blockRef == null) {
|
||||
BlockComponentChunk blockComponentChunk = chunkStore.getComponent(chunkRef, BlockComponentChunk.getComponentType());
|
||||
if (blockComponentChunk == null) {
|
||||
return false;
|
||||
} else {
|
||||
BlockSection section = chunkStore.getComponent(sectionRef, BlockSection.getComponentType());
|
||||
if (section != null) {
|
||||
int blockIndex = ChunkUtil.indexBlock(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
section.scheduleTick(blockIndex, now);
|
||||
Instant now = store.getExternalData()
|
||||
.getWorld()
|
||||
.getEntityStore()
|
||||
.getStore()
|
||||
.getResource(WorldTimeResource.getResourceType())
|
||||
.getGameTime();
|
||||
int blockIndexColumn = ChunkUtil.indexBlockInColumn(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
Ref<ChunkStore> blockRef = blockComponentChunk.getEntityReference(blockIndexColumn);
|
||||
FarmingBlock farmingBlock;
|
||||
if (blockRef == null) {
|
||||
Holder<ChunkStore> blockEntity = ChunkStore.REGISTRY.newHolder();
|
||||
blockEntity.putComponent(
|
||||
BlockModule.BlockStateInfo.getComponentType(), new BlockModule.BlockStateInfo(blockIndexColumn, chunkRef)
|
||||
);
|
||||
farmingBlock = new FarmingBlock();
|
||||
farmingBlock.setLastTickGameTime(now);
|
||||
farmingBlock.setCurrentStageSet(newStageSet);
|
||||
blockEntity.addComponent(FarmingBlock.getComponentType(), farmingBlock);
|
||||
blockRef = chunkStore.addEntity(blockEntity, AddReason.SPAWN);
|
||||
} else {
|
||||
farmingBlock = chunkStore.ensureAndGetComponent(blockRef, FarmingBlock.getComponentType());
|
||||
}
|
||||
|
||||
newStages[0].apply(chunkStore, sectionRef, blockRef, blockPosition.x, blockPosition.y, blockPosition.z, previousStage);
|
||||
return true;
|
||||
farmingBlock.setCurrentStageSet(newStageSet);
|
||||
farmingBlock.setGrowthProgress(0.0F);
|
||||
farmingBlock.setExecutions(0);
|
||||
farmingBlock.setGeneration(farmingBlock.getGeneration() + 1);
|
||||
farmingBlock.setLastTickGameTime(now);
|
||||
Ref<ChunkStore> sectionRef = world.getChunkStore()
|
||||
.getChunkSectionReferenceAtBlock(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
if (sectionRef == null) {
|
||||
return false;
|
||||
} else if (blockRef == null) {
|
||||
return false;
|
||||
} else {
|
||||
BlockSection section = chunkStore.getComponent(sectionRef, BlockSection.getComponentType());
|
||||
if (section != null) {
|
||||
int blockIndex = ChunkUtil.indexBlock(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
section.scheduleTick(blockIndex, now);
|
||||
}
|
||||
|
||||
newStages[0].apply(chunkStore, sectionRef, blockRef, blockPosition.x, blockPosition.y, blockPosition.z, previousStage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WorldChunk chunk = world.getChunkIfInMemory(ChunkUtil.indexChunkFromBlock(blockPosition.x, blockPosition.z));
|
||||
if (chunk != null) {
|
||||
chunk.breakBlock(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
}
|
||||
} else {
|
||||
WorldChunk chunk = world.getChunkIfInMemory(ChunkUtil.indexChunkFromBlock(blockPosition.x, blockPosition.z));
|
||||
if (chunk != null) {
|
||||
chunk.breakBlock(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
giveDrops(store, ref, centerPosition, blockType, harvestingDropType);
|
||||
WorldChunk chunk = world.getChunkIfInMemory(ChunkUtil.indexChunkFromBlock(blockPosition.x, blockPosition.z));
|
||||
if (chunk != null) {
|
||||
chunk.breakBlock(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
giveDrops(store, ref, centerPosition, blockType);
|
||||
WorldChunk chunk = world.getChunkIfInMemory(ChunkUtil.indexChunkFromBlock(blockPosition.x, blockPosition.z));
|
||||
if (chunk != null) {
|
||||
chunk.breakBlock(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void giveDrops(
|
||||
@Nonnull ComponentAccessor<EntityStore> store, @Nonnull Ref<EntityStore> ref, @Nonnull Vector3d origin, @Nonnull BlockType blockType
|
||||
@Nonnull ComponentAccessor<EntityStore> store,
|
||||
@Nonnull Ref<EntityStore> ref,
|
||||
@Nonnull Vector3d origin,
|
||||
@Nonnull BlockType blockType,
|
||||
@Nonnull HarvestingDropType harvestingDropType
|
||||
) {
|
||||
HarvestingDropType harvest = blockType.getGathering().getHarvest();
|
||||
String itemId = harvest.getItemId();
|
||||
String dropListId = harvest.getDropListId();
|
||||
String itemId = harvestingDropType.getItemId();
|
||||
String dropListId = harvestingDropType.getDropListId();
|
||||
|
||||
for (ItemStack itemStack : BlockHarvestUtils.getDrops(blockType, 1, itemId, dropListId)) {
|
||||
ItemUtils.interactivelyPickupItem(ref, itemStack, origin, store);
|
||||
|
||||
@@ -5,15 +5,16 @@ import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.Component;
|
||||
import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Vector3iUtil;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class CoopResidentComponent implements Component<EntityStore> {
|
||||
@Nonnull
|
||||
public static final BuilderCodec<CoopResidentComponent> CODEC = BuilderCodec.builder(CoopResidentComponent.class, CoopResidentComponent::new)
|
||||
.append(new KeyedCodec<>("CoopLocation", Vector3i.CODEC), (comp, ref) -> comp.coopLocation = ref, comp -> comp.coopLocation)
|
||||
.append(new KeyedCodec<>("CoopLocation", Vector3iUtil.CODEC), (comp, ref) -> comp.coopLocation = ref, comp -> comp.coopLocation)
|
||||
.add()
|
||||
.append(
|
||||
new KeyedCodec<>("MarkedForDespawn", BuilderCodec.BOOLEAN),
|
||||
@@ -51,7 +52,7 @@ public class CoopResidentComponent implements Component<EntityStore> {
|
||||
@Override
|
||||
public Component<EntityStore> clone() {
|
||||
CoopResidentComponent component = new CoopResidentComponent();
|
||||
component.coopLocation.assign(this.coopLocation);
|
||||
component.coopLocation.set(this.coopLocation);
|
||||
component.markedForDespawn = this.markedForDespawn;
|
||||
return component;
|
||||
}
|
||||
|
||||
@@ -12,12 +12,13 @@ import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.codecs.map.MapCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.range.IntRange;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3dUtil;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.ItemDropList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class FarmingCoopAsset implements JsonAssetWithMap<String, DefaultAssetMap<String, FarmingCoopAsset>> {
|
||||
@Nonnull
|
||||
@@ -39,8 +40,8 @@ public class FarmingCoopAsset implements JsonAssetWithMap<String, DefaultAssetMa
|
||||
.addValidator(ItemDropList.VALIDATOR_CACHE.getMapValueValidator())
|
||||
.add()
|
||||
.<Vector3d>append(
|
||||
new KeyedCodec<>("ResidentSpawnOffset", Vector3d.CODEC),
|
||||
(asset, residentSpawnOffset) -> asset.residentSpawnOffset.assign(residentSpawnOffset),
|
||||
new KeyedCodec<>("ResidentSpawnOffset", Vector3dUtil.CODEC),
|
||||
(asset, residentSpawnOffset) -> asset.residentSpawnOffset.set(residentSpawnOffset),
|
||||
asset -> asset.residentSpawnOffset
|
||||
)
|
||||
.addValidator(Validators.nonNull())
|
||||
|
||||
@@ -97,11 +97,11 @@ public class LightLevelGrowthModifierAsset extends GrowthModifierAsset {
|
||||
boolean onlySunlight = false;
|
||||
if (this.requireBoth) {
|
||||
active = this.checkArtificialLight(redLight, greenLight, blueLight) && this.checkSunLight(worldTimeResource, skyLight);
|
||||
} else if (this.checkArtificialLight(redLight, greenLight, blueLight)) {
|
||||
active = true;
|
||||
} else if (this.checkSunLight(worldTimeResource, skyLight)) {
|
||||
active = true;
|
||||
onlySunlight = true;
|
||||
} else if (this.checkArtificialLight(redLight, greenLight, blueLight)) {
|
||||
active = true;
|
||||
}
|
||||
|
||||
if (active) {
|
||||
|
||||
@@ -32,6 +32,35 @@ public class BlockStateFarmingStageData extends FarmingStageData {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApply(
|
||||
@Nonnull ComponentAccessor<ChunkStore> commandBuffer, @Nonnull Ref<ChunkStore> sectionRef, @Nonnull Ref<ChunkStore> blockRef, int x, int y, int z
|
||||
) {
|
||||
ChunkSection chunkSectionComponent = commandBuffer.getComponent(sectionRef, ChunkSection.getComponentType());
|
||||
if (chunkSectionComponent == null) {
|
||||
return true;
|
||||
} else {
|
||||
WorldChunk worldChunkComponent = commandBuffer.getComponent(chunkSectionComponent.getChunkColumnReference(), WorldChunk.getComponentType());
|
||||
if (worldChunkComponent == null) {
|
||||
return true;
|
||||
} else {
|
||||
int originBlockId = worldChunkComponent.getBlock(x, y, z);
|
||||
BlockType originBlockType = BlockType.getAssetMap().getAsset(originBlockId);
|
||||
if (originBlockType == null) {
|
||||
return true;
|
||||
} else {
|
||||
BlockType blockType = originBlockType.getBlockForState(this.state);
|
||||
if (blockType == null) {
|
||||
return true;
|
||||
} else {
|
||||
int newBlockId = BlockType.getAssetMap().getIndex(blockType.getId());
|
||||
return originBlockId == newBlockId ? true : testFillerPositions(worldChunkComponent, blockType, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(
|
||||
@Nonnull ComponentAccessor<ChunkStore> commandBuffer,
|
||||
@@ -71,9 +100,11 @@ public class BlockStateFarmingStageData extends FarmingStageData {
|
||||
int newBlockId = BlockType.getAssetMap().getIndex(blockType.getId());
|
||||
if (originBlockId != newBlockId) {
|
||||
int rotationIndex = worldChunkComponent.getRotationIndex(x, y, z);
|
||||
commandBuffer.getExternalData()
|
||||
.getWorld()
|
||||
.execute(() -> worldChunkComponent.setBlock(x, y, z, newBlockId, blockType, rotationIndex, 0, 2));
|
||||
commandBuffer.getExternalData().getWorld().execute(() -> {
|
||||
if (testFillerPositions(worldChunkComponent, blockType, x, y, z)) {
|
||||
worldChunkComponent.setBlock(x, y, z, newBlockId, blockType, rotationIndex, 0, 2);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,29 @@ public class BlockTypeFarmingStageData extends FarmingStageData {
|
||||
return this.block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApply(
|
||||
@Nonnull ComponentAccessor<ChunkStore> commandBuffer, @Nonnull Ref<ChunkStore> sectionRef, @Nonnull Ref<ChunkStore> blockRef, int x, int y, int z
|
||||
) {
|
||||
BlockType blockType = BlockType.getAssetMap().getAsset(this.block);
|
||||
if (blockType == null) {
|
||||
return true;
|
||||
} else {
|
||||
ChunkSection chunkSectionComponent = commandBuffer.getComponent(sectionRef, ChunkSection.getComponentType());
|
||||
if (chunkSectionComponent == null) {
|
||||
return true;
|
||||
} else {
|
||||
WorldChunk worldChunkComponent = commandBuffer.getComponent(chunkSectionComponent.getChunkColumnReference(), WorldChunk.getComponentType());
|
||||
if (worldChunkComponent == null) {
|
||||
return true;
|
||||
} else {
|
||||
int blockId = BlockType.getAssetMap().getIndex(this.block);
|
||||
return blockId == worldChunkComponent.getBlock(x, y, z) ? true : testFillerPositions(worldChunkComponent, blockType, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(
|
||||
@Nonnull ComponentAccessor<ChunkStore> commandBuffer,
|
||||
@@ -66,7 +89,9 @@ public class BlockTypeFarmingStageData extends FarmingStageData {
|
||||
} else {
|
||||
commandBuffer.getExternalData().getWorld().execute(() -> {
|
||||
int rotationIndex = worldChunkComponent.getRotationIndex(x, y, z);
|
||||
worldChunkComponent.setBlock(x, y, z, blockId, blockType, rotationIndex, 0, 2);
|
||||
if (testFillerPositions(worldChunkComponent, blockType, x, y, z)) {
|
||||
worldChunkComponent.setBlock(x, y, z, blockId, blockType, rotationIndex, 0, 2);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.util.FastRandom;
|
||||
import com.hypixel.hytale.math.util.HashUtil;
|
||||
import com.hypixel.hytale.math.util.MathUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.BlockMaterial;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.Rotation;
|
||||
@@ -42,6 +41,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class PrefabFarmingStageData extends FarmingStageData {
|
||||
@Nonnull
|
||||
@@ -197,14 +197,14 @@ public class PrefabFarmingStageData extends FarmingStageData {
|
||||
int bx = worldX + px;
|
||||
int by = worldY + py;
|
||||
int bz = worldZ + pz;
|
||||
if ((secondBlockId == 0 || secondBlockId == Integer.MIN_VALUE) && blockId != 0 && blockId != Integer.MIN_VALUE) {
|
||||
if (blockId != 0 && blockId != Integer.MIN_VALUE) {
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(bx, bz);
|
||||
WorldChunk nonTickingChunk = chunkAccessor.getNonTickingChunk(chunkIndex);
|
||||
if (nonTickingChunk == null) {
|
||||
WorldChunk nonTickingWorldChunkComponent = chunkAccessor.getNonTickingChunk(chunkIndex);
|
||||
if (nonTickingWorldChunkComponent == null) {
|
||||
return false;
|
||||
} else {
|
||||
int worldBlock = nonTickingChunk.getBlock(bx, by, bz);
|
||||
return !this.doesBlockObstruct(blockId, worldBlock);
|
||||
int worldBlockId = nonTickingWorldChunkComponent.getBlock(bx, by, bz);
|
||||
return worldBlockId == secondBlockId ? true : !this.doesBlockObstruct(blockId, worldBlockId);
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
@@ -229,6 +229,7 @@ public class PrefabFarmingStageData extends FarmingStageData {
|
||||
updatedSetBlockSettings |= 4;
|
||||
}
|
||||
|
||||
int worldBlockId = nonTickingChunk.getBlock(bx, by, bz);
|
||||
if (blockId != 0 && blockId != Integer.MIN_VALUE) {
|
||||
BlockType block = blockTypeMap.getAsset(blockId);
|
||||
if (block == null) {
|
||||
@@ -251,16 +252,22 @@ public class PrefabFarmingStageData extends FarmingStageData {
|
||||
return true;
|
||||
}
|
||||
|
||||
int worldBlock = nonTickingChunk.getBlock(bx, by, bz);
|
||||
if ((secondBlockId == 0 || secondBlockId == Integer.MIN_VALUE) && !this.canReplace(worldBlock, blockTypeMap)) {
|
||||
if ((secondBlockId == 0 || secondBlockId == Integer.MIN_VALUE) && !this.canReplace(worldBlockId, blockTypeMap)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (secondBlockId != 0
|
||||
&& secondBlockId != Integer.MIN_VALUE
|
||||
&& secondBlockId != worldBlockId
|
||||
&& !this.canReplace(worldBlockId, blockTypeMap)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nonTickingChunk.setBlock(bx, by, bz, blockId, block, rotation, filler, updatedSetBlockSettings);
|
||||
if (stateWrapper != null) {
|
||||
nonTickingChunk.setState(bx, by, bz, stateWrapper.clone());
|
||||
nonTickingChunk.setState(bx, by, bz, block, rotation, stateWrapper.clone());
|
||||
}
|
||||
} else if (secondBlockId != 0 && secondBlockId != Integer.MIN_VALUE) {
|
||||
} else if (secondBlockId != 0 && secondBlockId != Integer.MIN_VALUE && worldBlockId == secondBlockId) {
|
||||
nonTickingChunk.breakBlock(bx, by, bz, updatedSetBlockSettings);
|
||||
}
|
||||
|
||||
@@ -282,7 +289,7 @@ public class PrefabFarmingStageData extends FarmingStageData {
|
||||
IPrefabBuffer.iterateAllColumns(), (blockX, blockY, blockZ, blockId, chance, holder, supportValue, rotation, filler, t) -> {
|
||||
int bx = worldX + prefabRotation.getX(blockX, blockZ);
|
||||
int by = worldY + blockY;
|
||||
int bz = worldZ + prefabRotation.getX(blockZ, blockX);
|
||||
int bz = worldZ + prefabRotation.getZ(blockX, blockZ);
|
||||
if (blockId != 0 && blockId != Integer.MIN_VALUE) {
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(bx, bz);
|
||||
WorldChunk nonTickingWorldChunkComponent = chunkAccessor.getNonTickingChunk(chunkIndex);
|
||||
@@ -336,7 +343,7 @@ public class PrefabFarmingStageData extends FarmingStageData {
|
||||
|
||||
nonTickingWorldChunkComponent.setBlock(bx, by, bz, blockId, blockTypeAsset, rotation, filler, 2);
|
||||
if (holder != null) {
|
||||
nonTickingWorldChunkComponent.setState(bx, by, bz, holder.clone());
|
||||
nonTickingWorldChunkComponent.setState(bx, by, bz, blockTypeAsset, rotation, holder.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionState;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.WaitForDataFrom;
|
||||
@@ -33,6 +32,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.time.Instant;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class ChangeFarmingStageInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull
|
||||
@@ -99,9 +99,9 @@ public class ChangeFarmingStageInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull Vector3i targetBlock,
|
||||
@Nonnull CooldownHandler cooldownHandler
|
||||
) {
|
||||
int x = targetBlock.getX();
|
||||
int y = targetBlock.getY();
|
||||
int z = targetBlock.getZ();
|
||||
int x = targetBlock.x();
|
||||
int y = targetBlock.y();
|
||||
int z = targetBlock.z();
|
||||
LOGGER.atInfo()
|
||||
.log(
|
||||
"[ChangeFarmingStage] Starting interaction at pos=(%d, %d, %d), increaseBy=%s, decreaseBy=%s, targetStage=%d, targetStageSet=%s",
|
||||
@@ -270,8 +270,7 @@ public class ChangeFarmingStageInteraction extends SimpleBlockInteraction {
|
||||
stageIndex,
|
||||
farmingBlock.getGeneration()
|
||||
);
|
||||
Ref<ChunkStore> sectionRef = world.getChunkStore()
|
||||
.getChunkSectionReference(ChunkUtil.chunkCoordinate(x), ChunkUtil.chunkCoordinate(y), ChunkUtil.chunkCoordinate(z));
|
||||
Ref<ChunkStore> sectionRef = world.getChunkStore().getChunkSectionReferenceAtBlock(x, y, z);
|
||||
if (sectionRef != null && sectionRef.isValid()) {
|
||||
BlockSection blockSectionComponent = chunkStore.getComponent(sectionRef, BlockSection.getComponentType());
|
||||
if (blockSectionComponent != null) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionState;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.WaitForDataFrom;
|
||||
@@ -24,6 +23,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class FertilizeSoilInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull
|
||||
@@ -55,14 +55,14 @@ public class FertilizeSoilInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull Vector3i targetBlock,
|
||||
@Nonnull CooldownHandler cooldownHandler
|
||||
) {
|
||||
int x = targetBlock.getX();
|
||||
int z = targetBlock.getZ();
|
||||
int x = targetBlock.x();
|
||||
int z = targetBlock.z();
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(x, z);
|
||||
WorldChunk worldChunkComponent = world.getChunk(chunkIndex);
|
||||
if (worldChunkComponent == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
} else {
|
||||
Ref<ChunkStore> blockRef = worldChunkComponent.getBlockComponentEntity(x, targetBlock.getY(), z);
|
||||
Ref<ChunkStore> blockRef = worldChunkComponent.getBlockComponentEntity(x, targetBlock.y(), z);
|
||||
if (blockRef == null || !blockRef.isValid()) {
|
||||
blockRef = BlockModule.ensureBlockEntity(worldChunkComponent, targetBlock.x, targetBlock.y, targetBlock.z);
|
||||
}
|
||||
@@ -72,20 +72,20 @@ public class FertilizeSoilInteraction extends SimpleBlockInteraction {
|
||||
TilledSoilBlock tilledSoilComponent = chunkStore.getComponent(blockRef, TilledSoilBlock.getComponentType());
|
||||
if (tilledSoilComponent != null && !tilledSoilComponent.isFertilized()) {
|
||||
tilledSoilComponent.setFertilized(true);
|
||||
worldChunkComponent.setTicking(x, targetBlock.getY(), z, true);
|
||||
worldChunkComponent.setTicking(x, targetBlock.getY() + 1, z, true);
|
||||
worldChunkComponent.setTicking(x, targetBlock.y(), z, true);
|
||||
worldChunkComponent.setTicking(x, targetBlock.y() + 1, z, true);
|
||||
} else {
|
||||
FarmingBlock farmingBlockComponent = chunkStore.getComponent(blockRef, FarmingBlock.getComponentType());
|
||||
if (farmingBlockComponent == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
} else {
|
||||
Ref<ChunkStore> soilBlockRef = worldChunkComponent.getBlockComponentEntity(x, targetBlock.getY() - 1, z);
|
||||
Ref<ChunkStore> soilBlockRef = worldChunkComponent.getBlockComponentEntity(x, targetBlock.y() - 1, z);
|
||||
if (soilBlockRef != null && soilBlockRef.isValid()) {
|
||||
tilledSoilComponent = chunkStore.getComponent(soilBlockRef, TilledSoilBlock.getComponentType());
|
||||
if (tilledSoilComponent != null && !tilledSoilComponent.isFertilized()) {
|
||||
tilledSoilComponent.setFertilized(true);
|
||||
worldChunkComponent.setTicking(x, targetBlock.getY() - 1, z, true);
|
||||
worldChunkComponent.setTicking(x, targetBlock.getY(), z, true);
|
||||
worldChunkComponent.setTicking(x, targetBlock.y() - 1, z, true);
|
||||
worldChunkComponent.setTicking(x, targetBlock.y(), z, true);
|
||||
} else {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionState;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
@@ -23,6 +22,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class HarvestCropInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull
|
||||
|
||||
@@ -11,18 +11,15 @@ import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.RemoveReason;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Rotation3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3dUtil;
|
||||
import com.hypixel.hytale.protocol.BlockPosition;
|
||||
import com.hypixel.hytale.protocol.InteractionState;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace;
|
||||
import com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset;
|
||||
import com.hypixel.hytale.server.core.entity.EntityUtils;
|
||||
import com.hypixel.hytale.server.core.entity.InteractionContext;
|
||||
import com.hypixel.hytale.server.core.entity.LivingEntity;
|
||||
import com.hypixel.hytale.server.core.inventory.Inventory;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.modules.block.BlockModule;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.PersistentModel;
|
||||
@@ -38,8 +35,12 @@ import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import com.hypixel.hytale.server.npc.NPCPlugin;
|
||||
import com.hypixel.hytale.server.npc.entities.NPCEntity;
|
||||
import com.hypixel.hytale.server.npc.metadata.CapturedNPCMetadata;
|
||||
import com.hypixel.hytale.server.npc.storage.AlarmStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector3ic;
|
||||
|
||||
public class UseCaptureCrateInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull
|
||||
@@ -85,13 +86,13 @@ public class UseCaptureCrateInteraction extends SimpleBlockInteraction {
|
||||
super.tick0(firstRun, time, type, context, cooldownHandler);
|
||||
} else {
|
||||
Ref<EntityStore> ref = context.getEntity();
|
||||
if (!(EntityUtils.getEntity(ref, commandBuffer) instanceof LivingEntity livingEntity)) {
|
||||
InventoryComponent.Hotbar hotbarComponent = commandBuffer.getComponent(ref, InventoryComponent.Hotbar.getComponentType());
|
||||
if (hotbarComponent == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
super.tick0(firstRun, time, type, context, cooldownHandler);
|
||||
} else {
|
||||
Inventory inventory = livingEntity.getInventory();
|
||||
byte activeHotbarSlot = inventory.getActiveHotbarSlot();
|
||||
ItemStack inHandItemStack = inventory.getActiveHotbarItem();
|
||||
byte activeHotbarSlot = hotbarComponent.getActiveSlot();
|
||||
ItemStack inHandItemStack = hotbarComponent.getActiveItem();
|
||||
if (inHandItemStack == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
super.tick0(firstRun, time, type, context, cooldownHandler);
|
||||
@@ -149,8 +150,9 @@ public class UseCaptureCrateInteraction extends SimpleBlockInteraction {
|
||||
itemMetaData.setFullItemIcon(this.fullIcon);
|
||||
}
|
||||
|
||||
itemMetaData.setAlarmStore(npcComponent.getAlarmStore());
|
||||
ItemStack itemWithNPC = inHandItemStack.withMetadata(CapturedNPCMetadata.KEYED_CODEC, itemMetaData);
|
||||
inventory.getHotbar().replaceItemStackInSlot(activeHotbarSlot, item, itemWithNPC);
|
||||
hotbarComponent.getInventory().replaceItemStackInSlot(activeHotbarSlot, item, itemWithNPC);
|
||||
commandBuffer.removeEntity(targetEntity, RemoveReason.REMOVE);
|
||||
}
|
||||
}
|
||||
@@ -178,9 +180,11 @@ public class UseCaptureCrateInteraction extends SimpleBlockInteraction {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
} else {
|
||||
Ref<EntityStore> ref = context.getEntity();
|
||||
if (EntityUtils.getEntity(ref, commandBuffer) instanceof LivingEntity livingEntity) {
|
||||
Inventory inventory = livingEntity.getInventory();
|
||||
byte activeHotbarSlot = inventory.getActiveHotbarSlot();
|
||||
InventoryComponent.Hotbar hotbarComponent = commandBuffer.getComponent(ref, InventoryComponent.Hotbar.getComponentType());
|
||||
if (hotbarComponent == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
} else {
|
||||
byte activeHotbarSlot = hotbarComponent.getActiveSlot();
|
||||
CapturedNPCMetadata existingMeta = item.getFromMetadataOrNull("CapturedEntity", CapturedNPCMetadata.CODEC);
|
||||
if (existingMeta == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
@@ -208,10 +212,10 @@ public class UseCaptureCrateInteraction extends SimpleBlockInteraction {
|
||||
if (coopBlockComponent.tryPutResident(existingMeta, worldTimeResource)) {
|
||||
world.execute(
|
||||
() -> coopBlockComponent.ensureSpawnResidentsInWorld(
|
||||
world, world.getEntityStore().getStore(), new Vector3d(pos.x, pos.y, pos.z), new Vector3d().assign(Vector3d.FORWARD)
|
||||
world, world.getEntityStore().getStore(), new Vector3d(pos.x, pos.y, pos.z), new Vector3d().set(Vector3dUtil.FORWARD)
|
||||
)
|
||||
);
|
||||
inventory.getHotbar().replaceItemStackInSlot(activeHotbarSlot, item, noMetaItemStack);
|
||||
hotbarComponent.getInventory().replaceItemStackInSlot(activeHotbarSlot, item, noMetaItemStack);
|
||||
context.getState().state = InteractionState.Finished;
|
||||
} else {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
@@ -225,19 +229,23 @@ public class UseCaptureCrateInteraction extends SimpleBlockInteraction {
|
||||
if (context.getClientState() != null) {
|
||||
BlockFace blockFace = BlockFace.fromProtocolFace(context.getClientState().blockFace);
|
||||
if (blockFace != null) {
|
||||
spawnPos.add(blockFace.getDirection());
|
||||
Vector3ic direction = blockFace.getDirection();
|
||||
spawnPos.add(direction.x(), direction.y(), direction.z());
|
||||
}
|
||||
}
|
||||
|
||||
String roleId = existingMeta.getNpcNameKey();
|
||||
int roleIndex = NPCPlugin.get().getIndex(roleId);
|
||||
commandBuffer.run(_store -> NPCPlugin.get().spawnEntity(_store, roleIndex, spawnPos, Vector3f.ZERO, null, null));
|
||||
inventory.getHotbar().replaceItemStackInSlot(activeHotbarSlot, item, noMetaItemStack);
|
||||
AlarmStore savedAlarmStore = existingMeta.getAlarmStore();
|
||||
commandBuffer.run(_store -> NPCPlugin.get().spawnEntity(_store, roleIndex, spawnPos, Rotation3f.IDENTITY, null, (npc, _holder, _s) -> {
|
||||
if (savedAlarmStore != null) {
|
||||
npc.setAlarmStore(savedAlarmStore);
|
||||
}
|
||||
}, null));
|
||||
hotbarComponent.getInventory().replaceItemStackInSlot(activeHotbarSlot, item, noMetaItemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,11 @@ import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionState;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
import com.hypixel.hytale.server.core.entity.EntityUtils;
|
||||
import com.hypixel.hytale.server.core.entity.InteractionContext;
|
||||
import com.hypixel.hytale.server.core.entity.LivingEntity;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.modules.block.BlockModule;
|
||||
@@ -24,6 +22,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class UseCoopInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull
|
||||
@@ -42,14 +41,14 @@ public class UseCoopInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull Vector3i targetBlock,
|
||||
@Nonnull CooldownHandler cooldownHandler
|
||||
) {
|
||||
int x = targetBlock.getX();
|
||||
int z = targetBlock.getZ();
|
||||
int x = targetBlock.x();
|
||||
int z = targetBlock.z();
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(x, z);
|
||||
WorldChunk worldChunk = world.getChunk(chunkIndex);
|
||||
if (worldChunk == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
} else {
|
||||
Ref<ChunkStore> blockRef = worldChunk.getBlockComponentEntity(x, targetBlock.getY(), z);
|
||||
Ref<ChunkStore> blockRef = worldChunk.getBlockComponentEntity(x, targetBlock.y(), z);
|
||||
if (blockRef == null || !blockRef.isValid()) {
|
||||
blockRef = BlockModule.ensureBlockEntity(worldChunk, targetBlock.x, targetBlock.y, targetBlock.z);
|
||||
}
|
||||
@@ -61,19 +60,13 @@ public class UseCoopInteraction extends SimpleBlockInteraction {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
} else {
|
||||
Ref<EntityStore> ref = context.getEntity();
|
||||
if (EntityUtils.getEntity(ref, commandBuffer) instanceof LivingEntity livingEntity) {
|
||||
CombinedItemContainer inventoryContainer = livingEntity.getInventory().getCombinedHotbarFirst();
|
||||
if (inventoryContainer != null) {
|
||||
coopBlockComponent.gatherProduceFromContainer(inventoryContainer);
|
||||
BlockType currentBlockType = worldChunk.getBlockType(targetBlock);
|
||||
CombinedItemContainer inventoryContainer = InventoryComponent.getCombined(commandBuffer, ref, InventoryComponent.HOTBAR_FIRST);
|
||||
coopBlockComponent.gatherProduceFromContainer(inventoryContainer);
|
||||
BlockType currentBlockType = worldChunk.getBlockType(targetBlock);
|
||||
|
||||
assert currentBlockType != null;
|
||||
assert currentBlockType != null;
|
||||
|
||||
worldChunk.setBlockInteractionState(targetBlock, currentBlockType, coopBlockComponent.hasProduce() ? "Produce_Ready" : "default");
|
||||
}
|
||||
} else {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
}
|
||||
worldChunk.setBlockInteractionState(targetBlock, currentBlockType, coopBlockComponent.hasProduce() ? "Produce_Ready" : "default");
|
||||
}
|
||||
} else {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hypixel.hytale.builtin.adventure.farming.interactions;
|
||||
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.FarmingBlock;
|
||||
import com.hypixel.hytale.builtin.adventure.farming.states.TilledSoilBlock;
|
||||
import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
@@ -9,13 +8,12 @@ import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionState;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.WaitForDataFrom;
|
||||
import com.hypixel.hytale.server.core.entity.InteractionContext;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.modules.block.BlockModule;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
|
||||
import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
|
||||
import com.hypixel.hytale.server.core.modules.interaction.interaction.config.client.SimpleBlockInteraction;
|
||||
import com.hypixel.hytale.server.core.modules.time.WorldTimeResource;
|
||||
@@ -27,28 +25,27 @@ import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class UseWateringCanInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull
|
||||
public static final BuilderCodec<UseWateringCanInteraction> CODEC = BuilderCodec.builder(
|
||||
UseWateringCanInteraction.class, UseWateringCanInteraction::new, SimpleBlockInteraction.CODEC
|
||||
)
|
||||
.documentation("Waters the target farmable block.")
|
||||
.documentation("Waters the target farmable block. Supports configurable width and depth for directional area-of-effect watering.")
|
||||
.addField(new KeyedCodec<>("Duration", Codec.LONG), (interaction, duration) -> interaction.duration = duration, interaction -> interaction.duration)
|
||||
.addField(
|
||||
new KeyedCodec<>("RefreshModifiers", Codec.STRING_ARRAY),
|
||||
(interaction, refreshModifiers) -> interaction.refreshModifiers = refreshModifiers,
|
||||
interaction -> interaction.refreshModifiers
|
||||
)
|
||||
.addField(new KeyedCodec<>("RadiusX", Codec.INTEGER), (interaction, radiusX) -> interaction.radiusX = radiusX, interaction -> interaction.radiusX)
|
||||
.addField(new KeyedCodec<>("RadiusZ", Codec.INTEGER), (interaction, radiusZ) -> interaction.radiusZ = radiusZ, interaction -> interaction.radiusZ)
|
||||
.build();
|
||||
protected long duration;
|
||||
protected String[] refreshModifiers;
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public WaitForDataFrom getWaitForDataFrom() {
|
||||
return WaitForDataFrom.Server;
|
||||
}
|
||||
protected int radiusX;
|
||||
protected int radiusZ;
|
||||
|
||||
@Override
|
||||
protected void interactWithBlock(
|
||||
@@ -60,54 +57,82 @@ public class UseWateringCanInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull Vector3i targetBlock,
|
||||
@Nonnull CooldownHandler cooldownHandler
|
||||
) {
|
||||
int x = targetBlock.getX();
|
||||
int z = targetBlock.getZ();
|
||||
WorldTimeResource worldTimeResource = commandBuffer.getResource(WorldTimeResource.getResourceType());
|
||||
Instant gameTime = worldTimeResource.getGameTime();
|
||||
Instant wateredUntil = gameTime.plus(this.duration, ChronoUnit.SECONDS);
|
||||
int facingX = 0;
|
||||
int facingZ = -1;
|
||||
HeadRotation headRotation = commandBuffer.getComponent(context.getEntity(), HeadRotation.getComponentType());
|
||||
if (headRotation != null) {
|
||||
Vector3i facing = headRotation.getHorizontalAxisDirection();
|
||||
facingX = facing.x();
|
||||
facingZ = facing.z();
|
||||
}
|
||||
|
||||
if (facingX != 0 && facingZ != 0) {
|
||||
facingX = 0;
|
||||
}
|
||||
|
||||
int lateralX = facingZ != 0 ? 1 : 0;
|
||||
int lateralZ = facingX != 0 ? 1 : 0;
|
||||
int width = Math.max(this.radiusX, 1);
|
||||
int depth = Math.max(this.radiusZ, 1);
|
||||
int halfLeft = (width - 1) / 2;
|
||||
int halfRight = width - 1 - halfLeft;
|
||||
boolean anyWatered = false;
|
||||
|
||||
for (int forward = 0; forward < depth; forward++) {
|
||||
for (int lateral = -halfLeft; lateral <= halfRight; lateral++) {
|
||||
int bx = targetBlock.x() + lateral * lateralX + forward * facingX;
|
||||
int bz = targetBlock.z() + lateral * lateralZ + forward * facingZ;
|
||||
if (this.waterBlockAt(world, bx, targetBlock.y(), bz, wateredUntil)) {
|
||||
anyWatered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!anyWatered) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean waterBlockAt(@Nonnull World world, int x, int y, int z, @Nonnull Instant wateredUntil) {
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(x, z);
|
||||
WorldChunk worldChunk = world.getChunk(chunkIndex);
|
||||
if (worldChunk == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
return false;
|
||||
} else {
|
||||
Ref<ChunkStore> blockRef = worldChunk.getBlockComponentEntity(x, targetBlock.getY(), z);
|
||||
Store<ChunkStore> chunkStore = world.getChunkStore().getStore();
|
||||
Ref<ChunkStore> blockRef = worldChunk.getBlockComponentEntity(x, y, z);
|
||||
if (blockRef == null) {
|
||||
blockRef = BlockModule.ensureBlockEntity(worldChunk, targetBlock.x, targetBlock.y, targetBlock.z);
|
||||
blockRef = BlockModule.ensureBlockEntity(worldChunk, x, y, z);
|
||||
}
|
||||
|
||||
if (blockRef != null && blockRef.isValid()) {
|
||||
Store<ChunkStore> chunkStore = world.getChunkStore().getStore();
|
||||
WorldTimeResource worldTimeResource = commandBuffer.getResource(WorldTimeResource.getResourceType());
|
||||
TilledSoilBlock tilledSoilBlockComponent = chunkStore.getComponent(blockRef, TilledSoilBlock.getComponentType());
|
||||
if (tilledSoilBlockComponent != null) {
|
||||
Instant wateredUntil = worldTimeResource.getGameTime().plus(this.duration, ChronoUnit.SECONDS);
|
||||
tilledSoilBlockComponent.setWateredUntil(wateredUntil);
|
||||
worldChunk.setTicking(x, targetBlock.getY(), z, true);
|
||||
worldChunk.getBlockChunk().getSectionAtBlockY(targetBlock.y).scheduleTick(ChunkUtil.indexBlock(x, targetBlock.y, z), wateredUntil);
|
||||
worldChunk.setTicking(x, targetBlock.getY() + 1, z, true);
|
||||
worldChunk.setTicking(x, y, z, true);
|
||||
worldChunk.getBlockChunk().getSectionAtBlockY(y).scheduleTick(ChunkUtil.indexBlock(x, y, z), wateredUntil);
|
||||
worldChunk.setTicking(x, y + 1, z, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Ref<ChunkStore> soilBlockRef = worldChunk.getBlockComponentEntity(x, y - 1, z);
|
||||
if (soilBlockRef != null && soilBlockRef.isValid()) {
|
||||
TilledSoilBlock tilledSoilBlockComponent = chunkStore.getComponent(soilBlockRef, TilledSoilBlock.getComponentType());
|
||||
if (tilledSoilBlockComponent == null) {
|
||||
return false;
|
||||
} else {
|
||||
FarmingBlock farmingBlockComponent = chunkStore.getComponent(blockRef, FarmingBlock.getComponentType());
|
||||
if (farmingBlockComponent == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
} else {
|
||||
Ref<ChunkStore> soilBlockRef = worldChunk.getBlockComponentEntity(x, targetBlock.getY() - 1, z);
|
||||
if (soilBlockRef != null && soilBlockRef.isValid()) {
|
||||
tilledSoilBlockComponent = chunkStore.getComponent(soilBlockRef, TilledSoilBlock.getComponentType());
|
||||
if (tilledSoilBlockComponent == null) {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
} else {
|
||||
Instant wateredUntil = worldTimeResource.getGameTime().plus(this.duration, ChronoUnit.SECONDS);
|
||||
tilledSoilBlockComponent.setWateredUntil(wateredUntil);
|
||||
worldChunk.getBlockChunk()
|
||||
.getSectionAtBlockY(targetBlock.y - 1)
|
||||
.scheduleTick(ChunkUtil.indexBlock(x, targetBlock.y - 1, z), wateredUntil);
|
||||
worldChunk.setTicking(x, targetBlock.getY() - 1, z, true);
|
||||
worldChunk.setTicking(x, targetBlock.getY(), z, true);
|
||||
}
|
||||
} else {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
}
|
||||
}
|
||||
tilledSoilBlockComponent.setWateredUntil(wateredUntil);
|
||||
worldChunk.getBlockChunk().getSectionAtBlockY(y - 1).scheduleTick(ChunkUtil.indexBlock(x, y - 1, z), wateredUntil);
|
||||
worldChunk.setTicking(x, y - 1, z, true);
|
||||
worldChunk.setTicking(x, y, z, true);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.math.range.IntRange;
|
||||
import com.hypixel.hytale.math.util.MathUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Rotation3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3dUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3iUtil;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.ItemDrop;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.ItemDropList;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
@@ -58,6 +58,8 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class CoopBlock implements Component<ChunkStore> {
|
||||
@Nonnull
|
||||
@@ -254,21 +256,21 @@ public class CoopBlock implements Component<ChunkStore> {
|
||||
boolean residentDeployed = resident.getDeployedToWorld();
|
||||
PersistentRef residentEntityId = resident.getPersistentRef();
|
||||
if (!residentDeployed && residentEntityId == null) {
|
||||
Vector3d residentSpawnLocation = new Vector3d().assign(coopLocation).add(spawnOffsetIteration);
|
||||
Vector3d residentSpawnLocation = new Vector3d().set(coopLocation).add(spawnOffsetIteration);
|
||||
Builder<Role> roleBuilder = NPCPlugin.get().tryGetCachedValidRole(npcRoleIndex);
|
||||
if (roleBuilder != null) {
|
||||
spawningContext.setSpawnable((ISpawnableWithModel)roleBuilder);
|
||||
if (spawningContext.set(world, residentSpawnLocation.x, residentSpawnLocation.y, residentSpawnLocation.z)
|
||||
&& spawningContext.canSpawn() == SpawnTestResult.TEST_OK) {
|
||||
Pair<Ref<EntityStore>, NPCEntity> npcPair = NPCPlugin.get()
|
||||
.spawnEntity(store, npcRoleIndex, spawningContext.newPosition(), Vector3f.ZERO, null, null);
|
||||
.spawnEntity(store, npcRoleIndex, spawningContext.newPosition(), Rotation3f.IDENTITY, null, null);
|
||||
if (npcPair == null) {
|
||||
resident.setPersistentRef(null);
|
||||
resident.setDeployedToWorld(false);
|
||||
} else {
|
||||
Ref<EntityStore> npcRef = npcPair.first();
|
||||
NPCEntity npcComponent = npcPair.second();
|
||||
npcComponent.getLeashPoint().assign(coopLocation);
|
||||
npcComponent.getLeashPoint().set(coopLocation);
|
||||
if (npcRef != null && npcRef.isValid()) {
|
||||
UUIDComponent uuidComponent = store.getComponent(npcRef, UUIDComponent.getComponentType());
|
||||
if (uuidComponent == null) {
|
||||
@@ -276,7 +278,7 @@ public class CoopBlock implements Component<ChunkStore> {
|
||||
resident.setDeployedToWorld(false);
|
||||
} else {
|
||||
CoopResidentComponent coopResidentComponent = new CoopResidentComponent();
|
||||
coopResidentComponent.setCoopLocation(coopLocation.toVector3i());
|
||||
coopResidentComponent.setCoopLocation(Vector3dUtil.toVector3i(coopLocation));
|
||||
store.addComponent(npcRef, CoopResidentComponent.getComponentType(), coopResidentComponent);
|
||||
PersistentRef persistentRef = new PersistentRef();
|
||||
persistentRef.setEntity(npcRef, uuidComponent.getUuid());
|
||||
@@ -319,6 +321,17 @@ public class CoopBlock implements Component<ChunkStore> {
|
||||
} else if (!this.getCoopAcceptsNPC(resident.metadata.getNpcNameKey())) {
|
||||
residentsToRemove.add(resident);
|
||||
} else {
|
||||
ComponentType<EntityStore, NPCEntity> npcComponentType = NPCEntity.getComponentType();
|
||||
if (npcComponentType != null && resident.persistentRef != null) {
|
||||
NPCEntity npcComponent = store.getComponent(entityRef, npcComponentType);
|
||||
if (npcComponent != null && !resident.getMetadata().getNpcNameKey().equals(npcComponent.getRoleName())) {
|
||||
CapturedNPCMetadata metadata = FarmingUtil.generateCapturedNPCMetadata(store, entityRef, npcComponent.getRoleName());
|
||||
if (metadata != null) {
|
||||
resident.metadata = metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coopResidentComponent.setMarkedForDespawn(true);
|
||||
resident.setPersistentRef(null);
|
||||
resident.setDeployedToWorld(false);
|
||||
@@ -398,10 +411,12 @@ public class CoopBlock implements Component<ChunkStore> {
|
||||
@Nonnull World world, @Nonnull WorldTimeResource worldTimeResource, @Nonnull Store<EntityStore> store, int blockX, int blockY, int blockZ
|
||||
) {
|
||||
Vector3i location = new Vector3i(blockX, blockY, blockZ);
|
||||
world.execute(() -> this.ensureSpawnResidentsInWorld(world, store, location.toVector3d(), new Vector3d().assign(Vector3d.FORWARD)));
|
||||
world.execute(() -> this.ensureSpawnResidentsInWorld(world, store, Vector3iUtil.toVector3d(location), new Vector3d().set(Vector3dUtil.FORWARD)));
|
||||
this.generateProduceToInventory(worldTimeResource);
|
||||
Vector3d dropPosition = new Vector3d(blockX + 0.5F, blockY, blockZ + 0.5F);
|
||||
Holder<EntityStore>[] itemEntityHolders = ItemComponent.generateItemDrops(store, this.itemContainer.removeAllItemStacks(), dropPosition, Vector3f.ZERO);
|
||||
Holder<EntityStore>[] itemEntityHolders = ItemComponent.generateItemDrops(
|
||||
store, this.itemContainer.removeAllItemStacks(), dropPosition, Rotation3f.IDENTITY
|
||||
);
|
||||
if (itemEntityHolders.length > 0) {
|
||||
world.execute(() -> store.addEntities(itemEntityHolders, AddReason.SPAWN));
|
||||
}
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
package com.hypixel.hytale.builtin.adventure.farming.states;
|
||||
|
||||
import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.Component;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class FarmingBlockState implements Component<ChunkStore> {
|
||||
@Nonnull
|
||||
public static final BuilderCodec<FarmingBlockState> CODEC = BuilderCodec.builder(FarmingBlockState.class, FarmingBlockState::new)
|
||||
.append(new KeyedCodec<>("BaseCrop", Codec.STRING), (state, crop) -> state.baseCrop = crop, state -> state.baseCrop)
|
||||
.add()
|
||||
.append(new KeyedCodec<>("StageStart", Codec.INSTANT), (state, start) -> state.stageStart = start, state -> state.stageStart)
|
||||
.add()
|
||||
.append(
|
||||
new KeyedCodec<>("CurrentFarmingStageIndex", Codec.INTEGER),
|
||||
(baseFarmingBlockState, integer) -> baseFarmingBlockState.currentFarmingStageIndex = integer,
|
||||
baseFarmingBlockState -> baseFarmingBlockState.currentFarmingStageIndex
|
||||
)
|
||||
.add()
|
||||
.append(
|
||||
new KeyedCodec<>("CurrentFarmingStageSetName", Codec.STRING),
|
||||
(farmingBlockState, s) -> farmingBlockState.currentFarmingStageSetName = s,
|
||||
farmingBlockState -> farmingBlockState.currentFarmingStageSetName
|
||||
)
|
||||
.add()
|
||||
.append(new KeyedCodec<>("SpreadRate", Codec.FLOAT), (blockState, aFloat) -> blockState.spreadRate = aFloat, blockState -> blockState.spreadRate)
|
||||
.add()
|
||||
.build();
|
||||
public boolean loaded;
|
||||
public String baseCrop;
|
||||
public Instant stageStart;
|
||||
public String currentFarmingStageSetName;
|
||||
public int currentFarmingStageIndex;
|
||||
public Instant[] stageCompletionTimes;
|
||||
public String stageSetAfterHarvest;
|
||||
public double lastGrowthMultiplier;
|
||||
public float spreadRate = 1.0F;
|
||||
|
||||
public String getCurrentFarmingStageSetName() {
|
||||
return this.currentFarmingStageSetName;
|
||||
}
|
||||
|
||||
public void setCurrentFarmingStageSetName(String currentFarmingStageSetName) {
|
||||
this.currentFarmingStageSetName = currentFarmingStageSetName;
|
||||
}
|
||||
|
||||
public int getCurrentFarmingStageIndex() {
|
||||
return this.currentFarmingStageIndex;
|
||||
}
|
||||
|
||||
public void setCurrentFarmingStageIndex(int currentFarmingStageIndex) {
|
||||
this.currentFarmingStageIndex = currentFarmingStageIndex;
|
||||
}
|
||||
|
||||
public String getStageSetAfterHarvest() {
|
||||
return this.stageSetAfterHarvest;
|
||||
}
|
||||
|
||||
public void setStageSetAfterHarvest(String stageSetAfterHarvest) {
|
||||
this.stageSetAfterHarvest = stageSetAfterHarvest;
|
||||
}
|
||||
|
||||
public float getSpreadRate() {
|
||||
return this.spreadRate;
|
||||
}
|
||||
|
||||
public void setSpreadRate(float spreadRate) {
|
||||
this.spreadRate = spreadRate;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FarmingBlockState{loaded="
|
||||
+ this.loaded
|
||||
+ ", baseCrop="
|
||||
+ this.baseCrop
|
||||
+ ", stageStart="
|
||||
+ this.stageStart
|
||||
+ ", currentFarmingStageSetName='"
|
||||
+ this.currentFarmingStageSetName
|
||||
+ "', currentFarmingStageIndex="
|
||||
+ this.currentFarmingStageIndex
|
||||
+ ", stageCompletionTimes="
|
||||
+ Arrays.toString((Object[])this.stageCompletionTimes)
|
||||
+ ", stageSetAfterHarvest='"
|
||||
+ this.stageSetAfterHarvest
|
||||
+ "', lastGrowthMultiplier="
|
||||
+ this.lastGrowthMultiplier
|
||||
+ "} "
|
||||
+ super.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Component<ChunkStore> clone() {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected static class RefreshFlags {
|
||||
protected static final int REFRESH_ALL_FLAG = 1;
|
||||
protected static final int UNLOADING_FLAG = 2;
|
||||
protected static final int RETROACTIVE_FLAG = 4;
|
||||
protected static final int DEFAULT = 1;
|
||||
protected static final int ON_UNLOADING = 3;
|
||||
protected static final int ON_LOADING = 5;
|
||||
protected static final int NONE = 0;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.server.core.asset.type.gameplay.GameplayConfig;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.Item;
|
||||
import com.hypixel.hytale.server.core.asset.type.model.config.ModelParticle;
|
||||
import com.hypixel.hytale.server.core.asset.type.soundevent.config.SoundEvent;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -56,12 +57,32 @@ public class MemoriesGameplayConfig {
|
||||
)
|
||||
.addValidator(Validators.greaterThan(16))
|
||||
.add()
|
||||
.<String>appendInherited(
|
||||
new KeyedCodec<>("MemoriesRestoreSoundEventId", Codec.STRING),
|
||||
(activationEffects, s) -> activationEffects.memoriesRestoreSoundEventId = s,
|
||||
activationEffects -> activationEffects.memoriesRestoreSoundEventId,
|
||||
(activationEffects, parent) -> activationEffects.memoriesRestoreSoundEventId = parent.memoriesRestoreSoundEventId
|
||||
)
|
||||
.addValidator(Validators.nonNull())
|
||||
.addValidator(SoundEvent.VALIDATOR_CACHE.getValidator())
|
||||
.add()
|
||||
.<String>appendInherited(
|
||||
new KeyedCodec<>("MemoriesCatchSoundEventId", Codec.STRING),
|
||||
(memoriesGameplayConfig, s) -> memoriesGameplayConfig.memoriesCatchSoundEventId = s,
|
||||
memoriesGameplayConfig -> memoriesGameplayConfig.memoriesCatchSoundEventId,
|
||||
(memoriesGameplayConfig, parent) -> memoriesGameplayConfig.memoriesCatchSoundEventId = parent.memoriesCatchSoundEventId
|
||||
)
|
||||
.addValidator(Validators.nonNull())
|
||||
.addValidator(SoundEvent.VALIDATOR_CACHE.getValidator())
|
||||
.add()
|
||||
.build();
|
||||
private int[] memoriesAmountPerLevel;
|
||||
private String memoriesRecordParticles;
|
||||
private String memoriesCatchItemId;
|
||||
private ModelParticle memoriesCatchEntityParticle;
|
||||
private int memoriesCatchParticleViewDistance = 64;
|
||||
private String memoriesRestoreSoundEventId;
|
||||
private String memoriesCatchSoundEventId;
|
||||
|
||||
@Nullable
|
||||
public static MemoriesGameplayConfig get(@Nonnull GameplayConfig config) {
|
||||
@@ -80,6 +101,14 @@ public class MemoriesGameplayConfig {
|
||||
return this.memoriesCatchItemId;
|
||||
}
|
||||
|
||||
public String getMemoriesRestoreSoundEventId() {
|
||||
return this.memoriesRestoreSoundEventId;
|
||||
}
|
||||
|
||||
public String getMemoriesCatchSoundEventId() {
|
||||
return this.memoriesCatchSoundEventId;
|
||||
}
|
||||
|
||||
public ModelParticle getMemoriesCatchEntityParticle() {
|
||||
return this.memoriesCatchEntityParticle;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.hypixel.hytale.server.core.modules.interaction.interaction.config.ser
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.Universe;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import com.hypixel.hytale.server.core.util.BsonUtil;
|
||||
import com.hypixel.hytale.server.core.util.Config;
|
||||
@@ -56,7 +57,6 @@ import it.unimi.dsi.fastutil.objects.Object2DoubleMaps;
|
||||
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectRBTreeMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
@@ -65,9 +65,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bson.BsonDocument;
|
||||
|
||||
public class MemoriesPlugin extends JavaPlugin {
|
||||
@Nonnull
|
||||
@@ -128,15 +131,14 @@ public class MemoriesPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
protected void start() {
|
||||
try {
|
||||
Path path = Constants.UNIVERSE_PATH.resolve("memories.json");
|
||||
if (Files.exists(path)) {
|
||||
this.recordedMemories = RawJsonReader.readSync(path, MemoriesPlugin.RecordedMemories.CODEC, this.getLogger());
|
||||
} else {
|
||||
Path path = Constants.UNIVERSE_PATH.resolve("memories.json");
|
||||
if (Files.exists(path)) {
|
||||
this.recordedMemories = RawJsonReader.readSyncWithBak(path, MemoriesPlugin.RecordedMemories.CODEC, this.getLogger());
|
||||
if (this.recordedMemories == null) {
|
||||
this.recordedMemories = new MemoriesPlugin.RecordedMemories();
|
||||
}
|
||||
} catch (IOException var2) {
|
||||
throw new RuntimeException(var2);
|
||||
} else {
|
||||
this.recordedMemories = new MemoriesPlugin.RecordedMemories();
|
||||
}
|
||||
|
||||
this.hasInitializedMemories = true;
|
||||
@@ -146,16 +148,29 @@ public class MemoriesPlugin extends JavaPlugin {
|
||||
@Override
|
||||
protected void shutdown() {
|
||||
if (this.hasInitializedMemories) {
|
||||
this.saveMemories().join();
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private CompletableFuture<Void> saveMemories() {
|
||||
Path path = Constants.UNIVERSE_PATH.resolve("memories.json");
|
||||
return Universe.get().getStorageManager().doSave(path, () -> {
|
||||
this.recordedMemories.lock.readLock().lock();
|
||||
|
||||
CompletableFuture var3;
|
||||
try {
|
||||
BsonUtil.writeSync(Constants.UNIVERSE_PATH.resolve("memories.json"), MemoriesPlugin.RecordedMemories.CODEC, this.recordedMemories, this.getLogger());
|
||||
} catch (IOException var5) {
|
||||
throw new RuntimeException(var5);
|
||||
BsonDocument document = MemoriesPlugin.RecordedMemories.CODEC.encode(this.recordedMemories).asDocument();
|
||||
var3 = BsonUtil.writeDocument(path, document);
|
||||
} finally {
|
||||
this.recordedMemories.lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
return var3;
|
||||
}).exceptionally(e -> {
|
||||
this.getLogger().at(Level.SEVERE).withCause(e).log("Failed to save memories");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void onAssetsLoad() {
|
||||
@@ -224,11 +239,9 @@ public class MemoriesPlugin extends JavaPlugin {
|
||||
|
||||
try {
|
||||
if (playerMemories.takeMemories(this.recordedMemories.memories)) {
|
||||
BsonUtil.writeSync(Constants.UNIVERSE_PATH.resolve("memories.json"), MemoriesPlugin.RecordedMemories.CODEC, this.recordedMemories, this.getLogger());
|
||||
this.saveMemories();
|
||||
return true;
|
||||
}
|
||||
} catch (IOException var6) {
|
||||
throw new RuntimeException(var6);
|
||||
} finally {
|
||||
this.recordedMemories.lock.writeLock().unlock();
|
||||
}
|
||||
@@ -255,9 +268,7 @@ public class MemoriesPlugin extends JavaPlugin {
|
||||
|
||||
try {
|
||||
this.recordedMemories.memories.clear();
|
||||
BsonUtil.writeSync(Constants.UNIVERSE_PATH.resolve("memories.json"), MemoriesPlugin.RecordedMemories.CODEC, this.recordedMemories, this.getLogger());
|
||||
} catch (IOException var5) {
|
||||
throw new RuntimeException(var5);
|
||||
this.saveMemories();
|
||||
} finally {
|
||||
this.recordedMemories.lock.writeLock().unlock();
|
||||
}
|
||||
@@ -271,9 +282,7 @@ public class MemoriesPlugin extends JavaPlugin {
|
||||
this.recordedMemories.memories.addAll(entry.getValue());
|
||||
}
|
||||
|
||||
BsonUtil.writeSync(Constants.UNIVERSE_PATH.resolve("memories.json"), MemoriesPlugin.RecordedMemories.CODEC, this.recordedMemories, this.getLogger());
|
||||
} catch (IOException var6) {
|
||||
throw new RuntimeException(var6);
|
||||
this.saveMemories();
|
||||
} finally {
|
||||
this.recordedMemories.lock.writeLock().unlock();
|
||||
}
|
||||
@@ -286,7 +295,7 @@ public class MemoriesPlugin extends JavaPlugin {
|
||||
|
||||
this.recordedMemories.lock.writeLock().lock();
|
||||
|
||||
int var12;
|
||||
int var10;
|
||||
try {
|
||||
this.recordedMemories.memories.clear();
|
||||
List<Memory> allAvailableMemories = new ObjectArrayList<>();
|
||||
@@ -301,15 +310,13 @@ public class MemoriesPlugin extends JavaPlugin {
|
||||
this.recordedMemories.memories.add(allAvailableMemories.get(i));
|
||||
}
|
||||
|
||||
BsonUtil.writeSync(Constants.UNIVERSE_PATH.resolve("memories.json"), MemoriesPlugin.RecordedMemories.CODEC, this.recordedMemories, this.getLogger());
|
||||
var12 = actualCount;
|
||||
} catch (IOException var8) {
|
||||
throw new RuntimeException(var8);
|
||||
this.saveMemories();
|
||||
var10 = actualCount;
|
||||
} finally {
|
||||
this.recordedMemories.lock.writeLock().unlock();
|
||||
}
|
||||
|
||||
return var12;
|
||||
return var10;
|
||||
}
|
||||
|
||||
public static class MemoriesPluginConfig {
|
||||
|
||||
@@ -22,11 +22,12 @@ import com.hypixel.hytale.component.spatial.SpatialResource;
|
||||
import com.hypixel.hytale.component.spatial.SpatialStructure;
|
||||
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
||||
import com.hypixel.hytale.math.util.MathUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.protocol.GameMode;
|
||||
import com.hypixel.hytale.protocol.SoundCategory;
|
||||
import com.hypixel.hytale.protocol.packets.entities.SpawnModelParticles;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.asset.type.model.config.ModelParticle;
|
||||
import com.hypixel.hytale.server.core.asset.type.soundevent.config.SoundEvent;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
|
||||
@@ -36,6 +37,7 @@ import com.hypixel.hytale.server.core.modules.entity.item.ItemComponent;
|
||||
import com.hypixel.hytale.server.core.modules.entity.item.PickupItemComponent;
|
||||
import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.SoundUtil;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import com.hypixel.hytale.server.core.util.NotificationUtil;
|
||||
@@ -44,10 +46,11 @@ import com.hypixel.hytale.server.npc.entities.NPCEntity;
|
||||
import com.hypixel.hytale.server.npc.role.Role;
|
||||
import com.hypixel.hytale.server.worldgen.chunk.ChunkGenerator;
|
||||
import com.hypixel.hytale.server.worldgen.chunk.ZoneBiomeResult;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class NPCMemory extends Memory {
|
||||
@Nonnull
|
||||
@@ -222,7 +225,7 @@ public class NPCMemory extends Memory {
|
||||
|
||||
Vector3d position = transformComponent.getPosition();
|
||||
SpatialResource<Ref<EntityStore>, EntityStore> npcSpatialResource = store.getResource(NPCPlugin.get().getNpcSpatialResource());
|
||||
ObjectList<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
List<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
npcSpatialResource.getSpatialStructure().collect(position, this.radius, results);
|
||||
if (!results.isEmpty()) {
|
||||
PlayerRef playerRefComponent = archetypeChunk.getComponent(index, this.playerRefComponentType);
|
||||
@@ -262,7 +265,7 @@ public class NPCMemory extends Memory {
|
||||
MemoriesGameplayConfig memoriesGameplayConfig = MemoriesGameplayConfig.get(store.getExternalData().getWorld().getGameplayConfig());
|
||||
if (memoriesGameplayConfig != null) {
|
||||
ItemStack memoryItemStack = new ItemStack(memoriesGameplayConfig.getMemoriesCatchItemId());
|
||||
Vector3d memoryItemHolderPosition = npcTransformComponent.getPosition().clone();
|
||||
Vector3d memoryItemHolderPosition = new Vector3d(npcTransformComponent.getPosition());
|
||||
BoundingBox boundingBoxComponent = commandBuffer.getComponent(npcRef, BoundingBox.getComponentType());
|
||||
if (boundingBoxComponent != null) {
|
||||
memoryItemHolderPosition.y = memoryItemHolderPosition.y + boundingBoxComponent.getBoundingBox().middleY();
|
||||
@@ -279,6 +282,13 @@ public class NPCMemory extends Memory {
|
||||
pickupItemComponent.setInitialLifeTime(0.62F);
|
||||
commandBuffer.addEntity(memoryItemHolder, AddReason.SPAWN);
|
||||
displayCatchEntityParticles(memoriesGameplayConfig, memoryItemHolderPosition, npcRef, commandBuffer);
|
||||
String memoriesCatchSoundEventId = memoriesGameplayConfig.getMemoriesCatchSoundEventId();
|
||||
if (memoriesCatchSoundEventId != null) {
|
||||
int soundEventIndex = SoundEvent.getAssetMap().getIndex(memoriesCatchSoundEventId);
|
||||
if (soundEventIndex != 0) {
|
||||
SoundUtil.playSoundEvent3d(soundEventIndex, SoundCategory.SFX, npcTransformComponent.getPosition(), commandBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -321,7 +331,7 @@ public class NPCMemory extends Memory {
|
||||
SpawnModelParticles packet = new SpawnModelParticles(networkIdComponent.getId(), modelParticlesProtocol);
|
||||
SpatialResource<Ref<EntityStore>, EntityStore> spatialResource = commandBuffer.getResource(EntityModule.get().getPlayerSpatialResourceType());
|
||||
SpatialStructure<Ref<EntityStore>> spatialStructure = spatialResource.getSpatialStructure();
|
||||
ObjectList<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
List<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
spatialStructure.ordered(targetPosition, memoriesGameplayConfig.getMemoriesCatchParticleViewDistance(), results);
|
||||
|
||||
for (Ref<EntityStore> ref : results) {
|
||||
|
||||
@@ -12,12 +12,13 @@ import com.hypixel.hytale.codec.codecs.EnumCodec;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.spatial.SpatialResource;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.protocol.BlockPosition;
|
||||
import com.hypixel.hytale.protocol.SoundCategory;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.CustomPageLifetime;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.asset.type.gameplay.GameplayConfig;
|
||||
import com.hypixel.hytale.server.core.asset.type.soundevent.config.SoundEvent;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.entity.entities.player.pages.InteractiveCustomUIPage;
|
||||
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
|
||||
@@ -29,18 +30,20 @@ import com.hypixel.hytale.server.core.ui.builder.UICommandBuilder;
|
||||
import com.hypixel.hytale.server.core.ui.builder.UIEventBuilder;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.ParticleUtil;
|
||||
import com.hypixel.hytale.server.core.universe.world.SoundUtil;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class MemoriesPage extends InteractiveCustomUIPage<MemoriesPage.PageEventData> {
|
||||
@Nullable
|
||||
@@ -251,9 +254,16 @@ public class MemoriesPage extends InteractiveCustomUIPage<MemoriesPage.PageEvent
|
||||
MemoriesGameplayConfig memoriesGameplayConfig = MemoriesGameplayConfig.get(store.getExternalData().getWorld().getGameplayConfig());
|
||||
if (memoriesGameplayConfig != null) {
|
||||
SpatialResource<Ref<EntityStore>, EntityStore> playerSpatialResource = store.getResource(EntityModule.get().getPlayerSpatialResourceType());
|
||||
ObjectList<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
List<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
playerSpatialResource.getSpatialStructure().collect(this.recordMemoriesParticlesPosition, 75.0, results);
|
||||
ParticleUtil.spawnParticleEffect(memoriesGameplayConfig.getMemoriesRecordParticles(), this.recordMemoriesParticlesPosition, results, store);
|
||||
String restoreSoundEvent = memoriesGameplayConfig.getMemoriesRestoreSoundEventId();
|
||||
if (restoreSoundEvent != null) {
|
||||
int soundEventId = SoundEvent.getAssetMap().getIndex(restoreSoundEvent);
|
||||
if (soundEventId != 0) {
|
||||
SoundUtil.playSoundEvent3d(soundEventId, SoundCategory.SFX, this.recordMemoriesParticlesPosition, store);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.close();
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.tick.DelayedEntitySystem;
|
||||
import com.hypixel.hytale.math.vector.Transform;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.protocol.SoundCategory;
|
||||
import com.hypixel.hytale.server.core.asset.type.gameplay.GameplayConfig;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
|
||||
@@ -19,6 +18,7 @@ import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.spawn.ISpawnProvider;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class TempleRespawnPlayersSystem extends DelayedEntitySystem<EntityStore> {
|
||||
@Nonnull
|
||||
@@ -54,7 +54,7 @@ public class TempleRespawnPlayersSystem extends DelayedEntitySystem<EntityStore>
|
||||
assert transformComponent != null;
|
||||
|
||||
Vector3d position = transformComponent.getPosition();
|
||||
if (!(position.getY() > config.getMinYRespawn())) {
|
||||
if (!(position.y() > config.getMinYRespawn())) {
|
||||
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(index);
|
||||
ISpawnProvider spawnProvider = world.getWorldConfig().getSpawnProvider();
|
||||
Transform spawnTransform = spawnProvider.getSpawnPoint(ref, commandBuffer);
|
||||
|
||||
@@ -7,9 +7,9 @@ import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import java.util.Objects;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class BountyObjectiveTaskAsset extends ObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
|
||||
@@ -8,8 +8,8 @@ import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class KillObjectiveTaskAsset extends CountObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
|
||||
@@ -8,12 +8,13 @@ import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Vector3dUtil;
|
||||
import com.hypixel.hytale.server.spawning.assets.spawns.config.BeaconNPCSpawn;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class KillSpawnBeaconObjectiveTaskAsset extends KillObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
@@ -83,7 +84,7 @@ public class KillSpawnBeaconObjectiveTaskAsset extends KillObjectiveTaskAsset {
|
||||
.addValidator(BeaconNPCSpawn.VALIDATOR_CACHE.getValidator())
|
||||
.add()
|
||||
.append(
|
||||
new KeyedCodec<>("Offset", Vector3d.CODEC),
|
||||
new KeyedCodec<>("Offset", Vector3dUtil.CODEC),
|
||||
(objectiveSpawnBeacon, vector3d) -> objectiveSpawnBeacon.offset = vector3d,
|
||||
objectiveSpawnBeacon -> objectiveSpawnBeacon.offset
|
||||
)
|
||||
|
||||
@@ -8,10 +8,10 @@ import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.LegacyValidator;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.codec.validation.validator.ArrayValidator;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.spawning.assets.spawnmarker.config.SpawnMarker;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class KillSpawnMarkerObjectiveTaskAsset extends KillObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.hypixel.hytale.server.npc.role.Role;
|
||||
import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ActionCompleteTask extends ActionPlayAnimation {
|
||||
protected final boolean playAnimation;
|
||||
@@ -24,14 +25,14 @@ public class ActionCompleteTask extends ActionPlayAnimation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
public boolean canExecute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, @Nullable InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
Ref<EntityStore> targetRef = role.getStateSupport().getInteractionIterationTarget();
|
||||
boolean targetExists = targetRef != null && targetRef.isValid() && !store.getArchetype(targetRef).contains(DeathComponent.getComponentType());
|
||||
return super.canExecute(ref, role, sensorInfo, dt, store) && targetExists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
public boolean execute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, @Nullable InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
UUIDComponent parentUuidComponent = store.getComponent(ref, UUIDComponent.getComponentType());
|
||||
if (parentUuidComponent == null) {
|
||||
return false;
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.hypixel.hytale.server.npc.corecomponents.ActionBase;
|
||||
import com.hypixel.hytale.server.npc.role.Role;
|
||||
import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ActionStartObjective extends ActionBase {
|
||||
protected final String objectiveId;
|
||||
@@ -20,12 +21,12 @@ public class ActionStartObjective extends ActionBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
public boolean canExecute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, @Nullable InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
return super.canExecute(ref, role, sensorInfo, dt, store) && role.getStateSupport().getInteractionIterationTarget() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
public boolean execute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, @Nullable InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
super.execute(ref, role, sensorInfo, dt, store);
|
||||
Ref<EntityStore> interactionIterationTarget = role.getStateSupport().getInteractionIterationTarget();
|
||||
if (interactionIterationTarget == null) {
|
||||
|
||||
@@ -17,10 +17,10 @@ import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.math.vector.Rotation3f;
|
||||
import com.hypixel.hytale.math.vector.Transform;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Vector3dUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3iUtil;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.modules.entity.damage.Damage;
|
||||
@@ -34,6 +34,8 @@ import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class BountyObjectiveTask extends ObjectiveTask implements KillTask {
|
||||
@Nonnull
|
||||
@@ -80,13 +82,16 @@ public class BountyObjectiveTask extends ObjectiveTask implements KillTask {
|
||||
if (objectivePosition == null) {
|
||||
return null;
|
||||
} else {
|
||||
Vector3i spawnPosition = this.getAsset().getWorldLocationProvider().runCondition(world, objectivePosition.clone().floor().toVector3i());
|
||||
Vector3i spawnPosition = this.getAsset()
|
||||
.getWorldLocationProvider()
|
||||
.runCondition(world, Vector3dUtil.toVector3i(new Vector3d(objectivePosition).floor()));
|
||||
if (spawnPosition == null) {
|
||||
return null;
|
||||
} else {
|
||||
TransactionRecord[] transactionRecords = new TransactionRecord[2];
|
||||
String npcId = this.getAsset().getNpcId();
|
||||
Pair<Ref<EntityStore>, INonPlayerCharacter> npcPair = NPCPlugin.get().spawnNPC(store, npcId, null, spawnPosition.toVector3d(), Vector3f.ZERO);
|
||||
Pair<Ref<EntityStore>, INonPlayerCharacter> npcPair = NPCPlugin.get()
|
||||
.spawnNPC(store, npcId, null, Vector3iUtil.toVector3d(spawnPosition), Rotation3f.IDENTITY);
|
||||
if (npcPair == null) {
|
||||
return null;
|
||||
} else {
|
||||
|
||||
@@ -16,9 +16,9 @@ import com.hypixel.hytale.component.ComponentAccessor;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Rotation3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3dUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3iUtil;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
@@ -30,6 +30,8 @@ import it.unimi.dsi.fastutil.Pair;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class KillSpawnBeaconObjectiveTask extends KillObjectiveTask {
|
||||
@Nonnull
|
||||
@@ -77,7 +79,7 @@ public class KillSpawnBeaconObjectiveTask extends KillObjectiveTask {
|
||||
HytaleLogger logger = ObjectivePlugin.get().getLogger();
|
||||
|
||||
for (int i = 0; i < spawnBeaconConfigs.length; i++) {
|
||||
Vector3d spawnPosition = position.clone();
|
||||
Vector3d spawnPosition = new Vector3d(position);
|
||||
KillSpawnBeaconObjectiveTaskAsset.ObjectiveSpawnBeacon spawnBeaconConfig = spawnBeaconConfigs[i];
|
||||
String spawnBeaconId = spawnBeaconConfig.getSpawnBeaconId();
|
||||
int index = BeaconNPCSpawn.getAssetMap().getIndex(spawnBeaconId);
|
||||
@@ -93,9 +95,9 @@ public class KillSpawnBeaconObjectiveTask extends KillObjectiveTask {
|
||||
|
||||
WorldLocationProvider worldLocationCondition = spawnBeaconConfig.getWorldLocationProvider();
|
||||
if (worldLocationCondition != null) {
|
||||
Vector3i potentialSpawnLocation = worldLocationCondition.runCondition(world, spawnPosition.toVector3i());
|
||||
Vector3i potentialSpawnLocation = worldLocationCondition.runCondition(world, Vector3dUtil.toVector3i(spawnPosition));
|
||||
if (potentialSpawnLocation != null) {
|
||||
spawnPosition = potentialSpawnLocation.toVector3d();
|
||||
spawnPosition = Vector3iUtil.toVector3d(potentialSpawnLocation);
|
||||
} else {
|
||||
spawnPosition = null;
|
||||
}
|
||||
@@ -106,7 +108,7 @@ public class KillSpawnBeaconObjectiveTask extends KillObjectiveTask {
|
||||
} else {
|
||||
BeaconSpawnWrapper wrapper = SpawningPlugin.get().getBeaconSpawnWrapper(index);
|
||||
Pair<Ref<EntityStore>, LegacySpawnBeaconEntity> spawnBeaconPair = LegacySpawnBeaconEntity.create(
|
||||
wrapper, spawnPosition, Vector3f.FORWARD, componentAccessor
|
||||
wrapper, spawnPosition, Rotation3f.IDENTITY, componentAccessor
|
||||
);
|
||||
spawnBeaconPair.second().setObjectiveUUID(objective.getObjectiveUUID());
|
||||
UUIDComponent spawnBeaconUuidComponent = componentAccessor.getComponent(spawnBeaconPair.first(), UUIDComponent.getComponentType());
|
||||
|
||||
@@ -13,15 +13,15 @@ import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.spatial.SpatialResource;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import com.hypixel.hytale.server.spawning.SpawningPlugin;
|
||||
import com.hypixel.hytale.server.spawning.spawnmarkers.SpawnMarkerEntity;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class KillSpawnMarkerObjectiveTask extends KillObjectiveTask {
|
||||
@Nonnull
|
||||
@@ -51,7 +51,7 @@ public class KillSpawnMarkerObjectiveTask extends KillObjectiveTask {
|
||||
Vector3d objectivePosition = objective.getPosition(store);
|
||||
if (objectivePosition != null) {
|
||||
KillSpawnMarkerObjectiveTaskAsset asset = this.getAsset();
|
||||
ObjectList<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
List<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
SpatialResource<Ref<EntityStore>, EntityStore> spatialResource = store.getResource(SpawningPlugin.get().getSpawnMarkerSpatialResource());
|
||||
spatialResource.getSpatialStructure().collect(objectivePosition, asset.getRadius(), results);
|
||||
String[] spawnMarkerIds = asset.getSpawnMarkerIds();
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.hypixel.hytale.server.npc.corecomponents.ActionBase;
|
||||
import com.hypixel.hytale.server.npc.role.Role;
|
||||
import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ActionOpenBarterShop extends ActionBase {
|
||||
@Nonnull
|
||||
@@ -23,12 +24,12 @@ public class ActionOpenBarterShop extends ActionBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
public boolean canExecute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, @Nullable InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
return super.canExecute(ref, role, sensorInfo, dt, store) && role.getStateSupport().getInteractionIterationTarget() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
public boolean execute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, @Nullable InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
super.execute(ref, role, sensorInfo, dt, store);
|
||||
Ref<EntityStore> playerReference = role.getStateSupport().getInteractionIterationTarget();
|
||||
if (playerReference == null) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.hypixel.hytale.server.npc.corecomponents.ActionBase;
|
||||
import com.hypixel.hytale.server.npc.role.Role;
|
||||
import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ActionOpenShop extends ActionBase {
|
||||
@Nonnull
|
||||
@@ -23,12 +24,12 @@ public class ActionOpenShop extends ActionBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
public boolean canExecute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, @Nullable InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
return super.canExecute(ref, role, sensorInfo, dt, store) && role.getStateSupport().getInteractionIterationTarget() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
public boolean execute(@Nonnull Ref<EntityStore> ref, @Nonnull Role role, @Nullable InfoProvider sensorInfo, double dt, @Nonnull Store<EntityStore> store) {
|
||||
super.execute(ref, role, sensorInfo, dt, store);
|
||||
Ref<EntityStore> playerReference = role.getStateSupport().getInteractionIterationTarget();
|
||||
if (playerReference == null) {
|
||||
|
||||
@@ -18,7 +18,6 @@ import com.hypixel.hytale.component.ComponentAccessor;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.function.consumer.TriConsumer;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.protocol.packets.assets.TrackOrUpdateObjective;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
@@ -41,6 +40,7 @@ import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class Objective implements NetworkSerializable<com.hypixel.hytale.protocol.Objective> {
|
||||
@Nonnull
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.hypixel.hytale.builtin.adventure.objectives;
|
||||
import com.hypixel.hytale.assetstore.AssetRegistry;
|
||||
import com.hypixel.hytale.assetstore.event.LoadedAssetsEvent;
|
||||
import com.hypixel.hytale.assetstore.map.DefaultAssetMap;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.blockstates.TreasureChestState;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.blockstates.TreasureChestBlock;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.commands.ObjectiveCommand;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.completion.ClearObjectiveItemsCompletion;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.completion.GiveItemsCompletion;
|
||||
@@ -29,6 +29,8 @@ import com.hypixel.hytale.builtin.adventure.objectives.historydata.ObjectiveHist
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.historydata.ObjectiveLineHistoryData;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.historydata.ObjectiveRewardHistoryData;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.interactions.CanBreakRespawnPointInteraction;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.interactions.DestroyTreasureConditionInteraction;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.interactions.OpenTreasureContainerInteraction;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.interactions.StartObjectiveInteraction;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.markers.ObjectiveMarkerProvider;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.markers.objectivelocation.ObjectiveLocationMarker;
|
||||
@@ -36,6 +38,7 @@ import com.hypixel.hytale.builtin.adventure.objectives.markers.objectivelocation
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.markers.reachlocation.ReachLocationMarker;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.markers.reachlocation.ReachLocationMarkerAsset;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.markers.reachlocation.ReachLocationMarkerSystems;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.systems.ObjectiveInventoryChangeSystem;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.systems.ObjectiveItemEntityRemovalSystem;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.systems.ObjectivePlayerSetupSystem;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.task.CraftObjectiveTask;
|
||||
@@ -60,7 +63,7 @@ import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.spatial.SpatialResource;
|
||||
import com.hypixel.hytale.event.EventRegistry;
|
||||
import com.hypixel.hytale.function.function.TriFunction;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.math.vector.Rotation3f;
|
||||
import com.hypixel.hytale.protocol.packets.assets.TrackOrUpdateObjective;
|
||||
import com.hypixel.hytale.protocol.packets.assets.UntrackObjective;
|
||||
import com.hypixel.hytale.server.core.HytaleServer;
|
||||
@@ -77,10 +80,7 @@ import com.hypixel.hytale.server.core.asset.type.weather.config.Weather;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.entity.entities.player.data.PlayerConfigData;
|
||||
import com.hypixel.hytale.server.core.event.events.entity.LivingEntityInventoryChangeEvent;
|
||||
import com.hypixel.hytale.server.core.event.events.player.PlayerDisconnectEvent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.PersistentModel;
|
||||
@@ -96,7 +96,7 @@ import com.hypixel.hytale.server.core.universe.datastore.DataStoreProvider;
|
||||
import com.hypixel.hytale.server.core.universe.datastore.DiskDataStoreProvider;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.events.AddWorldEvent;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.BlockStateModule;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import com.hypixel.hytale.server.core.util.Config;
|
||||
import java.util.Arrays;
|
||||
@@ -127,6 +127,7 @@ public class ObjectivePlugin extends JavaPlugin {
|
||||
private ComponentType<EntityStore, ObjectiveHistoryComponent> objectiveHistoryComponentType;
|
||||
private ComponentType<EntityStore, ReachLocationMarker> reachLocationMarkerComponentType;
|
||||
private ComponentType<EntityStore, ObjectiveLocationMarker> objectiveLocationMarkerComponentType;
|
||||
private ComponentType<ChunkStore, TreasureChestBlock> treasureChestComponentType;
|
||||
@Nullable
|
||||
private ObjectiveDataStore objectiveDataStore;
|
||||
|
||||
@@ -248,7 +249,6 @@ public class ObjectivePlugin extends JavaPlugin {
|
||||
eventRegistry.register(PlayerDisconnectEvent.class, this::onPlayerDisconnect);
|
||||
eventRegistry.register(LoadedAssetsEvent.class, ObjectiveLocationMarkerAsset.class, ObjectivePlugin::onObjectiveLocationMarkerChange);
|
||||
eventRegistry.register(LoadedAssetsEvent.class, ModelAsset.class, this::onModelAssetChange);
|
||||
eventRegistry.registerGlobal(LivingEntityInventoryChangeEvent.class, this::onLivingEntityInventoryChange);
|
||||
eventRegistry.registerGlobal(AddWorldEvent.class, this::onWorldAdded);
|
||||
this.getCommandRegistry().registerCommand(new ObjectiveCommand());
|
||||
EntityModule entityModule = EntityModule.get();
|
||||
@@ -291,16 +291,15 @@ public class ObjectivePlugin extends JavaPlugin {
|
||||
);
|
||||
entityStoreRegistry.registerSystem(new ObjectivePlayerSetupSystem(this.objectiveHistoryComponentType, Player.getComponentType()));
|
||||
entityStoreRegistry.registerSystem(new ObjectiveItemEntityRemovalSystem());
|
||||
entityStoreRegistry.registerSystem(new ObjectiveInventoryChangeSystem());
|
||||
this.getCodecRegistry(Interaction.CODEC).register("StartObjective", StartObjectiveInteraction.class, StartObjectiveInteraction.CODEC);
|
||||
this.getCodecRegistry(Interaction.CODEC).register("CanBreakRespawnPoint", CanBreakRespawnPointInteraction.class, CanBreakRespawnPointInteraction.CODEC);
|
||||
BlockStateModule.get().registerBlockState(TreasureChestState.class, "TreasureChest", TreasureChestState.CODEC);
|
||||
this.getCodecRegistry(Interaction.CODEC)
|
||||
.register("DestroyTreasureCondition", DestroyTreasureConditionInteraction.class, DestroyTreasureConditionInteraction.CODEC);
|
||||
this.getCodecRegistry(Interaction.CODEC)
|
||||
.register("OpenTreasureContainer", OpenTreasureContainerInteraction.class, OpenTreasureContainerInteraction.CODEC);
|
||||
this.treasureChestComponentType = this.getChunkStoreRegistry().registerComponent(TreasureChestBlock.class, "TreasureChest", TreasureChestBlock.CODEC);
|
||||
this.getCodecRegistry(GameplayConfig.PLUGIN_CODEC).register(ObjectiveGameplayConfig.class, "Objective", ObjectiveGameplayConfig.CODEC);
|
||||
entityStoreRegistry.registerSystem(
|
||||
new EntityModule.TangibleMigrationSystem(Query.or(ObjectiveLocationMarker.getComponentType(), ReachLocationMarker.getComponentType())), true
|
||||
);
|
||||
entityStoreRegistry.registerSystem(
|
||||
new EntityModule.HiddenFromPlayerMigrationSystem(Query.or(ObjectiveLocationMarker.getComponentType(), ReachLocationMarker.getComponentType())), true
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -331,6 +330,10 @@ public class ObjectivePlugin extends JavaPlugin {
|
||||
return this.objectiveLocationMarkerComponentType;
|
||||
}
|
||||
|
||||
public ComponentType<ChunkStore, TreasureChestBlock> getTreasureChestComponentType() {
|
||||
return this.treasureChestComponentType;
|
||||
}
|
||||
|
||||
public <T extends ObjectiveTaskAsset, U extends ObjectiveTask> void registerTask(
|
||||
String id,
|
||||
Class<T> assetClass,
|
||||
@@ -414,15 +417,15 @@ public class ObjectivePlugin extends JavaPlugin {
|
||||
participantReference -> {
|
||||
Player playerComponent = store.getComponent(participantReference, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
PlayerRef playerRefComponent = store.getComponent(participantReference, PlayerRef.getComponentType());
|
||||
|
||||
assert playerRefComponent != null;
|
||||
|
||||
if (!this.canPlayerDoObjective(playerComponent, objectiveAssetId)) {
|
||||
playerComponent.sendMessage(
|
||||
playerRefComponent.sendMessage(
|
||||
Message.translation("server.modules.objective.playerAlreadyDoingObjective").param("title", assetTitleMessage)
|
||||
);
|
||||
} else {
|
||||
PlayerRef playerRefComponent = store.getComponent(participantReference, PlayerRef.getComponentType());
|
||||
|
||||
assert playerRefComponent != null;
|
||||
|
||||
UUIDComponent uuidComponent = store.getComponent(participantReference, UUIDComponent.getComponentType());
|
||||
|
||||
assert uuidComponent != null;
|
||||
@@ -831,8 +834,8 @@ public class ObjectivePlugin extends JavaPlugin {
|
||||
|
||||
assert transformComponent != null;
|
||||
|
||||
Vector3f rotation = transformComponent.getRotation();
|
||||
objectiveLocationMarkerComponent.updateLocationMarkerValues(objectiveLocationMarkerAsset, rotation.getYaw(), store);
|
||||
Rotation3f rotation = transformComponent.getRotation();
|
||||
objectiveLocationMarkerComponent.updateLocationMarkerValues(objectiveLocationMarkerAsset, rotation.yaw(), store);
|
||||
ModelComponent modelComponent = archetypeChunk.getComponent(index, ModelComponent.getComponentType());
|
||||
|
||||
assert modelComponent != null;
|
||||
@@ -885,56 +888,6 @@ public class ObjectivePlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void onLivingEntityInventoryChange(@Nonnull LivingEntityInventoryChangeEvent event) {
|
||||
if (this.objectiveDataStore != null) {
|
||||
if (event.getEntity() instanceof Player player) {
|
||||
Set<UUID> activeObjectiveUUIDs = player.getPlayerConfigData().getActiveObjectiveUUIDs();
|
||||
if (!activeObjectiveUUIDs.isEmpty()) {
|
||||
Set<UUID> inventoryItemObjectiveUUIDs = null;
|
||||
CombinedItemContainer inventory = player.getInventory().getCombinedHotbarFirst();
|
||||
|
||||
for (short i = 0; i < inventory.getCapacity(); i++) {
|
||||
ItemStack itemStack = inventory.getItemStack(i);
|
||||
if (!ItemStack.isEmpty(itemStack)) {
|
||||
UUID objectiveUUID = itemStack.getFromMetadataOrNull(StartObjectiveInteraction.OBJECTIVE_UUID);
|
||||
if (objectiveUUID != null) {
|
||||
if (inventoryItemObjectiveUUIDs == null) {
|
||||
inventoryItemObjectiveUUIDs = new HashSet<>(activeObjectiveUUIDs);
|
||||
}
|
||||
|
||||
inventoryItemObjectiveUUIDs.add(objectiveUUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<EntityStore> reference = player.getReference();
|
||||
if (reference != null && reference.isValid()) {
|
||||
Store<EntityStore> store = reference.getStore();
|
||||
World world = store.getExternalData().getWorld();
|
||||
|
||||
for (UUID activeObjectiveUUID : activeObjectiveUUIDs) {
|
||||
if (inventoryItemObjectiveUUIDs == null || !inventoryItemObjectiveUUIDs.contains(activeObjectiveUUID)) {
|
||||
Objective objective = this.objectiveDataStore.getObjective(activeObjectiveUUID);
|
||||
if (objective != null) {
|
||||
ObjectiveAsset objectiveAsset = objective.getObjectiveAsset();
|
||||
if (objectiveAsset != null && objectiveAsset.isRemoveOnItemDrop()) {
|
||||
world.execute(() -> {
|
||||
UUIDComponent uuidComponent = store.getComponent(reference, UUIDComponent.getComponentType());
|
||||
|
||||
assert uuidComponent != null;
|
||||
|
||||
get().removePlayerFromExistingObjective(store, uuidComponent.getUuid(), activeObjectiveUUID);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onWorldAdded(@Nonnull AddWorldEvent event) {
|
||||
event.getWorld().getWorldMapManager().addMarkerProvider("objectives", ObjectiveMarkerProvider.INSTANCE);
|
||||
}
|
||||
|
||||
@@ -6,25 +6,24 @@ import com.hypixel.hytale.builtin.adventure.objectives.events.TreasureChestOpeni
|
||||
import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.Component;
|
||||
import com.hypixel.hytale.component.ComponentAccessor;
|
||||
import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.event.IEventDispatcher;
|
||||
import com.hypixel.hytale.server.core.HytaleServer;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.BlockState;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.state.BreakValidatedBlockState;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.state.ItemContainerState;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class TreasureChestState extends ItemContainerState implements BreakValidatedBlockState {
|
||||
public class TreasureChestBlock implements Component<ChunkStore> {
|
||||
@Nonnull
|
||||
public static final BuilderCodec<TreasureChestState> CODEC = BuilderCodec.builder(TreasureChestState.class, TreasureChestState::new, BlockState.BASE_CODEC)
|
||||
public static final BuilderCodec<TreasureChestBlock> CODEC = BuilderCodec.builder(TreasureChestBlock.class, TreasureChestBlock::new)
|
||||
.append(
|
||||
new KeyedCodec<>("ObjectiveUUID", Codec.UUID_BINARY),
|
||||
(treasureChestState, uuid) -> treasureChestState.objectiveUUID = uuid,
|
||||
@@ -48,9 +47,21 @@ public class TreasureChestState extends ItemContainerState implements BreakValid
|
||||
protected UUID chestUUID;
|
||||
protected boolean opened;
|
||||
|
||||
@Override
|
||||
public static ComponentType<ChunkStore, TreasureChestBlock> getComponentType() {
|
||||
return ObjectivePlugin.get().getTreasureChestComponentType();
|
||||
}
|
||||
|
||||
public TreasureChestBlock() {
|
||||
}
|
||||
|
||||
public TreasureChestBlock(UUID objectiveUUID, UUID chestUUID, boolean opened) {
|
||||
this.objectiveUUID = objectiveUUID;
|
||||
this.chestUUID = chestUUID;
|
||||
this.opened = opened;
|
||||
}
|
||||
|
||||
public boolean canOpen(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor) {
|
||||
if (!this.opened) {
|
||||
if (!this.opened && this.objectiveUUID != null) {
|
||||
UUIDComponent uuidComponent = componentAccessor.getComponent(ref, UUIDComponent.getComponentType());
|
||||
|
||||
assert uuidComponent != null;
|
||||
@@ -62,17 +73,15 @@ public class TreasureChestState extends ItemContainerState implements BreakValid
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDestroy(@Nonnull Ref<EntityStore> playerRef, @Nonnull ComponentAccessor<EntityStore> componentAccessor) {
|
||||
return this.opened;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(@Nonnull Ref<EntityStore> ref, @Nonnull World world, @Nonnull Store<EntityStore> store) {
|
||||
IEventDispatcher<TreasureChestOpeningEvent, TreasureChestOpeningEvent> dispatcher = HytaleServer.get()
|
||||
.getEventBus()
|
||||
.dispatchFor(TreasureChestOpeningEvent.class, world.getName());
|
||||
if (dispatcher.hasListener()) {
|
||||
if (dispatcher.hasListener() && this.objectiveUUID != null) {
|
||||
dispatcher.dispatch(new TreasureChestOpeningEvent(this.objectiveUUID, this.chestUUID, ref, store));
|
||||
}
|
||||
|
||||
@@ -83,9 +92,18 @@ public class TreasureChestState extends ItemContainerState implements BreakValid
|
||||
this.opened = opened;
|
||||
}
|
||||
|
||||
public void setObjectiveData(UUID objectiveUUID, UUID chestUUID, List<ItemStack> itemStacks) {
|
||||
public boolean isOpened() {
|
||||
return this.opened;
|
||||
}
|
||||
|
||||
public void setObjectiveData(UUID objectiveUUID, UUID chestUUID) {
|
||||
this.objectiveUUID = objectiveUUID;
|
||||
this.chestUUID = chestUUID;
|
||||
this.itemContainer.addItemStacks(itemStacks);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Component<ChunkStore> clone() {
|
||||
return new TreasureChestBlock(this.objectiveUUID, this.chestUUID, this.opened);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,7 @@ import com.hypixel.hytale.builtin.adventure.objectives.config.completion.ClearOb
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.config.completion.ObjectiveCompletionAsset;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.interactions.StartObjectiveInteraction;
|
||||
import com.hypixel.hytale.component.ComponentAccessor;
|
||||
import com.hypixel.hytale.server.core.entity.EntityUtils;
|
||||
import com.hypixel.hytale.server.core.entity.LivingEntity;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
@@ -26,16 +25,14 @@ public class ClearObjectiveItemsCompletion extends ObjectiveCompletion {
|
||||
@Override
|
||||
public void handle(@Nonnull Objective objective, @Nonnull ComponentAccessor<EntityStore> componentAccessor) {
|
||||
objective.forEachParticipant((participantReference, objectiveUuid) -> {
|
||||
if (EntityUtils.getEntity(participantReference, componentAccessor) instanceof LivingEntity livingEntity) {
|
||||
CombinedItemContainer inventory = livingEntity.getInventory().getCombinedHotbarFirst();
|
||||
CombinedItemContainer inventory = InventoryComponent.getCombined(componentAccessor, participantReference, InventoryComponent.HOTBAR_FIRST);
|
||||
|
||||
for (short i = 0; i < inventory.getCapacity(); i++) {
|
||||
ItemStack itemStack = inventory.getItemStack(i);
|
||||
if (itemStack != null) {
|
||||
UUID savedObjectiveUuid = itemStack.getFromMetadataOrNull(StartObjectiveInteraction.OBJECTIVE_UUID);
|
||||
if (objectiveUuid.equals(savedObjectiveUuid)) {
|
||||
inventory.removeItemStackFromSlot(i);
|
||||
}
|
||||
for (short i = 0; i < inventory.getCapacity(); i++) {
|
||||
ItemStack itemStack = inventory.getItemStack(i);
|
||||
if (itemStack != null) {
|
||||
UUID savedObjectiveUuid = itemStack.getFromMetadataOrNull(StartObjectiveInteraction.OBJECTIVE_UUID);
|
||||
if (objectiveUuid.equals(savedObjectiveUuid)) {
|
||||
inventory.removeItemStackFromSlot(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,11 @@ import com.hypixel.hytale.builtin.adventure.objectives.historydata.ItemObjective
|
||||
import com.hypixel.hytale.component.ComponentAccessor;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.entity.EntityUtils;
|
||||
import com.hypixel.hytale.server.core.entity.LivingEntity;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.inventory.Inventory;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.inventory.container.SimpleItemContainer;
|
||||
import com.hypixel.hytale.server.core.modules.item.ItemModule;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
@@ -41,33 +40,33 @@ public class GiveItemsCompletion extends ObjectiveCompletion {
|
||||
boolean showItemNotification = world.getGameplayConfig().getShowItemPickupNotifications();
|
||||
objective.forEachParticipant(
|
||||
(participantReference, asset, objectiveHistoryData) -> {
|
||||
if (EntityUtils.getEntity(participantReference, componentAccessor) instanceof LivingEntity livingEntity) {
|
||||
Inventory inventory = livingEntity.getInventory();
|
||||
List itemStacks = ItemModule.get().getRandomItemDrops(asset.getDropListId());
|
||||
SimpleItemContainer.addOrDropItemStacks(store, participantReference, inventory.getCombinedHotbarFirst(), itemStacks);
|
||||
Player playerComponent = componentAccessor.getComponent(participantReference, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
PlayerRef playerRefComponent = componentAccessor.getComponent(participantReference, PlayerRef.getComponentType());
|
||||
CombinedItemContainer hotbarFirstCombinedItemContainer = InventoryComponent.getCombined(
|
||||
componentAccessor, participantReference, InventoryComponent.HOTBAR_FIRST
|
||||
);
|
||||
List<ItemStack> itemStacks = ItemModule.get().getRandomItemDrops(asset.getDropListId());
|
||||
SimpleItemContainer.addOrDropItemStacks(store, participantReference, hotbarFirstCombinedItemContainer, itemStacks);
|
||||
Player playerComponent = componentAccessor.getComponent(participantReference, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
PlayerRef playerRefComponent = componentAccessor.getComponent(participantReference, PlayerRef.getComponentType());
|
||||
|
||||
assert playerRefComponent != null;
|
||||
assert playerRefComponent != null;
|
||||
|
||||
UUIDComponent uuidComponent = store.getComponent(participantReference, UUIDComponent.getComponentType());
|
||||
UUIDComponent uuidComponent = store.getComponent(participantReference, UUIDComponent.getComponentType());
|
||||
|
||||
assert uuidComponent != null;
|
||||
assert uuidComponent != null;
|
||||
|
||||
UUID uuid = uuidComponent.getUuid();
|
||||
UUID uuid = uuidComponent.getUuid();
|
||||
|
||||
for (ItemStack itemStack : itemStacks) {
|
||||
objectiveHistoryData.addRewardForPlayerUUID(uuid, new ItemObjectiveRewardHistoryData(itemStack.getItemId(), itemStack.getQuantity()));
|
||||
if (showItemNotification) {
|
||||
Message itemNameMessage = Message.translation(itemStack.getItem().getTranslationKey());
|
||||
NotificationUtil.sendNotification(
|
||||
playerRefComponent.getPacketHandler(),
|
||||
Message.translation("server.objectives.itemObjectiveCompletion").param("item", itemNameMessage),
|
||||
null,
|
||||
itemStack.toPacket()
|
||||
);
|
||||
}
|
||||
for (ItemStack itemStack : itemStacks) {
|
||||
objectiveHistoryData.addRewardForPlayerUUID(uuid, new ItemObjectiveRewardHistoryData(itemStack.getItemId(), itemStack.getQuantity()));
|
||||
if (showItemNotification) {
|
||||
Message itemNameMessage = Message.translation(itemStack.getItem().getTranslationKey());
|
||||
NotificationUtil.sendNotification(
|
||||
playerRefComponent.getPacketHandler(),
|
||||
Message.translation("server.objectives.itemObjectiveCompletion").param("item", itemNameMessage),
|
||||
null,
|
||||
itemStack.toPacket()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.spatial.SpatialResource;
|
||||
import com.hypixel.hytale.math.shape.Box;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class ObjectiveLocationAreaBox extends ObjectiveLocationMarkerArea {
|
||||
@Nonnull
|
||||
|
||||
@@ -9,13 +9,13 @@ import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.spatial.SpatialResource;
|
||||
import com.hypixel.hytale.math.shape.Box;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.VectorSphereUtil;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class ObjectiveLocationAreaRadius extends ObjectiveLocationMarkerArea {
|
||||
@Nonnull
|
||||
|
||||
@@ -6,11 +6,11 @@ import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.spatial.SpatialResource;
|
||||
import com.hypixel.hytale.math.shape.Box;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public abstract class ObjectiveLocationMarkerArea {
|
||||
@Nonnull
|
||||
|
||||
@@ -5,8 +5,8 @@ import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public abstract class CountObjectiveTaskAsset extends ObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
|
||||
@@ -5,9 +5,9 @@ import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.Item;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class CraftObjectiveTaskAsset extends CountObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.hypixel.hytale.builtin.adventure.objectives.config.taskcondition.Task
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class GatherObjectiveTaskAsset extends CountObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
|
||||
@@ -6,11 +6,12 @@ import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
|
||||
import com.hypixel.hytale.codec.lookup.CodecMapCodec;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Vector3iUtil;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public abstract class ObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
@@ -30,7 +31,7 @@ public abstract class ObjectiveTaskAsset {
|
||||
)
|
||||
.add()
|
||||
.append(
|
||||
new KeyedCodec<>("MapMarkerPositions", new ArrayCodec<>(Vector3i.CODEC, Vector3i[]::new)),
|
||||
new KeyedCodec<>("MapMarkerPositions", new ArrayCodec<>(Vector3iUtil.CODEC, Vector3i[]::new)),
|
||||
(taskAsset, positions) -> taskAsset.mapMarkers = positions,
|
||||
taskAsset -> taskAsset.mapMarkers
|
||||
)
|
||||
|
||||
@@ -8,12 +8,12 @@ import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.ItemDropList;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class TreasureMapObjectiveTaskAsset extends ObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.hypixel.hytale.builtin.adventure.objectives.config.taskcondition.Task
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class UseBlockObjectiveTaskAsset extends CountObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
|
||||
@@ -5,10 +5,10 @@ import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import java.util.Objects;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class UseEntityObjectiveTaskAsset extends CountObjectiveTaskAsset {
|
||||
@Nonnull
|
||||
|
||||
@@ -7,9 +7,9 @@ import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.component.ComponentAccessor;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.inventory.Inventory;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@@ -69,32 +69,24 @@ public class SoloInventoryCondition extends TaskConditionAsset {
|
||||
|
||||
@Override
|
||||
public boolean isConditionFulfilled(@Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nonnull Ref<EntityStore> ref, Set<UUID> objectivePlayers) {
|
||||
Player playerComponent = componentAccessor.getComponent(ref, Player.getComponentType());
|
||||
if (playerComponent == null) {
|
||||
return false;
|
||||
} else {
|
||||
Inventory inventory = playerComponent.getInventory();
|
||||
if (this.holdInHand) {
|
||||
ItemStack itemInHand = inventory.getItemInHand();
|
||||
if (itemInHand == null) {
|
||||
return false;
|
||||
} else {
|
||||
return !this.blockTypeOrTagTask.isBlockTypeIncluded(itemInHand.getItemId()) ? false : inventory.getItemInHand().getQuantity() >= this.quantity;
|
||||
}
|
||||
if (this.holdInHand) {
|
||||
ItemStack itemInHand = InventoryComponent.getItemInHand(componentAccessor, ref);
|
||||
if (itemInHand == null) {
|
||||
return false;
|
||||
} else {
|
||||
return inventory.getCombinedHotbarFirst().countItemStacks(itemStack -> this.blockTypeOrTagTask.isBlockTypeIncluded(itemStack.getItemId()))
|
||||
>= this.quantity;
|
||||
return !this.blockTypeOrTagTask.isBlockTypeIncluded(itemInHand.getItemId()) ? false : itemInHand.getQuantity() >= this.quantity;
|
||||
}
|
||||
} else {
|
||||
CombinedItemContainer combinedInventory = InventoryComponent.getCombined(componentAccessor, ref, InventoryComponent.HOTBAR_FIRST);
|
||||
return combinedInventory.countItemStacks(itemStack -> this.blockTypeOrTagTask.isBlockTypeIncluded(itemStack.getItemId())) >= this.quantity;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumeCondition(@Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nonnull Ref<EntityStore> ref, Set<UUID> objectivePlayers) {
|
||||
Player playerComponent = componentAccessor.getComponent(ref, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
if (this.consumeOnCompletion) {
|
||||
this.blockTypeOrTagTask.consumeItemStacks(playerComponent.getInventory().getCombinedHotbarFirst(), this.quantity);
|
||||
}
|
||||
if (this.consumeOnCompletion) {
|
||||
CombinedItemContainer combinedInventory = InventoryComponent.getCombined(componentAccessor, ref, InventoryComponent.HOTBAR_FIRST);
|
||||
this.blockTypeOrTagTask.consumeItemStacks(combinedInventory, this.quantity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@ import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.iterator.SpiralIterator;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.util.MathUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class CheckTagWorldHeightRadiusProvider extends WorldLocationProvider {
|
||||
@Nonnull
|
||||
|
||||
@@ -7,11 +7,11 @@ import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.util.MathUtil;
|
||||
import com.hypixel.hytale.math.util.TrigMathUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class LocationRadiusProvider extends WorldLocationProvider {
|
||||
@Nonnull
|
||||
@@ -52,7 +52,7 @@ public class LocationRadiusProvider extends WorldLocationProvider {
|
||||
public Vector3i runCondition(@Nonnull World world, @Nonnull Vector3i position) {
|
||||
double angle = Math.random() * (float) (Math.PI * 2);
|
||||
int radius = MathUtil.randomInt(this.minRadius, this.maxRadius);
|
||||
Vector3i newPosition = position.clone();
|
||||
Vector3i newPosition = new Vector3i(position);
|
||||
newPosition.add((int)(radius * TrigMathUtil.cos(angle)), 0, (int)(radius * TrigMathUtil.sin(angle)));
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(newPosition.x, newPosition.z);
|
||||
WorldChunk worldChunkComponent = world.getChunk(chunkIndex);
|
||||
|
||||
@@ -6,13 +6,13 @@ import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class LookBlocksBelowProvider extends WorldLocationProvider {
|
||||
@Nonnull
|
||||
@@ -96,7 +96,7 @@ public class LookBlocksBelowProvider extends WorldLocationProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public Vector3i runCondition(@Nonnull World world, @Nonnull Vector3i position) {
|
||||
Vector3i newPosition = position.clone();
|
||||
Vector3i newPosition = new Vector3i(position);
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(newPosition.x, newPosition.z);
|
||||
WorldChunk worldChunkComponent = world.getChunk(chunkIndex);
|
||||
if (worldChunkComponent == null) {
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.hypixel.hytale.builtin.adventure.objectives.config.worldlocationprov
|
||||
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.codec.lookup.CodecMapCodec;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public abstract class WorldLocationProvider {
|
||||
@Nonnull
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionState;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.WaitForDataFrom;
|
||||
@@ -21,6 +20,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class CanBreakRespawnPointInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.hypixel.hytale.builtin.adventure.objectives.interactions;
|
||||
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.blockstates.TreasureChestBlock;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.protocol.InteractionState;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.WaitForDataFrom;
|
||||
import com.hypixel.hytale.server.core.entity.InteractionContext;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
|
||||
import com.hypixel.hytale.server.core.modules.interaction.interaction.config.client.SimpleBlockInteraction;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class DestroyTreasureConditionInteraction extends SimpleBlockInteraction {
|
||||
public static final BuilderCodec<DestroyTreasureConditionInteraction> CODEC = BuilderCodec.builder(
|
||||
DestroyTreasureConditionInteraction.class, DestroyTreasureConditionInteraction::new, SimpleBlockInteraction.CODEC
|
||||
)
|
||||
.documentation("Checks if the target treasure block is destroyable")
|
||||
.build();
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public WaitForDataFrom getWaitForDataFrom() {
|
||||
return WaitForDataFrom.Server;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void interactWithBlock(
|
||||
@Nonnull World world,
|
||||
@Nonnull CommandBuffer<EntityStore> commandBuffer,
|
||||
@Nonnull InteractionType type,
|
||||
@Nonnull InteractionContext context,
|
||||
@Nullable ItemStack itemInHand,
|
||||
@Nonnull Vector3i pos,
|
||||
@Nonnull CooldownHandler cooldownHandler
|
||||
) {
|
||||
Ref<EntityStore> ref = context.getEntity();
|
||||
Player playerComponent = commandBuffer.getComponent(ref, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
ChunkStore chunkStore = world.getChunkStore();
|
||||
Ref<ChunkStore> chunkRef = chunkStore.getChunkReference(ChunkUtil.indexChunkFromBlock(pos.x, pos.z));
|
||||
if (chunkRef != null) {
|
||||
Store<ChunkStore> chunkEntityStore = chunkStore.getStore();
|
||||
BlockComponentChunk blockComponentChunk = chunkEntityStore.getComponent(chunkRef, BlockComponentChunk.getComponentType());
|
||||
if (blockComponentChunk != null) {
|
||||
Ref<ChunkStore> blockRef = blockComponentChunk.getEntityReference(ChunkUtil.indexBlockInColumn(pos.x, pos.y, pos.z));
|
||||
if (blockRef != null) {
|
||||
TreasureChestBlock treasureBlock = chunkEntityStore.getComponent(blockRef, TreasureChestBlock.getComponentType());
|
||||
if (treasureBlock != null) {
|
||||
if (treasureBlock.canDestroy(ref, commandBuffer)) {
|
||||
context.getState().state = InteractionState.Finished;
|
||||
} else {
|
||||
context.getState().state = InteractionState.Failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void simulateInteractWithBlock(
|
||||
@Nonnull InteractionType type, @Nonnull InteractionContext context, @Nullable ItemStack itemInHand, @Nonnull World world, @Nonnull Vector3i targetBlock
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.hypixel.hytale.builtin.adventure.objectives.interactions;
|
||||
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.blockstates.TreasureChestBlock;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.Page;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
import com.hypixel.hytale.server.core.entity.InteractionContext;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.entity.entities.player.windows.ContainerBlockWindow;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.modules.block.components.ItemContainerBlock;
|
||||
import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
|
||||
import com.hypixel.hytale.server.core.modules.interaction.interaction.config.client.SimpleBlockInteraction;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.SoundUtil;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class OpenTreasureContainerInteraction extends SimpleBlockInteraction {
|
||||
public static final BuilderCodec<OpenTreasureContainerInteraction> CODEC = BuilderCodec.builder(
|
||||
OpenTreasureContainerInteraction.class, OpenTreasureContainerInteraction::new, SimpleBlockInteraction.CODEC
|
||||
)
|
||||
.documentation("Opens the container of the block currently being interacted with.")
|
||||
.build();
|
||||
|
||||
@Override
|
||||
protected void interactWithBlock(
|
||||
@Nonnull World world,
|
||||
@Nonnull CommandBuffer<EntityStore> commandBuffer,
|
||||
@Nonnull InteractionType type,
|
||||
@Nonnull InteractionContext context,
|
||||
@Nullable ItemStack itemInHand,
|
||||
@Nonnull Vector3i pos,
|
||||
@Nonnull CooldownHandler cooldownHandler
|
||||
) {
|
||||
Ref<EntityStore> ref = context.getEntity();
|
||||
Store<EntityStore> store = ref.getStore();
|
||||
Player playerComponent = commandBuffer.getComponent(ref, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
ChunkStore chunkStore = world.getChunkStore();
|
||||
Ref<ChunkStore> chunkRef = chunkStore.getChunkReference(ChunkUtil.indexChunkFromBlock(pos.x, pos.z));
|
||||
if (chunkRef != null) {
|
||||
BlockComponentChunk blockComponentChunk = chunkStore.getStore().getComponent(chunkRef, BlockComponentChunk.getComponentType());
|
||||
if (blockComponentChunk != null) {
|
||||
Ref<ChunkStore> blockRef = blockComponentChunk.getEntityReference(ChunkUtil.indexBlockInColumn(pos.x, pos.y, pos.z));
|
||||
if (blockRef != null) {
|
||||
ItemContainerBlock itemContainerBlock = chunkStore.getStore().getComponent(blockRef, ItemContainerBlock.getComponentType());
|
||||
TreasureChestBlock treasureBlock = chunkStore.getStore().getComponent(blockRef, TreasureChestBlock.getComponentType());
|
||||
if (itemContainerBlock != null && treasureBlock != null) {
|
||||
BlockType blockType = world.getBlockType(pos.x, pos.y, pos.z);
|
||||
if (treasureBlock.canOpen(ref, commandBuffer)) {
|
||||
UUIDComponent uuidComponent = commandBuffer.getComponent(ref, UUIDComponent.getComponentType());
|
||||
|
||||
assert uuidComponent != null;
|
||||
|
||||
UUID uuid = uuidComponent.getUuid();
|
||||
WorldChunk chunk = world.getChunk(ChunkUtil.indexChunkFromBlock(pos.x, pos.z));
|
||||
ContainerBlockWindow window = new ContainerBlockWindow(
|
||||
pos.x, pos.y, pos.z, chunk.getRotationIndex(pos.x, pos.y, pos.z), blockType, itemContainerBlock.getItemContainer()
|
||||
);
|
||||
Map<UUID, ContainerBlockWindow> windows = itemContainerBlock.getWindows();
|
||||
if (windows.putIfAbsent(uuid, window) == null) {
|
||||
if (playerComponent.getPageManager().setPageWithWindows(ref, store, Page.Bench, true, window)) {
|
||||
window.registerCloseEvent(event -> {
|
||||
windows.remove(uuid, window);
|
||||
BlockType currentBlockType = world.getBlockType(pos);
|
||||
if (windows.isEmpty()) {
|
||||
world.setBlockInteractionState(pos, currentBlockType, "CloseWindow");
|
||||
}
|
||||
|
||||
BlockType interactionStatex = currentBlockType.getBlockForState("CloseWindow");
|
||||
if (interactionStatex != null) {
|
||||
int soundEventIndexx = interactionStatex.getInteractionSoundEventIndex();
|
||||
if (soundEventIndexx != 0) {
|
||||
int rotationIndexx = chunk.getRotationIndex(pos.x, pos.y, pos.z);
|
||||
Vector3d soundPosx = new Vector3d();
|
||||
blockType.getBlockCenter(rotationIndexx, soundPosx);
|
||||
soundPosx.add(pos.x, pos.y, pos.z);
|
||||
SoundUtil.playSoundEvent3d(ref, soundEventIndexx, soundPosx, commandBuffer);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (windows.size() == 1) {
|
||||
world.setBlockInteractionState(pos, blockType, "OpenWindow");
|
||||
}
|
||||
|
||||
BlockType interactionState = blockType.getBlockForState("OpenWindow");
|
||||
if (interactionState == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int soundEventIndex = interactionState.getInteractionSoundEventIndex();
|
||||
if (soundEventIndex == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int rotationIndex = chunk.getRotationIndex(pos.x, pos.y, pos.z);
|
||||
Vector3d soundPos = new Vector3d();
|
||||
blockType.getBlockCenter(rotationIndex, soundPos);
|
||||
soundPos.add(pos.x, pos.y, pos.z);
|
||||
SoundUtil.playSoundEvent3d(ref, soundEventIndex, soundPos, commandBuffer);
|
||||
} else {
|
||||
windows.remove(uuid, window);
|
||||
}
|
||||
}
|
||||
|
||||
treasureBlock.onOpen(ref, world, store);
|
||||
}
|
||||
} else {
|
||||
PlayerRef playerRefComponent = commandBuffer.getComponent(ref, PlayerRef.getComponentType());
|
||||
if (playerRefComponent != null) {
|
||||
playerRefComponent.sendMessage(
|
||||
Message.translation("server.interactions.invalidBlockState")
|
||||
.param("interaction", this.getClass().getSimpleName())
|
||||
.param("blockState", chunkStore.getStore().getArchetype(blockRef).toString())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void simulateInteractWithBlock(
|
||||
@Nonnull InteractionType type, @Nonnull InteractionContext context, @Nullable ItemStack itemInHand, @Nonnull World world, @Nonnull Vector3i targetBlock
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,6 @@ public class ObjectiveTaskMarker {
|
||||
}
|
||||
|
||||
public MapMarker toProto() {
|
||||
return new MapMarker(this.id, this.name.getFormattedMessage(), null, this.icon, PositionUtil.toTransformPacket(this.transform), null, null);
|
||||
return new MapMarker(this.id, this.name.getFormattedMessage(), this.icon, PositionUtil.toTransformPacket(this.transform), null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,7 @@ import com.hypixel.hytale.component.system.HolderSystem;
|
||||
import com.hypixel.hytale.component.system.RefSystem;
|
||||
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.math.vector.Rotation3f;
|
||||
import com.hypixel.hytale.protocol.packets.assets.TrackOrUpdateObjective;
|
||||
import com.hypixel.hytale.protocol.packets.assets.UntrackObjective;
|
||||
import com.hypixel.hytale.server.core.asset.type.model.config.Model;
|
||||
@@ -44,15 +43,16 @@ import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.Universe;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class ObjectiveLocationMarkerSystems {
|
||||
public static class EnsureNetworkSendableSystem extends HolderSystem<EntityStore> {
|
||||
@@ -154,8 +154,8 @@ public class ObjectiveLocationMarkerSystems {
|
||||
|
||||
assert transformComponent != null;
|
||||
|
||||
Vector3f rotation = transformComponent.getRotation();
|
||||
objectiveLocationMarkerComponent.updateLocationMarkerValues(markerAsset, rotation.getYaw(), store);
|
||||
Rotation3f rotation = transformComponent.getRotation();
|
||||
objectiveLocationMarkerComponent.updateLocationMarkerValues(markerAsset, rotation.yaw(), store);
|
||||
ModelComponent modelComponent = store.getComponent(ref, this.modelComponentType);
|
||||
|
||||
assert modelComponent != null;
|
||||
@@ -304,7 +304,7 @@ public class ObjectiveLocationMarkerSystems {
|
||||
this.setupMarker(store, objectiveLocationMarkerComponent, entityReference, position, uuid, commandBuffer);
|
||||
} else if (!activeObjective.isCompleted()) {
|
||||
SpatialResource<Ref<EntityStore>, EntityStore> spatialResource = store.getResource(this.playerSpatialComponent);
|
||||
ObjectList<Ref<EntityStore>> playerRefs = SpatialResource.getThreadLocalReferenceList();
|
||||
List<Ref<EntityStore>> playerRefs = SpatialResource.getThreadLocalReferenceList();
|
||||
objectiveLocationMarkerComponent.area.getPlayersInExitArea(spatialResource, playerRefs, position);
|
||||
HashSet<UUID> playersInExitArea = new HashSet<>(playerRefs.size());
|
||||
PlayerRef[] playersInEntryArea = new PlayerRef[playerRefs.size()];
|
||||
|
||||
@@ -24,18 +24,18 @@ import com.hypixel.hytale.component.system.HolderSystem;
|
||||
import com.hypixel.hytale.component.system.RefSystem;
|
||||
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
|
||||
import com.hypixel.hytale.server.core.modules.entity.system.PlayerSpatialSystem;
|
||||
import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class ReachLocationMarkerSystems {
|
||||
@Nonnull
|
||||
@@ -198,7 +198,7 @@ public class ReachLocationMarkerSystems {
|
||||
Set<UUID> players = reachLocationMarkerComponent.getPlayers();
|
||||
players.clear();
|
||||
SpatialResource<Ref<EntityStore>, EntityStore> spatialResource = store.getResource(this.playerSpatialComponent);
|
||||
ObjectList<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
List<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
TransformComponent transformComponent = archetypeChunk.getComponent(index, this.transformComponentType);
|
||||
|
||||
assert transformComponent != null;
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.hypixel.hytale.builtin.adventure.objectives.systems;
|
||||
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.Objective;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.ObjectiveDataStore;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.ObjectivePlugin;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.config.ObjectiveAsset;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.interactions.StartObjectiveInteraction;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.task.InventoryChangeAware;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.task.ObjectiveTask;
|
||||
import com.hypixel.hytale.component.ArchetypeChunk;
|
||||
import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.EntityEventSystem;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryChangeEvent;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ObjectiveInventoryChangeSystem extends EntityEventSystem<EntityStore, InventoryChangeEvent> {
|
||||
public ObjectiveInventoryChangeSystem() {
|
||||
super(InventoryChangeEvent.class);
|
||||
}
|
||||
|
||||
public void handle(
|
||||
int index,
|
||||
@Nonnull ArchetypeChunk<EntityStore> archetypeChunk,
|
||||
@Nonnull Store<EntityStore> store,
|
||||
@Nonnull CommandBuffer<EntityStore> commandBuffer,
|
||||
@Nonnull InventoryChangeEvent event
|
||||
) {
|
||||
ObjectiveDataStore objectiveDataStore = ObjectivePlugin.get().getObjectiveDataStore();
|
||||
if (objectiveDataStore != null) {
|
||||
Player playerComponent = archetypeChunk.getComponent(index, Player.getComponentType());
|
||||
|
||||
assert playerComponent != null;
|
||||
|
||||
Set<UUID> activeObjectiveUUIDs = playerComponent.getPlayerConfigData().getActiveObjectiveUUIDs();
|
||||
if (!activeObjectiveUUIDs.isEmpty()) {
|
||||
Ref<EntityStore> ref = archetypeChunk.getReferenceTo(index);
|
||||
handleRemoveOnItemDrop(ref, activeObjectiveUUIDs, objectiveDataStore, store);
|
||||
|
||||
for (UUID objectiveUUID : activeObjectiveUUIDs) {
|
||||
Objective objective = objectiveDataStore.getObjective(objectiveUUID);
|
||||
if (objective != null) {
|
||||
ObjectiveTask[] currentTasks = objective.getCurrentTasks();
|
||||
if (currentTasks != null) {
|
||||
for (ObjectiveTask task : currentTasks) {
|
||||
if (task instanceof InventoryChangeAware aware) {
|
||||
aware.onInventoryChange(objective, ref, store, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleRemoveOnItemDrop(
|
||||
@Nonnull Ref<EntityStore> ref, @Nonnull Set<UUID> activeObjectiveUUIDs, @Nonnull ObjectiveDataStore objectiveDataStore, @Nonnull Store<EntityStore> store
|
||||
) {
|
||||
Set<UUID> inventoryItemObjectiveUUIDs = null;
|
||||
CombinedItemContainer combinedInventory = InventoryComponent.getCombined(store, ref, InventoryComponent.HOTBAR_FIRST);
|
||||
|
||||
for (short i = 0; i < combinedInventory.getCapacity(); i++) {
|
||||
ItemStack itemStack = combinedInventory.getItemStack(i);
|
||||
if (!ItemStack.isEmpty(itemStack)) {
|
||||
UUID objectiveUUID = itemStack.getFromMetadataOrNull(StartObjectiveInteraction.OBJECTIVE_UUID);
|
||||
if (objectiveUUID != null) {
|
||||
if (inventoryItemObjectiveUUIDs == null) {
|
||||
inventoryItemObjectiveUUIDs = new HashSet<>(activeObjectiveUUIDs);
|
||||
}
|
||||
|
||||
inventoryItemObjectiveUUIDs.add(objectiveUUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UUIDComponent uuidComponent = store.getComponent(ref, UUIDComponent.getComponentType());
|
||||
|
||||
assert uuidComponent != null;
|
||||
|
||||
for (UUID activeObjectiveUUID : activeObjectiveUUIDs) {
|
||||
if (inventoryItemObjectiveUUIDs == null || !inventoryItemObjectiveUUIDs.contains(activeObjectiveUUID)) {
|
||||
Objective objective = objectiveDataStore.getObjective(activeObjectiveUUID);
|
||||
if (objective != null) {
|
||||
ObjectiveAsset objectiveAsset = objective.getObjectiveAsset();
|
||||
if (objectiveAsset != null && objectiveAsset.isRemoveOnItemDrop()) {
|
||||
ObjectivePlugin.get().removePlayerFromExistingObjective(store, uuidComponent.getUuid(), activeObjectiveUUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Query<EntityStore> getQuery() {
|
||||
return Player.getComponentType();
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,15 @@ package com.hypixel.hytale.builtin.adventure.objectives.task;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.Objective;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.config.task.BlockTagOrItemIdField;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.config.task.GatherObjectiveTaskAsset;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.transaction.RegistrationTransactionRecord;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.transaction.TransactionRecord;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.ComponentAccessor;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.MathUtil;
|
||||
import com.hypixel.hytale.server.core.entity.LivingEntity;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.event.events.entity.LivingEntityInventoryChangeEvent;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryChangeEvent;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.Universe;
|
||||
@@ -24,7 +22,7 @@ import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class GatherObjectiveTask extends CountObjectiveTask {
|
||||
public class GatherObjectiveTask extends CountObjectiveTask implements InventoryChangeAware {
|
||||
@Nonnull
|
||||
public static final BuilderCodec<GatherObjectiveTask> CODEC = BuilderCodec.builder(
|
||||
GatherObjectiveTask.class, GatherObjectiveTask::new, CountObjectiveTask.CODEC
|
||||
@@ -57,28 +55,21 @@ public class GatherObjectiveTask extends CountObjectiveTask {
|
||||
}
|
||||
}
|
||||
|
||||
this.eventRegistry.register(LivingEntityInventoryChangeEvent.class, world.getName(), event -> {
|
||||
LivingEntity livingEntity = event.getEntity();
|
||||
if (livingEntity instanceof Player) {
|
||||
Ref<EntityStore> ref = livingEntity.getReference();
|
||||
if (ref != null && ref.isValid()) {
|
||||
World refWorld = store.getExternalData().getWorld();
|
||||
refWorld.execute(() -> {
|
||||
if (ref.isValid()) {
|
||||
UUIDComponent uuidComponent = store.getComponent(ref, UUIDComponent.getComponentType());
|
||||
if (uuidComponent != null) {
|
||||
Set<UUID> activePlayerUUIDs = objective.getActivePlayerUUIDs();
|
||||
if (activePlayerUUIDs.contains(uuidComponent.getUuid())) {
|
||||
int count = this.countObjectiveItemInInventories(activePlayerUUIDs, store);
|
||||
this.setTaskCompletion(store, ref, count, objective);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryChange(
|
||||
@Nonnull Objective objective, @Nonnull Ref<EntityStore> playerRef, @Nonnull Store<EntityStore> store, @Nonnull InventoryChangeEvent event
|
||||
) {
|
||||
UUIDComponent uuidComponent = store.getComponent(playerRef, UUIDComponent.getComponentType());
|
||||
if (uuidComponent != null) {
|
||||
Set<UUID> activePlayerUUIDs = objective.getActivePlayerUUIDs();
|
||||
if (activePlayerUUIDs.contains(uuidComponent.getUuid())) {
|
||||
int count = this.countObjectiveItemInInventories(activePlayerUUIDs, store);
|
||||
this.setTaskCompletion(store, playerRef, count, objective);
|
||||
}
|
||||
});
|
||||
return RegistrationTransactionRecord.wrap(this.eventRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
private int countObjectiveItemInInventories(@Nonnull Set<UUID> participatingPlayers, @Nonnull ComponentAccessor<EntityStore> componentAccessor) {
|
||||
@@ -90,12 +81,8 @@ public class GatherObjectiveTask extends CountObjectiveTask {
|
||||
if (playerRefComponent != null) {
|
||||
Ref<EntityStore> playerRef = playerRefComponent.getReference();
|
||||
if (playerRef != null && playerRef.isValid()) {
|
||||
Player playerComponent = componentAccessor.getComponent(playerRef, Player.getComponentType());
|
||||
|
||||
assert playerComponent != null;
|
||||
|
||||
CombinedItemContainer inventory = playerComponent.getInventory().getCombinedHotbarFirst();
|
||||
count += inventory.countItemStacks(itemStack -> blockTypeOrSet.isBlockTypeIncluded(itemStack.getItemId()));
|
||||
CombinedItemContainer combinedInventory = InventoryComponent.getCombined(componentAccessor, playerRef, InventoryComponent.HOTBAR_FIRST);
|
||||
count += combinedInventory.countItemStacks(itemStack -> blockTypeOrSet.isBlockTypeIncluded(itemStack.getItemId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.hypixel.hytale.builtin.adventure.objectives.task;
|
||||
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.Objective;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryChangeEvent;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface InventoryChangeAware {
|
||||
void onInventoryChange(@Nonnull Objective var1, @Nonnull Ref<EntityStore> var2, @Nonnull Store<EntityStore> var3, @Nonnull InventoryChangeEvent var4);
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.event.EventRegistry;
|
||||
import com.hypixel.hytale.math.vector.Transform;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.packets.assets.UpdateObjectiveTask;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.io.NetworkSerializer;
|
||||
@@ -34,6 +33,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public abstract class ObjectiveTask implements NetworkSerializer<Objective, com.hypixel.hytale.protocol.ObjectiveTask> {
|
||||
@Nonnull
|
||||
|
||||
@@ -14,16 +14,16 @@ import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.vector.Transform;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.entity.UUIDComponent;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class ReachLocationTask extends ObjectiveTask {
|
||||
@Nonnull
|
||||
@@ -79,7 +79,7 @@ public class ReachLocationTask extends ObjectiveTask {
|
||||
return null;
|
||||
} else {
|
||||
String targetLocationId = this.getAsset().getTargetLocationId();
|
||||
List<Ref<EntityStore>> reachLocationMarkerEntities = new ObjectArrayList<>();
|
||||
List<Ref<EntityStore>> reachLocationMarkerEntities = new ReferenceArrayList<>();
|
||||
store.forEachChunk(REACH_LOCATION_MARKER_COMPONENT_TYPE, (archetypeChunk, componentStoreCommandBuffer) -> {
|
||||
for (int index = 0; index < archetypeChunk.size(); index++) {
|
||||
ReachLocationMarker reachLocationMarkerComponent = archetypeChunk.getComponent(index, REACH_LOCATION_MARKER_COMPONENT_TYPE);
|
||||
@@ -100,7 +100,7 @@ public class ReachLocationTask extends ObjectiveTask {
|
||||
assert closestMarkerReachComponent != null;
|
||||
|
||||
Vector3d closestPosition = closestMarkerTransformComponent.getPosition();
|
||||
double shortestDistance = closestPosition.distanceSquaredTo(currentLocation);
|
||||
double shortestDistance = closestPosition.distanceSquared(currentLocation);
|
||||
String closestLocationName = closestMarkerReachComponent.getLocationName();
|
||||
|
||||
for (int i = 1; i < reachLocationMarkerEntities.size(); i++) {
|
||||
@@ -114,7 +114,7 @@ public class ReachLocationTask extends ObjectiveTask {
|
||||
assert markerReachLocationComponent != null;
|
||||
|
||||
Vector3d pos = markerTransformComponent.getPosition();
|
||||
double distance = pos.distanceSquaredTo(currentLocation);
|
||||
double distance = pos.distanceSquared(currentLocation);
|
||||
String locationName = markerReachLocationComponent.getLocationName();
|
||||
if (distance < shortestDistance && locationName != null) {
|
||||
shortestDistance = distance;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.hypixel.hytale.builtin.adventure.objectives.task;
|
||||
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.Objective;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.ObjectivePlugin;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.blockstates.TreasureChestState;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.blockstates.TreasureChestBlock;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.config.task.TreasureMapObjectiveTaskAsset;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.events.TreasureChestOpeningEvent;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.markers.ObjectiveTaskMarker;
|
||||
@@ -20,16 +20,14 @@ import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.util.MathUtil;
|
||||
import com.hypixel.hytale.math.util.TrigMathUtil;
|
||||
import com.hypixel.hytale.math.vector.Transform;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Vector3dUtil;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.modules.block.components.ItemContainerBlock;
|
||||
import com.hypixel.hytale.server.core.modules.item.ItemModule;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.BlockState;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.BlockStateModule;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.state.ItemContainerState;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -38,6 +36,8 @@ import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class TreasureMapObjectiveTask extends ObjectiveTask {
|
||||
@Nonnull
|
||||
@@ -140,15 +140,23 @@ public class TreasureMapObjectiveTask extends ObjectiveTask {
|
||||
if (conditionPosition == null) {
|
||||
return transactionRecord.fail("Position not safe to spawn chest");
|
||||
} else {
|
||||
TreasureChestState treasureChestState = this.spawnChestBlock(world, conditionPosition, chestConfig.getChestBlockTypeKey(), transactionRecord);
|
||||
if (treasureChestState == null) {
|
||||
Ref<ChunkStore> treasureChestRef = this.spawnChestBlock(world, conditionPosition, chestConfig.getChestBlockTypeKey(), transactionRecord);
|
||||
if (treasureChestRef == null) {
|
||||
return transactionRecord;
|
||||
} else {
|
||||
TreasureChestBlock treasureChest = treasureChestRef.getStore().getComponent(treasureChestRef, TreasureChestBlock.getComponentType());
|
||||
|
||||
assert treasureChest != null;
|
||||
|
||||
ItemContainerBlock container = treasureChestRef.getStore().getComponent(treasureChestRef, ItemContainerBlock.getComponentType());
|
||||
|
||||
assert container != null;
|
||||
|
||||
UUID chestUUID = UUID.randomUUID();
|
||||
List<ItemStack> stacks = ItemModule.get().getRandomItemDrops(chestConfig.getDroplistId());
|
||||
treasureChestState.setObjectiveData(objective.getObjectiveUUID(), chestUUID, stacks);
|
||||
treasureChest.setObjectiveData(objective.getObjectiveUUID(), chestUUID);
|
||||
container.getItemContainer().addItemStacks(stacks);
|
||||
this.chestUUIDs.add(chestUUID);
|
||||
treasureChestState.getChunk().setState(conditionPosition.getX(), conditionPosition.getY(), conditionPosition.getZ(), treasureChestState);
|
||||
ObjectivePlugin.get().getLogger().at(Level.INFO).log("Spawned chest at: " + conditionPosition);
|
||||
ObjectiveTaskMarker marker = new ObjectiveTaskMarker(
|
||||
this.getChestMarkerIDFromUUID(chestUUID), new Transform(conditionPosition), "Home.png", Message.translation("server.objectives.treasure.marker")
|
||||
@@ -160,7 +168,7 @@ public class TreasureMapObjectiveTask extends ObjectiveTask {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private TreasureChestState spawnChestBlock(
|
||||
private Ref<ChunkStore> spawnChestBlock(
|
||||
@Nonnull World world, @Nonnull Vector3i conditionPosition, String chestBlockTypeKey, @Nonnull SpawnTreasureChestTransactionRecord transactionRecord
|
||||
) {
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(conditionPosition.x, conditionPosition.z);
|
||||
@@ -169,18 +177,23 @@ public class TreasureMapObjectiveTask extends ObjectiveTask {
|
||||
return null;
|
||||
} else {
|
||||
worldChunk.setBlock(conditionPosition.x, conditionPosition.y, conditionPosition.z, chestBlockTypeKey);
|
||||
BlockState blockState = worldChunk.getState(conditionPosition.x, conditionPosition.y, conditionPosition.z);
|
||||
if (!(blockState instanceof ItemContainerState)) {
|
||||
transactionRecord.fail("BlockState is not a container");
|
||||
Ref<ChunkStore> blockEntity = worldChunk.getBlockComponentEntity(conditionPosition.x, conditionPosition.y, conditionPosition.z);
|
||||
if (blockEntity == null) {
|
||||
transactionRecord.fail("Missing block entity");
|
||||
return null;
|
||||
} else {
|
||||
TreasureChestState treasureChestState = BlockStateModule.get()
|
||||
.createBlockState(TreasureChestState.class, worldChunk, conditionPosition.clone(), blockState.getBlockType());
|
||||
TreasureChestBlock treasureChestState = world.getChunkStore().getStore().getComponent(blockEntity, TreasureChestBlock.getComponentType());
|
||||
if (treasureChestState == null) {
|
||||
transactionRecord.fail("Failed to create TreasureChestState!");
|
||||
transactionRecord.fail("Missing TreasureChestBlock!");
|
||||
return null;
|
||||
} else {
|
||||
return treasureChestState;
|
||||
ItemContainerBlock container = world.getChunkStore().getStore().getComponent(blockEntity, ItemContainerBlock.getComponentType());
|
||||
if (container == null) {
|
||||
transactionRecord.fail("Missing ItemContainerBlock!");
|
||||
return null;
|
||||
} else {
|
||||
return blockEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,10 +213,10 @@ public class TreasureMapObjectiveTask extends ObjectiveTask {
|
||||
double angle = Math.random() * (float) (Math.PI * 2);
|
||||
float radius = MathUtil.randomFloat(chestConfig.getMinRadius(), chestConfig.getMaxRadius());
|
||||
Vector3d objectivePosition = objective.getPosition(componentAccessor);
|
||||
Vector3d position = objectivePosition.clone().floor();
|
||||
Vector3d position = new Vector3d(objectivePosition).floor();
|
||||
position.add(radius * TrigMathUtil.cos(angle), 0.0, radius * TrigMathUtil.sin(angle));
|
||||
position.y = world.getChunk(ChunkUtil.indexChunkFromBlock(position.x, position.z)).getHeight(MathUtil.floor(position.x), MathUtil.floor(position.z));
|
||||
conditionPosition = chestConfig.getWorldLocationProvider().runCondition(world, position.toVector3i());
|
||||
conditionPosition = chestConfig.getWorldLocationProvider().runCondition(world, Vector3dUtil.toVector3i(position));
|
||||
}
|
||||
|
||||
return conditionPosition;
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package com.hypixel.hytale.builtin.adventure.objectives.transaction;
|
||||
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.blockstates.TreasureChestState;
|
||||
import com.hypixel.hytale.builtin.adventure.objectives.blockstates.TreasureChestBlock;
|
||||
import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Vector3iUtil;
|
||||
import com.hypixel.hytale.server.core.universe.Universe;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.BlockState;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class SpawnTreasureChestTransactionRecord extends TransactionRecord {
|
||||
@Nonnull
|
||||
@@ -25,7 +27,7 @@ public class SpawnTreasureChestTransactionRecord extends TransactionRecord {
|
||||
)
|
||||
.add()
|
||||
.append(
|
||||
new KeyedCodec<>("BlockPosition", Vector3i.CODEC),
|
||||
new KeyedCodec<>("BlockPosition", Vector3iUtil.CODEC),
|
||||
(spawnTreasureChestTransactionRecord, vector3d) -> spawnTreasureChestTransactionRecord.blockPosition = vector3d,
|
||||
spawnTreasureChestTransactionRecord -> spawnTreasureChestTransactionRecord.blockPosition
|
||||
)
|
||||
@@ -47,9 +49,12 @@ public class SpawnTreasureChestTransactionRecord extends TransactionRecord {
|
||||
World world = Universe.get().getWorld(this.worldUUID);
|
||||
if (world != null) {
|
||||
WorldChunk worldChunk = world.getChunk(ChunkUtil.indexChunkFromBlock(this.blockPosition.x, this.blockPosition.z));
|
||||
BlockState blockState = worldChunk.getState(this.blockPosition.x, this.blockPosition.y, this.blockPosition.z);
|
||||
if (blockState instanceof TreasureChestState) {
|
||||
((TreasureChestState)blockState).setOpened(true);
|
||||
Ref<ChunkStore> blockEntityRef = worldChunk.getBlockComponentEntity(this.blockPosition.x, this.blockPosition.y, this.blockPosition.z);
|
||||
if (blockEntityRef != null) {
|
||||
TreasureChestBlock treasureChest = blockEntityRef.getStore().getComponent(blockEntityRef, TreasureChestBlock.getComponentType());
|
||||
if (treasureChest != null) {
|
||||
treasureChest.setOpened(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@ import com.hypixel.hytale.codec.validation.Validators;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.Item;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.entity.entities.player.pages.choices.ChoiceInteraction;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -56,10 +57,8 @@ public class GiveItemInteraction extends ChoiceInteraction {
|
||||
|
||||
@Override
|
||||
public void run(@Nonnull Store<EntityStore> store, @Nonnull Ref<EntityStore> ref, @Nonnull PlayerRef playerRef) {
|
||||
Player playerComponent = store.getComponent(ref, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
playerComponent.getInventory().getCombinedHotbarFirst().addItemStack(new ItemStack(this.itemId, this.quantity));
|
||||
}
|
||||
CombinedItemContainer combinedInventory = InventoryComponent.getCombined(store, ref, InventoryComponent.HOTBAR_FIRST);
|
||||
combinedInventory.addItemStack(new ItemStack(this.itemId, this.quantity));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.entity.ItemUtils;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.entity.entities.player.pages.InteractiveCustomUIPage;
|
||||
import com.hypixel.hytale.server.core.inventory.Inventory;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
|
||||
@@ -79,7 +79,7 @@ public class BarterPage extends InteractiveCustomUIPage<BarterPage.BarterEventDa
|
||||
Player playerComponent = playerEntityRef != null ? store.getComponent(playerEntityRef, Player.getComponentType()) : null;
|
||||
ItemContainer playerInventory = null;
|
||||
if (playerComponent != null) {
|
||||
playerInventory = playerComponent.getInventory().getCombinedHotbarFirst();
|
||||
playerInventory = InventoryComponent.getCombined(store, playerEntityRef, InventoryComponent.HOTBAR_FIRST);
|
||||
}
|
||||
|
||||
BarterTrade[] trades = barterState.getResolvedTrades(this.shopAsset, gameTime);
|
||||
@@ -172,12 +172,11 @@ public class BarterPage extends InteractiveCustomUIPage<BarterPage.BarterEventDa
|
||||
if (playerEntityRef != null) {
|
||||
Player playerComponent = store.getComponent(playerEntityRef, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
Inventory inventory = playerComponent.getInventory();
|
||||
CombinedItemContainer container = inventory.getCombinedHotbarFirst();
|
||||
CombinedItemContainer combinedInventory = InventoryComponent.getCombined(store, playerEntityRef, InventoryComponent.HOTBAR_FIRST);
|
||||
int maxQuantity = Math.min(requestedQuantity, currentStock);
|
||||
|
||||
for (BarterItemStack inputStack : trade.getInput()) {
|
||||
int has = this.countItemsInContainer(container, inputStack.getItemId());
|
||||
int has = this.countItemsInContainer(combinedInventory, inputStack.getItemId());
|
||||
int canAfford = has / inputStack.getQuantity();
|
||||
maxQuantity = Math.min(maxQuantity, canAfford);
|
||||
}
|
||||
@@ -187,12 +186,12 @@ public class BarterPage extends InteractiveCustomUIPage<BarterPage.BarterEventDa
|
||||
|
||||
for (BarterItemStack inputStack : trade.getInput()) {
|
||||
int toRemove = inputStack.getQuantity() * quantity;
|
||||
this.removeItemsFromContainer(container, inputStack.getItemId(), toRemove);
|
||||
this.removeItemsFromContainer(combinedInventory, inputStack.getItemId(), toRemove);
|
||||
}
|
||||
|
||||
BarterItemStack output = trade.getOutput();
|
||||
ItemStack outputStack = new ItemStack(output.getItemId(), output.getQuantity() * quantity);
|
||||
ItemStackTransaction transaction = container.addItemStack(outputStack);
|
||||
ItemStackTransaction transaction = combinedInventory.addItemStack(outputStack);
|
||||
ItemStack remainder = transaction.getRemainder();
|
||||
if (remainder != null && !remainder.isEmpty()) {
|
||||
int addedQty = outputStack.getQuantity() - remainder.getQuantity();
|
||||
@@ -228,7 +227,7 @@ public class BarterPage extends InteractiveCustomUIPage<BarterPage.BarterEventDa
|
||||
Player playerComponent = playerEntityRef != null ? store.getComponent(playerEntityRef, Player.getComponentType()) : null;
|
||||
ItemContainer playerInventory = null;
|
||||
if (playerComponent != null) {
|
||||
playerInventory = playerComponent.getInventory().getCombinedHotbarFirst();
|
||||
playerInventory = InventoryComponent.getCombined(store, playerEntityRef, InventoryComponent.HOTBAR_FIRST);
|
||||
}
|
||||
|
||||
for (int i = 0; i < trades.length; i++) {
|
||||
|
||||
@@ -6,33 +6,31 @@ import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.RemoveReason;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.dependency.Dependency;
|
||||
import com.hypixel.hytale.component.dependency.Order;
|
||||
import com.hypixel.hytale.component.dependency.SystemDependency;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.RefSystem;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.util.HashUtil;
|
||||
import com.hypixel.hytale.protocol.GameMode;
|
||||
import com.hypixel.hytale.server.core.asset.type.gameplay.GameplayConfig;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
|
||||
import com.hypixel.hytale.server.core.inventory.container.SimpleItemContainer;
|
||||
import com.hypixel.hytale.server.core.inventory.transaction.ItemStackSlotTransaction;
|
||||
import com.hypixel.hytale.server.core.inventory.transaction.ItemStackTransaction;
|
||||
import com.hypixel.hytale.server.core.inventory.transaction.ListTransaction;
|
||||
import com.hypixel.hytale.server.core.modules.block.BlockModule;
|
||||
import com.hypixel.hytale.server.core.modules.block.components.ItemContainerBlock;
|
||||
import com.hypixel.hytale.server.core.modules.item.ItemModule;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.BlockStateModule;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.state.ItemContainerState;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.shorts.ShortArrayList;
|
||||
import it.unimi.dsi.fastutil.shorts.ShortLists;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -47,12 +45,14 @@ public class StashPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
this.getChunkStoreRegistry().registerSystem(new StashPlugin.StashSystem(BlockStateModule.get().getComponentType(ItemContainerState.class)));
|
||||
this.getChunkStoreRegistry().registerSystem(new StashPlugin.StashSystem(ItemContainerBlock.getComponentType()));
|
||||
this.getCodecRegistry(GameplayConfig.PLUGIN_CODEC).register(StashGameplayConfig.class, "Stash", StashGameplayConfig.CODEC);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ListTransaction<ItemStackTransaction> stash(@Nonnull ItemContainerState containerState, boolean clearDropList) {
|
||||
public static ListTransaction<ItemStackTransaction> stash(
|
||||
BlockModule.BlockStateInfo blockStateInfo, @Nonnull ItemContainerBlock containerState, boolean clearDropList
|
||||
) {
|
||||
String droplist = containerState.getDroplist();
|
||||
if (droplist == null) {
|
||||
return null;
|
||||
@@ -61,7 +61,7 @@ public class StashPlugin extends JavaPlugin {
|
||||
if (stacks.isEmpty()) {
|
||||
return ListTransaction.getEmptyTransaction(true);
|
||||
} else {
|
||||
ItemContainer itemContainer = containerState.getItemContainer();
|
||||
SimpleItemContainer itemContainer = containerState.getItemContainer();
|
||||
short capacity = itemContainer.getCapacity();
|
||||
ShortArrayList slots = new ShortArrayList(capacity);
|
||||
|
||||
@@ -69,8 +69,13 @@ public class StashPlugin extends JavaPlugin {
|
||||
slots.add(s);
|
||||
}
|
||||
|
||||
Vector3i blockPosition = containerState.getBlockPosition();
|
||||
long positionHash = blockPosition.hashCode();
|
||||
WorldChunk wc = blockStateInfo.getChunkRef().getStore().getComponent(blockStateInfo.getChunkRef(), WorldChunk.getComponentType());
|
||||
int x = ChunkUtil.xFromBlockInColumn(blockStateInfo.getIndex());
|
||||
int y = ChunkUtil.yFromBlockInColumn(blockStateInfo.getIndex());
|
||||
int z = ChunkUtil.zFromBlockInColumn(blockStateInfo.getIndex());
|
||||
int worldX = ChunkUtil.worldCoordFromLocalCoord(wc.getX(), x);
|
||||
int worldZ = ChunkUtil.worldCoordFromLocalCoord(wc.getZ(), z);
|
||||
long positionHash = HashUtil.hash(worldX, y, worldZ);
|
||||
Random rnd = new Random(positionHash);
|
||||
ShortLists.shuffle(slots, rnd);
|
||||
boolean anySucceeded = false;
|
||||
@@ -79,8 +84,7 @@ public class StashPlugin extends JavaPlugin {
|
||||
short slot = slots.getShort(idx);
|
||||
ItemStackSlotTransaction transaction = itemContainer.addItemStackToSlot(slot, stacks.get(idx));
|
||||
if (transaction.getRemainder() != null && !transaction.getRemainder().isEmpty()) {
|
||||
LOGGER.at(Level.WARNING)
|
||||
.log("Could not add Item to Stash at %d, %d, %d: %s", blockPosition.x, blockPosition.y, blockPosition.z, transaction.getRemainder());
|
||||
LOGGER.at(Level.WARNING).log("Could not add Item to Stash at %d, %d, %d: %s", worldX, y, worldZ, transaction.getRemainder());
|
||||
} else {
|
||||
anySucceeded = true;
|
||||
}
|
||||
@@ -97,18 +101,20 @@ public class StashPlugin extends JavaPlugin {
|
||||
|
||||
private static class StashSystem extends RefSystem<ChunkStore> {
|
||||
@Nonnull
|
||||
private final ComponentType<ChunkStore, ItemContainerState> itemContainerStateComponentType;
|
||||
private final ComponentType<ChunkStore, ItemContainerBlock> itemContainerStateComponentType;
|
||||
@Nonnull
|
||||
private final Set<Dependency<ChunkStore>> dependencies;
|
||||
private final ComponentType<ChunkStore, BlockModule.BlockStateInfo> blockStateInfoComponentType = BlockModule.BlockStateInfo.getComponentType();
|
||||
@Nonnull
|
||||
private final Query<ChunkStore> query;
|
||||
|
||||
public StashSystem(@Nonnull ComponentType<ChunkStore, ItemContainerState> itemContainerStateComponentType) {
|
||||
public StashSystem(@Nonnull ComponentType<ChunkStore, ItemContainerBlock> itemContainerStateComponentType) {
|
||||
this.itemContainerStateComponentType = itemContainerStateComponentType;
|
||||
this.dependencies = Set.of(new SystemDependency<>(Order.AFTER, BlockStateModule.LegacyBlockStateRefSystem.class));
|
||||
this.query = Query.and(itemContainerStateComponentType, this.blockStateInfoComponentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<ChunkStore> getQuery() {
|
||||
return this.itemContainerStateComponentType;
|
||||
return this.query;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,13 +123,17 @@ public class StashPlugin extends JavaPlugin {
|
||||
) {
|
||||
World world = store.getExternalData().getWorld();
|
||||
if (world.getWorldConfig().getGameMode() != GameMode.Creative) {
|
||||
ItemContainerState itemContainerStateComponent = store.getComponent(ref, this.itemContainerStateComponentType);
|
||||
ItemContainerBlock itemContainerStateComponent = store.getComponent(ref, this.itemContainerStateComponentType);
|
||||
|
||||
assert itemContainerStateComponent != null;
|
||||
|
||||
BlockModule.BlockStateInfo blockStateInfo = store.getComponent(ref, this.blockStateInfoComponentType);
|
||||
|
||||
assert blockStateInfo != null;
|
||||
|
||||
StashGameplayConfig stashGameplayConfig = StashGameplayConfig.getOrDefault(world.getGameplayConfig());
|
||||
boolean clearContainerDropList = stashGameplayConfig.isClearContainerDropList();
|
||||
StashPlugin.stash(itemContainerStateComponent, clearContainerDropList);
|
||||
StashPlugin.stash(blockStateInfo, itemContainerStateComponent, clearContainerDropList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,11 +142,5 @@ public class StashPlugin extends JavaPlugin {
|
||||
@Nonnull Ref<ChunkStore> ref, @Nonnull RemoveReason reason, @Nonnull Store<ChunkStore> store, @Nonnull CommandBuffer<ChunkStore> commandBuffer
|
||||
) {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Dependency<ChunkStore>> getDependencies() {
|
||||
return this.dependencies;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,8 @@ import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.Component;
|
||||
import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.math.vector.Rotation3f;
|
||||
import com.hypixel.hytale.math.vector.Transform;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.core.asset.type.wordlist.WordList;
|
||||
import com.hypixel.hytale.server.core.modules.entity.teleport.Teleport;
|
||||
import com.hypixel.hytale.server.core.universe.Universe;
|
||||
@@ -20,6 +18,8 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class Teleporter implements Component<ChunkStore> {
|
||||
@Nonnull
|
||||
@@ -158,7 +158,7 @@ public class Teleporter implements Component<ChunkStore> {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Teleport toTeleport(@Nonnull Vector3d currentPosition, @Nonnull Vector3f currentRotation, @Nonnull Vector3i blockPosition) {
|
||||
public Teleport toTeleport(@Nonnull Vector3d currentPosition, @Nonnull Rotation3f currentRotation, @Nonnull Vector3i blockPosition) {
|
||||
if (this.warp != null && !this.warp.isEmpty()) {
|
||||
Warp targetWarp = TeleportPlugin.get().getWarps().get(this.warp.toLowerCase());
|
||||
return targetWarp != null ? targetWarp.toTeleport() : null;
|
||||
@@ -167,7 +167,7 @@ public class Teleporter implements Component<ChunkStore> {
|
||||
World world = Universe.get().getWorld(this.worldUuid);
|
||||
if (world != null) {
|
||||
if (this.relativeMask != 0) {
|
||||
Transform teleportTransform = this.transform.clone();
|
||||
Transform teleportTransform = new Transform(this.transform);
|
||||
Transform.applyMaskedRelativeTransform(teleportTransform, this.relativeMask, currentPosition, currentRotation, blockPosition);
|
||||
return Teleport.createForPlayer(world, teleportTransform);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ public class Teleporter implements Component<ChunkStore> {
|
||||
}
|
||||
|
||||
if (this.relativeMask != 0) {
|
||||
Transform teleportTransform = this.transform.clone();
|
||||
Transform teleportTransform = new Transform(this.transform);
|
||||
Transform.applyMaskedRelativeTransform(teleportTransform, this.relativeMask, currentPosition, currentRotation, blockPosition);
|
||||
return Teleport.createForPlayer(teleportTransform);
|
||||
} else {
|
||||
|
||||
@@ -10,8 +10,6 @@ import com.hypixel.hytale.component.CommandBuffer;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.spatial.SpatialResource;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionState;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.WaitForDataFrom;
|
||||
@@ -32,9 +30,11 @@ import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class TeleporterInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull
|
||||
@@ -99,7 +99,7 @@ public class TeleporterInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull World world, @Nonnull CommandBuffer<EntityStore> commandBuffer, @Nonnull InteractionContext context, @Nonnull Vector3i targetBlock
|
||||
) {
|
||||
ChunkStore chunkStore = world.getChunkStore();
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(targetBlock.getX(), targetBlock.getZ());
|
||||
long chunkIndex = ChunkUtil.indexChunkFromBlock(targetBlock.x(), targetBlock.z());
|
||||
BlockComponentChunk blockComponentChunk = chunkStore.getChunkComponent(chunkIndex, BlockComponentChunk.getComponentType());
|
||||
if (blockComponentChunk == null) {
|
||||
return false;
|
||||
@@ -171,7 +171,7 @@ public class TeleporterInteraction extends SimpleBlockInteraction {
|
||||
SpatialResource<Ref<EntityStore>, EntityStore> playerSpatialResource = commandBuffer.getResource(
|
||||
EntityModule.get().getPlayerSpatialResourceType()
|
||||
);
|
||||
ObjectList<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
List<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
|
||||
playerSpatialResource.getSpatialStructure().collect(particlePosition, 75.0, results);
|
||||
ParticleUtil.spawnParticleEffect(this.particle, particlePosition, results, commandBuffer);
|
||||
}
|
||||
@@ -196,5 +196,8 @@ public class TeleporterInteraction extends SimpleBlockInteraction {
|
||||
protected void simulateInteractWithBlock(
|
||||
@Nonnull InteractionType type, @Nonnull InteractionContext context, @Nullable ItemStack itemInHand, @Nonnull World world, @Nonnull Vector3i targetBlock
|
||||
) {
|
||||
if (context.getServerState() != null) {
|
||||
context.getState().state = context.getServerState().state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ package com.hypixel.hytale.builtin.adventure.teleporter.interaction.server;
|
||||
import com.hypixel.hytale.builtin.adventure.teleporter.TeleporterPlugin;
|
||||
import com.hypixel.hytale.component.Component;
|
||||
import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class UsedTeleporter implements Component<EntityStore> {
|
||||
@Nullable
|
||||
@@ -58,7 +58,7 @@ public class UsedTeleporter implements Component<EntityStore> {
|
||||
public Component<EntityStore> clone() {
|
||||
UsedTeleporter clone = new UsedTeleporter();
|
||||
clone.destinationWorldUuid = this.destinationWorldUuid;
|
||||
clone.destinationPosition = this.destinationPosition.clone();
|
||||
clone.destinationPosition = new Vector3d(this.destinationPosition);
|
||||
clone.clearOutXZ = this.clearOutXZ;
|
||||
clone.clearOutXZSquared = this.clearOutXZSquared;
|
||||
clone.clearOutY = this.clearOutY;
|
||||
|
||||
@@ -71,18 +71,18 @@ public class TeleporterSettingsPage extends InteractiveCustomUIPage<TeleporterSe
|
||||
commandBuilder.set("#BlockRelative #CheckBox.Value", (relativeMask & 64) != 0);
|
||||
Transform transform = teleporter.getTransform();
|
||||
if (transform != null) {
|
||||
commandBuilder.set("#X #Input.Value", transform.getPosition().getX());
|
||||
commandBuilder.set("#Y #Input.Value", transform.getPosition().getY());
|
||||
commandBuilder.set("#Z #Input.Value", transform.getPosition().getZ());
|
||||
commandBuilder.set("#X #Input.Value", transform.getPosition().x());
|
||||
commandBuilder.set("#Y #Input.Value", transform.getPosition().y());
|
||||
commandBuilder.set("#Z #Input.Value", transform.getPosition().z());
|
||||
}
|
||||
|
||||
commandBuilder.set("#X #CheckBox.Value", (relativeMask & 1) != 0);
|
||||
commandBuilder.set("#Y #CheckBox.Value", (relativeMask & 2) != 0);
|
||||
commandBuilder.set("#Z #CheckBox.Value", (relativeMask & 4) != 0);
|
||||
if (transform != null) {
|
||||
commandBuilder.set("#Yaw #Input.Value", transform.getRotation().getYaw());
|
||||
commandBuilder.set("#Pitch #Input.Value", transform.getRotation().getPitch());
|
||||
commandBuilder.set("#Roll #Input.Value", transform.getRotation().getRoll());
|
||||
commandBuilder.set("#Yaw #Input.Value", transform.getRotation().yaw());
|
||||
commandBuilder.set("#Pitch #Input.Value", transform.getRotation().pitch());
|
||||
commandBuilder.set("#Roll #Input.Value", transform.getRotation().roll());
|
||||
}
|
||||
|
||||
commandBuilder.set("#Yaw #CheckBox.Value", (relativeMask & 8) != 0);
|
||||
@@ -227,9 +227,9 @@ public class TeleporterSettingsPage extends InteractiveCustomUIPage<TeleporterSe
|
||||
case FULL:
|
||||
teleporterComponent.setWorldUuid(data.world != null && !data.world.isEmpty() ? UUID.fromString(data.world) : null);
|
||||
Transform transform = new Transform();
|
||||
transform.getPosition().setX(data.x);
|
||||
transform.getPosition().setY(data.y);
|
||||
transform.getPosition().setZ(data.z);
|
||||
transform.getPosition().x = data.x;
|
||||
transform.getPosition().y = data.y;
|
||||
transform.getPosition().z = data.z;
|
||||
transform.getRotation().setYaw(data.yaw);
|
||||
transform.getRotation().setPitch(data.pitch);
|
||||
transform.getRotation().setRoll(data.roll);
|
||||
|
||||
@@ -12,8 +12,6 @@ import com.hypixel.hytale.component.dependency.Order;
|
||||
import com.hypixel.hytale.component.dependency.SystemDependency;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
||||
import com.hypixel.hytale.math.vector.Vector2d;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
|
||||
import com.hypixel.hytale.server.core.modules.entity.teleport.PendingTeleport;
|
||||
import com.hypixel.hytale.server.core.modules.entity.teleport.Teleport;
|
||||
@@ -25,6 +23,8 @@ import java.time.Duration;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector2d;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class ClearUsedTeleporterSystem extends EntityTickingSystem<EntityStore> {
|
||||
@Nonnull
|
||||
|
||||
@@ -11,9 +11,8 @@ import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.RefChangeSystem;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Rotation3f;
|
||||
import com.hypixel.hytale.math.vector.Transform;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.Rotation;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.RotationTuple;
|
||||
import com.hypixel.hytale.server.core.modules.block.BlockModule;
|
||||
@@ -29,6 +28,7 @@ import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class CreateWarpWhenTeleporterPlacedSystem extends RefChangeSystem<ChunkStore, PlacedByInteractionComponent> {
|
||||
@Nonnull
|
||||
@@ -107,7 +107,7 @@ public class CreateWarpWhenTeleporterPlacedSystem extends RefChangeSystem<ChunkS
|
||||
Rotation rotationYaw = rotationTuple.yaw();
|
||||
float warpRotationYaw = (float)rotationYaw.getRadians() + (float)Math.toRadians(180.0);
|
||||
Vector3d warpPosition = new Vector3d(x, y, z).add(0.5, 0.65, 0.5);
|
||||
Transform warpTransform = new Transform(warpPosition, new Vector3f(Float.NaN, warpRotationYaw, Float.NaN));
|
||||
Transform warpTransform = new Transform(warpPosition, new Rotation3f(Float.NaN, warpRotationYaw, Float.NaN));
|
||||
String warpId = name.toLowerCase();
|
||||
Warp warp = new Warp(warpTransform, name, worldChunk.getWorld(), "*Teleporter", Instant.now());
|
||||
TeleportPlugin teleportPlugin = TeleportPlugin.get();
|
||||
|
||||
@@ -187,7 +187,7 @@ public class AmbientEmitterSystems {
|
||||
if (spawnedEmitterRef != null && spawnedEmitterRef.isValid()) {
|
||||
TransformComponent ownedEmitterTransform = commandBuffer.getComponent(spawnedEmitterRef, this.transformComponentType);
|
||||
if (ownedEmitterTransform != null) {
|
||||
if (transformComponent.getPosition().distanceSquaredTo(ownedEmitterTransform.getPosition()) > 1.0) {
|
||||
if (transformComponent.getPosition().distanceSquared(ownedEmitterTransform.getPosition()) > 1.0) {
|
||||
ownedEmitterTransform.setPosition(transformComponent.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorAuthorization;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorInitialize;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorUpdateJsonAsset;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.io.handlers.IPacketHandler;
|
||||
import com.hypixel.hytale.server.core.io.handlers.SubPacketHandler;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
@@ -38,23 +37,17 @@ public class AssetEditorGamePacketHandler implements SubPacketHandler {
|
||||
public void handle(AssetEditorInitialize packet) {
|
||||
PlayerRef playerRef = this.packetHandler.getPlayerRef();
|
||||
Ref<EntityStore> ref = playerRef.getReference();
|
||||
if (ref != null && ref.isValid()) {
|
||||
if (ref == null || !ref.isValid()) {
|
||||
throw new RuntimeException("Unable to process AssetEditorInitialize packet. Player ref is invalid!");
|
||||
} else if (this.lacksPermission(playerRef, false)) {
|
||||
this.packetHandler.getPlayerRef().getPacketHandler().write(new AssetEditorAuthorization(false));
|
||||
} else {
|
||||
Store<EntityStore> store = ref.getStore();
|
||||
World world = store.getExternalData().getWorld();
|
||||
world.execute(() -> {
|
||||
Player playerComponent = store.getComponent(ref, Player.getComponentType());
|
||||
|
||||
assert playerComponent != null;
|
||||
|
||||
if (this.lacksPermission(playerComponent, false)) {
|
||||
this.packetHandler.getPlayerRef().getPacketHandler().write(new AssetEditorAuthorization(false));
|
||||
} else {
|
||||
this.packetHandler.getPlayerRef().getPacketHandler().write(new AssetEditorAuthorization(true));
|
||||
AssetEditorPlugin.get().handleInitializeEditor(ref, store);
|
||||
}
|
||||
this.packetHandler.getPlayerRef().getPacketHandler().write(new AssetEditorAuthorization(true));
|
||||
AssetEditorPlugin.get().handleInitializeEditor(ref, store);
|
||||
});
|
||||
} else {
|
||||
throw new RuntimeException("Unable to process AssetEditorInitialize packet. Player ref is invalid!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,40 +55,26 @@ public class AssetEditorGamePacketHandler implements SubPacketHandler {
|
||||
public void handle(@Nonnull AssetEditorUpdateJsonAsset packet) {
|
||||
PlayerRef playerRef = this.packetHandler.getPlayerRef();
|
||||
Ref<EntityStore> ref = playerRef.getReference();
|
||||
if (ref != null && ref.isValid()) {
|
||||
Store<EntityStore> store = ref.getStore();
|
||||
World world = store.getExternalData().getWorld();
|
||||
world.execute(
|
||||
if (ref == null || !ref.isValid()) {
|
||||
throw new RuntimeException("Unable to process AssetEditorUpdateJsonAsset packet. Player ref is invalid!");
|
||||
} else if (!this.lacksPermission(playerRef, true)) {
|
||||
CompletableFuture.runAsync(
|
||||
() -> {
|
||||
Player playerComponent = store.getComponent(ref, Player.getComponentType());
|
||||
if (!this.lacksPermission(playerComponent, true)) {
|
||||
CompletableFuture.runAsync(
|
||||
() -> {
|
||||
LOGGER.at(Level.INFO).log("%s updating json asset at %s", this.packetHandler.getPlayerRef().getUsername(), packet.path);
|
||||
EditorClient mockClient = new EditorClient(playerRef);
|
||||
AssetEditorPlugin.get()
|
||||
.handleJsonAssetUpdate(
|
||||
mockClient,
|
||||
packet.path != null ? new AssetPath(packet.path) : null,
|
||||
packet.assetType,
|
||||
packet.assetIndex,
|
||||
packet.commands,
|
||||
packet.token
|
||||
);
|
||||
}
|
||||
LOGGER.at(Level.INFO).log("%s updating json asset at %s", this.packetHandler.getPlayerRef().getUsername(), packet.path);
|
||||
EditorClient mockClient = new EditorClient(playerRef);
|
||||
AssetEditorPlugin.get()
|
||||
.handleJsonAssetUpdate(
|
||||
mockClient, packet.path != null ? new AssetPath(packet.path) : null, packet.assetType, packet.assetIndex, packet.commands, packet.token
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
throw new RuntimeException("Unable to process AssetEditorUpdateJsonAsset packet. Player ref is invalid!");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean lacksPermission(@Nonnull Player player, boolean shouldShowDenialMessage) {
|
||||
if (!player.hasPermission("hytale.editor.asset")) {
|
||||
private boolean lacksPermission(@Nonnull PlayerRef playerRef, boolean shouldShowDenialMessage) {
|
||||
if (!playerRef.hasPermission("hytale.editor.asset")) {
|
||||
if (shouldShowDenialMessage) {
|
||||
player.sendMessage(Messages.USAGE_DENIED);
|
||||
playerRef.sendMessage(Messages.USAGE_DENIED);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorUpdateAsset;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorUpdateAssetPack;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorUpdateJsonAsset;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorUpdateWeatherPreviewLock;
|
||||
import com.hypixel.hytale.protocol.packets.connection.Disconnect;
|
||||
import com.hypixel.hytale.protocol.packets.connection.ClientDisconnect;
|
||||
import com.hypixel.hytale.protocol.packets.connection.DisconnectType;
|
||||
import com.hypixel.hytale.protocol.packets.connection.Pong;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.UpdateLanguage;
|
||||
@@ -110,8 +110,8 @@ public class AssetEditorPacketHandler extends GenericPacketHandler {
|
||||
}
|
||||
|
||||
public void registerHandlers() {
|
||||
this.registerHandler(1, p -> this.handle((Disconnect)p));
|
||||
this.registerHandler(3, p -> this.handlePong((Pong)p));
|
||||
this.registerHandler(1, p -> this.handle((ClientDisconnect)p));
|
||||
this.registerHandler(4, p -> this.handlePong((Pong)p));
|
||||
this.registerHandler(321, p -> this.handle((AssetEditorRequestChildrenList)p));
|
||||
this.registerHandler(324, p -> this.handle((AssetEditorUpdateAsset)p));
|
||||
this.registerHandler(323, p -> this.handle((AssetEditorUpdateJsonAsset)p));
|
||||
@@ -382,12 +382,19 @@ public class AssetEditorPacketHandler extends GenericPacketHandler {
|
||||
|
||||
public void handle(@Nonnull AssetEditorCreateAssetPack packet) {
|
||||
if (!this.lacksPermission(packet.token, "hytale.editor.packs.create")) {
|
||||
LOGGER.at(Level.INFO).log("%s is creating a new asset pack: %s:%s", this.editorClient.getUsername(), packet.manifest.group, packet.manifest.name);
|
||||
AssetEditorPlugin.get().handleCreateAssetPack(this.editorClient, packet.manifest, packet.token);
|
||||
LOGGER.at(Level.INFO)
|
||||
.log(
|
||||
"%s is creating a new asset pack: %s:%s (directory index: %d)",
|
||||
this.editorClient.getUsername(),
|
||||
packet.manifest.group,
|
||||
packet.manifest.name,
|
||||
packet.targetDirectoryIndex
|
||||
);
|
||||
AssetEditorPlugin.get().handleCreateAssetPack(this.editorClient, packet.manifest, packet.token, packet.targetDirectoryIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(@Nonnull Disconnect packet) {
|
||||
public void handle(@Nonnull ClientDisconnect packet) {
|
||||
switch (packet.type) {
|
||||
case Disconnect:
|
||||
this.disconnectReason.setClientDisconnectType(DisconnectType.Disconnect);
|
||||
@@ -403,7 +410,7 @@ public class AssetEditorPacketHandler extends GenericPacketHandler {
|
||||
this.editorClient.getUsername(),
|
||||
NettyUtil.formatRemoteAddress(this.getChannel()),
|
||||
packet.type.name(),
|
||||
packet.reason
|
||||
packet.reason.name()
|
||||
);
|
||||
this.getChannel().close();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorFetchJsonAsset
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorFileEntry;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorJsonAssetUpdated;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorLastModifiedAssets;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorModsDirectories;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorPopupNotificationType;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorRebuildCaches;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorRequestChildrenListReply;
|
||||
@@ -76,7 +77,6 @@ import com.hypixel.hytale.server.core.Options;
|
||||
import com.hypixel.hytale.server.core.asset.AssetModule;
|
||||
import com.hypixel.hytale.server.core.asset.AssetPackRegisterEvent;
|
||||
import com.hypixel.hytale.server.core.asset.AssetPackUnregisterEvent;
|
||||
import com.hypixel.hytale.server.core.asset.AssetRegistryLoader;
|
||||
import com.hypixel.hytale.server.core.asset.common.events.CommonAssetMonitorEvent;
|
||||
import com.hypixel.hytale.server.core.config.ModConfig;
|
||||
import com.hypixel.hytale.server.core.io.PacketHandler;
|
||||
@@ -88,6 +88,7 @@ import com.hypixel.hytale.server.core.plugin.JavaPlugin;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
|
||||
import com.hypixel.hytale.server.core.plugin.PluginManager;
|
||||
import com.hypixel.hytale.server.core.plugin.PluginState;
|
||||
import com.hypixel.hytale.server.core.schema.SchemaGenerator;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import com.hypixel.hytale.server.core.util.BsonUtil;
|
||||
@@ -215,7 +216,9 @@ public class AssetEditorPlugin extends JavaPlugin {
|
||||
@Override
|
||||
protected void shutdown() {
|
||||
InitialPacketHandler.EDITOR_PACKET_HANDLER_SUPPLIER = null;
|
||||
String message = HytaleServer.get().isShuttingDown() ? "Server is shutting down!" : "Asset editor was disabled!";
|
||||
Message message = HytaleServer.get().isShuttingDown()
|
||||
? Message.translation("server.general.disconnect.stoppingServer")
|
||||
: Message.translation("server.general.disconnect.assetEditorDisabled");
|
||||
|
||||
for (Set<EditorClient> clients : this.uuidToEditorClients.values()) {
|
||||
for (EditorClient client : clients) {
|
||||
@@ -276,7 +279,7 @@ public class AssetEditorPlugin extends JavaPlugin {
|
||||
client.getPacketHandler().sendPing();
|
||||
} catch (Exception var6) {
|
||||
this.getLogger().at(Level.SEVERE).withCause(var6).log("Failed to send ping to " + client);
|
||||
client.getPacketHandler().disconnect("Exception when sending ping packet!");
|
||||
client.getPacketHandler().disconnect(Message.translation("server.general.disconnect.pingException"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -578,7 +581,7 @@ public class AssetEditorPlugin extends JavaPlugin {
|
||||
|
||||
private void initializeAssetEditor(boolean updateLoadedAssets) {
|
||||
long start = System.nanoTime();
|
||||
Map<String, Schema> schemas = AssetRegistryLoader.generateSchemas(new SchemaContext(), new BsonDocument());
|
||||
Map<String, Schema> schemas = SchemaGenerator.generateAssetSchemas();
|
||||
schemas.remove("NPCRole.json");
|
||||
schemas.remove("other.json");
|
||||
AssetEditorSetupSchemas setupSchemasPacket = new AssetEditorSetupSchemas(new SchemaFile[schemas.size()]);
|
||||
@@ -650,6 +653,16 @@ public class AssetEditorPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
editorClient.getPacketHandler().write(packSetupPacket);
|
||||
if (canCreateAssetPacks) {
|
||||
List<Path> modsDirectories = this.getModsDirectories();
|
||||
String[] dirStrings = new String[modsDirectories.size()];
|
||||
|
||||
for (int j = 0; j < modsDirectories.size(); j++) {
|
||||
dirStrings[j] = modsDirectories.get(j).toString();
|
||||
}
|
||||
|
||||
editorClient.getPacketHandler().write(new AssetEditorModsDirectories(dirStrings));
|
||||
}
|
||||
|
||||
for (DataSource dataSource : this.assetPackDataSources.values()) {
|
||||
dataSource.getAssetTree().sendPackets(editorClient);
|
||||
@@ -824,7 +837,19 @@ public class AssetEditorPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void handleCreateAssetPack(@Nonnull EditorClient editorClient, @Nonnull AssetPackManifest packetManifest, int requestToken) {
|
||||
@Nonnull
|
||||
private List<Path> getModsDirectories() {
|
||||
List<Path> directories = new ObjectArrayList<>();
|
||||
directories.add(PluginManager.MODS_PATH.toAbsolutePath());
|
||||
|
||||
for (Path modsPath : Options.getOptionSet().valuesOf(Options.MODS_DIRECTORIES)) {
|
||||
directories.add(modsPath.toAbsolutePath());
|
||||
}
|
||||
|
||||
return directories;
|
||||
}
|
||||
|
||||
public void handleCreateAssetPack(@Nonnull EditorClient editorClient, @Nonnull AssetPackManifest packetManifest, int requestToken, int targetDirectoryIndex) {
|
||||
if (packetManifest.name == null || packetManifest.name.isEmpty()) {
|
||||
editorClient.sendFailureReply(requestToken, Messages.PACK_NAME_REQUIRED);
|
||||
} else if (packetManifest.group != null && !packetManifest.group.isEmpty()) {
|
||||
@@ -842,8 +867,8 @@ public class AssetEditorPlugin extends JavaPlugin {
|
||||
if (packetManifest.version != null && !packetManifest.version.isEmpty()) {
|
||||
try {
|
||||
manifest.setVersion(Semver.fromString(packetManifest.version));
|
||||
} catch (IllegalArgumentException var13) {
|
||||
this.getLogger().at(Level.WARNING).withCause(var13).log("Invalid version format: %s", packetManifest.version);
|
||||
} catch (IllegalArgumentException var15) {
|
||||
this.getLogger().at(Level.WARNING).withCause(var15).log("Invalid version format: %s", packetManifest.version);
|
||||
editorClient.sendFailureReply(requestToken, Messages.INVALID_VERSION_FORMAT);
|
||||
return;
|
||||
}
|
||||
@@ -868,39 +893,44 @@ public class AssetEditorPlugin extends JavaPlugin {
|
||||
if (this.assetPackDataSources.containsKey(packId)) {
|
||||
editorClient.sendFailureReply(requestToken, Messages.PACK_ALREADY_EXISTS);
|
||||
} else {
|
||||
Path modsPath = PluginManager.MODS_PATH;
|
||||
String dirName = AssetPathUtil.removeInvalidFileNameChars(
|
||||
packetManifest.group != null ? packetManifest.group + "." + packetManifest.name : packetManifest.name
|
||||
);
|
||||
Path normalized = Path.of(dirName).normalize();
|
||||
if (AssetPathUtil.isInvalidFileName(normalized)) {
|
||||
editorClient.sendFailureReply(requestToken, Messages.INVALID_FILE_NAME);
|
||||
} else {
|
||||
Path packPath = modsPath.resolve(normalized).normalize();
|
||||
if (!packPath.startsWith(modsPath)) {
|
||||
editorClient.sendFailureReply(requestToken, Messages.PACK_OUTSIDE_DIRECTORY);
|
||||
} else if (Files.exists(packPath)) {
|
||||
editorClient.sendFailureReply(requestToken, Messages.PACK_ALREADY_EXISTS_AT_PATH);
|
||||
List<Path> modsDirectories = this.getModsDirectories();
|
||||
if (targetDirectoryIndex >= 0 && targetDirectoryIndex < modsDirectories.size()) {
|
||||
Path modsPath = modsDirectories.get(targetDirectoryIndex);
|
||||
String dirName = AssetPathUtil.removeInvalidFileNameChars(
|
||||
packetManifest.group != null ? packetManifest.group + "." + packetManifest.name : packetManifest.name
|
||||
);
|
||||
Path normalized = Path.of(dirName).normalize();
|
||||
if (AssetPathUtil.isInvalidFileName(normalized)) {
|
||||
editorClient.sendFailureReply(requestToken, Messages.INVALID_FILE_NAME);
|
||||
} else {
|
||||
try {
|
||||
Files.createDirectories(packPath);
|
||||
Path manifestPath = packPath.resolve("manifest.json");
|
||||
BsonUtil.writeSync(manifestPath, PluginManifest.CODEC, manifest, this.getLogger());
|
||||
HytaleServerConfig serverConfig = HytaleServer.get().getConfig();
|
||||
HytaleServerConfig.setBoot(serverConfig, new PluginIdentifier(manifest), true);
|
||||
serverConfig.markChanged();
|
||||
if (serverConfig.consumeHasChanged()) {
|
||||
HytaleServerConfig.save(serverConfig).join();
|
||||
}
|
||||
Path packPath = modsPath.resolve(normalized).normalize();
|
||||
if (!packPath.startsWith(modsPath)) {
|
||||
editorClient.sendFailureReply(requestToken, Messages.PACK_OUTSIDE_DIRECTORY);
|
||||
} else if (Files.exists(packPath)) {
|
||||
editorClient.sendFailureReply(requestToken, Messages.PACK_ALREADY_EXISTS_AT_PATH);
|
||||
} else {
|
||||
try {
|
||||
Files.createDirectories(packPath);
|
||||
Path manifestPath = packPath.resolve("manifest.json");
|
||||
BsonUtil.writeSync(manifestPath, PluginManifest.CODEC, manifest, this.getLogger());
|
||||
HytaleServerConfig serverConfig = HytaleServer.get().getConfig();
|
||||
HytaleServerConfig.setBoot(serverConfig, new PluginIdentifier(manifest), true);
|
||||
serverConfig.markChanged();
|
||||
if (serverConfig.consumeHasChanged()) {
|
||||
HytaleServerConfig.save(serverConfig).join();
|
||||
}
|
||||
|
||||
AssetModule.get().registerPack(packId, packPath, manifest, false);
|
||||
editorClient.sendSuccessReply(requestToken, Messages.PACK_CREATED);
|
||||
this.getLogger().at(Level.INFO).log("Created new pack: %s at %s", packId, packPath);
|
||||
} catch (IOException var12) {
|
||||
this.getLogger().at(Level.SEVERE).withCause(var12).log("Failed to create pack %s", packId);
|
||||
editorClient.sendFailureReply(requestToken, Messages.PACK_CREATION_FAILED);
|
||||
AssetModule.get().registerPack(packId, packPath, manifest, false);
|
||||
editorClient.sendSuccessReply(requestToken, Messages.PACK_CREATED);
|
||||
this.getLogger().at(Level.INFO).log("Created new pack: %s at %s", packId, packPath);
|
||||
} catch (IOException var14) {
|
||||
this.getLogger().at(Level.SEVERE).withCause(var14).log("Failed to create pack %s", packId);
|
||||
editorClient.sendFailureReply(requestToken, Messages.PACK_CREATION_FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
editorClient.sendFailureReply(requestToken, Messages.INVALID_TARGET_DIRECTORY);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -20,8 +20,6 @@ import com.hypixel.hytale.event.EventRegistry;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.protocol.InstantData;
|
||||
import com.hypixel.hytale.protocol.Model;
|
||||
import com.hypixel.hytale.protocol.Vector2f;
|
||||
import com.hypixel.hytale.protocol.Vector3f;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorPopupNotificationType;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorPreviewCameraSettings;
|
||||
import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorUpdateModelPreview;
|
||||
@@ -38,7 +36,9 @@ import com.hypixel.hytale.server.core.asset.type.item.config.ItemArmor;
|
||||
import com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset;
|
||||
import com.hypixel.hytale.server.core.asset.type.weather.config.Weather;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
|
||||
import com.hypixel.hytale.server.core.io.PacketHandler;
|
||||
import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
|
||||
import com.hypixel.hytale.server.core.modules.entity.player.PlayerSkinComponent;
|
||||
@@ -60,6 +60,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
@Deprecated
|
||||
public class AssetSpecificFunctionality {
|
||||
@@ -214,21 +216,35 @@ public class AssetSpecificFunctionality {
|
||||
|
||||
private static void equipItem(@Nonnull Path assetPath, @Nonnull EditorClient editorClient) {
|
||||
PlayerRef playerRef = tryGetPlayer(editorClient);
|
||||
if (playerRef != null) {
|
||||
Player player = playerRef.getComponent(Player.getComponentType());
|
||||
String key = Item.getAssetStore().decodeFilePathKey(assetPath);
|
||||
Item item = Item.getAssetMap().getAsset(key);
|
||||
if (item == null) {
|
||||
editorClient.sendPopupNotification(
|
||||
AssetEditorPopupNotificationType.Error, Message.translation("server.assetEditor.messages.unknownItem").param("id", key.toString())
|
||||
if (playerRef != null && playerRef.isValid()) {
|
||||
Ref<EntityStore> ref = playerRef.getReference();
|
||||
if (ref != null && ref.isValid()) {
|
||||
Store<EntityStore> store = ref.getStore();
|
||||
World world = store.getExternalData().getWorld();
|
||||
world.execute(
|
||||
() -> {
|
||||
String key = Item.getAssetStore().decodeFilePathKey(assetPath);
|
||||
if (key != null) {
|
||||
Item item = Item.getAssetMap().getAsset(key);
|
||||
if (item == null) {
|
||||
editorClient.sendPopupNotification(
|
||||
AssetEditorPopupNotificationType.Error, Message.translation("server.assetEditor.messages.unknownItem").param("id", key)
|
||||
);
|
||||
} else {
|
||||
ItemArmor itemArmor = item.getArmor();
|
||||
if (itemArmor != null) {
|
||||
InventoryComponent.Armor armorComponent = store.getComponent(ref, InventoryComponent.Armor.getComponentType());
|
||||
if (armorComponent != null) {
|
||||
armorComponent.getInventory().setItemStackForSlot((short)itemArmor.getArmorSlot().ordinal(), new ItemStack(key));
|
||||
}
|
||||
} else {
|
||||
CombinedItemContainer combinedInventory = InventoryComponent.getCombined(store, ref, InventoryComponent.HOTBAR_FIRST);
|
||||
combinedInventory.addItemStack(new ItemStack(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
ItemArmor itemArmor = item.getArmor();
|
||||
if (itemArmor != null) {
|
||||
player.getInventory().getArmor().setItemStackForSlot((short)itemArmor.getArmorSlot().ordinal(), new ItemStack(key));
|
||||
} else {
|
||||
player.getInventory().getCombinedHotbarFirst().addItemStack(new ItemStack(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,4 +90,6 @@ public class Messages {
|
||||
public static final Message PACK_GROUP_REQUIRED = Message.translation("server.assetEditor.messages.packGroupRequired");
|
||||
@Nonnull
|
||||
public static final Message PACK_ALREADY_EXISTS = Message.translation("server.assetEditor.messages.packAlreadyExists");
|
||||
@Nonnull
|
||||
public static final Message INVALID_TARGET_DIRECTORY = Message.translation("server.assetEditor.messages.invalidTargetDirectory");
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@ import com.hypixel.hytale.component.Holder;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.BlockPosition;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
@@ -39,6 +37,8 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class BedInteraction extends SimpleBlockInteraction {
|
||||
@Nonnull
|
||||
@@ -90,16 +90,16 @@ public class BedInteraction extends SimpleBlockInteraction {
|
||||
boolean isOwner = playerUuid.equals(ownerUUID);
|
||||
if (isOwner) {
|
||||
BlockPosition targetBlockPosition = context.getMetaStore().getMetaObject(TARGET_BLOCK_RAW);
|
||||
Vector3f whereWasHit = new Vector3f(targetBlockPosition.x + 0.5F, targetBlockPosition.y + 0.5F, targetBlockPosition.z + 0.5F);
|
||||
Vector3d whereWasHit = new Vector3d(targetBlockPosition.x + 0.5, targetBlockPosition.y + 0.5, targetBlockPosition.z + 0.5);
|
||||
BlockMountAPI.BlockMountResult result = BlockMountAPI.mountOnBlock(ref, commandBuffer, pos, whereWasHit);
|
||||
if (result instanceof BlockMountAPI.DidNotMount) {
|
||||
playerComponent.sendMessage(Message.translation("server.interactions.didNotMount").param("state", result.toString()));
|
||||
playerRefComponent.sendMessage(Message.translation("server.interactions.didNotMount").param("state", result.toString()));
|
||||
} else if (result instanceof BlockMountAPI.Mounted) {
|
||||
commandBuffer.putComponent(ref, PlayerSomnolence.getComponentType(), PlayerSleep.NoddingOff.createComponent());
|
||||
commandBuffer.run(s -> SleepNotificationSystem.maybeDoNotification(s, false));
|
||||
}
|
||||
} else if (ownerUUID != null) {
|
||||
playerComponent.sendMessage(MESSAGE_SERVER_CUSTOM_UI_RESPAWN_POINT_CLAIMED);
|
||||
playerRefComponent.sendMessage(MESSAGE_SERVER_CUSTOM_UI_RESPAWN_POINT_CLAIMED);
|
||||
} else {
|
||||
PlayerRespawnPointData[] respawnPoints = playerComponent.getPlayerConfigData()
|
||||
.getPerWorldData(world.getName())
|
||||
@@ -148,9 +148,7 @@ public class BedInteraction extends SimpleBlockInteraction {
|
||||
for (int i = 0; i < respawnPoints.length; i++) {
|
||||
PlayerRespawnPointData respawnPoint = respawnPoints[i];
|
||||
Vector3i respawnPointPosition = respawnPoint.getBlockPosition();
|
||||
if (respawnPointPosition.distanceTo(currentRespawnPointPosition.x, respawnPointPosition.y, currentRespawnPointPosition.z) < radiusLimitRespawnPoint
|
||||
)
|
||||
{
|
||||
if (respawnPointPosition.distance(currentRespawnPointPosition.x, respawnPointPosition.y, currentRespawnPointPosition.z) < radiusLimitRespawnPoint) {
|
||||
nearbyRespawnPointList.add(respawnPoint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hypixel.hytale.builtin.beds.respawn;
|
||||
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.Page;
|
||||
@@ -17,6 +16,7 @@ import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.state.RespawnBlock;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class OverrideNearbyRespawnPointPage extends RespawnPointPage {
|
||||
@Nonnull
|
||||
@@ -53,7 +53,7 @@ public class OverrideNearbyRespawnPointPage extends RespawnPointPage {
|
||||
if (headRotationComponent != null) {
|
||||
PlayerRef playerRefComponent = store.getComponent(ref, PlayerRef.getComponentType());
|
||||
if (playerRefComponent != null) {
|
||||
double direction = Math.toDegrees(headRotationComponent.getRotation().getYaw());
|
||||
double direction = Math.toDegrees(headRotationComponent.getRotation().yaw());
|
||||
commandBuilder.set(
|
||||
"#DescriptionLabel.Text",
|
||||
Message.translation("server.customUI.overrideNearbyRespawnPoint.label")
|
||||
@@ -68,8 +68,7 @@ public class OverrideNearbyRespawnPointPage extends RespawnPointPage {
|
||||
commandBuilder.set(selector + ".Disabled", true);
|
||||
commandBuilder.set(selector + " #Name.Text", nearbyRespawnPoint.getName());
|
||||
Vector3i nearbyRespawnPointPosition = nearbyRespawnPoint.getBlockPosition();
|
||||
int distance = (int)this.respawnPointPosition
|
||||
.distanceTo(nearbyRespawnPointPosition.x, this.respawnPointPosition.y, nearbyRespawnPointPosition.z);
|
||||
int distance = (int)this.respawnPointPosition.distance(nearbyRespawnPointPosition.x, this.respawnPointPosition.y, nearbyRespawnPointPosition.z);
|
||||
commandBuilder.set(selector + " #Distance.Text", Message.translation("server.customUI.respawnPointDistance").param("distance", distance));
|
||||
double angle = Math.atan2(nearbyRespawnPointPosition.z - this.respawnPointPosition.z, nearbyRespawnPointPosition.x - this.respawnPointPosition.x);
|
||||
commandBuilder.set(selector + " #Icon.Angle", Math.toDegrees(angle) + direction + 90.0);
|
||||
|
||||
@@ -8,8 +8,6 @@ import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.shape.Box;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.CustomPageLifetime;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.Page;
|
||||
@@ -31,6 +29,8 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public abstract class RespawnPointPage extends InteractiveCustomUIPage<RespawnPointPage.RespawnPointEventData> {
|
||||
@Nonnull
|
||||
@@ -70,7 +70,7 @@ public abstract class RespawnPointPage extends InteractiveCustomUIPage<RespawnPo
|
||||
WorldChunk chunk = world.getChunkIfInMemory(chunkIndex);
|
||||
if (chunk != null) {
|
||||
chunk.markNeedsSaving();
|
||||
BlockType blockType = chunk.getBlockType(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
|
||||
BlockType blockType = chunk.getBlockType(blockPosition.x(), blockPosition.y(), blockPosition.z());
|
||||
if (blockType != null) {
|
||||
int rotationIndex = chunk.getRotationIndex(blockPosition.x, blockPosition.y, blockPosition.z);
|
||||
BlockBoundingBoxes blockBoundingBoxAsset = BlockBoundingBoxes.getAssetMap().getAsset(blockType.getHitboxTypeIndex());
|
||||
@@ -79,7 +79,7 @@ public abstract class RespawnPointPage extends InteractiveCustomUIPage<RespawnPo
|
||||
double blockCenterWidthOffset = hitbox.min.x + hitbox.width() / 2.0;
|
||||
double blockCenterDepthOffset = hitbox.min.z + hitbox.depth() / 2.0;
|
||||
Vector3d respawnPosition = new Vector3d(
|
||||
blockPosition.getX() + blockCenterWidthOffset, blockPosition.getY() + hitbox.height(), blockPosition.getZ() + blockCenterDepthOffset
|
||||
blockPosition.x() + blockCenterWidthOffset, blockPosition.y() + hitbox.height(), blockPosition.z() + blockCenterDepthOffset
|
||||
);
|
||||
PlayerRespawnPointData respawnPointData = new PlayerRespawnPointData(blockPosition, respawnPosition, respawnPointName);
|
||||
PlayerWorldData perWorldData = playerComponent.getPlayerConfigData().getPerWorldData(world.getName());
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hypixel.hytale.builtin.beds.respawn;
|
||||
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.Page;
|
||||
@@ -18,6 +17,7 @@ import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.state.RespawnBlock;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class SelectOverrideRespawnPointPage extends RespawnPointPage {
|
||||
@Nonnull
|
||||
@@ -59,7 +59,7 @@ public class SelectOverrideRespawnPointPage extends RespawnPointPage {
|
||||
if (playerRefComponent != null) {
|
||||
HeadRotation rotationComponent = store.getComponent(ref, HeadRotation.getComponentType());
|
||||
if (rotationComponent != null) {
|
||||
float lookYaw = rotationComponent.getRotation().getYaw();
|
||||
float lookYaw = rotationComponent.getRotation().yaw();
|
||||
double direction = Math.toDegrees(lookYaw);
|
||||
|
||||
for (int i = 0; i < this.respawnPoints.length; i++) {
|
||||
@@ -68,7 +68,7 @@ public class SelectOverrideRespawnPointPage extends RespawnPointPage {
|
||||
commandBuilder.append("#RespawnPointList", "Pages/OverrideRespawnPointButton.ui");
|
||||
commandBuilder.set(selector + " #Name.Text", respawnPoint.getName());
|
||||
Vector3i respawnPointPosition = respawnPoint.getBlockPosition();
|
||||
int distance = (int)this.respawnPointToAddPosition.distanceTo(respawnPointPosition.x, this.respawnPointToAddPosition.y, respawnPointPosition.z);
|
||||
int distance = (int)this.respawnPointToAddPosition.distance(respawnPointPosition.x, this.respawnPointToAddPosition.y, respawnPointPosition.z);
|
||||
commandBuilder.set(selector + " #Distance.Text", Message.translation("server.customUI.respawnPointDistance").param("distance", distance));
|
||||
double angle = Math.atan2(respawnPointPosition.z - this.respawnPointToAddPosition.z, respawnPointPosition.x - this.respawnPointToAddPosition.x);
|
||||
commandBuilder.set(selector + " #Icon.Angle", Math.toDegrees(angle) + direction + 90.0);
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hypixel.hytale.builtin.beds.respawn;
|
||||
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.Page;
|
||||
@@ -17,6 +16,7 @@ import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.meta.state.RespawnBlock;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class SetNameRespawnPointPage extends RespawnPointPage {
|
||||
@Nonnull
|
||||
|
||||
@@ -139,7 +139,7 @@ public class EnterBedSystem extends RefChangeSystem<EntityStore, MountedComponen
|
||||
// 08: istore 2
|
||||
// 09: aload 1
|
||||
// 0a: iload 2
|
||||
// 0b: invokedynamic typeSwitch (Ljava/lang/Object;I)I bsm=java/lang/runtime/SwitchBootstraps.typeSwitch (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; args=[ null.invoke Ljava/lang/Enum$EnumDesc;, com/hypixel/hytale/builtin/beds/sleep/systems/world/CanSleepInWorld$NotDuringSleepHoursRange ]
|
||||
// 0b: invokedynamic typeSwitch (Lcom/hypixel/hytale/builtin/beds/sleep/systems/world/CanSleepInWorld$Result;I)I bsm=java/lang/runtime/SwitchBootstraps.typeSwitch (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; args=[ null.invoke Ljava/lang/Enum$EnumDesc;, com/hypixel/hytale/builtin/beds/sleep/systems/world/CanSleepInWorld$NotDuringSleepHoursRange ]
|
||||
// 10: lookupswitch 45 2 0 28 1 34
|
||||
// 2c: getstatic com/hypixel/hytale/builtin/beds/sleep/systems/player/EnterBedSystem.MESSAGE_SERVER_INTERACTIONS_SLEEP_GAME_TIME_PAUSED Lcom/hypixel/hytale/server/core/Message;
|
||||
// 2f: goto 40
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.shape.Box;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.protocol.BlockMaterial;
|
||||
import com.hypixel.hytale.server.core.asset.type.blockhitbox.BlockBoundingBoxes;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace;
|
||||
@@ -25,6 +24,8 @@ import com.hypixel.hytale.server.core.util.FillerBlockUtil;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector3ic;
|
||||
|
||||
public class BlockPhysicsUtil {
|
||||
public static final int DOESNT_SATISFY = 0;
|
||||
@@ -244,14 +245,14 @@ public class BlockPhysicsUtil {
|
||||
RequiredBlockFaceSupport[] requiredBlockFaceSupports = requiredBlockFaceSupportMap.get(blockFace);
|
||||
if (requiredBlockFaceSupports != null && requiredBlockFaceSupports.length != 0) {
|
||||
BlockFace[] connectingFaces = blockFace.getConnectingFaces();
|
||||
Vector3i[] connectingFaceOffsets = blockFace.getConnectingFaceOffsets();
|
||||
Vector3ic[] connectingFaceOffsets = blockFace.getConnectingFaceOffsets();
|
||||
|
||||
for (int i = 0; i < connectingFaces.length; i++) {
|
||||
BlockFace neighbourBlockFace = connectingFaces[i];
|
||||
Vector3i neighbourDirection = connectingFaceOffsets[i];
|
||||
int neighbourX = blockX + neighbourDirection.x;
|
||||
int neighbourY = blockY + neighbourDirection.y;
|
||||
int neighbourZ = blockZ + neighbourDirection.z;
|
||||
Vector3ic neighbourDirection = connectingFaceOffsets[i];
|
||||
int neighbourX = blockX + neighbourDirection.x();
|
||||
int neighbourY = blockY + neighbourDirection.y();
|
||||
int neighbourZ = blockZ + neighbourDirection.z();
|
||||
if (!boundingBox.containsBlock(origin, neighbourX, neighbourY, neighbourZ)) {
|
||||
BlockSection neighbourBlockSection;
|
||||
FluidSection neighbourFluidSection;
|
||||
@@ -279,7 +280,7 @@ public class BlockPhysicsUtil {
|
||||
int neighbourRotation = neighbourBlockSection.getRotationIndex(neighbourX, neighbourY, neighbourZ);
|
||||
BlockType neighbourBlockType = BlockType.getAssetMap().getAsset(neighbourBlockId);
|
||||
Fluid neighbourFluid = Fluid.getAssetMap().getAsset(neighbourFluidId);
|
||||
neighbourFillerOffset.assign(
|
||||
neighbourFillerOffset.set(
|
||||
FillerBlockUtil.unpackX(neighbourFiller), FillerBlockUtil.unpackY(neighbourFiller), FillerBlockUtil.unpackZ(neighbourFiller)
|
||||
);
|
||||
boolean doesSatisfySupport = false;
|
||||
|
||||
@@ -69,18 +69,10 @@ public class PrefabBufferValidator {
|
||||
if (Files.isRegularFile(path) && path.toString().endsWith(".prefab.json")) {
|
||||
try {
|
||||
IPrefabBuffer prefab = PrefabBufferUtil.getCached(path);
|
||||
|
||||
String var4;
|
||||
try {
|
||||
String results = validate(prefab, options);
|
||||
var4 = results != null ? path + "\n" + results : null;
|
||||
} finally {
|
||||
prefab.release();
|
||||
}
|
||||
|
||||
return var4;
|
||||
} catch (Throwable var9) {
|
||||
return path + "\n\t" + ExceptionUtil.combineMessages(var9, "\n\t");
|
||||
String results = validate(prefab, options);
|
||||
return results != null ? path + "\n" + results : null;
|
||||
} catch (Throwable var4) {
|
||||
return path + "\n\t" + ExceptionUtil.combineMessages(var4, "\n\t");
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.hypixel.hytale.codec.store.StoredCodec;
|
||||
import com.hypixel.hytale.common.map.IWeightedElement;
|
||||
import com.hypixel.hytale.component.Holder;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
||||
import com.hypixel.hytale.server.core.prefab.config.SelectionPrefabSerializer;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -22,12 +21,6 @@ public class BlockSpawnerEntry implements IWeightedElement {
|
||||
.add()
|
||||
.append(new KeyedCodec<>("Weight", Codec.DOUBLE), (entry, d) -> entry.weight = d, entry -> entry.weight)
|
||||
.add()
|
||||
.append(
|
||||
new KeyedCodec<>("State", Codec.BSON_DOCUMENT),
|
||||
(entry, wrapper, extraInfo) -> entry.blockComponents = SelectionPrefabSerializer.legacyStateDecode(wrapper),
|
||||
(entry, extraInfo) -> null
|
||||
)
|
||||
.add()
|
||||
.append(
|
||||
new KeyedCodec<>("Components", new StoredCodec<>(ChunkStore.HOLDER_CODEC_KEY)),
|
||||
(entry, holder) -> entry.blockComponents = holder,
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.hypixel.hytale.component.Holder;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.RemoveReason;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.data.unknown.UnknownComponents;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.RefSystem;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
@@ -26,6 +25,7 @@ import com.hypixel.hytale.server.core.asset.type.blocktype.config.Rotation;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.RotationTuple;
|
||||
import com.hypixel.hytale.server.core.asset.type.blocktype.config.VariantRotation;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.Item;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.ItemDropList;
|
||||
import com.hypixel.hytale.server.core.modules.block.BlockModule;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
|
||||
@@ -35,7 +35,6 @@ import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BlockSpawnerPlugin extends JavaPlugin {
|
||||
@Nonnull
|
||||
@@ -62,12 +61,11 @@ public class BlockSpawnerPlugin extends JavaPlugin {
|
||||
.setPath("Item/Block/Spawners"))
|
||||
.setCodec(BlockSpawnerTable.CODEC))
|
||||
.setKeyFunction(BlockSpawnerTable::getId))
|
||||
.loadsAfter(Item.class, BlockType.class))
|
||||
.loadsAfter(Item.class, BlockType.class, ItemDropList.class))
|
||||
.build()
|
||||
);
|
||||
this.blockSpawnerComponentType = this.getChunkStoreRegistry().registerComponent(BlockSpawner.class, "BlockSpawner", BlockSpawner.CODEC);
|
||||
this.getChunkStoreRegistry().registerSystem(new BlockSpawnerPlugin.BlockSpawnerSystem());
|
||||
this.getChunkStoreRegistry().registerSystem(new BlockSpawnerPlugin.MigrateBlockSpawner());
|
||||
this.getEventRegistry().registerGlobal(PrefabBufferValidator.ValidateBlockEvent.class, BlockSpawnerPlugin::validatePrefabBlock);
|
||||
}
|
||||
|
||||
@@ -202,7 +200,7 @@ public class BlockSpawnerPlugin extends JavaPlugin {
|
||||
BlockType blockType = BlockType.getAssetMap().getAsset(blockId);
|
||||
worldChunkComponent.setBlock(x, y, z, blockId, blockType, rotation.index(), 0, flags);
|
||||
if (holder != null) {
|
||||
worldChunkComponent.setState(x, y, z, holder.clone());
|
||||
worldChunkComponent.setState(x, y, z, blockType, rotation.index(), holder.clone());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -219,29 +217,4 @@ public class BlockSpawnerPlugin extends JavaPlugin {
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public static class MigrateBlockSpawner extends BlockModule.MigrationSystem {
|
||||
@Override
|
||||
public void onEntityAdd(@Nonnull Holder<ChunkStore> holder, @Nonnull AddReason reason, @Nonnull Store<ChunkStore> store) {
|
||||
UnknownComponents<ChunkStore> unknown = holder.getComponent(ChunkStore.REGISTRY.getUnknownComponentType());
|
||||
|
||||
assert unknown != null;
|
||||
|
||||
BlockSpawner blockSpawner = unknown.removeComponent("blockspawner", BlockSpawner.CODEC);
|
||||
if (blockSpawner != null) {
|
||||
holder.putComponent(BlockSpawner.getComponentType(), blockSpawner);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityRemoved(@Nonnull Holder<ChunkStore> holder, @Nonnull RemoveReason reason, @Nonnull Store<ChunkStore> store) {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Query<ChunkStore> getQuery() {
|
||||
return ChunkStore.REGISTRY.getUnknownComponentType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.hypixel.hytale.builtin.blockspawner.state.BlockSpawner;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.command.system.CommandContext;
|
||||
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
|
||||
@@ -18,6 +17,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import com.hypixel.hytale.server.core.util.TargetUtil;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class BlockSpawnerGetCommand extends AbstractWorldCommand {
|
||||
@Nonnull
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.hypixel.hytale.builtin.blockspawner.state.BlockSpawner;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.command.system.CommandContext;
|
||||
import com.hypixel.hytale.server.core.command.system.arguments.system.FlagArg;
|
||||
@@ -23,6 +22,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import com.hypixel.hytale.server.core.util.TargetUtil;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class BlockSpawnerSetCommand extends AbstractWorldCommand {
|
||||
@Nonnull
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hypixel.hytale.builtin.blocktick;
|
||||
|
||||
import com.hypixel.hytale.assetstore.map.BlockTypeAssetMap;
|
||||
import com.hypixel.hytale.builtin.blocktick.procedure.BasicChanceBlockGrowthProcedure;
|
||||
import com.hypixel.hytale.builtin.blocktick.procedure.SplitChanceBlockGrowthProcedure;
|
||||
import com.hypixel.hytale.builtin.blocktick.system.ChunkBlockTickSystem;
|
||||
@@ -19,6 +18,9 @@ import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
|
||||
import com.hypixel.hytale.server.core.universe.world.events.ChunkPreLoadProcessEvent;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import java.util.function.IntConsumer;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BlockTickPlugin extends JavaPlugin implements IBlockTickProvider {
|
||||
@@ -59,7 +61,7 @@ public class BlockTickPlugin extends JavaPlugin implements IBlockTickProvider {
|
||||
if (!this.isEnabled()) {
|
||||
return 0;
|
||||
} else {
|
||||
BlockChunk blockChunkComponent = worldChunk.getBlockChunk();
|
||||
BlockChunk blockChunkComponent = holder.getComponent(BlockChunk.getComponentType());
|
||||
if (blockChunkComponent != null && blockChunkComponent.consumeNeedsPhysics()) {
|
||||
ChunkColumn chunkColumnComponent = holder.getComponent(ChunkColumn.getComponentType());
|
||||
if (chunkColumnComponent == null) {
|
||||
@@ -69,25 +71,26 @@ public class BlockTickPlugin extends JavaPlugin implements IBlockTickProvider {
|
||||
if (sections == null) {
|
||||
return 0;
|
||||
} else {
|
||||
BlockTypeAssetMap<String, BlockType> assetMap = BlockType.getAssetMap();
|
||||
BlockTickPlugin.Preprocessor preprocessor = BlockTickPlugin.Preprocessor.LOCAL.get();
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < sections.length; i++) {
|
||||
Holder<ChunkStore> sectionHolder = sections[i];
|
||||
BlockSection blockSectionComponent = sectionHolder.ensureAndGetComponent(BlockSection.getComponentType());
|
||||
if (!blockSectionComponent.isSolidAir()) {
|
||||
for (int blockIdx = 0; blockIdx < 32768; blockIdx++) {
|
||||
int blockId = blockSectionComponent.get(blockIdx);
|
||||
BlockType blockType = assetMap.getAsset(blockId);
|
||||
if (blockType != null && blockType.getTickProcedure() != null) {
|
||||
blockSectionComponent.setTicking(blockIdx, true);
|
||||
blockChunkComponent.markNeedsSaving();
|
||||
count++;
|
||||
}
|
||||
BlockSection section = sectionHolder.ensureAndGetComponent(BlockSection.getComponentType());
|
||||
if (!section.isSolidAir()) {
|
||||
preprocessor.clear();
|
||||
section.forEachValue(preprocessor.typeCollector);
|
||||
if (!preprocessor.tickingIds.isEmpty()) {
|
||||
section.find(preprocessor.tickingIds, preprocessor.indexCollector);
|
||||
count += section.setTicking(preprocessor.tickingIndices, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
blockChunkComponent.markNeedsSaving();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
@@ -96,4 +99,28 @@ public class BlockTickPlugin extends JavaPlugin implements IBlockTickProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Preprocessor {
|
||||
public static final ThreadLocal<BlockTickPlugin.Preprocessor> LOCAL = ThreadLocal.withInitial(BlockTickPlugin.Preprocessor::new);
|
||||
public final IntList tickingIds = new IntArrayList();
|
||||
public final IntList tickingIndices = new IntArrayList();
|
||||
public final IntConsumer typeCollector = this::collectType;
|
||||
public final IntConsumer indexCollector = this::collectIndex;
|
||||
|
||||
public void clear() {
|
||||
this.tickingIds.clear();
|
||||
this.tickingIndices.clear();
|
||||
}
|
||||
|
||||
private void collectType(int value) {
|
||||
BlockType type = BlockType.getAssetMap().getAsset(value);
|
||||
if (type != null && type.getTickProcedure() != null) {
|
||||
this.tickingIds.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void collectIndex(int index) {
|
||||
this.tickingIndices.add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,11 +72,15 @@ public class ChunkBlockTickSystem {
|
||||
@Nonnull
|
||||
private static final ComponentType<ChunkStore, WorldChunk> COMPONENT_TYPE_WORLD_CHUNK = WorldChunk.getComponentType();
|
||||
@Nonnull
|
||||
private static final ComponentType<ChunkStore, BlockChunk> COMPONENT_TYPE_BLOCK_CHUNK = BlockChunk.getComponentType();
|
||||
@Nonnull
|
||||
private static final Query<ChunkStore> QUERY = Query.and(COMPONENT_TYPE_WORLD_CHUNK, COMPONENT_TYPE_BLOCK_CHUNK);
|
||||
@Nonnull
|
||||
private static final Set<Dependency<ChunkStore>> DEPENDENCIES = Set.of(new SystemDependency<>(Order.AFTER, ChunkBlockTickSystem.PreTick.class));
|
||||
|
||||
@Override
|
||||
public Query<ChunkStore> getQuery() {
|
||||
return COMPONENT_TYPE_WORLD_CHUNK;
|
||||
return QUERY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -98,29 +102,26 @@ public class ChunkBlockTickSystem {
|
||||
|
||||
assert worldChunkComponent != null;
|
||||
|
||||
BlockChunk blockChunk = archetypeChunk.getComponent(index, COMPONENT_TYPE_BLOCK_CHUNK);
|
||||
|
||||
assert blockChunk != null;
|
||||
|
||||
try {
|
||||
tick(reference, worldChunkComponent);
|
||||
} catch (Throwable var9) {
|
||||
ChunkBlockTickSystem.LOGGER.at(Level.SEVERE).withCause(var9).log("Failed to tick chunk: %s", worldChunkComponent);
|
||||
tick(reference, blockChunk, worldChunkComponent);
|
||||
} catch (Throwable var10) {
|
||||
ChunkBlockTickSystem.LOGGER.at(Level.SEVERE).withCause(var10).log("Failed to tick chunk: %s", worldChunkComponent);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void tick(@Nonnull Ref<ChunkStore> ref, @Nonnull WorldChunk worldChunk) {
|
||||
BlockChunk blockChunkComponent = worldChunk.getBlockChunk();
|
||||
if (blockChunkComponent == null) {
|
||||
ChunkBlockTickSystem.LOGGER
|
||||
.at(Level.WARNING)
|
||||
.log("World chunk (%d, %d) has no BlockChunk component, skipping block ticking.", worldChunk.getX(), worldChunk.getZ());
|
||||
} else {
|
||||
int ticked = blockChunkComponent.forEachTicking(ref, worldChunk, (r, c, localX, localY, localZ, blockId) -> {
|
||||
World world = c.getWorld();
|
||||
int blockX = c.getX() << 5 | localX;
|
||||
int blockZ = c.getZ() << 5 | localZ;
|
||||
return tickProcedure(world, c, blockX, localY, blockZ, blockId);
|
||||
});
|
||||
if (ticked > 0) {
|
||||
ChunkBlockTickSystem.LOGGER.at(Level.FINER).log("Ticked %d blocks in chunk (%d, %d)", ticked, worldChunk.getX(), worldChunk.getZ());
|
||||
}
|
||||
protected static void tick(@Nonnull Ref<ChunkStore> ref, @Nonnull BlockChunk blockChunkComponent, @Nonnull WorldChunk worldChunk) {
|
||||
int ticked = blockChunkComponent.forEachTicking(ref, worldChunk, (r, c, localX, localY, localZ, blockId) -> {
|
||||
World world = c.getWorld();
|
||||
int blockX = c.getX() << 5 | localX;
|
||||
int blockZ = c.getZ() << 5 | localZ;
|
||||
return tickProcedure(world, c, blockX, localY, blockZ, blockId);
|
||||
});
|
||||
if (ticked > 0) {
|
||||
ChunkBlockTickSystem.LOGGER.at(Level.FINER).log("Ticked %d blocks in chunk (%d, %d)", ticked, worldChunk.getX(), worldChunk.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,14 @@ package com.hypixel.hytale.builtin.buildertools;
|
||||
import com.hypixel.hytale.builtin.buildertools.commands.CopyCommand;
|
||||
import com.hypixel.hytale.builtin.buildertools.prefabeditor.PrefabEditSession;
|
||||
import com.hypixel.hytale.builtin.buildertools.prefabeditor.PrefabEditSessionManager;
|
||||
import com.hypixel.hytale.builtin.buildertools.prefabeditor.PrefabEditingMetadata;
|
||||
import com.hypixel.hytale.builtin.buildertools.tooloperations.ToolOperation;
|
||||
import com.hypixel.hytale.component.Ref;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.math.Axis;
|
||||
import com.hypixel.hytale.math.util.MathUtil;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import com.hypixel.hytale.math.vector.Vector3f;
|
||||
import com.hypixel.hytale.math.vector.Vector3i;
|
||||
import com.hypixel.hytale.math.vector.Rotation3f;
|
||||
import com.hypixel.hytale.protocol.BlockPosition;
|
||||
import com.hypixel.hytale.protocol.ColorLight;
|
||||
import com.hypixel.hytale.protocol.InteractionType;
|
||||
@@ -26,6 +25,7 @@ import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolGeneralAction
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolLineAction;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolOnUseInteraction;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolPasteClipboard;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolResetClipboardRotation;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolRotateClipboard;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolSelectionToolAskForClipboard;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolSelectionToolReplyWithClipboard;
|
||||
@@ -39,14 +39,16 @@ import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolSetEntityTran
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolSetNPCDebug;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolSetTransformationModeState;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolStackArea;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.ClipboardEntityChange;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.PrefabSetAnchor;
|
||||
import com.hypixel.hytale.protocol.packets.buildertools.PrefabUnselectPrefab;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.BlockChange;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.EditorBlocksChange;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.FluidChange;
|
||||
import com.hypixel.hytale.protocol.packets.interface_.NotificationStyle;
|
||||
import com.hypixel.hytale.protocol.packets.player.LoadHotbar;
|
||||
import com.hypixel.hytale.protocol.packets.player.SaveHotbar;
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.asset.type.buildertool.config.BrushData;
|
||||
import com.hypixel.hytale.server.core.asset.type.buildertool.config.BuilderTool;
|
||||
import com.hypixel.hytale.server.core.command.commands.world.entity.EntityCloneCommand;
|
||||
import com.hypixel.hytale.server.core.command.commands.world.entity.EntityRemoveCommand;
|
||||
@@ -75,6 +77,7 @@ import com.hypixel.hytale.server.core.prefab.selection.standard.BlockSelection;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import com.hypixel.hytale.server.core.util.NotificationUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -84,6 +87,8 @@ import java.util.logging.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joml.Quaterniond;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
@Nonnull
|
||||
@@ -123,7 +128,7 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
@Override
|
||||
public void registerHandlers() {
|
||||
if (BuilderToolsPlugin.get().isDisabled()) {
|
||||
this.packetHandler.registerNoOpHandlers(400, 401, 412, 409, 403, 406, 407, 413, 414, 417);
|
||||
this.packetHandler.registerNoOpHandlers(400, 401, 412, 409, 403, 406, 427, 407, 413, 414, 417, 426);
|
||||
} else {
|
||||
IWorldPacketHandler.registerHandler(this.packetHandler, 106, this::handleLoadHotbar, BuilderToolsPacketHandler::hasPermission);
|
||||
IWorldPacketHandler.registerHandler(this.packetHandler, 107, this::handleSaveHotbar, BuilderToolsPacketHandler::hasPermission);
|
||||
@@ -134,6 +139,7 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
this.packetHandler, 408, this::handleBuilderToolSetTransformationModeState, BuilderToolsPacketHandler::hasPermission
|
||||
);
|
||||
IWorldPacketHandler.registerHandler(this.packetHandler, 417, this::handlePrefabUnselectPrefab, BuilderToolsPacketHandler::hasPermission);
|
||||
IWorldPacketHandler.registerHandler(this.packetHandler, 426, this::handlePrefabSetAnchor, BuilderToolsPacketHandler::hasPermission);
|
||||
IWorldPacketHandler.registerHandler(this.packetHandler, 421, this::handleBuilderToolSetEntityPickupEnabled, BuilderToolsPacketHandler::hasPermission);
|
||||
IWorldPacketHandler.registerHandler(this.packetHandler, 422, this::handleBuilderToolSetEntityLight, BuilderToolsPacketHandler::hasPermission);
|
||||
IWorldPacketHandler.registerHandler(this.packetHandler, 423, this::handleBuilderToolSetNPCDebug, BuilderToolsPacketHandler::hasPermission);
|
||||
@@ -148,6 +154,9 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
IWorldPacketHandler.registerHandler(
|
||||
this.packetHandler, 406, this::handleBuilderToolRotateClipboard, p -> hasPermission(p, "hytale.editor.selection.clipboard")
|
||||
);
|
||||
IWorldPacketHandler.registerHandler(
|
||||
this.packetHandler, 427, this::handleBuilderToolResetClipboardRotation, p -> hasPermission(p, "hytale.editor.selection.clipboard")
|
||||
);
|
||||
IWorldPacketHandler.registerHandler(
|
||||
this.packetHandler, 407, this::handleBuilderToolPasteClipboard, p -> hasPermission(p, "hytale.editor.selection.clipboard")
|
||||
);
|
||||
@@ -215,33 +224,30 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
@Nonnull World world,
|
||||
@Nonnull Store<EntityStore> store
|
||||
) {
|
||||
Player playerComponent = store.getComponent(ref, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
int targetId = packet.entityId;
|
||||
Ref<EntityStore> targetRef = world.getEntityStore().getRefFromNetworkId(targetId);
|
||||
if (targetRef != null && targetRef.isValid()) {
|
||||
Player targetPlayerComponent = store.getComponent(targetRef, Player.getComponentType());
|
||||
if (targetPlayerComponent != null) {
|
||||
playerComponent.sendMessage(Message.translation("server.builderTools.entityTool.cannotTargetPlayer"));
|
||||
} else {
|
||||
LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet);
|
||||
switch (packet.action) {
|
||||
case Freeze:
|
||||
UUIDComponent uuidComponent = store.getComponent(targetRef, UUIDComponent.getComponentType());
|
||||
if (uuidComponent != null) {
|
||||
CommandManager.get().handleCommand(playerComponent, "npc freeze --toggle --entity " + uuidComponent.getUuid());
|
||||
}
|
||||
break;
|
||||
case Clone:
|
||||
world.execute(() -> EntityCloneCommand.cloneEntity(playerComponent, targetRef, store));
|
||||
break;
|
||||
case Remove:
|
||||
world.execute(() -> EntityRemoveCommand.removeEntity(ref, targetRef, store));
|
||||
}
|
||||
}
|
||||
int targetId = packet.entityId;
|
||||
Ref<EntityStore> targetRef = world.getEntityStore().getRefFromNetworkId(targetId);
|
||||
if (targetRef != null && targetRef.isValid()) {
|
||||
Player targetPlayerComponent = store.getComponent(targetRef, Player.getComponentType());
|
||||
if (targetPlayerComponent != null) {
|
||||
playerRef.sendMessage(Message.translation("server.builderTools.entityTool.cannotTargetPlayer"));
|
||||
} else {
|
||||
playerComponent.sendMessage(Message.translation("server.general.entityNotFound").param("id", targetId));
|
||||
LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet);
|
||||
switch (packet.action) {
|
||||
case Freeze:
|
||||
UUIDComponent uuidComponent = store.getComponent(targetRef, UUIDComponent.getComponentType());
|
||||
if (uuidComponent != null) {
|
||||
CommandManager.get().handleCommand(playerRef, "npc freeze --toggle --entity " + uuidComponent.getUuid());
|
||||
}
|
||||
break;
|
||||
case Clone:
|
||||
world.execute(() -> EntityCloneCommand.cloneEntity(playerRef, targetRef, store));
|
||||
break;
|
||||
case Remove:
|
||||
world.execute(() -> EntityRemoveCommand.removeEntity(ref, targetRef, store));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
playerRef.sendMessage(Message.translation("server.general.entityNotFound").param("id", targetId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +296,7 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
|
||||
BuilderToolsPlugin.BuilderState builderState = BuilderToolsPlugin.getState(playerComponent, playerRef);
|
||||
Vector3d position = transformComponent.getPosition();
|
||||
Vector3i intTriple = new Vector3i(MathUtil.floor(position.getX()), MathUtil.floor(position.getY()), MathUtil.floor(position.getZ()));
|
||||
Vector3i intTriple = new Vector3i(MathUtil.floor(position.x()), MathUtil.floor(position.y()), MathUtil.floor(position.z()));
|
||||
BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> {
|
||||
if (packet.action == BuilderToolAction.SelectionPosition1) {
|
||||
builderState.pos1(intTriple, componentAccessor);
|
||||
@@ -366,22 +372,13 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
);
|
||||
prototypeSettings.setFluidChangesForPlaySelectionToolPasteMode(fluidChangesArray);
|
||||
ArrayList<PrototypePlayerBuilderToolSettings.EntityChange> entityChanges = new ArrayList<>();
|
||||
int selectionX = selection.getX();
|
||||
int selectionY = selection.getY();
|
||||
int selectionZ = selection.getZ();
|
||||
selection.forEachEntity(
|
||||
holder -> {
|
||||
TransformComponent transform = holder.getComponent(TransformComponent.getComponentType());
|
||||
if (transform != null && transform.getPosition() != null) {
|
||||
Vector3d pos = transform.getPosition();
|
||||
entityChanges.add(
|
||||
new PrototypePlayerBuilderToolSettings.EntityChange(
|
||||
pos.getX() + selectionX, pos.getY() + selectionY, pos.getZ() + selectionZ, holder.clone()
|
||||
)
|
||||
);
|
||||
}
|
||||
selection.forEachEntity(holder -> {
|
||||
TransformComponent transform = holder.getComponent(TransformComponent.getComponentType());
|
||||
if (transform != null && transform.getPosition() != null) {
|
||||
Vector3d pos = transform.getPosition();
|
||||
entityChanges.add(new PrototypePlayerBuilderToolSettings.EntityChange(pos.x(), pos.y(), pos.z(), holder.clone()));
|
||||
}
|
||||
);
|
||||
});
|
||||
prototypeSettings.setEntityChangesForPlaySelectionToolPasteMode(entityChanges.toArray(PrototypePlayerBuilderToolSettings.EntityChange[]::new));
|
||||
FluidChange[] packetFluids = new FluidChange[fluidChangesArray.length];
|
||||
|
||||
@@ -390,7 +387,24 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
packetFluids[i] = new FluidChange(fc.x(), fc.y(), fc.z(), fc.fluidId(), fc.fluidLevel());
|
||||
}
|
||||
|
||||
playerRef.getPacketHandler().write(new BuilderToolSelectionToolReplyWithClipboard(blocksChange, packetFluids));
|
||||
ClipboardEntityChange[] packetEntities = new ClipboardEntityChange[entityChanges.size()];
|
||||
|
||||
for (int i = 0; i < entityChanges.size(); i++) {
|
||||
PrototypePlayerBuilderToolSettings.EntityChange ec = entityChanges.get(i);
|
||||
packetEntities[i] = BlockSelection.toClipboardEntityChange(ec.entityHolder(), anchorX, anchorY, anchorZ);
|
||||
}
|
||||
|
||||
if (blocksChange != null && blocksChange.length > 4000000) {
|
||||
NotificationUtil.sendNotification(
|
||||
playerRef.getPacketHandler(),
|
||||
Message.translation("server.builderTools.copycut.tooLarge"),
|
||||
Message.translation("server.builderTools.copycut.tooLarge.detail").param("overCount", blocksChange.length - 4000000),
|
||||
NotificationStyle.Warning
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
playerRef.getPacketHandler().write(new BuilderToolSelectionToolReplyWithClipboard(blocksChange, packetFluids, packetEntities));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -417,11 +431,11 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
}
|
||||
|
||||
boolean finalKeepEmptyBlocks = keepEmptyBlocks;
|
||||
Quaterniond rotation = new Quaterniond(packet.rotation.x, packet.rotation.y, packet.rotation.z, packet.rotation.w);
|
||||
Quaterniond rotation = new Quaterniond(packet.rotation);
|
||||
Vector3i translationOffset = new Vector3i(packet.translationOffset.x, packet.translationOffset.y, packet.translationOffset.z);
|
||||
Vector3i initialSelectionMin = new Vector3i(packet.initialSelectionMin.x, packet.initialSelectionMin.y, packet.initialSelectionMin.z);
|
||||
Vector3i initialSelectionMax = new Vector3i(packet.initialSelectionMax.x, packet.initialSelectionMax.y, packet.initialSelectionMax.z);
|
||||
Vector3f rotationOrigin = new Vector3f(packet.initialRotationOrigin.x, packet.initialRotationOrigin.y, packet.initialRotationOrigin.z);
|
||||
Rotation3f rotationOrigin = new Rotation3f(packet.initialRotationOrigin.x(), packet.initialRotationOrigin.y(), packet.initialRotationOrigin.z());
|
||||
PrototypePlayerBuilderToolSettings prototypeSettings = ToolOperation.getOrCreatePrototypeSettings(playerRef.getUuid());
|
||||
BuilderToolsPlugin.addToQueue(
|
||||
playerComponent,
|
||||
@@ -430,105 +444,120 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
int blockCount = s.getSelection().getSelectionVolume();
|
||||
boolean large = blockCount > 20000;
|
||||
if (large) {
|
||||
playerComponent.sendMessage(Message.translation("server.builderTools.selection.large.warning"));
|
||||
playerRef.sendMessage(Message.translation("server.builderTools.selection.large.warning"));
|
||||
}
|
||||
|
||||
if (prototypeSettings.getBlockChangesForPlaySelectionToolPasteMode() == null) {
|
||||
s.select(initialSelectionMin, initialSelectionMax, "server.builderTools.selectReasons.selectionTranslatePacket", componentAccessor);
|
||||
List<Ref<EntityStore>> lastTransformRefs = prototypeSettings.getLastTransformEntityRefs();
|
||||
HashSet<Ref<EntityStore>> skipSet = lastTransformRefs != null ? new HashSet<>(lastTransformRefs) : null;
|
||||
if (packet.cutOriginal) {
|
||||
s.copyOrCut(
|
||||
r,
|
||||
initialSelectionMin.x,
|
||||
initialSelectionMin.y,
|
||||
initialSelectionMin.z,
|
||||
initialSelectionMax.x,
|
||||
initialSelectionMax.y,
|
||||
initialSelectionMax.z,
|
||||
154,
|
||||
null,
|
||||
skipSet,
|
||||
store
|
||||
);
|
||||
} else {
|
||||
s.copyOrCut(
|
||||
r,
|
||||
initialSelectionMin.x,
|
||||
initialSelectionMin.y,
|
||||
initialSelectionMin.z,
|
||||
initialSelectionMax.x,
|
||||
initialSelectionMax.y,
|
||||
initialSelectionMax.z,
|
||||
152,
|
||||
store
|
||||
);
|
||||
}
|
||||
try {
|
||||
if (prototypeSettings.getBlockChangesForPlaySelectionToolPasteMode() == null) {
|
||||
s.select(initialSelectionMin, initialSelectionMax, "server.builderTools.selectReasons.selectionTranslatePacket", componentAccessor);
|
||||
List<Ref<EntityStore>> lastTransformRefs = prototypeSettings.getLastTransformEntityRefs();
|
||||
HashSet<Ref<EntityStore>> skipSet = lastTransformRefs != null ? new HashSet<>(lastTransformRefs) : null;
|
||||
if (packet.cutOriginal) {
|
||||
s.copyOrCut(
|
||||
r,
|
||||
initialSelectionMin.x,
|
||||
initialSelectionMin.y,
|
||||
initialSelectionMin.z,
|
||||
initialSelectionMax.x,
|
||||
initialSelectionMax.y,
|
||||
initialSelectionMax.z,
|
||||
154,
|
||||
null,
|
||||
skipSet,
|
||||
store
|
||||
);
|
||||
} else {
|
||||
s.copyOrCut(
|
||||
r,
|
||||
initialSelectionMin.x,
|
||||
initialSelectionMin.y,
|
||||
initialSelectionMin.z,
|
||||
initialSelectionMax.x,
|
||||
initialSelectionMax.y,
|
||||
initialSelectionMax.z,
|
||||
152,
|
||||
store
|
||||
);
|
||||
}
|
||||
|
||||
BlockSelection selection = s.getSelection();
|
||||
BlockChange[] blocksChange = selection.toPacket().blocksChange;
|
||||
prototypeSettings.setBlockChangesForPlaySelectionToolPasteMode(blocksChange);
|
||||
ArrayList<PrototypePlayerBuilderToolSettings.FluidChange> fluidChanges = new ArrayList<>();
|
||||
int anchorX = selection.getAnchorX();
|
||||
int anchorY = selection.getAnchorY();
|
||||
int anchorZ = selection.getAnchorZ();
|
||||
selection.forEachFluid(
|
||||
(x, y, z, fluidId, fluidLevel) -> fluidChanges.add(
|
||||
new PrototypePlayerBuilderToolSettings.FluidChange(x - anchorX, y - anchorY, z - anchorZ, fluidId, fluidLevel)
|
||||
)
|
||||
);
|
||||
prototypeSettings.setFluidChangesForPlaySelectionToolPasteMode(fluidChanges.toArray(PrototypePlayerBuilderToolSettings.FluidChange[]::new));
|
||||
ArrayList<PrototypePlayerBuilderToolSettings.EntityChange> entityChanges = new ArrayList<>();
|
||||
int selectionX = selection.getX();
|
||||
int selectionY = selection.getY();
|
||||
int selectionZ = selection.getZ();
|
||||
selection.forEachEntity(
|
||||
holder -> {
|
||||
BlockSelection selection = s.getSelection();
|
||||
BlockChange[] blocksChange = selection.toPacket().blocksChange;
|
||||
prototypeSettings.setBlockChangesForPlaySelectionToolPasteMode(blocksChange);
|
||||
ArrayList<PrototypePlayerBuilderToolSettings.FluidChange> fluidChanges = new ArrayList<>();
|
||||
int anchorX = selection.getAnchorX();
|
||||
int anchorY = selection.getAnchorY();
|
||||
int anchorZ = selection.getAnchorZ();
|
||||
selection.forEachFluid(
|
||||
(x, y, z, fluidId, fluidLevel) -> fluidChanges.add(
|
||||
new PrototypePlayerBuilderToolSettings.FluidChange(x - anchorX, y - anchorY, z - anchorZ, fluidId, fluidLevel)
|
||||
)
|
||||
);
|
||||
prototypeSettings.setFluidChangesForPlaySelectionToolPasteMode(fluidChanges.toArray(PrototypePlayerBuilderToolSettings.FluidChange[]::new));
|
||||
ArrayList<PrototypePlayerBuilderToolSettings.EntityChange> entityChanges = new ArrayList<>();
|
||||
selection.forEachEntity(holder -> {
|
||||
TransformComponent transform = holder.getComponent(TransformComponent.getComponentType());
|
||||
if (transform != null && transform.getPosition() != null) {
|
||||
Vector3d pos = transform.getPosition();
|
||||
entityChanges.add(
|
||||
new PrototypePlayerBuilderToolSettings.EntityChange(
|
||||
pos.getX() + selectionX, pos.getY() + selectionY, pos.getZ() + selectionZ, holder.clone()
|
||||
)
|
||||
);
|
||||
entityChanges.add(new PrototypePlayerBuilderToolSettings.EntityChange(pos.x(), pos.y(), pos.z(), holder.clone()));
|
||||
}
|
||||
}
|
||||
);
|
||||
prototypeSettings.setEntityChangesForPlaySelectionToolPasteMode(entityChanges.toArray(PrototypePlayerBuilderToolSettings.EntityChange[]::new));
|
||||
prototypeSettings.setBlockChangeOffsetOrigin(new Vector3i(selection.getX(), selection.getY(), selection.getZ()));
|
||||
}
|
||||
|
||||
Vector3i blockChangeOffsetOrigin = prototypeSettings.getBlockChangeOffsetOrigin();
|
||||
if (packet.initialPastePointForClipboardPaste != null) {
|
||||
blockChangeOffsetOrigin = new Vector3i(
|
||||
packet.initialPastePointForClipboardPaste.x, packet.initialPastePointForClipboardPaste.y, packet.initialPastePointForClipboardPaste.z
|
||||
);
|
||||
}
|
||||
|
||||
if (blockChangeOffsetOrigin == null) {
|
||||
playerComponent.sendMessage(Message.translation("server.builderTools.selection.noBlockChangeOffsetOrigin"));
|
||||
} else {
|
||||
s.transformThenPasteClipboard(
|
||||
prototypeSettings.getBlockChangesForPlaySelectionToolPasteMode(),
|
||||
prototypeSettings.getFluidChangesForPlaySelectionToolPasteMode(),
|
||||
prototypeSettings.getEntityChangesForPlaySelectionToolPasteMode(),
|
||||
rotation,
|
||||
translationOffset,
|
||||
rotationOrigin,
|
||||
blockChangeOffsetOrigin,
|
||||
finalKeepEmptyBlocks,
|
||||
prototypeSettings,
|
||||
componentAccessor
|
||||
);
|
||||
s.select(initialSelectionMin, initialSelectionMax, "server.builderTools.selectReasons.selectionTranslatePacket", componentAccessor);
|
||||
s.transformSelectionPoints(rotation, translationOffset, rotationOrigin);
|
||||
if (large) {
|
||||
playerComponent.sendMessage(Message.translation("server.builderTools.selection.large.complete"));
|
||||
});
|
||||
prototypeSettings.setEntityChangesForPlaySelectionToolPasteMode(
|
||||
entityChanges.toArray(PrototypePlayerBuilderToolSettings.EntityChange[]::new)
|
||||
);
|
||||
prototypeSettings.setBlockChangeOffsetOrigin(new Vector3i(selection.getX(), selection.getY(), selection.getZ()));
|
||||
}
|
||||
|
||||
BlockChange[] localBlockChanges = prototypeSettings.getBlockChangesForPlaySelectionToolPasteMode();
|
||||
PrototypePlayerBuilderToolSettings.FluidChange[] localFluidChanges = prototypeSettings.getFluidChangesForPlaySelectionToolPasteMode();
|
||||
PrototypePlayerBuilderToolSettings.EntityChange[] localEntityChanges = prototypeSettings.getEntityChangesForPlaySelectionToolPasteMode();
|
||||
Vector3i blockChangeOffsetOrigin = prototypeSettings.getBlockChangeOffsetOrigin();
|
||||
if (packet.initialPastePointForClipboardPaste != null) {
|
||||
blockChangeOffsetOrigin = new Vector3i(
|
||||
packet.initialPastePointForClipboardPaste.x, packet.initialPastePointForClipboardPaste.y, packet.initialPastePointForClipboardPaste.z
|
||||
);
|
||||
}
|
||||
|
||||
if (blockChangeOffsetOrigin != null) {
|
||||
prototypeSettings.setLastTransformEntityRefs(null);
|
||||
s.transformThenPasteClipboard(
|
||||
localBlockChanges,
|
||||
localFluidChanges,
|
||||
localEntityChanges,
|
||||
rotation,
|
||||
translationOffset,
|
||||
rotationOrigin,
|
||||
blockChangeOffsetOrigin,
|
||||
finalKeepEmptyBlocks,
|
||||
prototypeSettings,
|
||||
componentAccessor
|
||||
);
|
||||
s.select(initialSelectionMin, initialSelectionMax, "server.builderTools.selectReasons.selectionTranslatePacket", componentAccessor);
|
||||
s.transformSelectionPoints(rotation, translationOffset, rotationOrigin);
|
||||
if (!packet.isExitingTransformMode) {
|
||||
prototypeSettings.setBlockChangeOffsetOrigin(
|
||||
new Vector3i(
|
||||
blockChangeOffsetOrigin.x + translationOffset.x,
|
||||
blockChangeOffsetOrigin.y + translationOffset.y,
|
||||
blockChangeOffsetOrigin.z + translationOffset.z
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (large) {
|
||||
playerRef.sendMessage(Message.translation("server.builderTools.selection.large.complete"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
playerRef.sendMessage(Message.translation("server.builderTools.selection.noBlockChangeOffsetOrigin"));
|
||||
} catch (Exception var27) {
|
||||
LOGGER.at(Level.WARNING).log("Error during selection transform", var27);
|
||||
return;
|
||||
} finally {
|
||||
if (packet.isExitingTransformMode) {
|
||||
prototypeSettings.setInSelectionTransformationMode(false);
|
||||
prototypeSettings.setLastTransformEntityRefs(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -619,7 +648,27 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
? Axis.X
|
||||
: (packet.axis == com.hypixel.hytale.protocol.packets.buildertools.Axis.Y ? Axis.Y : Axis.Z);
|
||||
LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet);
|
||||
BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.rotate(r, axis, packet.angle, componentAccessor));
|
||||
BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> {
|
||||
s.setSkipNextPreviewRebuild(true);
|
||||
s.rotate(r, axis, packet.angle, componentAccessor);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void handleBuilderToolResetClipboardRotation(
|
||||
@Nonnull BuilderToolResetClipboardRotation packet,
|
||||
@Nonnull PlayerRef playerRef,
|
||||
@Nonnull Ref<EntityStore> ref,
|
||||
@Nonnull World world,
|
||||
@Nonnull Store<EntityStore> store
|
||||
) {
|
||||
Player playerComponent = store.getComponent(ref, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet);
|
||||
BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> {
|
||||
s.setSkipNextPreviewRebuild(true);
|
||||
s.resetClipboardRotation(r, componentAccessor);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,7 +698,6 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
BuilderTool builderTool = BuilderTool.getActiveBuilderTool(playerComponent);
|
||||
if (builderTool != null && builderTool.getId().equals("Line")) {
|
||||
BuilderTool.ArgData args = builderTool.getItemArgData(playerComponent.getInventory().getItemInHand());
|
||||
BrushData.Values brushData = args.brush();
|
||||
Map<String, Object> tool = args.tool();
|
||||
if (tool != null) {
|
||||
int lineWidth = (Integer)tool.get("bLineWidth");
|
||||
@@ -679,7 +727,7 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
lineOrigin,
|
||||
lineSpacing,
|
||||
lineDensity,
|
||||
ToolOperation.combineMasks(brushData, s.getGlobalMask()),
|
||||
ToolOperation.combineMasks(args, s.getGlobalMask()),
|
||||
componentAccessor
|
||||
)
|
||||
);
|
||||
@@ -720,17 +768,16 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
boolean hasLookOrientation = modelTransform.lookOrientation != null;
|
||||
boolean hasBodyOrientation = modelTransform.bodyOrientation != null;
|
||||
if (hasPosition) {
|
||||
transformComponent.getPosition().assign(modelTransform.position.x, modelTransform.position.y, modelTransform.position.z);
|
||||
transformComponent.getPosition().set(modelTransform.position.x, modelTransform.position.y, modelTransform.position.z);
|
||||
}
|
||||
|
||||
if (hasLookOrientation && headRotation != null) {
|
||||
headRotation.getRotation()
|
||||
.assign(modelTransform.lookOrientation.pitch, modelTransform.lookOrientation.yaw, modelTransform.lookOrientation.roll);
|
||||
headRotation.getRotation().set(modelTransform.lookOrientation.pitch, modelTransform.lookOrientation.yaw, modelTransform.lookOrientation.roll);
|
||||
}
|
||||
|
||||
if (hasBodyOrientation) {
|
||||
transformComponent.getRotation()
|
||||
.assign(modelTransform.bodyOrientation.pitch, modelTransform.bodyOrientation.yaw, modelTransform.bodyOrientation.roll);
|
||||
.set(modelTransform.bodyOrientation.pitch, modelTransform.bodyOrientation.yaw, modelTransform.bodyOrientation.roll);
|
||||
}
|
||||
|
||||
if (hasPosition || hasLookOrientation || hasBodyOrientation) {
|
||||
@@ -748,20 +795,46 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
@Nonnull World world,
|
||||
@Nonnull Store<EntityStore> store
|
||||
) {
|
||||
Player playerComponent = store.getComponent(ref, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet);
|
||||
PrefabEditSessionManager prefabEditSessionManager = BuilderToolsPlugin.get().getPrefabEditSessionManager();
|
||||
PrefabEditSession prefabEditSession = prefabEditSessionManager.getPrefabEditSession(playerRef.getUuid());
|
||||
if (prefabEditSession == null) {
|
||||
playerComponent.sendMessage(Message.translation("server.commands.editprefab.notInEditSession"));
|
||||
LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet);
|
||||
PrefabEditSessionManager prefabEditSessionManager = BuilderToolsPlugin.get().getPrefabEditSessionManager();
|
||||
PrefabEditSession prefabEditSession = prefabEditSessionManager.getPrefabEditSession(playerRef.getUuid());
|
||||
if (prefabEditSession == null) {
|
||||
playerRef.sendMessage(Message.translation("server.commands.editprefab.notInEditSession"));
|
||||
} else {
|
||||
if (prefabEditSession.clearSelectedPrefab(ref, store)) {
|
||||
playerRef.sendMessage(Message.translation("server.commands.editprefab.unselected"));
|
||||
} else {
|
||||
if (prefabEditSession.clearSelectedPrefab(ref, store)) {
|
||||
playerComponent.sendMessage(Message.translation("server.commands.editprefab.unselected"));
|
||||
} else {
|
||||
playerComponent.sendMessage(Message.translation("server.commands.editprefab.noPrefabSelected"));
|
||||
playerRef.sendMessage(Message.translation("server.commands.editprefab.noPrefabSelected"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handlePrefabSetAnchor(
|
||||
@Nonnull PrefabSetAnchor packet, @Nonnull PlayerRef playerRef, @Nonnull Ref<EntityStore> ref, @Nonnull World world, @Nonnull Store<EntityStore> store
|
||||
) {
|
||||
LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet);
|
||||
PrefabEditSessionManager prefabEditSessionManager = BuilderToolsPlugin.get().getPrefabEditSessionManager();
|
||||
PrefabEditSession prefabEditSession = prefabEditSessionManager.getPrefabEditSession(playerRef.getUuid());
|
||||
if (prefabEditSession == null) {
|
||||
playerRef.sendMessage(Message.translation("server.commands.editprefab.notInEditSession"));
|
||||
} else {
|
||||
PrefabEditingMetadata prefabEditingMetadata = null;
|
||||
Vector3i targetBlockPos = new Vector3i(packet.x, packet.y, packet.z);
|
||||
|
||||
for (PrefabEditingMetadata value : prefabEditSession.getLoadedPrefabMetadata().values()) {
|
||||
boolean isWithinPrefab = value.isLocationWithinPrefabBoundingBox(new Vector3i(packet.x, packet.y, packet.z));
|
||||
if (isWithinPrefab) {
|
||||
prefabEditingMetadata = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (prefabEditingMetadata == null) {
|
||||
playerRef.sendMessage(Message.translation("server.commands.editprefab.select.error.noPrefabFound"));
|
||||
} else {
|
||||
prefabEditingMetadata.setAnchorPoint(targetBlockPos, world);
|
||||
prefabEditingMetadata.sendAnchorHighlightingPacket(playerRef.getPacketHandler());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,15 +847,12 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
) {
|
||||
Ref<EntityStore> targetRef = world.getEntityStore().getRefFromNetworkId(packet.entityId);
|
||||
if (targetRef != null && targetRef.isValid()) {
|
||||
PropComponent propComponent = store.getComponent(targetRef, PropComponent.getComponentType());
|
||||
if (propComponent != null) {
|
||||
EntityScaleComponent scaleComponent = store.getComponent(targetRef, EntityScaleComponent.getComponentType());
|
||||
if (scaleComponent == null) {
|
||||
scaleComponent = new EntityScaleComponent(packet.scale);
|
||||
store.addComponent(targetRef, EntityScaleComponent.getComponentType(), scaleComponent);
|
||||
} else {
|
||||
scaleComponent.setScale(packet.scale);
|
||||
}
|
||||
EntityScaleComponent scaleComponent = store.getComponent(targetRef, EntityScaleComponent.getComponentType());
|
||||
if (scaleComponent == null) {
|
||||
scaleComponent = new EntityScaleComponent(packet.scale);
|
||||
store.addComponent(targetRef, EntityScaleComponent.getComponentType(), scaleComponent);
|
||||
} else {
|
||||
scaleComponent.setScale(packet.scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -854,18 +924,15 @@ public class BuilderToolsPacketHandler implements SubPacketHandler {
|
||||
@Nonnull World world,
|
||||
@Nonnull Store<EntityStore> store
|
||||
) {
|
||||
Player playerComponent = store.getComponent(ref, Player.getComponentType());
|
||||
if (playerComponent != null) {
|
||||
Ref<EntityStore> targetRef = world.getEntityStore().getRefFromNetworkId(packet.entityId);
|
||||
if (targetRef != null && targetRef.isValid()) {
|
||||
NPCMarkerComponent npcMarkerComponent = store.getComponent(targetRef, NPCMarkerComponent.getComponentType());
|
||||
if (npcMarkerComponent != null) {
|
||||
UUIDComponent uuidComponent = store.getComponent(targetRef, UUIDComponent.getComponentType());
|
||||
if (uuidComponent != null) {
|
||||
UUID uuid = uuidComponent.getUuid();
|
||||
String command = packet.enabled ? "npc debug set display --entity " + uuid : "npc debug clear --entity " + uuid;
|
||||
CommandManager.get().handleCommand(playerComponent, command);
|
||||
}
|
||||
Ref<EntityStore> targetRef = world.getEntityStore().getRefFromNetworkId(packet.entityId);
|
||||
if (targetRef != null && targetRef.isValid()) {
|
||||
NPCMarkerComponent npcMarkerComponent = store.getComponent(targetRef, NPCMarkerComponent.getComponentType());
|
||||
if (npcMarkerComponent != null) {
|
||||
UUIDComponent uuidComponent = store.getComponent(targetRef, UUIDComponent.getComponentType());
|
||||
if (uuidComponent != null) {
|
||||
UUID uuid = uuidComponent.getUuid();
|
||||
String command = packet.enabled ? "npc debug set display --entity " + uuid : "npc debug clear --entity " + uuid;
|
||||
CommandManager.get().handleCommand(playerRef, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,9 @@ import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.component.Holder;
|
||||
import com.hypixel.hytale.component.RemoveReason;
|
||||
import com.hypixel.hytale.component.Store;
|
||||
import com.hypixel.hytale.component.dependency.Dependency;
|
||||
import com.hypixel.hytale.component.dependency.Order;
|
||||
import com.hypixel.hytale.component.dependency.SystemDependency;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.HolderSystem;
|
||||
import com.hypixel.hytale.server.core.asset.type.item.config.BuilderToolItemReferenceAsset;
|
||||
@@ -12,16 +15,19 @@ import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.inventory.Inventory;
|
||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||
import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
|
||||
import com.hypixel.hytale.server.core.modules.entity.player.PlayerSystems;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderToolsSystems {
|
||||
public static class EnsureBuilderTools extends HolderSystem<EntityStore> {
|
||||
@Nonnull
|
||||
private static final ComponentType<EntityStore, Player> PLAYER_COMPONENT_TYPE = Player.getComponentType();
|
||||
private final Set<Dependency<EntityStore>> dependencies = Set.of(new SystemDependency<>(Order.AFTER, PlayerSystems.PlayerInitSystem.class));
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@@ -57,5 +63,11 @@ public class BuilderToolsSystems {
|
||||
@Override
|
||||
public void onEntityRemoved(@Nonnull Holder<EntityStore> holder, @Nonnull RemoveReason reason, @Nonnull Store<EntityStore> store) {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Dependency<EntityStore>> getDependencies() {
|
||||
return this.dependencies;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user