Dungeon tinkering
Nothing gameplay-affecting here.
This commit is contained in:
parent
6d07184b18
commit
71ba0229c5
35 changed files with 1173 additions and 1 deletions
|
@ -53,6 +53,7 @@ import wayoftime.bloodmagic.network.BloodMagicPacketHandler;
|
|||
import wayoftime.bloodmagic.potion.BloodMagicPotions;
|
||||
import wayoftime.bloodmagic.registry.ModTranquilityHandlers;
|
||||
import wayoftime.bloodmagic.ritual.RitualManager;
|
||||
import wayoftime.bloodmagic.structures.ModDungeons;
|
||||
import wayoftime.bloodmagic.tile.TileAlchemicalReactionChamber;
|
||||
import wayoftime.bloodmagic.tile.TileAlchemyArray;
|
||||
import wayoftime.bloodmagic.tile.TileAlchemyTable;
|
||||
|
@ -127,6 +128,7 @@ public class BloodMagic
|
|||
context.registerConfig(ModConfig.Type.CLIENT, ConfigManager.CLIENT_SPEC);
|
||||
|
||||
ModTranquilityHandlers.init();
|
||||
ModDungeons.init();
|
||||
}
|
||||
|
||||
private void registerRecipes(RegistryEvent.Register<IRecipeSerializer<?>> event)
|
||||
|
|
|
@ -117,6 +117,7 @@ public class BloodMagicBlocks
|
|||
public static final RegistryObject<Block> DUNGEON_BRICK_1 = DUNGEONBLOCKS.register("dungeon_brick1", () -> new Block(Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE).harvestLevel(2).setRequiresTool()));
|
||||
public static final RegistryObject<Block> DUNGEON_BRICK_2 = DUNGEONBLOCKS.register("dungeon_brick2", () -> new Block(Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE).harvestLevel(2).setRequiresTool()));
|
||||
public static final RegistryObject<Block> DUNGEON_BRICK_3 = DUNGEONBLOCKS.register("dungeon_brick3", () -> new Block(Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE).harvestLevel(2).setRequiresTool()));
|
||||
public static final RegistryObject<Block> DUNGEON_ORE = DUNGEONBLOCKS.register("dungeon_ore", () -> new Block(Properties.create(Material.ROCK).hardnessAndResistance(3.0F, 3.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE).harvestLevel(2).setRequiresTool()));
|
||||
|
||||
public static final RegistryObject<Block> DUNGEON_STONE = BLOCKS.register("dungeon_stone", () -> new Block(Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE).harvestLevel(2).setRequiresTool()));
|
||||
public static final RegistryObject<Block> DUNGEON_EYE = DUNGEONBLOCKS.register("dungeon_eye", () -> new Block(Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE).harvestLevel(2).setRequiresTool().setLightLevel((state) -> {
|
||||
|
|
|
@ -366,6 +366,8 @@ public class GeneratorLanguage extends LanguageProvider
|
|||
addBlock(BloodMagicBlocks.DUNGEON_PILLAR_SPECIAL, "Accented Demon Stone Pillar");
|
||||
addBlock(BloodMagicBlocks.DUNGEON_EYE, "Demon Eye");
|
||||
|
||||
addBlock(BloodMagicBlocks.DUNGEON_ORE, "Demonite");
|
||||
|
||||
// Item names
|
||||
addItem(BloodMagicItems.WEAK_BLOOD_ORB, "Weak Blood Orb");
|
||||
addItem(BloodMagicItems.APPRENTICE_BLOOD_ORB, "Apprentice Blood Orb");
|
||||
|
|
|
@ -31,6 +31,7 @@ import wayoftime.bloodmagic.common.registration.impl.BloodOrbDeferredRegister;
|
|||
import wayoftime.bloodmagic.common.registration.impl.BloodOrbRegistryObject;
|
||||
import wayoftime.bloodmagic.orb.BloodOrb;
|
||||
import wayoftime.bloodmagic.ritual.EnumRuneType;
|
||||
import wayoftime.bloodmagic.structures.ItemDungeonTester;
|
||||
import wayoftime.bloodmagic.will.EnumDemonWillType;
|
||||
|
||||
public class BloodMagicItems
|
||||
|
@ -231,4 +232,9 @@ public class BloodMagicItems
|
|||
public static final RegistryObject<Item> DUNGEON_POLISHED_WALL_BLOCK = ITEMS.register("dungeon_polished_wall", () -> new BlockItem(BloodMagicBlocks.DUNGEON_POLISHED_WALL.get(), new Item.Properties().group(BloodMagic.TAB)));
|
||||
public static final RegistryObject<Item> DUNGEON_BRICK_GATE_BLOCK = ITEMS.register("dungeon_brick_gate", () -> new BlockItem(BloodMagicBlocks.DUNGEON_BRICK_GATE.get(), new Item.Properties().group(BloodMagic.TAB)));
|
||||
public static final RegistryObject<Item> DUNGEON_POLISHED_GATE_BLOCK = ITEMS.register("dungeon_polished_gate", () -> new BlockItem(BloodMagicBlocks.DUNGEON_POLISHED_GATE.get(), new Item.Properties().group(BloodMagic.TAB)));
|
||||
|
||||
public static final RegistryObject<Item> DUNGEON_ORE_BLOCK = ITEMS.register("dungeon_ore", () -> new BlockItem(BloodMagicBlocks.DUNGEON_ORE.get(), new Item.Properties().group(BloodMagic.TAB)));
|
||||
|
||||
public static final RegistryObject<Item> DUNGEON_TESTER = BASICITEMS.register("dungeon_tester", ItemDungeonTester::new);
|
||||
|
||||
}
|
||||
|
|
28
src/main/java/wayoftime/bloodmagic/gson/SerializerBase.java
Normal file
28
src/main/java/wayoftime/bloodmagic/gson/SerializerBase.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package wayoftime.bloodmagic.gson;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
public abstract class SerializerBase<T> implements JsonDeserializer<T>, JsonSerializer<T>
|
||||
{
|
||||
@Override
|
||||
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException
|
||||
{
|
||||
return context.deserialize(json, getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
return context.serialize(src);
|
||||
}
|
||||
|
||||
public abstract Class<T> getType();
|
||||
}
|
128
src/main/java/wayoftime/bloodmagic/gson/Serializers.java
Normal file
128
src/main/java/wayoftime/bloodmagic/gson/Serializers.java
Normal file
|
@ -0,0 +1,128 @@
|
|||
package wayoftime.bloodmagic.gson;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.datasync.DataParameter;
|
||||
import net.minecraft.network.datasync.DataSerializers;
|
||||
import net.minecraft.network.datasync.IDataSerializer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import wayoftime.bloodmagic.will.EnumDemonWillType;
|
||||
|
||||
public class Serializers
|
||||
{
|
||||
// Data serializers
|
||||
public static final IDataSerializer<EnumDemonWillType> WILL_TYPE_SERIALIZER = new IDataSerializer<EnumDemonWillType>()
|
||||
{
|
||||
@Override
|
||||
public void write(PacketBuffer buf, EnumDemonWillType value)
|
||||
{
|
||||
buf.writeEnumValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumDemonWillType read(PacketBuffer buf)
|
||||
{
|
||||
return buf.readEnumValue(EnumDemonWillType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataParameter<EnumDemonWillType> createKey(int id)
|
||||
{
|
||||
return new DataParameter<>(id, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumDemonWillType copyValue(EnumDemonWillType value)
|
||||
{
|
||||
return EnumDemonWillType.valueOf(value.name());
|
||||
}
|
||||
};
|
||||
|
||||
// Serializers
|
||||
public static final SerializerBase<Direction> FACING_SERIALIZER = new SerializerBase<Direction>()
|
||||
{
|
||||
@Override
|
||||
public Class<Direction> getType()
|
||||
{
|
||||
return Direction.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException
|
||||
{
|
||||
return Direction.byName(json.getAsString());
|
||||
}
|
||||
};
|
||||
public static final SerializerBase<ResourceLocation> RESOURCELOCATION_SERIALIZER = new SerializerBase<ResourceLocation>()
|
||||
{
|
||||
@Override
|
||||
public Class<ResourceLocation> getType()
|
||||
{
|
||||
return ResourceLocation.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException
|
||||
{
|
||||
String domain = json.getAsJsonObject().get("domain").getAsString();
|
||||
String path = json.getAsJsonObject().get("path").getAsString();
|
||||
return new ResourceLocation(domain, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ResourceLocation src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("domain", src.getNamespace());
|
||||
object.addProperty("path", src.getPath());
|
||||
return object;
|
||||
}
|
||||
};
|
||||
public static final SerializerBase<ItemStack> ITEMMETA_SERIALIZER = new SerializerBase<ItemStack>()
|
||||
{
|
||||
@Override
|
||||
public Class<ItemStack> getType()
|
||||
{
|
||||
return ItemStack.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException
|
||||
{
|
||||
ResourceLocation registryName = context.deserialize(json.getAsJsonObject().get("registryName").getAsJsonObject(), ResourceLocation.class);
|
||||
int meta = json.getAsJsonObject().get("meta").getAsInt();
|
||||
return new ItemStack(ForgeRegistries.ITEMS.getValue(registryName), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.add("registryName", context.serialize(src.getItem().getRegistryName()));
|
||||
jsonObject.addProperty("meta", src.getDamage());
|
||||
return jsonObject;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().registerTypeAdapter(FACING_SERIALIZER.getType(), FACING_SERIALIZER).registerTypeAdapter(RESOURCELOCATION_SERIALIZER.getType(), RESOURCELOCATION_SERIALIZER).registerTypeAdapter(ITEMMETA_SERIALIZER.getType(), ITEMMETA_SERIALIZER).create();
|
||||
|
||||
static
|
||||
{
|
||||
DataSerializers.registerSerializer(WILL_TYPE_SERIALIZER);
|
||||
}
|
||||
}
|
196
src/main/java/wayoftime/bloodmagic/structures/Dungeon.java
Normal file
196
src/main/java/wayoftime/bloodmagic/structures/Dungeon.java
Normal file
|
@ -0,0 +1,196 @@
|
|||
package wayoftime.bloodmagic.structures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.gen.feature.template.PlacementSettings;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import wayoftime.bloodmagic.ritual.AreaDescriptor;
|
||||
import wayoftime.bloodmagic.util.BMLog;
|
||||
|
||||
public class Dungeon
|
||||
{
|
||||
public static boolean placeStructureAtPosition(Random rand, ServerWorld world, BlockPos pos)
|
||||
{
|
||||
long startTime = System.nanoTime();
|
||||
|
||||
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
|
||||
|
||||
PlacementSettings settings = new PlacementSettings();
|
||||
Mirror mir = Mirror.NONE;
|
||||
|
||||
settings.setMirror(mir);
|
||||
|
||||
Rotation rot = Rotation.NONE;
|
||||
|
||||
settings.setRotation(rot);
|
||||
settings.setIgnoreEntities(true);
|
||||
settings.setChunk(null);
|
||||
|
||||
// settings.setReplacedBlock(null);
|
||||
|
||||
// settings.setIgnoreStructureBlock(false);
|
||||
settings.func_215223_c(true);
|
||||
|
||||
// PlacementSettings placementsettings = (new PlacementSettings()).setMirror(this.mirror).setRotation(this.rotation).setIgnoreEntities(this.ignoreEntities).setChunk((ChunkPos)null);
|
||||
// if (this.integrity < 1.0F) {
|
||||
// placementsettings.clearProcessors().addProcessor(new IntegrityProcessor(MathHelper.clamp(this.integrity, 0.0F, 1.0F))).setRandom(func_214074_b(this.seed));
|
||||
// }
|
||||
//
|
||||
// BlockPos blockpos2 = blockpos.add(this.position);
|
||||
// p_242689_3_.func_237144_a_(p_242689_1_, blockpos2, placementsettings, func_214074_b(this.seed));
|
||||
|
||||
DungeonRoom room = getRandomRoom(rand);
|
||||
roomMap.put(pos, Pair.of(room, settings.copy()));
|
||||
descriptorList.addAll(room.getAreaDescriptors(settings, pos));
|
||||
for (Direction facing : Direction.values())
|
||||
{
|
||||
if (availableDoorMap.containsKey(facing))
|
||||
{
|
||||
List<BlockPos> doorList = availableDoorMap.get(facing);
|
||||
doorList.addAll(room.getDoorOffsetsForFacing(settings, facing, pos));
|
||||
} else
|
||||
{
|
||||
List<BlockPos> doorList = room.getDoorOffsetsForFacing(settings, facing, pos);
|
||||
availableDoorMap.put(facing, doorList);
|
||||
}
|
||||
}
|
||||
|
||||
// Initial AreaDescriptors and door positions are initialized. Time for fun!
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
List<Direction> facingList = new ArrayList<>();
|
||||
for (Entry<Direction, List<BlockPos>> entry : availableDoorMap.entrySet())
|
||||
{
|
||||
if (entry.getValue() != null && !entry.getValue().isEmpty())
|
||||
{
|
||||
facingList.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.shuffle(facingList); // Shuffle the list so that it is random what is chosen
|
||||
|
||||
Pair<Direction, BlockPos> removedDoor1 = null;
|
||||
Pair<Direction, BlockPos> removedDoor2 = null;
|
||||
BlockPos roomLocation = null;
|
||||
|
||||
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
|
||||
DungeonRoom testingRoom = getRandomRoom(rand);
|
||||
|
||||
List<BlockPos> otherDoorList = testingRoom.getDoorOffsetsForFacing(settings, oppositeDoorFacing, BlockPos.ZERO);
|
||||
if (otherDoorList != null && !otherDoorList.isEmpty())
|
||||
{
|
||||
// See if one of these doors works.
|
||||
Collections.shuffle(otherDoorList);
|
||||
BlockPos testDoor = otherDoorList.get(0);
|
||||
testDoor: for (BlockPos availableDoor : availableDoorList)
|
||||
{
|
||||
// TODO: Test if it fits, then add the doors to the list.
|
||||
roomLocation = availableDoor.subtract(testDoor).add(doorFacing.getDirectionVec());
|
||||
|
||||
List<AreaDescriptor> descriptors = testingRoom.getAreaDescriptors(settings, roomLocation);
|
||||
for (AreaDescriptor testDesc : descriptors)
|
||||
{
|
||||
for (AreaDescriptor currentDesc : descriptorList)
|
||||
{
|
||||
if (testDesc.intersects(currentDesc))
|
||||
{
|
||||
break testDoor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
roomMap.put(roomLocation, Pair.of(testingRoom, settings.copy()));
|
||||
descriptorList.addAll(descriptors);
|
||||
removedDoor1 = Pair.of(doorFacing, availableDoor);
|
||||
removedDoor2 = Pair.of(oppositeDoorFacing, testDoor.add(roomLocation));
|
||||
|
||||
room = testingRoom;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Collections.shuffle(otherDoorList);
|
||||
}
|
||||
|
||||
if (removedDoor1 != null)
|
||||
{
|
||||
for (Direction facing : Direction.values())
|
||||
{
|
||||
if (availableDoorMap.containsKey(facing))
|
||||
{
|
||||
List<BlockPos> doorList = availableDoorMap.get(facing);
|
||||
doorList.addAll(room.getDoorOffsetsForFacing(settings, facing, roomLocation));
|
||||
} else
|
||||
{
|
||||
List<BlockPos> doorList = room.getDoorOffsetsForFacing(settings, facing, roomLocation);
|
||||
availableDoorMap.put(facing, doorList);
|
||||
}
|
||||
}
|
||||
|
||||
Direction face = removedDoor1.getKey();
|
||||
if (availableDoorMap.containsKey(face))
|
||||
{
|
||||
availableDoorMap.get(face).remove(removedDoor1.getRight());
|
||||
}
|
||||
}
|
||||
|
||||
if (removedDoor2 != null)
|
||||
{
|
||||
Direction face = removedDoor2.getKey();
|
||||
if (availableDoorMap.containsKey(face))
|
||||
{
|
||||
availableDoorMap.get(face).remove(removedDoor2.getRight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long endTime = System.nanoTime();
|
||||
|
||||
long duration = (endTime - startTime); // divide by 1000000 to get milliseconds.
|
||||
BMLog.DEBUG.info("Duration: " + duration + "(ns), " + duration / 1000000 + "(ms)");
|
||||
|
||||
// Building what I've got
|
||||
for (Entry<BlockPos, Pair<DungeonRoom, PlacementSettings>> entry : roomMap.entrySet())
|
||||
{
|
||||
BlockPos placementPos = entry.getKey();
|
||||
DungeonRoom placedRoom = entry.getValue().getKey();
|
||||
PlacementSettings placementSettings = entry.getValue().getValue();
|
||||
|
||||
placedRoom.placeStructureAtPosition(rand, placementSettings, world, placementPos);
|
||||
}
|
||||
|
||||
System.out.println(roomMap.size());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static DungeonRoom getRandomRoom(Random rand)
|
||||
{
|
||||
// System.out.println("Dungeon size: " + DungeonRoomRegistry.dungeonWeightMap.size());
|
||||
return DungeonRoomRegistry.getRandomDungeonRoom(rand);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package wayoftime.bloodmagic.structures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.gen.feature.template.PlacementSettings;
|
||||
import net.minecraft.world.gen.feature.template.Template;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import wayoftime.bloodmagic.ritual.AreaDescriptor;
|
||||
|
||||
public class DungeonRoom
|
||||
{
|
||||
public int dungeonWeight = 1;
|
||||
public Map<String, BlockPos> structureMap = new HashMap<>();
|
||||
|
||||
public Map<Direction, List<BlockPos>> doorMap = new HashMap<>(); // Map of doors. The EnumFacing indicates what way
|
||||
// this door faces.
|
||||
public List<AreaDescriptor.Rectangle> descriptorList = new ArrayList<>();
|
||||
|
||||
public DungeonRoom(Map<String, BlockPos> structureMap, Map<Direction, List<BlockPos>> doorMap, List<AreaDescriptor.Rectangle> descriptorList)
|
||||
{
|
||||
this.structureMap = structureMap;
|
||||
this.doorMap = doorMap;
|
||||
this.descriptorList = descriptorList;
|
||||
}
|
||||
|
||||
public List<AreaDescriptor> getAreaDescriptors(PlacementSettings settings, BlockPos offset)
|
||||
{
|
||||
List<AreaDescriptor> newList = new ArrayList<>();
|
||||
|
||||
for (AreaDescriptor desc : descriptorList)
|
||||
{
|
||||
newList.add(desc.rotateDescriptor(settings).offset(offset));
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
public List<BlockPos> getDoorOffsetsForFacing(PlacementSettings settings, Direction facing, BlockPos offset)
|
||||
{
|
||||
List<BlockPos> offsetList = new ArrayList<>();
|
||||
|
||||
// Direction originalFacing = DungeonUtil.rotate(settings.getMirror(), settings.getRotation(), facing);
|
||||
Direction originalFacing = DungeonUtil.reverseRotate(settings.getMirror(), settings.getRotation(), facing);
|
||||
// Direction originalFacing = facing;
|
||||
if (doorMap.containsKey(originalFacing))
|
||||
{
|
||||
List<BlockPos> doorList = doorMap.get(originalFacing);
|
||||
for (BlockPos doorPos : doorList)
|
||||
{
|
||||
offsetList.add(Template.transformedBlockPos(settings, doorPos).add(offset));
|
||||
}
|
||||
}
|
||||
|
||||
return offsetList;
|
||||
}
|
||||
|
||||
public boolean placeStructureAtPosition(Random rand, PlacementSettings settings, ServerWorld world, BlockPos pos)
|
||||
{
|
||||
for (Entry<String, BlockPos> entry : structureMap.entrySet())
|
||||
{
|
||||
ResourceLocation location = new ResourceLocation(entry.getKey());
|
||||
DungeonStructure structure = new DungeonStructure(location);
|
||||
BlockPos offsetPos = Template.transformedBlockPos(settings, entry.getValue());
|
||||
|
||||
structure.placeStructureAtPosition(rand, settings, world, pos.add(offsetPos));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package wayoftime.bloodmagic.structures;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
import wayoftime.bloodmagic.gson.Serializers;
|
||||
|
||||
public class DungeonRoomLoader
|
||||
{
|
||||
public static void saveDungeons()
|
||||
{
|
||||
for (DungeonRoom room : DungeonRoomRegistry.dungeonWeightMap.keySet())
|
||||
{
|
||||
saveSingleDungeon(room);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveSingleDungeon(DungeonRoom room)
|
||||
{
|
||||
String json = Serializers.GSON.toJson(room);
|
||||
|
||||
Writer writer;
|
||||
try
|
||||
{
|
||||
File file = new File("config/BloodMagic/schematics");
|
||||
file.mkdirs();
|
||||
|
||||
writer = new FileWriter("config/BloodMagic/schematics/" + new Random().nextInt() + ".json");
|
||||
writer.write(json);
|
||||
writer.close();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadDungeons()
|
||||
{
|
||||
try
|
||||
{
|
||||
// System.out.println("LOADING DEMON DUNGEONS");
|
||||
|
||||
URL schematicURL = DungeonRoomLoader.class.getResource(resLocToResourcePath(new ResourceLocation("bloodmagic:schematics")));
|
||||
List<String> schematics = Serializers.GSON.fromJson(Resources.toString(schematicURL, Charsets.UTF_8), new TypeToken<List<String>>()
|
||||
{
|
||||
}.getType());
|
||||
for (String schematicKey : schematics)
|
||||
{
|
||||
ResourceLocation schematic = new ResourceLocation(schematicKey);
|
||||
URL dungeonURL = DungeonRoomLoader.class.getResource(resLocToResourcePath(schematic));
|
||||
DungeonRoom dungeonRoom = Serializers.GSON.fromJson(Resources.toString(dungeonURL, Charsets.UTF_8), DungeonRoom.class);
|
||||
DungeonRoomRegistry.registerDungeonRoom(dungeonRoom, Math.max(1, dungeonRoom.dungeonWeight));
|
||||
}
|
||||
|
||||
System.out.println("# schematics: " + schematics.size());
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void test()
|
||||
{
|
||||
ResourceLocation id = new ResourceLocation(BloodMagic.MODID, "testGson");
|
||||
String s = id.getNamespace();
|
||||
String s1 = id.getPath();
|
||||
InputStream inputstream = null;
|
||||
|
||||
try
|
||||
{
|
||||
inputstream = DungeonRoomLoader.class.getResourceAsStream("/assets/" + s + "/schematics/" + s1 + ".nbt");
|
||||
// this.readTemplateFromStream(s1, inputstream);
|
||||
return;
|
||||
} catch (Throwable var10)
|
||||
{
|
||||
|
||||
} finally
|
||||
{
|
||||
IOUtils.closeQuietly(inputstream);
|
||||
}
|
||||
}
|
||||
|
||||
public static String resLocToResourcePath(ResourceLocation resourceLocation)
|
||||
{
|
||||
return "/assets/" + resourceLocation.getNamespace() + "/schematics/" + resourceLocation.getPath() + ".json";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package wayoftime.bloodmagic.structures;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
public class DungeonRoomRegistry
|
||||
{
|
||||
public static Map<DungeonRoom, Integer> dungeonWeightMap = new HashMap<>();
|
||||
private static int totalWeight = 0;
|
||||
|
||||
public static void registerDungeonRoom(DungeonRoom room, int weight)
|
||||
{
|
||||
dungeonWeightMap.put(room, weight);
|
||||
totalWeight += weight;
|
||||
}
|
||||
|
||||
public static DungeonRoom getRandomDungeonRoom(Random rand)
|
||||
{
|
||||
int wantedWeight = rand.nextInt(totalWeight);
|
||||
for (Entry<DungeonRoom, Integer> entry : dungeonWeightMap.entrySet())
|
||||
{
|
||||
wantedWeight -= entry.getValue();
|
||||
if (wantedWeight < 0)
|
||||
{
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package wayoftime.bloodmagic.structures;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.gen.feature.template.PlacementSettings;
|
||||
import net.minecraft.world.gen.feature.template.Template;
|
||||
import net.minecraft.world.gen.feature.template.TemplateManager;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import wayoftime.bloodmagic.util.BMLog;
|
||||
|
||||
public class DungeonStructure
|
||||
{
|
||||
public ResourceLocation resource;
|
||||
|
||||
public DungeonStructure(ResourceLocation resource)
|
||||
{
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public boolean placeStructureAtPosition(Random rand, PlacementSettings settings, ServerWorld world, BlockPos pos)
|
||||
{
|
||||
|
||||
if (pos == null)
|
||||
return false;
|
||||
|
||||
MinecraftServer minecraftserver = world.getServer();
|
||||
TemplateManager templatemanager = world.getStructureTemplateManager();
|
||||
|
||||
Template template = templatemanager.getTemplate(resource);
|
||||
|
||||
if (template == null)
|
||||
{
|
||||
System.out.println("Invalid template for location: " + resource);
|
||||
BMLog.DEBUG.warn("Invalid template for location: " + resource);
|
||||
return false;
|
||||
}
|
||||
|
||||
// settings.func_189946_a(MathHelper.clamp_float(schema.integrity, 0.0F, 1.0F));
|
||||
|
||||
BlockPos offset = Template.transformedBlockPos(settings, new BlockPos(0, 0, 0));
|
||||
BlockPos finalPos = pos.add(offset);
|
||||
// template.addBlocksToWorldChunk(world, finalPos, settings);
|
||||
template.func_237144_a_(world, finalPos, settings, rand);
|
||||
// template.func_237152_b_(world, finalPos, settings, rand);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public DungeonStructure copy()
|
||||
{
|
||||
return new DungeonStructure(resource);
|
||||
}
|
||||
}
|
106
src/main/java/wayoftime/bloodmagic/structures/DungeonTester.java
Normal file
106
src/main/java/wayoftime/bloodmagic/structures/DungeonTester.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
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
|
||||
{
|
||||
public static void testDungeonGeneration(ServerWorld world, BlockPos pos)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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));
|
||||
//
|
||||
// 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++)
|
||||
{
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package wayoftime.bloodmagic.structures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.gen.feature.template.PlacementSettings;
|
||||
|
||||
public class DungeonUtil
|
||||
{
|
||||
public static Direction rotate(Mirror mirror, Rotation rotation, Direction original)
|
||||
{
|
||||
return rotation.rotate(mirror.mirror(original));
|
||||
}
|
||||
|
||||
public static Direction reverseRotate(Mirror mirror, Rotation rotation, Direction original)
|
||||
{
|
||||
return mirror.mirror(getOppositeRotation(rotation).rotate(original));
|
||||
}
|
||||
|
||||
public static Direction getFacingForSettings(PlacementSettings settings, Direction original)
|
||||
{
|
||||
return rotate(settings.getMirror(), settings.getRotation(), original);
|
||||
}
|
||||
|
||||
public static Rotation getOppositeRotation(Rotation rotation)
|
||||
{
|
||||
switch (rotation)
|
||||
{
|
||||
case CLOCKWISE_90:
|
||||
return Rotation.COUNTERCLOCKWISE_90;
|
||||
case COUNTERCLOCKWISE_90:
|
||||
return Rotation.CLOCKWISE_90;
|
||||
default:
|
||||
return rotation;
|
||||
}
|
||||
}
|
||||
|
||||
public static void addRoom(Map<Direction, List<BlockPos>> doorMap, Direction facing, BlockPos offsetPos)
|
||||
{
|
||||
if (doorMap.containsKey(facing))
|
||||
{
|
||||
doorMap.get(facing).add(offsetPos);
|
||||
} else
|
||||
{
|
||||
List<BlockPos> doorList = new ArrayList<>();
|
||||
doorList.add(offsetPos);
|
||||
doorMap.put(facing, doorList);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package wayoftime.bloodmagic.structures;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
|
||||
public class ItemDungeonTester extends Item
|
||||
{
|
||||
public ItemDungeonTester()
|
||||
{
|
||||
super(new Item.Properties().maxStackSize(1).group(BloodMagic.TAB));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand)
|
||||
{
|
||||
if (!world.isRemote && world instanceof ServerWorld)
|
||||
{
|
||||
System.out.println("Test");
|
||||
DungeonTester.testDungeonElementWithOutput((ServerWorld) world, player.getPosition());
|
||||
}
|
||||
return super.onItemRightClick(world, player, hand);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package wayoftime.bloodmagic.structures;
|
||||
|
||||
public class ModDungeons
|
||||
{
|
||||
public static void init()
|
||||
{
|
||||
// ResourceLocation resource = new ResourceLocation(Constants.Mod.MODID, "HallChest1");
|
||||
//
|
||||
// Map<String, BlockPos> structureMap = new HashMap<String, BlockPos>();
|
||||
// structureMap.put(resource.toString(), new BlockPos(0, 0, 0));
|
||||
//
|
||||
// Map<EnumFacing, List<BlockPos>> doorMap = new HashMap<EnumFacing, List<BlockPos>>();
|
||||
// List<AreaDescriptor.Rectangle> descriptorList = new ArrayList<AreaDescriptor.Rectangle>();
|
||||
// descriptorList.add(new AreaDescriptor.Rectangle(new BlockPos(0, 0, 0), 12, 5, 9));
|
||||
//
|
||||
// DungeonUtil.addRoom(doorMap, EnumFacing.EAST, new BlockPos(11, 0, 4));
|
||||
// DungeonUtil.addRoom(doorMap, EnumFacing.WEST, new BlockPos(0, 0, 4));
|
||||
//
|
||||
// DungeonRoom room = new DungeonRoom(structureMap, doorMap, descriptorList);
|
||||
// DungeonRoomLoader.saveSingleDungeon(room);
|
||||
//
|
||||
// DungeonRoomRegistry.registerDungeonRoom(room, 1);
|
||||
//
|
||||
// DungeonRoomLoader.saveDungeons();
|
||||
|
||||
DungeonRoomLoader.loadDungeons();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue