Browse Source

Start of dungeon algorithm

pull/275/head
kingbdogz 10 months ago
parent
commit
f9aa316645
12 changed files with 299 additions and 3 deletions
  1. +3
    -2
      build.gradle
  2. +1
    -1
      lib/orbis-lib
  3. +4
    -0
      src/main/java/com/gildedgames/aether/common/CommonProxy.java
  4. +18
    -0
      src/main/java/com/gildedgames/aether/common/dungeons/Dungeon.java
  5. +8
    -0
      src/main/java/com/gildedgames/aether/common/dungeons/DungeonGenStep.java
  6. +77
    -0
      src/main/java/com/gildedgames/aether/common/dungeons/DungeonGenerator.java
  7. +45
    -0
      src/main/java/com/gildedgames/aether/common/dungeons/DungeonViewer.java
  8. +84
    -0
      src/main/java/com/gildedgames/aether/common/dungeons/GuiDungeonViewer.java
  9. +9
    -0
      src/main/java/com/gildedgames/aether/common/dungeons/IDungeon.java
  10. +13
    -0
      src/main/java/com/gildedgames/aether/common/dungeons/IDungeonDefinition.java
  11. +9
    -0
      src/main/java/com/gildedgames/aether/common/dungeons/IDungeonGenerator.java
  12. +28
    -0
      src/main/java/com/gildedgames/aether/common/dungeons/InfectedTreeDungeonDefinition.java

+ 3
- 2
build.gradle View File

@@ -58,6 +58,9 @@ sourceSets {
api {
java { srcDir "src/api/java" }
}
test {
java { srcDir "src/test/java" }
}
}

jar {
@@ -105,14 +108,12 @@ processResources {

from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
exclude 'assets/**'

expand 'version': project.version, 'mcversion': project.minecraft.version
}

from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
exclude 'assets/**'
}
}



+ 1
- 1
lib/orbis-lib

@@ -1 +1 @@
Subproject commit 20ea91eb142eec7b4f4813f7ad5fc9c6265f0cab
Subproject commit ecf4564c7979bf66b8e3c5db44a0a37e722486a3

+ 4
- 0
src/main/java/com/gildedgames/aether/common/CommonProxy.java View File

@@ -3,6 +3,7 @@ package com.gildedgames.aether.common;
import com.gildedgames.aether.api.AetherAPI;
import com.gildedgames.aether.api.IAetherServices;
import com.gildedgames.aether.api.net.IGildedGamesAccountApi;
import com.gildedgames.aether.common.dungeons.DungeonViewer;
import com.gildedgames.aether.common.events.PostAetherTravelEvent;
import com.gildedgames.aether.common.network.api.GildedGamesAccountApiImpl;
import com.gildedgames.aether.common.shop.*;
@@ -91,6 +92,9 @@ public class CommonProxy implements IAetherServices
public void postInit(final FMLPostInitializationEvent event)
{
this.content().postInit();

DungeonViewer viewer = new DungeonViewer();
MinecraftForge.EVENT_BUS.register(viewer);
}

public void onServerAboutToStart(final FMLServerAboutToStartEvent event)


+ 18
- 0
src/main/java/com/gildedgames/aether/common/dungeons/Dungeon.java View File

@@ -0,0 +1,18 @@
package com.gildedgames.aether.common.dungeons;

import com.gildedgames.orbis.lib.core.world_objects.BlueprintRegion;

import java.util.List;

public class Dungeon implements IDungeon {
private List<BlueprintRegion> rooms;

public Dungeon(List<BlueprintRegion> rooms) {
this.rooms = rooms;
}

@Override
public List<BlueprintRegion> rooms() {
return this.rooms;
}
}

+ 8
- 0
src/main/java/com/gildedgames/aether/common/dungeons/DungeonGenStep.java View File

@@ -0,0 +1,8 @@
package com.gildedgames.aether.common.dungeons;

public enum DungeonGenStep {
PUSH_ROOMS_APART,
SELECT_HUBS,
FIND_PATHWAYS,
FINISH,
}

+ 77
- 0
src/main/java/com/gildedgames/aether/common/dungeons/DungeonGenerator.java View File

@@ -0,0 +1,77 @@
package com.gildedgames.aether.common.dungeons;

import com.gildedgames.orbis.lib.core.world_objects.BlueprintRegion;
import com.gildedgames.orbis.lib.data.blueprint.BlueprintData;
import com.gildedgames.orbis.lib.util.RegionHelp;
import com.google.common.collect.Lists;
import net.minecraft.util.math.BlockPos;
import java.util.Iterator;

import java.util.List;
import java.util.Random;

public class DungeonGenerator implements IDungeonGenerator {
@Override
public IDungeon generate(IDungeonDefinition definition, Random rand) {
List<BlueprintRegion> rooms = Lists.newArrayList();
int extraRooms =rand.nextInt(definition.getMaxRooms() - definition.getMinRooms());
int targetRooms = definition.getMinRooms() + extraRooms;

for (int i = 0; i < targetRooms; i++) {
BlueprintData data = definition.possibleBlueprints().get(rand.nextInt(definition.possibleBlueprints().size()));
BlueprintRegion room = new BlueprintRegion(getRandomPos(rand), data);
rooms.add(room);
}

return new Dungeon(rooms);
}

private BlockPos getRandomPos(Random rand) {
int x = rand.nextInt(20) * (rand.nextBoolean() ? -1 : 1);
int y = rand.nextInt(20);
int z = rand.nextInt(20) * (rand.nextBoolean() ? -1 : 1);

return new BlockPos(x, y, z);
}

@Override
public boolean step(DungeonGenStep step, IDungeon soFar) {
switch (step) {
case PUSH_ROOMS_APART: {
boolean anyIntersect = false;
List<BlueprintRegion> intersecting = Lists.newArrayList();
for (BlueprintRegion room : soFar.rooms()) {
RegionHelp.fetchIntersecting2D(room, soFar.rooms(), intersecting);
Iterator<BlueprintRegion> it = intersecting.iterator();

while (it.hasNext()) {
BlueprintRegion r = it.next();

if (r == room) {
continue;
}

int diffX = room.getMin().getX() < r.getMin().getX() ? 1 : -1;
int diffZ = room.getMin().getZ() < r.getMin().getZ() ? 1 : -1;

BlockPos min = r.getMin().add(diffX, 0, diffZ);
BlockPos max = r.getMax().add(diffX, 0, diffZ);

r.setBounds(min, max);
room.setBounds(room.getMin().add(-diffX, 0, -diffZ), room.getMax().add(-diffX, 0, -diffZ));

it.remove();

anyIntersect = true;
}

intersecting.clear();
}

return !anyIntersect;
}
}

return false;
}
}

+ 45
- 0
src/main/java/com/gildedgames/aether/common/dungeons/DungeonViewer.java View File

@@ -0,0 +1,45 @@
package com.gildedgames.aether.common.dungeons;

import com.gildedgames.orbis.lib.core.world_objects.BlueprintRegion;
import com.gildedgames.orbis.lib.data.blueprint.BlueprintData;
import com.gildedgames.orbis.lib.data.region.Region;
import com.google.common.collect.Lists;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

import java.util.Random;

public class DungeonViewer
{
public static BlueprintData data1 = new BlueprintData(new Region(BlockPos.ORIGIN, new BlockPos(5, 5, 5)));
public static BlueprintData data2 = new BlueprintData(new Region(BlockPos.ORIGIN, new BlockPos(15, 5, 5)));
public static BlueprintData data3 = new BlueprintData(new Region(BlockPos.ORIGIN, new BlockPos(25, 5, 15)));

public static InfectedTreeDungeonDefinition def = new InfectedTreeDungeonDefinition(Lists.newArrayList(data1, data2, data3));

private IDungeon dungeon;
private IDungeonGenerator generator;

public DungeonViewer() {
this.generator = new DungeonGenerator();
this.dungeon = this.generator.generate(def, new Random());
}

@SubscribeEvent
public void drawScreen(GuiOpenEvent event) {
if (event.getGui() instanceof GuiMainMenu) {
event.setGui(new GuiDungeonViewer(this.generator, this.dungeon));
}
}

}

+ 84
- 0
src/main/java/com/gildedgames/aether/common/dungeons/GuiDungeonViewer.java View File

@@ -0,0 +1,84 @@
package com.gildedgames.aether.common.dungeons;

import com.gildedgames.aether.common.AetherCore;
import com.gildedgames.orbis.lib.client.gui.util.GuiTexture;
import com.gildedgames.orbis.lib.client.gui.util.gui_library.GuiElement;
import com.gildedgames.orbis.lib.client.gui.util.gui_library.GuiViewerNoContainer;
import com.gildedgames.orbis.lib.client.gui.util.gui_library.IGuiContext;
import com.gildedgames.orbis.lib.client.rect.Dim2D;
import com.gildedgames.orbis.lib.client.rect.Rect;
import com.gildedgames.orbis.lib.core.world_objects.BlueprintRegion;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

import java.io.IOException;
import java.util.Random;

public class GuiDungeonViewer extends GuiViewerNoContainer
{
private static final ResourceLocation TEXTURE_BASE = AetherCore.getResource("textures/gui/guidebook/guidebook_base.png");

private IDungeon dungeon;

private IDungeonGenerator generator;

public GuiDungeonViewer(IDungeonGenerator generator, IDungeon dungeon)
{
super(new GuiElement(Dim2D.flush(), false));

this.generator = generator;
this.dungeon = dungeon;
}

@Override
public void onGuiClosed()
{
super.onGuiClosed();
}

@Override
public void build(IGuiContext context) {
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
super.drawScreen(mouseX, mouseY, partialTicks);

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);


for (BlueprintRegion room : this.dungeon.rooms()) {
GlStateManager.pushMatrix();

double scale = 2.0;

Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE_BASE);
GlStateManager.translate(room.getMin().getX() + (this.width / 2), room.getMin().getZ() + (this.height / 2), 0);
//GlStateManager.scale(scale, scale, scale);
GuiTexture.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, room.getWidth(), room.getLength(), room.getWidth(), room.getLength());

GlStateManager.popMatrix();
}

boolean finished = this.generator.step(DungeonGenStep.PUSH_ROOMS_APART, this.dungeon);

// if (finished) {
// IDungeonGenerator gen = new DungeonGenerator();
// this.dungeon = gen.generate(DungeonViewer.def, new Random());
// }
}

@Override
protected void keyTyped(final char typedChar, final int keyCode) throws IOException
{
IDungeonGenerator gen = new DungeonGenerator();
this.dungeon = gen.generate(DungeonViewer.def, new Random());
}

}

+ 9
- 0
src/main/java/com/gildedgames/aether/common/dungeons/IDungeon.java View File

@@ -0,0 +1,9 @@
package com.gildedgames.aether.common.dungeons;

import com.gildedgames.orbis.lib.core.world_objects.BlueprintRegion;

import java.util.List;

public interface IDungeon {
List<BlueprintRegion> rooms();
}

+ 13
- 0
src/main/java/com/gildedgames/aether/common/dungeons/IDungeonDefinition.java View File

@@ -0,0 +1,13 @@
package com.gildedgames.aether.common.dungeons;

import com.gildedgames.orbis.lib.data.blueprint.BlueprintData;

import java.util.List;

public interface IDungeonDefinition {
List<BlueprintData> possibleBlueprints();

int getMinRooms();

int getMaxRooms();
}

+ 9
- 0
src/main/java/com/gildedgames/aether/common/dungeons/IDungeonGenerator.java View File

@@ -0,0 +1,9 @@
package com.gildedgames.aether.common.dungeons;

import java.util.Random;

public interface IDungeonGenerator {
IDungeon generate(IDungeonDefinition definition, Random rand);

boolean step(DungeonGenStep step, IDungeon soFar);
}

+ 28
- 0
src/main/java/com/gildedgames/aether/common/dungeons/InfectedTreeDungeonDefinition.java View File

@@ -0,0 +1,28 @@
package com.gildedgames.aether.common.dungeons;

import com.gildedgames.orbis.lib.data.blueprint.BlueprintData;

import java.util.List;

public class InfectedTreeDungeonDefinition implements IDungeonDefinition {
private List<BlueprintData> possibleBlueprints;

public InfectedTreeDungeonDefinition(List<BlueprintData> possibleBlueprints) {
this.possibleBlueprints = possibleBlueprints;
}

@Override
public List<BlueprintData> possibleBlueprints() {
return this.possibleBlueprints;
}

@Override
public int getMinRooms() {
return 15;
}

@Override
public int getMaxRooms() {
return 30;
}
}

Loading…
Cancel
Save