Properly added API

Actually put the API in the correct spot >.>
This commit is contained in:
WayofTime 2020-11-15 16:33:42 -05:00
parent 2dafb837f1
commit bc2530583a
13 changed files with 187 additions and 33 deletions

View file

@ -0,0 +1,80 @@
package wayoftime.bloodmagic.api;
import javax.annotation.Nonnull;
import net.minecraft.block.BlockState;
/**
* The main interface between a plugin and Blood Magic's internals.
*
* This API is intended for <i>compatibility</i> between other mods and Blood
* Magic. More advanced integration is out of the scope of this API and are
* considered "addons".
*
* To get an instance of this without actually creating an
* {@link IBloodMagicPlugin}, use {@link BloodMagicPlugin.Inject}.
*/
public interface IBloodMagicAPI
{
// /**
// * Retrieves the instance of the blacklist.
// *
// * @return the active {@link IBloodMagicBlacklist} instance
// */
// @Nonnull
// IBloodMagicBlacklist getBlacklist();
/**
* Retrieves the instance of the recipe registrar.
*
* @return the active {@link IBloodMagicRecipeRegistrar} instance
*/
@Nonnull
IBloodMagicRecipeRegistrar getRecipeRegistrar();
/**
* Retrieves the instance of the value manager.
*
* @return the active {@link IBloodMagicValueManager} instance
*/
@Nonnull
IBloodMagicValueManager getValueManager();
/**
* Registers an {@link IBlockState} as a given component for the Blood Altar.
* <p>
* Valid component types:
* <ul>
* <li>GLOWSTONE</li>
* <li>BLOODSTONE</li>
* <li>BEACON</li>
* <li>BLOODRUNE</li>
* <li>CRYSTAL</li>
* <li>NOTAIR</li>
* </ul>
*
* @param state The state to register
* @param componentType The type of Blood Altar component to register as.
*/
void registerAltarComponent(@Nonnull BlockState state, @Nonnull String componentType);
/**
* Removes an {@link IBlockState} from the component mappings
* <p>
* Valid component types:
* <ul>
* <li>GLOWSTONE</li>
* <li>BLOODSTONE</li>
* <li>BEACON</li>
* <li>BLOODRUNE</li>
* <li>CRYSTAL</li>
* <li>NOTAIR</li>
* </ul>
*
* @param state The state to unregister
* @param componentType The type of Blood Altar component to unregister from.
*/
void unregisterAltarComponent(@Nonnull BlockState state, @Nonnull String componentType);
}

View file

@ -0,0 +1,100 @@
package wayoftime.bloodmagic.api;
/**
* Allows recipe addition and removal.
*/
public interface IBloodMagicRecipeRegistrar
{
// /**
// * Adds a new recipe to the Blood Altar.
// *
// * @param input An input {@link Ingredient}.
// * @param output An output {@link ItemStack}.
// * @param minimumTier The minimum Blood Altar tier required for this recipe.
// * @param syphon The amount of Life Essence to syphon from the Blood Altar
// * over the course of the craft.
// * @param consumeRate How quickly the Life Essence is syphoned.
// * @param drainRate How quickly progress is lost if the Blood Altar runs out
// * of Life Essence during the craft.
// */
// void addBloodAltar(@Nonnull Ingredient input, @Nonnull ItemStack output, @Nonnegative int minimumTier,
// @Nonnegative int syphon, @Nonnegative int consumeRate, @Nonnegative int drainRate);
//
// /**
// * Removes a Blood Altar recipe based on an input {@link ItemStack}.
// *
// * @param input The input item to remove the recipe of.
// * @return Whether or not a recipe was removed.
// */
// boolean removeBloodAltar(@Nonnull ItemStack input);
//
// /**
// * Adds a new recipe to the Alchemy Table.
// *
// * @param output An output {@link ItemStack}.
// * @param syphon The amount of Life Essence to syphon from the Blood Orb's
// * bound network over the course of the craft.
// * @param ticks The amount of ticks it takes to complete the craft.
// * @param minimumTier The minimum Blood Orb tier required for this recipe.
// * @param input An array of {@link Ingredient}s to accept as inputs.
// */
// void addAlchemyTable(@Nonnull ItemStack output, @Nonnegative int syphon, @Nonnegative int ticks,
// @Nonnegative int minimumTier, @Nonnull Ingredient... input);
//
// /**
// * Removes an Alchemy Table recipe based on an input {@link ItemStack} array.
// *
// * @param input The input items to remove the recipe of.
// * @return Whether or not a recipe was removed.
// */
// boolean removeAlchemyTable(@Nonnull ItemStack... input);
//
// /**
// * Adds a new recipe to the Soul/Tartaric Forge.
// *
// * @param output An output {@link ItemStack}.
// * @param minimumSouls The minimum number of souls that must be contained in the
// * Soul Gem.
// * @param soulDrain The number of souls to drain from the Soul Gem.
// * @param input An array of {@link Ingredient}s to accept as inputs.
// */
// void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls, @Nonnegative double soulDrain,
// @Nonnull Ingredient... input);
//
// /**
// * Removes a Soul/Tartaric Forge recipe based on an input {@link ItemStack}
// * array.
// *
// * @param input The input items to remove the recipe of.
// * @return Whether or not a recipe was removed.
// */
// boolean removeTartaricForge(@Nonnull ItemStack... input);
//
// /**
// * Adds a new recipe to the Alchemy Array.
// *
// * @param input An input {@link Ingredient}. First item put into the
// * Alchemy Array.
// * @param catalyst A catalyst {@link Ingredient}. Second item put into the
// * Alchemy Array.
// * @param output An output {@link ItemStack}.
// * @param circleTexture The texture to render for the Alchemy Array circle.
// */
// void addAlchemyArray(@Nonnull Ingredient input, @Nonnull Ingredient catalyst, @Nonnull ItemStack output,
// @Nullable ResourceLocation circleTexture);
//
// /**
// * Removes an Alchemy Array recipe based on an input {@link ItemStack} and it's
// * catalyst {@link ItemStack}.
// *
// * @param input The input item to remove the recipe of.
// * @param catalyst The catalyst item to remove the recipe of.
// * @return Whether or not a recipe was removed.
// */
// boolean removeAlchemyArray(@Nonnull ItemStack input, @Nonnull ItemStack catalyst);
//
// void addSacrificeCraft(@Nonnull ItemStack output, @Nonnegative double healthRequired, @Nonnull Ingredient... input);
//
// boolean removeSacrificeCraft(@Nonnull ItemStack... input);
}

View file

@ -0,0 +1,45 @@
package wayoftime.bloodmagic.api;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import net.minecraft.block.BlockState;
import net.minecraft.util.ResourceLocation;
/**
* Allows value modification for various features of Blood Magic such as
* Sacrificial values.
*/
public interface IBloodMagicValueManager
{
/**
* Sets the amount of LP received per health point from sacrificing the given
* entity. By default, this is 25. Setting the value to 0 effectively disables
* sacrificing.
*
* @param entityId The registry name of the entity.
* @param value The amount of LP per health point to receive upon sacrifice.
*/
void setSacrificialValue(@Nonnull ResourceLocation entityId, @Nonnegative int value);
/**
* Sets the Tranquility value of a given {@link IBlockState}.
* <p>
* Valid tranquility types:
* <ul>
* <li>PLANT</li>
* <li>CROP</li>
* <li>TREE</li>
* <li>EARTHEN</li>
* <li>WATER</li>
* <li>FIRE</li>
* <li>LAVA</li>
* </ul>
*
* @param state The {@link IBlockState} to set the value of.
* @param tranquilityType The type of Tranquility this block should provide.
* @param value The amount of tranquility this block should provide.
*/
void setTranquility(@Nonnull BlockState state, @Nonnull String tranquilityType, double value);
}

View file

@ -0,0 +1,129 @@
package wayoftime.bloodmagic.api;
import javax.annotation.Nonnull;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapedRecipe;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.registries.ForgeRegistries;
import wayoftime.bloodmagic.util.Constants;
/**
* Copied liberally from Mekanism. Thanks, pupnewfster!
*
*/
public class SerializerHelper
{
private SerializerHelper()
{
}
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
private static void validateKey(@Nonnull JsonObject json, @Nonnull String key)
{
if (!json.has(key))
{
throw new JsonSyntaxException("Missing '" + key + "', expected to find an object");
}
if (!json.get(key).isJsonObject())
{
throw new JsonSyntaxException("Expected '" + key + "' to be an object");
}
}
public static ItemStack getItemStack(@Nonnull JsonObject json, @Nonnull String key)
{
validateKey(json, key);
return ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, key));
}
public static JsonElement serializeItemStack(@Nonnull ItemStack stack)
{
JsonObject json = new JsonObject();
json.addProperty(Constants.JSON.ITEM, stack.getItem().getRegistryName().toString());
if (stack.getCount() > 1)
{
json.addProperty(Constants.JSON.COUNT, stack.getCount());
}
if (stack.hasTag())
{
json.addProperty(Constants.JSON.NBT, stack.getTag().toString());
}
return json;
}
public static FluidStack getFluidStack(@Nonnull JsonObject json, @Nonnull String key)
{
validateKey(json, key);
return deserializeFluid(JSONUtils.getJsonObject(json, key));
}
public static FluidStack deserializeFluid(@Nonnull JsonObject json)
{
if (!json.has(Constants.JSON.AMOUNT))
{
throw new JsonSyntaxException("Expected to receive a amount that is greater than zero");
}
JsonElement count = json.get(Constants.JSON.AMOUNT);
if (!JSONUtils.isNumber(count))
{
throw new JsonSyntaxException("Expected amount to be a number greater than zero.");
}
int amount = count.getAsJsonPrimitive().getAsInt();
if (amount < 1)
{
throw new JsonSyntaxException("Expected amount to be greater than zero.");
}
ResourceLocation resourceLocation = new ResourceLocation(JSONUtils.getString(json, Constants.JSON.FLUID));
Fluid fluid = ForgeRegistries.FLUIDS.getValue(resourceLocation);
if (fluid == null || fluid == Fluids.EMPTY)
{
throw new JsonSyntaxException("Invalid fluid type '" + resourceLocation + "'");
}
CompoundNBT nbt = null;
if (json.has(Constants.JSON.NBT))
{
JsonElement jsonNBT = json.get(Constants.JSON.NBT);
try
{
if (jsonNBT.isJsonObject())
{
nbt = JsonToNBT.getTagFromJson(GSON.toJson(jsonNBT));
} else
{
nbt = JsonToNBT.getTagFromJson(JSONUtils.getString(jsonNBT, Constants.JSON.NBT));
}
} catch (CommandSyntaxException e)
{
throw new JsonSyntaxException("Invalid NBT entry for fluid '" + resourceLocation + "'");
}
}
return new FluidStack(fluid, amount, nbt);
}
public static JsonElement serializeFluidStack(@Nonnull FluidStack stack)
{
JsonObject json = new JsonObject();
json.addProperty(Constants.JSON.FLUID, stack.getFluid().getRegistryName().toString());
json.addProperty(Constants.JSON.AMOUNT, stack.getAmount());
if (stack.hasTag())
{
json.addProperty(Constants.JSON.NBT, stack.getTag().toString());
}
return json;
}
}

View file

@ -10,7 +10,6 @@ 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;
@ -29,10 +28,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
Map<BlockPos, Pair<DungeonRoom, PlacementSettings>> roomMap = new HashMap<>(); // Placement positions in terms
// // of actual positions
List<Pair<BlockPos, Pair<DungeonRoom, PlacementSettings>>> roomList = new ArrayList<>();
// List<Pair<BlockPos, Pair<DungeonRoom, PlacementSettings>>> roomList = new ArrayList<>();
PlacementSettings settings = new PlacementSettings();
Mirror mir = Mirror.NONE;
@ -58,12 +57,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();
// List<Rotation> rotationInfo = new ArrayList();
int n = 1;
// int n = 1;
DungeonRoom room = getRandomRoom(rand);
// roomMap.put(pos, Pair.of(room, settings.copy()));
roomList.add(Pair.of(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())
{
@ -78,7 +77,7 @@ public class Dungeon
}
}
rotationInfo.add(settings.getRotation());
// rotationInfo.add(settings.getRotation());
// Initial AreaDescriptors and door positions are initialized. Time for fun!
for (int i = 0; i < 100; i++)
@ -133,22 +132,22 @@ public class Dungeon
}
}
// roomMap.put(roomLocation, Pair.of(testingRoom, settings.copy()));
roomList.add(Pair.of(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);
}
// 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;
}
@ -197,24 +196,24 @@ public class Dungeon
BMLog.DEBUG.info("Duration: " + duration + "(ns), " + duration / 1000000 + "(ms)");
// Building what I've got
n = 0;
// for (Entry<BlockPos, Pair<DungeonRoom, PlacementSettings>> entry : roomMap.entrySet())
for (Pair<BlockPos, Pair<DungeonRoom, PlacementSettings>> entry : roomList)
// n = 0;
for (Entry<BlockPos, Pair<DungeonRoom, PlacementSettings>> entry : roomMap.entrySet())
// for (Pair<BlockPos, Pair<DungeonRoom, PlacementSettings>> entry : roomList)
{
n++;
// 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());
// 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(roomList.size());
// System.out.println(roomList.size());
return false;
}

View file

@ -1,5 +1,5 @@
{
"dungeonWeight": 4,
"dungeonWeight": 2,
"structureMap": {
"bloodmagic:four_way_corridor": {
"x": 0,

View file

@ -1,5 +1,5 @@
{
"dungeonWeight": 8,
"dungeonWeight": 4,
"structureMap": {
"bloodmagic:ore_hold_1": {
"x": 0,

View file

@ -0,0 +1,70 @@
{
"dungeonWeight": 2,
"structureMap": {
"bloodmagic:overlapped_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": 4,
"z": 5
}
],
"east": [
{
"x": 10,
"y": 4,
"z": 5
}
]
},
"descriptorList": [
{
"minimumOffset": {
"x": 3,
"y": 0,
"z": 0
},
"maximumOffset": {
"x": 8,
"y": 5,
"z": 11
},
"blockPosCache": [],
"cache": true
},
{
"minimumOffset": {
"x": 0,
"y": 4,
"z": 3
},
"maximumOffset": {
"x": 11,
"y": 9,
"z": 8
},
"blockPosCache": [],
"cache": true
}
]
}

View file

@ -1,3 +1,7 @@
[
"bloodmagic:t_corridor"
"bloodmagic:t_corridor",
"bloodmagic:four_way_corridor_loot",
"bloodmagic:four_way_corridor",
"bloodmagic:ore_hold_1",
"bloodmagic:straight_corridor"
]

View file

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

View file

@ -1,5 +1,5 @@
{
"dungeonWeight": 4,
"dungeonWeight": 2,
"structureMap": {
"bloodmagic:straight_corridor": {
"x": 0,

View file

@ -1,5 +1,5 @@
{
"dungeonWeight": 12,
"dungeonWeight": 2,
"structureMap": {
"bloodmagic:t_corridor": {
"x": 0,