Dungeon tinkering

Nothing gameplay-affecting here.
This commit is contained in:
WayofTime 2020-11-15 12:07:01 -05:00
parent 6d07184b18
commit 71ba0229c5
35 changed files with 1173 additions and 1 deletions

View file

@ -18,6 +18,7 @@ c67498a81f8dd53770da51df45192b171cdd234c assets/bloodmagic/blockstates/dungeon_b
8b568926830785a5cb848fb36d4ae01e67590501 assets/bloodmagic/blockstates/dungeon_brick_stairs.json
6c10c79909e008b960f2d78543f55847eec7a226 assets/bloodmagic/blockstates/dungeon_brick_wall.json
8a04e502b6965d912793699d61071e44428fceb8 assets/bloodmagic/blockstates/dungeon_eye.json
fe31978b41dc50c21f413c81410221f657fd4d23 assets/bloodmagic/blockstates/dungeon_ore.json
388af5c6d34f62d66d987760871c64793df84a37 assets/bloodmagic/blockstates/dungeon_pillar_cap.json
8d8d58ad890f339b75dbdfc710b30dc00eed2ef3 assets/bloodmagic/blockstates/dungeon_pillar_center.json
48e7b0533fa722eb66956e01de661ebac6470da7 assets/bloodmagic/blockstates/dungeon_pillar_special.json
@ -52,7 +53,7 @@ e6d9cf699667aaa47efff37b2b033895dee29c15 assets/bloodmagic/blockstates/waterritu
42f26f715bddd16c069f9b51e3767b36477c8908 assets/bloodmagic/blockstates/woodtilepath.json
3c6ce233dae6c1307d9016406c324bbe844b4e1e assets/bloodmagic/blockstates/wornstonebrickpath.json
d59655f12d1724b73b77c373fb6864fcff69db12 assets/bloodmagic/blockstates/wornstonetilepath.json
d3b0f3df0b83423d59343a185b28f6de543b64bb assets/bloodmagic/lang/en_us.json
e7aab24fc4aa77601119478854ad929a1f384132 assets/bloodmagic/lang/en_us.json
34445195b9f2459475cde53454bc8e37d32865d7 assets/bloodmagic/models/block/accelerationrune.json
bcdbccc49d4509571be6988762ab87126275a4c8 assets/bloodmagic/models/block/airritualstone.json
adf6c0b1e25451609486dc8c8cfbd9cf0f8c67f4 assets/bloodmagic/models/block/alchemicalreactionchamber.json
@ -113,6 +114,7 @@ ffb2021036b74d29fca5fc706885f3e1399c2950 assets/bloodmagic/models/block/dungeon_
a7d371e5d0efefae2729131bda16120bfe477bb8 assets/bloodmagic/models/block/dungeon_brick_wall_side.json
bd152efd619489661cac86a80190bf9e88c86363 assets/bloodmagic/models/block/dungeon_brick_wall_side_tall.json
19ae530a34eb5cee35dc7b9cdd51c9c2d61fdc9e assets/bloodmagic/models/block/dungeon_eye.json
61eb4e5ede53a8278d2d95fbeb40dc01424f2895 assets/bloodmagic/models/block/dungeon_ore.json
a4449c1d14c46bcda58b542c3efdddadff15bedc assets/bloodmagic/models/block/dungeon_pillar_cap.json
1752cc99d0c334016bebd0e8027b8abe3ca5d7e8 assets/bloodmagic/models/block/dungeon_pillar_cap_down.json
f171162bb4b86e70f2b2f13f3393704d295a4d86 assets/bloodmagic/models/block/dungeon_pillar_cap_east.json
@ -205,6 +207,7 @@ f866879eed9f1bd7eebac14495de599ca3ad855d assets/bloodmagic/models/item/dungeon_b
2ec6a2c66e88981ff54e74035bb3adb1ec4f6396 assets/bloodmagic/models/item/dungeon_brick_stairs.json
098a26f4e9222c801f9a17a6db1b266ad4085003 assets/bloodmagic/models/item/dungeon_brick_wall.json
0a48c4fd74036702ae2d72a9b2333c2bdf5ab31b assets/bloodmagic/models/item/dungeon_eye.json
95a45fae0890e626aa5e5ff85b9884bd30087244 assets/bloodmagic/models/item/dungeon_ore.json
ba5c610437b7d3a84820109c32d204310ff41fd7 assets/bloodmagic/models/item/dungeon_pillar_cap.json
d098a544e7b9918a45106c2cbc5e10baea66502a assets/bloodmagic/models/item/dungeon_pillar_center.json
5284f1cc7508546c66669564182fe5056053333d assets/bloodmagic/models/item/dungeon_pillar_special.json
@ -214,6 +217,7 @@ d098a544e7b9918a45106c2cbc5e10baea66502a assets/bloodmagic/models/item/dungeon_p
f3b763d6edc3c75655797481f05e02d409f481d9 assets/bloodmagic/models/item/dungeon_polished_wall.json
2ecba4811bd02698f6a34b5cdd9160426f7bda63 assets/bloodmagic/models/item/dungeon_smallbrick.json
2d7a8a3ed9f91a5bf5c277c6342c69e97692d347 assets/bloodmagic/models/item/dungeon_stone.json
027369d4162f28a808223ca7b22bdb68de28f290 assets/bloodmagic/models/item/dungeon_tester.json
6186d2045f87b1e6cc7006226993a93b63d650ff assets/bloodmagic/models/item/dungeon_tile.json
21e8a4fa93ba249684e0624a10a6f0f00ff6d194 assets/bloodmagic/models/item/dungeon_tilespecial.json
10aceefca3ad3f0da773cb317c4effc6c06051ea assets/bloodmagic/models/item/duskritualstone.json
@ -413,6 +417,7 @@ be050ff812ae62793e3c51d7c2ab343294ede7f0 data/bloodmagic/loot_tables/blocks/dung
0d30aeb91425e2419abf555e9baab34475f45afc data/bloodmagic/loot_tables/blocks/dungeon_brick_stairs.json
fa335aded871280065ca02db79d6de59ced7f6c9 data/bloodmagic/loot_tables/blocks/dungeon_brick_wall.json
47baa958866616d96eb39e2671a4cf488e0abae2 data/bloodmagic/loot_tables/blocks/dungeon_eye.json
234675dab5d5ff7e1fec0e13cede1f141811fc92 data/bloodmagic/loot_tables/blocks/dungeon_ore.json
53864c213b973e67006cda4596877bcdd3474396 data/bloodmagic/loot_tables/blocks/dungeon_pillar_cap.json
db8be3b67639ab451d0a28e0674240094ceea046 data/bloodmagic/loot_tables/blocks/dungeon_pillar_center.json
c3deab4dd4ef8c1cf6f217d660ea07e5d7bd8555 data/bloodmagic/loot_tables/blocks/dungeon_pillar_special.json

View file

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "bloodmagic:block/dungeon_ore"
}
}
}

View file

@ -22,6 +22,7 @@
"block.bloodmagic.dungeon_brick_stairs": "Demon Brick Stairs",
"block.bloodmagic.dungeon_brick_wall": "Demon Brick Wall",
"block.bloodmagic.dungeon_eye": "Demon Eye",
"block.bloodmagic.dungeon_ore": "Demonite",
"block.bloodmagic.dungeon_pillar_cap": "Demon Stone Pillar Cap",
"block.bloodmagic.dungeon_pillar_center": "Demon Stone Pillar",
"block.bloodmagic.dungeon_pillar_special": "Accented Demon Stone Pillar",

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "bloodmagic:block/dungeon/dungeon_ore"
}
}

View file

@ -0,0 +1,3 @@
{
"parent": "bloodmagic:block/dungeon_ore"
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "bloodmagic:item/dungeon_tester"
}
}

View file

@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "bloodmagic:dungeon_ore"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}

View file

@ -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)

View file

@ -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) -> {

View file

@ -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");

View file

@ -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);
}

View 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();
}

View 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);
}
}

View 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);
}
}

View file

@ -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;
}
}

View file

@ -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";
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View 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++;
}
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -0,0 +1,56 @@
{
"dungeonWeight": 4,
"structureMap": {
"bloodmagic:four_way_corridor": {
"x": 0,
"y": 0,
"z": 0
}
},
"doorMap": {
"north": [
{
"x": 5,
"y": 0,
"z": 0
}
],
"south": [
{
"x": 5,
"y": 0,
"z": 10
}
],
"west": [
{
"x": 0,
"y": 0,
"z": 5
}
],
"east": [
{
"x": 10,
"y": 0,
"z": 5
}
]
},
"descriptorList": [
{
"minimumOffset": {
"x": 0,
"y": 0,
"z": 0
},
"maximumOffset": {
"x": 11,
"y": 6,
"z": 11
},
"blockPosCache": [],
"cache": true
}
]
}

View file

@ -0,0 +1,56 @@
{
"dungeonWeight": 1,
"structureMap": {
"bloodmagic:four_way_corridor_loot": {
"x": 0,
"y": 0,
"z": 0
}
},
"doorMap": {
"north": [
{
"x": 5,
"y": 5,
"z": 0
}
],
"south": [
{
"x": 5,
"y": 5,
"z": 10
}
],
"west": [
{
"x": 0,
"y": 5,
"z": 5
}
],
"east": [
{
"x": 10,
"y": 5,
"z": 5
}
]
},
"descriptorList": [
{
"minimumOffset": {
"x": 0,
"y": 0,
"z": 0
},
"maximumOffset": {
"x": 11,
"y": 11,
"z": 11
},
"blockPosCache": [],
"cache": true
}
]
}

View file

@ -0,0 +1,69 @@
{
"dungeonWeight": 8,
"structureMap": {
"bloodmagic:ore_hold_1": {
"x": 0,
"y": 0,
"z": 0
}
},
"doorMap": {
"north": [
{
"x": 5,
"y": 0,
"z": 0
},
{
"x": 2,
"y": 5,
"z": 0
},
{
"x": 12,
"y": 5,
"z": 0
}
],
"south": [
{
"x": 5,
"y": 0,
"z": 14
},
{
"x": 2,
"y": 5,
"z": 14
},
{
"x": 12,
"y": 5,
"z": 14
}
],
"west": [
{
"x": 0,
"y": 5,
"z": 7
}
]
},
"descriptorList": [
{
"minimumOffset": {
"x": 0,
"y": 0,
"z": 0
},
"maximumOffset": {
"x": 15,
"y": 12,
"z": 15
},
"blockPosCache": [],
"cache": true
}
]
}

View file

@ -0,0 +1,3 @@
[
"bloodmagic:t_corridor"
]

View file

@ -0,0 +1,42 @@
{
"dungeonWeight": 4,
"structureMap": {
"bloodmagic:straight_corridor": {
"x": 0,
"y": 0,
"z": 0
}
},
"doorMap": {
"west": [
{
"x": 0,
"y": 0,
"z": 2
}
],
"east": [
{
"x": 10,
"y": 0,
"z": 2
}
]
},
"descriptorList": [
{
"minimumOffset": {
"x": 0,
"y": 0,
"z": 0
},
"maximumOffset": {
"x": 11,
"y": 5,
"z": 5
},
"blockPosCache": [],
"cache": true
}
]
}

View file

@ -0,0 +1,49 @@
{
"dungeonWeight": 12,
"structureMap": {
"bloodmagic:t_corridor": {
"x": 0,
"y": 0,
"z": 0
}
},
"doorMap": {
"north": [
{
"x": 5,
"y": 0,
"z": 0
}
],
"west": [
{
"x": 0,
"y": 0,
"z": 5
}
],
"east": [
{
"x": 10,
"y": 0,
"z": 5
}
]
},
"descriptorList": [
{
"minimumOffset": {
"x": 0,
"y": 0,
"z": 0
},
"maximumOffset": {
"x": 11,
"y": 5,
"z": 8
},
"blockPosCache": [],
"cache": true
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 902 B