This commit is contained in:
1 parent
e0db794528
commit
15d66f5ac8
4 files changed
+139
-65
No files matched your search
@@ -0,0 +1,7 @@
|
||||
package dev.hytalemodding;
|
||||
|
||||
public enum RitualSetupState {
|
||||
INCOMPLETE,
|
||||
COMPLETE,
|
||||
CHANGED
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.npc.NPCPlugin;
|
||||
import dev.hytalemodding.definitions.RitualDefinitions;
|
||||
import dev.hytalemodding.definitions.RitualPattern;
|
||||
import dev.hytalemodding.definitions.RitualSacrifice;
|
||||
import dev.hytalemodding.definitions.RitualTypes;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
@@ -29,8 +30,8 @@ public class RitualSpawner {
|
||||
RitualPlugin.LOGGER.atInfo().log(
|
||||
"a block got %s at the position: %d, %d, %d with the block id: %s",
|
||||
placedRemovedString, targetPosition.x, targetPosition.y, targetPosition.z, blockId);
|
||||
// RitualTypes ritualType = checkPatterns(ritualDefinitions.containsCenterBlock(blockId), targetPosition, world);
|
||||
RitualTypes ritualType = getRitualTypeFromBlock(blockId, targetPosition, world);
|
||||
Vector3i ritualCenter = new Vector3i(targetPosition);
|
||||
RitualTypes ritualType = getRitualTypeFromBlock(blockId, ritualCenter, world, true);
|
||||
if(!ritualType.equals(RitualTypes.NONE)) {
|
||||
RitualPlugin.LOGGER.atInfo().log(
|
||||
"a ritual pattern got completed"
|
||||
@@ -44,70 +45,45 @@ public class RitualSpawner {
|
||||
int soundIndex = SoundEvent.getAssetMap().getIndex(soundId);
|
||||
world.execute(() -> {
|
||||
// Play sound
|
||||
SoundUtil.playSoundEvent3d(soundIndex, SoundCategory.SFX, blockToEntityPos(targetPosition), world.getEntityStore().getStore());
|
||||
SoundUtil.playSoundEvent3d(soundIndex, SoundCategory.SFX, blockToEntityPos(ritualCenter), world.getEntityStore().getStore());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void sacrificeDropEvent(String itemId, Vector3d targetPosition, World world) {
|
||||
Vector3i blockPosition = entityToBlockPos(targetPosition);
|
||||
RitualPlugin.LOGGER.atInfo().log(
|
||||
/*RitualPlugin.LOGGER.atInfo().log(
|
||||
"an item got thrown at the position: %f, %f, %f with the item id: %s",
|
||||
targetPosition.x, targetPosition.y, targetPosition.z, itemId);*/
|
||||
RitualPlugin.LOGGER.atInfo().log(
|
||||
"an item got thrown at the position: %d, %d, %d with the item id: %s",
|
||||
blockPosition.x, blockPosition.y, blockPosition.z, itemId);
|
||||
RitualTypes ritualType = getRitualTypeFromSacrifice(blockPosition, world);
|
||||
RitualTypes ritualType = getRitualTypeFromSacrifice(itemId, blockPosition, world);
|
||||
if (!ritualType.equals(RitualTypes.NONE)) {
|
||||
if (ritualType.equals(RitualTypes.SKELETON)) {
|
||||
RitualPlugin.LOGGER.atInfo().log("Ritual complete");
|
||||
world.execute(() -> {
|
||||
NPCPlugin.get().spawnNPC(world.getEntityStore().getStore(), "Skeleton", null, targetPosition, new Rotation3f(0, 0, 0));
|
||||
NPCPlugin.get().spawnNPC(world.getEntityStore().getStore(), "Skeleton", null, blockToEntityPos(blockPosition), new Rotation3f(0, 0, 0));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RitualTypes getRitualTypeFromSacrifice(Vector3i centerPosition, World world) {
|
||||
int radius = 1;
|
||||
RitualTypes getRitualTypeFromSacrifice(String itemId, Vector3i centerPosition, World world) {
|
||||
List<Integer> possibleSetups = getFullRitualSetupRange();
|
||||
checkSacrificePalette(possibleSetups, itemId);
|
||||
int radius = getMaxSacrificeRadius(possibleSetups);
|
||||
for (int ix = centerPosition.x - radius; ix <= centerPosition.x + radius; ix++) {
|
||||
for (int iy = centerPosition.y - radius; iy <= centerPosition.y + radius; iy++) {
|
||||
for (int iz = centerPosition.z - radius; iz <= centerPosition.z + radius; iz++) {
|
||||
Vector3i samplePosition = new Vector3i(ix, iy, iz);
|
||||
String blockId = getBlockId(samplePosition, world);
|
||||
List<Integer> possibleSetups = getFullRitualSetupRange();
|
||||
possibleSetups = checkCenterBlock(possibleSetups, blockId);
|
||||
if (!possibleSetups.isEmpty()) {
|
||||
possibleSetups = checkPatterns(possibleSetups, samplePosition, world, samplePosition, "Empty");
|
||||
if (!possibleSetups.isEmpty()) {
|
||||
return ritualDefinitions.getRitualType(possibleSetups.getFirst());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return RitualTypes.NONE;
|
||||
}
|
||||
|
||||
RitualTypes getRitualTypeFromBlock(String blockId, Vector3i blockPosition, World world) {
|
||||
List<Integer> fullSetupRange = getFullRitualSetupRange();
|
||||
List<Integer> possibleSetups = checkCenterBlock(new ArrayList<>(fullSetupRange), blockId);
|
||||
if (!possibleSetups.isEmpty()) {
|
||||
possibleSetups = checkPatterns(possibleSetups, blockPosition, world, blockPosition, "Empty");
|
||||
if (!possibleSetups.isEmpty()) {
|
||||
return ritualDefinitions.getRitualType(possibleSetups.getFirst());
|
||||
}
|
||||
}
|
||||
possibleSetups = checkPatternPalette(new ArrayList<>(fullSetupRange), blockId);
|
||||
if (possibleSetups.size() <= 0) {
|
||||
return RitualTypes.NONE;
|
||||
}
|
||||
int radius = getMaxRadius(possibleSetups);
|
||||
for (int ix = blockPosition.x - radius; ix <= blockPosition.x + radius; ix++) {
|
||||
for (int iy = blockPosition.y - radius; iy <= blockPosition.y + radius; iy++) {
|
||||
for (int iz = blockPosition.z - radius; iz <= blockPosition.z + radius; iz++) {
|
||||
Vector3i samplePosition = new Vector3i(ix, iy, iz);
|
||||
List<Integer> setupsAtPosition = checkCenterBlock(new ArrayList<>(possibleSetups), getBlockId(samplePosition, world));
|
||||
List<Integer> setupsAtPosition = new ArrayList<>(possibleSetups);
|
||||
checkCenterBlock(setupsAtPosition, blockId);
|
||||
if (!setupsAtPosition.isEmpty()) {
|
||||
setupsAtPosition = checkPatterns(setupsAtPosition, samplePosition, world, blockPosition, blockId);
|
||||
checkPatterns(setupsAtPosition, samplePosition, world, samplePosition, "Empty");
|
||||
if (!setupsAtPosition.isEmpty()) {
|
||||
centerPosition.set(samplePosition);
|
||||
return ritualDefinitions.getRitualType(setupsAtPosition.getFirst());
|
||||
}
|
||||
}
|
||||
@@ -117,66 +93,136 @@ public class RitualSpawner {
|
||||
return RitualTypes.NONE;
|
||||
}
|
||||
|
||||
List<Integer> checkCenterBlock(List<Integer> ritualSetups, String blockId) {
|
||||
ritualSetups.removeIf(ritualSetup -> !ritualDefinitions.getCenterBlockId(ritualSetup).equals(blockId));
|
||||
return ritualSetups;
|
||||
RitualTypes getRitualTypeFromBlock(String blockId, Vector3i blockPosition, World world, boolean onlyShowChanges) {
|
||||
List<Integer> possibleSetups = getFullRitualSetupRange();
|
||||
checkCenterBlock(possibleSetups, blockId);
|
||||
if (!possibleSetups.isEmpty()) {
|
||||
checkPatterns(possibleSetups, blockPosition, world, blockPosition, blockId);
|
||||
if (!possibleSetups.isEmpty()) {
|
||||
return ritualDefinitions.getRitualType(possibleSetups.getFirst());
|
||||
}
|
||||
}
|
||||
possibleSetups = getFullRitualSetupRange();
|
||||
checkPatternPalette(possibleSetups, blockId);
|
||||
if (possibleSetups.size() <= 0) {
|
||||
return RitualTypes.NONE;
|
||||
}
|
||||
int radius = getMaxPatternRadius(possibleSetups);
|
||||
for (int ix = blockPosition.x - radius; ix <= blockPosition.x + radius; ix++) {
|
||||
for (int iy = blockPosition.y - radius; iy <= blockPosition.y + radius; iy++) {
|
||||
for (int iz = blockPosition.z - radius; iz <= blockPosition.z + radius; iz++) {
|
||||
Vector3i samplePosition = new Vector3i(ix, iy, iz);
|
||||
List<Integer> setupsAtPosition = new ArrayList<>(possibleSetups);
|
||||
checkCenterBlock(setupsAtPosition, getBlockId(samplePosition, world));
|
||||
if (!setupsAtPosition.isEmpty()) {
|
||||
boolean didChange = checkPatterns(setupsAtPosition, samplePosition, world, blockPosition, blockId);
|
||||
// one setup needs to be valid and either a change happened or no changes are required
|
||||
if (!setupsAtPosition.isEmpty() && (didChange || !onlyShowChanges)) {
|
||||
blockPosition.set(samplePosition);
|
||||
return ritualDefinitions.getRitualType(setupsAtPosition.getFirst());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return RitualTypes.NONE;
|
||||
}
|
||||
|
||||
List<Integer> checkPatternPalette(List<Integer> ritualSetups, String blockId) {
|
||||
void checkCenterBlock(List<Integer> ritualSetups, String blockId) {
|
||||
ritualSetups.removeIf(ritualSetup -> !ritualDefinitions.getCenterBlockId(ritualSetup).equals(blockId));
|
||||
}
|
||||
|
||||
void checkPatternPalette(List<Integer> ritualSetups, String blockId) {
|
||||
List<Integer> possibleSetups = new ArrayList<>(ritualSetups);
|
||||
for (Integer ritualSetup : ritualSetups) {
|
||||
for (Integer possibleSetup : possibleSetups) {
|
||||
boolean isPossibleSetup = false;
|
||||
List<RitualPattern> ritualPatterns = ritualDefinitions.getPatterns(ritualSetup);
|
||||
List<RitualPattern> ritualPatterns = ritualDefinitions.getPatterns(possibleSetup);
|
||||
for (RitualPattern ritualPattern : ritualPatterns) {
|
||||
if (ritualPattern.blockId().equals(blockId)){
|
||||
if (ritualPattern.blockId().equals(blockId)) {
|
||||
isPossibleSetup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isPossibleSetup) {
|
||||
possibleSetups.remove(ritualSetup);
|
||||
ritualSetups.remove(possibleSetup);
|
||||
}
|
||||
}
|
||||
return possibleSetups;
|
||||
}
|
||||
|
||||
List<Integer> checkPatterns(List<Integer> ritualSetups, Vector3i centerPosition, World world, Vector3i placedBlockPosition, String placedBlockId) {
|
||||
void checkSacrificePalette(List<Integer> ritualSetups, String itemId) {
|
||||
List<Integer> possibleSetups = new ArrayList<>(ritualSetups);
|
||||
for (Integer ritualSetup : ritualSetups) {
|
||||
List<RitualPattern> ritualPatterns = ritualDefinitions.getPatterns(ritualSetup);
|
||||
//RitualPlugin.LOGGER.atInfo().log("ritualPatterns size in checkPatterns() is %d", ritualPatterns.size());
|
||||
for (RitualPattern ritualPattern : ritualPatterns) {
|
||||
if(!checkPattern(ritualPattern, centerPosition, world, placedBlockPosition, placedBlockId)) {
|
||||
possibleSetups.remove(ritualSetup);
|
||||
for (Integer possibleSetup : possibleSetups) {
|
||||
boolean isPossibleSetup = false;
|
||||
List<RitualSacrifice> ritualSacrifices = ritualDefinitions.getSacrifices(possibleSetup);
|
||||
for (RitualSacrifice ritualSacrifice : ritualSacrifices) {
|
||||
if (ritualSacrifice.itemId().equals(itemId)) {
|
||||
isPossibleSetup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isPossibleSetup) {
|
||||
ritualSetups.remove(possibleSetup);
|
||||
}
|
||||
}
|
||||
return possibleSetups;
|
||||
}
|
||||
|
||||
boolean checkPattern(RitualPattern ritualPattern, Vector3i centerPosition, World world, Vector3i placedBlockPosition, String placedBlockId) {
|
||||
boolean checkPatterns(List<Integer> ritualSetups, Vector3i centerPosition, World world, Vector3i placedBlockPosition, String placedBlockId) {
|
||||
List<Integer> possibleSetups = new ArrayList<>(ritualSetups);
|
||||
boolean didChange = false;
|
||||
for (Integer possibleSetup : possibleSetups) {
|
||||
List<RitualPattern> ritualPatterns = ritualDefinitions.getPatterns(possibleSetup);
|
||||
boolean didChangeThisSetup = false;
|
||||
for (RitualPattern ritualPattern : ritualPatterns) {
|
||||
RitualSetupState state = checkPattern(ritualPattern, centerPosition, world, placedBlockPosition, placedBlockId);
|
||||
if(state.equals(RitualSetupState.INCOMPLETE)) {
|
||||
ritualSetups.remove(possibleSetup);
|
||||
didChangeThisSetup = false;
|
||||
break;
|
||||
} else if (state.equals(RitualSetupState.CHANGED)) {
|
||||
didChangeThisSetup = true;
|
||||
}
|
||||
}
|
||||
didChange |= didChangeThisSetup;
|
||||
}
|
||||
return didChange;
|
||||
}
|
||||
|
||||
RitualSetupState checkPattern(RitualPattern ritualPattern, Vector3i centerPosition, World world, Vector3i placedBlockPosition, String placedBlockId) {
|
||||
int countMatches = 0;
|
||||
int radius = ritualPattern.radius();
|
||||
boolean validBlockChanged = false;
|
||||
for (int ix = centerPosition.x - radius; ix <= centerPosition.x + radius; ix++) {
|
||||
for (int iy = centerPosition.y - radius; iy <= centerPosition.y + radius; iy++) {
|
||||
for (int iz = centerPosition.z - radius; iz <= centerPosition.z + radius; iz++) {
|
||||
Vector3i samplePosition = new Vector3i(ix, iy, iz);
|
||||
String blockId;
|
||||
boolean blockChanged;
|
||||
if (samplePosition.equals(placedBlockPosition)) {
|
||||
blockId = placedBlockId;
|
||||
blockChanged = true;
|
||||
} else {
|
||||
blockId = getBlockId(samplePosition, world);
|
||||
blockChanged = false;
|
||||
}
|
||||
if (blockId.equals(ritualPattern.blockId())) {
|
||||
countMatches++;
|
||||
validBlockChanged |= blockChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return countMatches >= ritualPattern.amount();
|
||||
// the pattern now just has enough or not enough matching blocks
|
||||
if (countMatches == ritualPattern.amount() && validBlockChanged) {
|
||||
return RitualSetupState.CHANGED;
|
||||
// the pattern state stayed the same
|
||||
} else if (countMatches >= ritualPattern.amount()) {
|
||||
return RitualSetupState.COMPLETE;
|
||||
} else {
|
||||
return RitualSetupState.INCOMPLETE;
|
||||
}
|
||||
}
|
||||
|
||||
int getMaxRadius(List<Integer> ritualSetups) {
|
||||
int getMaxPatternRadius(List<Integer> ritualSetups) {
|
||||
int maxRadius = 0;
|
||||
for (Integer ritualSetup : ritualSetups) {
|
||||
List<RitualPattern> ritualPatterns = ritualDefinitions.getPatterns(ritualSetup);
|
||||
@@ -189,6 +235,19 @@ public class RitualSpawner {
|
||||
return maxRadius;
|
||||
}
|
||||
|
||||
int getMaxSacrificeRadius(List<Integer> ritualSetups) {
|
||||
int maxRadius = 0;
|
||||
for (Integer ritualSetup : ritualSetups) {
|
||||
List<RitualSacrifice> ritualSacrifices = ritualDefinitions.getSacrifices(ritualSetup);
|
||||
for (RitualSacrifice ritualSacrifice : ritualSacrifices) {
|
||||
if (maxRadius < ritualSacrifice.radius()) {
|
||||
maxRadius = ritualSacrifice.radius();
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxRadius;
|
||||
}
|
||||
|
||||
List<Integer> getFullRitualSetupRange() {
|
||||
List<Integer> possibleSetups = new ArrayList<>();
|
||||
for (int i = 0; i < ritualDefinitions.getRitualSetupsCount(); i++) {
|
||||
@@ -211,6 +270,6 @@ public class RitualSpawner {
|
||||
}
|
||||
|
||||
Vector3i entityToBlockPos(Vector3d entityPosition) {
|
||||
return new Vector3i(entityPosition, 0);
|
||||
return new Vector3i(entityPosition.sub(0.5, 1, 0.5), 3);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public class RitualDefinitions {
|
||||
public RitualDefinitions() {
|
||||
// Crude skeleton ritual
|
||||
ritualSetups.add(new RitualSetup("Deco_Bone_Skulls", RitualTypes.SKELETON)
|
||||
.addPatern("Furniture_Crude_Torch", 2, 4, false, true)
|
||||
.addPattern("Furniture_Crude_Torch", 2, 4, false, true)
|
||||
.addSacrifice("Ingredient_Life_Essence", 1, 1, true));
|
||||
}
|
||||
|
||||
@@ -29,6 +29,10 @@ public class RitualDefinitions {
|
||||
return ritualSetups.get(setupIndex).getPatterns();
|
||||
}
|
||||
|
||||
public List<RitualSacrifice> getSacrifices(int setupIndex) {
|
||||
return ritualSetups.get(setupIndex).getSacrifices();
|
||||
}
|
||||
|
||||
public RitualSacrifice getSacrificeItemId(int setupIndex, int sacrificeIndex) {
|
||||
return ritualSetups.get(setupIndex).getSacrificeItemId(sacrificeIndex);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class RitualSetup {
|
||||
this.centerBlockId = centerBlockId;
|
||||
}
|
||||
|
||||
public RitualSetup addPatern(String blockId, int radius, int amount, boolean shouldConsume, boolean shouldInteract) {
|
||||
public RitualSetup addPattern(String blockId, int radius, int amount, boolean shouldConsume, boolean shouldInteract) {
|
||||
patterns.add(new RitualPattern(blockId, radius, amount, shouldConsume, shouldInteract));
|
||||
return this;
|
||||
}
|
||||
@@ -40,6 +40,10 @@ public class RitualSetup {
|
||||
return patterns;
|
||||
}
|
||||
|
||||
public List<RitualSacrifice> getSacrifices() {
|
||||
return sacrifices;
|
||||
}
|
||||
|
||||
public RitualSacrifice getSacrificeItemId(int index) {
|
||||
return sacrifices.get(index);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user