Dungeon Fix
:rooBlank:
This commit is contained in:
parent
6f7cd030e6
commit
2dafb837f1
|
@ -10,6 +10,7 @@ import java.util.Random;
|
|||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
|
@ -28,8 +29,10 @@ public class Dungeon
|
|||
Map<Direction, List<BlockPos>> availableDoorMap = new HashMap<>(); // Map of doors. The EnumFacing indicates
|
||||
// what way this door faces.
|
||||
List<AreaDescriptor> descriptorList = new ArrayList<>();
|
||||
Map<BlockPos, Pair<DungeonRoom, PlacementSettings>> roomMap = new HashMap<>(); // Placement positions in terms
|
||||
// of actual positions
|
||||
// Map<BlockPos, Pair<DungeonRoom, PlacementSettings>> roomMap = new HashMap<>(); // Placement positions in terms
|
||||
// // of actual positions
|
||||
|
||||
List<Pair<BlockPos, Pair<DungeonRoom, PlacementSettings>>> roomList = new ArrayList<>();
|
||||
|
||||
PlacementSettings settings = new PlacementSettings();
|
||||
Mirror mir = Mirror.NONE;
|
||||
|
@ -55,8 +58,12 @@ public class Dungeon
|
|||
// BlockPos blockpos2 = blockpos.add(this.position);
|
||||
// p_242689_3_.func_237144_a_(p_242689_1_, blockpos2, placementsettings, func_214074_b(this.seed));
|
||||
|
||||
List<Rotation> rotationInfo = new ArrayList();
|
||||
|
||||
int n = 1;
|
||||
DungeonRoom room = getRandomRoom(rand);
|
||||
roomMap.put(pos, Pair.of(room, settings.copy()));
|
||||
// roomMap.put(pos, Pair.of(room, settings.copy()));
|
||||
roomList.add(Pair.of(pos, Pair.of(room, settings.copy())));
|
||||
descriptorList.addAll(room.getAreaDescriptors(settings, pos));
|
||||
for (Direction facing : Direction.values())
|
||||
{
|
||||
|
@ -71,9 +78,12 @@ public class Dungeon
|
|||
}
|
||||
}
|
||||
|
||||
rotationInfo.add(settings.getRotation());
|
||||
|
||||
// Initial AreaDescriptors and door positions are initialized. Time for fun!
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
// Get which facing of doors are available.
|
||||
List<Direction> facingList = new ArrayList<>();
|
||||
for (Entry<Direction, List<BlockPos>> entry : availableDoorMap.entrySet())
|
||||
{
|
||||
|
@ -89,13 +99,15 @@ public class Dungeon
|
|||
Pair<Direction, BlockPos> removedDoor2 = null;
|
||||
BlockPos roomLocation = null;
|
||||
|
||||
for (Direction doorFacing : facingList)
|
||||
testDirection: for (Direction doorFacing : facingList)
|
||||
{
|
||||
Direction oppositeDoorFacing = doorFacing.getOpposite();
|
||||
List<BlockPos> availableDoorList = availableDoorMap.get(doorFacing); // May need to copy here
|
||||
Collections.shuffle(availableDoorList);
|
||||
|
||||
settings.setRotation(Rotation.values()[rand.nextInt(Rotation.values().length)]); // Same for the Mirror
|
||||
Rotation randRotation = Rotation.values()[rand.nextInt(Rotation.values().length)];
|
||||
// Rotation randRotation = Rotation.CLOCKWISE_90;
|
||||
settings.setRotation(randRotation); // Same for the Mirror
|
||||
DungeonRoom testingRoom = getRandomRoom(rand);
|
||||
|
||||
List<BlockPos> otherDoorList = testingRoom.getDoorOffsetsForFacing(settings, oppositeDoorFacing, BlockPos.ZERO);
|
||||
|
@ -121,13 +133,24 @@ public class Dungeon
|
|||
}
|
||||
}
|
||||
|
||||
roomMap.put(roomLocation, Pair.of(testingRoom, settings.copy()));
|
||||
// roomMap.put(roomLocation, Pair.of(testingRoom, settings.copy()));
|
||||
roomList.add(Pair.of(roomLocation, Pair.of(testingRoom, settings.copy())));
|
||||
descriptorList.addAll(descriptors);
|
||||
removedDoor1 = Pair.of(doorFacing, availableDoor);
|
||||
removedDoor2 = Pair.of(oppositeDoorFacing, testDoor.add(roomLocation));
|
||||
|
||||
room = testingRoom;
|
||||
n++;
|
||||
rotationInfo.add(randRotation);
|
||||
System.out.println("Placement: " + n);
|
||||
|
||||
for (Direction facing : Direction.values())
|
||||
{
|
||||
List<BlockPos> testingDoorList = testingRoom.getDoorOffsetsForFacing(settings, facing, BlockPos.ZERO);
|
||||
System.out.println("Door Facing: " + facing + ", Door List: " + testingDoorList);
|
||||
}
|
||||
|
||||
break testDirection;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -174,16 +197,24 @@ public class Dungeon
|
|||
BMLog.DEBUG.info("Duration: " + duration + "(ns), " + duration / 1000000 + "(ms)");
|
||||
|
||||
// Building what I've got
|
||||
for (Entry<BlockPos, Pair<DungeonRoom, PlacementSettings>> entry : roomMap.entrySet())
|
||||
n = 0;
|
||||
// for (Entry<BlockPos, Pair<DungeonRoom, PlacementSettings>> entry : roomMap.entrySet())
|
||||
for (Pair<BlockPos, Pair<DungeonRoom, PlacementSettings>> entry : roomList)
|
||||
{
|
||||
n++;
|
||||
BlockPos placementPos = entry.getKey();
|
||||
DungeonRoom placedRoom = entry.getValue().getKey();
|
||||
PlacementSettings placementSettings = entry.getValue().getValue();
|
||||
|
||||
placedRoom.placeStructureAtPosition(rand, placementSettings, world, placementPos);
|
||||
|
||||
world.setBlockState(placementPos, Blocks.REDSTONE_BLOCK.getDefaultState(), 3);
|
||||
System.out.println("Supposed Rotation for " + n + ": " + rotationInfo.get(n - 1));
|
||||
System.out.println("Placement: " + n + ", BlockPos: " + placementPos + ", Rotation: " + placementSettings.getRotation());
|
||||
}
|
||||
|
||||
System.out.println(roomMap.size());
|
||||
// System.out.println(roomMap.size());
|
||||
System.out.println(roomList.size());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,9 @@
|
|||
package wayoftime.bloodmagic.structures;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.gen.feature.template.PlacementSettings;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
|
||||
public class DungeonTester
|
||||
{
|
||||
|
@ -25,82 +14,82 @@ public class DungeonTester
|
|||
|
||||
public static void testDungeonElementWithOutput(ServerWorld world, BlockPos pos)
|
||||
{
|
||||
// Dungeon.placeStructureAtPosition(new Random(), world, pos);
|
||||
ResourceLocation resource = new ResourceLocation(BloodMagic.MODID, "t_corridor");
|
||||
|
||||
// DungeonStructure structure = new DungeonStructure(resource);
|
||||
// Map<DungeonStructure, BlockPos> structureMap = new HashMap<DungeonStructure, BlockPos>();
|
||||
// structureMap.put(structure, new BlockPos(0, 0, 0));
|
||||
|
||||
Map<String, BlockPos> structureMap = new HashMap();
|
||||
structureMap.put(resource.toString(), BlockPos.ZERO);
|
||||
|
||||
// Map<Direction, List<BlockPos>> doorMap = new HashMap<Direction, List<BlockPos>>();
|
||||
// List<AreaDescriptor.Rectangle> descriptorList = new ArrayList<AreaDescriptor.Rectangle>();
|
||||
// descriptorList.add(new AreaDescriptor.Rectangle(new BlockPos(0, 0, 0), 11, 5, 8));
|
||||
Dungeon.placeStructureAtPosition(new Random(), world, pos);
|
||||
// ResourceLocation resource = new ResourceLocation(BloodMagic.MODID, "t_corridor");
|
||||
//
|
||||
// DungeonUtil.addRoom(doorMap, Direction.NORTH, new BlockPos(5, 0, 0));
|
||||
// DungeonUtil.addRoom(doorMap, Direction.EAST, new BlockPos(10, 0, 5));
|
||||
// DungeonUtil.addRoom(doorMap, Direction.WEST, new BlockPos(0, 0, 5));
|
||||
//// DungeonStructure structure = new DungeonStructure(resource);
|
||||
//// Map<DungeonStructure, BlockPos> structureMap = new HashMap<DungeonStructure, BlockPos>();
|
||||
//// structureMap.put(structure, new BlockPos(0, 0, 0));
|
||||
//
|
||||
// DungeonRoom room = new DungeonRoom(structureMap, doorMap, descriptorList);
|
||||
|
||||
DungeonRoom room = Dungeon.getRandomRoom(new Random());
|
||||
|
||||
PlacementSettings settings = new PlacementSettings();
|
||||
|
||||
Mirror mir = Mirror.NONE;
|
||||
settings.setMirror(mir);
|
||||
|
||||
net.minecraft.util.Rotation rot = Rotation.NONE;
|
||||
settings.setRotation(rot);
|
||||
|
||||
settings.setIgnoreEntities(true);
|
||||
settings.setChunk((ChunkPos) null);
|
||||
settings.func_215223_c(true);
|
||||
// settings.setReplacedBlock((Block) null);
|
||||
// settings.setIgnoreStructureBlock(false);
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (Mirror mirror : Mirror.values())
|
||||
{
|
||||
System.out.print("Mirror: " + mirror + '\n');
|
||||
int j = 0;
|
||||
for (Rotation rotation : Rotation.values())
|
||||
{
|
||||
System.out.print("Rotation: " + rotation + '\n');
|
||||
settings.setRotation(rotation);
|
||||
settings.setMirror(mirror);
|
||||
|
||||
BlockPos offsetPos = pos.add(i * 32, 0, j * 32);
|
||||
room.placeStructureAtPosition(new Random(), settings, world, offsetPos);
|
||||
|
||||
world.setBlockState(offsetPos, Blocks.REDSTONE_BLOCK.getDefaultState(), 3);
|
||||
|
||||
// List<AreaDescriptor> descriptors = room.getAreaDescriptors(settings, offsetPos);
|
||||
// for (AreaDescriptor desc : descriptors)
|
||||
// Map<String, BlockPos> structureMap = new HashMap();
|
||||
// structureMap.put(resource.toString(), BlockPos.ZERO);
|
||||
//
|
||||
//// Map<Direction, List<BlockPos>> doorMap = new HashMap<Direction, List<BlockPos>>();
|
||||
//// List<AreaDescriptor.Rectangle> descriptorList = new ArrayList<AreaDescriptor.Rectangle>();
|
||||
//// descriptorList.add(new AreaDescriptor.Rectangle(new BlockPos(0, 0, 0), 11, 5, 8));
|
||||
////
|
||||
//// DungeonUtil.addRoom(doorMap, Direction.NORTH, new BlockPos(5, 0, 0));
|
||||
//// DungeonUtil.addRoom(doorMap, Direction.EAST, new BlockPos(10, 0, 5));
|
||||
//// DungeonUtil.addRoom(doorMap, Direction.WEST, new BlockPos(0, 0, 5));
|
||||
////
|
||||
//// DungeonRoom room = new DungeonRoom(structureMap, doorMap, descriptorList);
|
||||
//
|
||||
// DungeonRoom room = Dungeon.getRandomRoom(new Random());
|
||||
//
|
||||
// PlacementSettings settings = new PlacementSettings();
|
||||
//
|
||||
// Mirror mir = Mirror.NONE;
|
||||
// settings.setMirror(mir);
|
||||
//
|
||||
// net.minecraft.util.Rotation rot = Rotation.NONE;
|
||||
// settings.setRotation(rot);
|
||||
//
|
||||
// settings.setIgnoreEntities(true);
|
||||
// settings.setChunk((ChunkPos) null);
|
||||
// settings.func_215223_c(true);
|
||||
//// settings.setReplacedBlock((Block) null);
|
||||
//// settings.setIgnoreStructureBlock(false);
|
||||
//
|
||||
// int i = 0;
|
||||
//
|
||||
// for (Mirror mirror : Mirror.values())
|
||||
// {
|
||||
// System.out.print("Mirror: " + mirror + '\n');
|
||||
// int j = 0;
|
||||
// for (Rotation rotation : Rotation.values())
|
||||
// {
|
||||
// System.out.print("Rotation: " + rotation + '\n');
|
||||
// settings.setRotation(rotation);
|
||||
// settings.setMirror(mirror);
|
||||
//
|
||||
// BlockPos offsetPos = pos.add(i * 32, 0, j * 32);
|
||||
// room.placeStructureAtPosition(new Random(), settings, world, offsetPos);
|
||||
//
|
||||
// world.setBlockState(offsetPos, Blocks.REDSTONE_BLOCK.getDefaultState(), 3);
|
||||
//
|
||||
//// List<AreaDescriptor> descriptors = room.getAreaDescriptors(settings, offsetPos);
|
||||
//// for (AreaDescriptor desc : descriptors)
|
||||
//// {
|
||||
//// List<BlockPos> posList = desc.getContainedPositions(new BlockPos(0, 0, 0));
|
||||
//// for (BlockPos placePos : posList)
|
||||
//// {
|
||||
//// world.setBlockState(placePos, Blocks.REDSTONE_BLOCK.getDefaultState());
|
||||
//// }
|
||||
//// }
|
||||
//
|
||||
//// for (Direction facing : Direction.HORIZONTALS)
|
||||
// for (int k = 0; k < 4; k++)
|
||||
// {
|
||||
// List<BlockPos> posList = desc.getContainedPositions(new BlockPos(0, 0, 0));
|
||||
// for (BlockPos placePos : posList)
|
||||
// Direction facing = Direction.byHorizontalIndex(k);
|
||||
// List<BlockPos> doorList = room.getDoorOffsetsForFacing(settings, facing, offsetPos);
|
||||
// for (BlockPos doorPos : doorList)
|
||||
// {
|
||||
// world.setBlockState(placePos, Blocks.REDSTONE_BLOCK.getDefaultState());
|
||||
// System.out.print("Door at " + doorPos + " facing " + facing + '\n');
|
||||
// }
|
||||
// }
|
||||
|
||||
// for (Direction facing : Direction.HORIZONTALS)
|
||||
for (int k = 0; k < 4; k++)
|
||||
{
|
||||
Direction facing = Direction.byHorizontalIndex(k);
|
||||
List<BlockPos> doorList = room.getDoorOffsetsForFacing(settings, facing, offsetPos);
|
||||
for (BlockPos doorPos : doorList)
|
||||
{
|
||||
System.out.print("Door at " + doorPos + " facing " + facing + '\n');
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
// j++;
|
||||
// }
|
||||
// i++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue