Skip to content

Commit

Permalink
Updated block subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
SmokeyStack committed Jul 15, 2024
1 parent c98e327 commit 7f7d2ea
Show file tree
Hide file tree
Showing 22 changed files with 453 additions and 407 deletions.
24 changes: 4 additions & 20 deletions adk/data/include/block/block_experience_dropping.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#pragma once

#include <string>

#include "block/block.h"
#include "block/block_component.h"
#include "block/block_property.h"
#include "json.hpp"
#include "shared_construct.h"
#include "component/custom.h"
#include "component/tag.h"

namespace adk {
/**
Expand All @@ -18,12 +14,8 @@ namespace adk {
* @brief Construct a new Experience Dropping Block object
*
* @param experienced_dropped Amount of experience dropped
*
* @param property BlockProperty
*/
BlockExperienceDropping(int experienced_dropped, BlockProperty property) : Block(property) {
experienced_dropped_ = experienced_dropped;
}
BlockExperienceDropping(int experienced_dropped) : experienced_dropped_(experienced_dropped) {}

/**
* @brief Generates the json object
Expand All @@ -34,15 +26,7 @@ namespace adk {
*
* @return nlohmann::json
*/
nlohmann::json Generate(std::string mod_id, std::string id) {
output_ = Block::Generate(mod_id, id);

output_["minecraft:block"]["components"] = UpdateCustomComponents(output_["minecraft:block"]["components"], { "adk-lib:on_player_destroy_drop_experience" });
std::string tag = "adk-lib:drop_experience_" + std::to_string(experienced_dropped_);
output_["minecraft:block"]["components"]["tag:" + tag] = nlohmann::json::object();

return output_;
}
nlohmann::json Generate(std::string mod_id, std::string id) override;
private:
int experienced_dropped_;
};
Expand Down
29 changes: 2 additions & 27 deletions adk/data/include/block/block_flower.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#pragma once

#include <string>

#include "block/block_component.h"
#include "block/block_plant.h"
#include "block/block_property.h"
#include "json.hpp"

namespace adk {
/**
Expand All @@ -15,10 +10,8 @@ namespace adk {
public:
/**
* @brief Construct a new Flower Block object
*
* @param property BlockProperty
*/
BlockFlower(BlockProperty property) : BlockPlant(property) {}
BlockFlower() {}

/**
* @brief Generates the json object
Expand All @@ -29,24 +22,6 @@ namespace adk {
*
* @return nlohmann::json
*/
nlohmann::json Generate(std::string mod_id, std::string id) {
output_ = BlockPlant::Generate(mod_id, id);

output_["minecraft:block"]["components"].update(
helper_.Translation(std::vector<double>{0.0, -0.0625, 0.0})
);
output_["minecraft:block"]["components"].update(
helper_.BoxCollision(false)
);
output_["minecraft:block"]["components"].update(
helper_.BoxSelection(
std::vector<int>{-3, 0, -3},
std::vector<int>{6, 10, 6},
id
)
);

return output_;
}
nlohmann::json Generate(std::string mod_id, std::string id) override;
};
} // namespace adk
68 changes: 2 additions & 66 deletions adk/data/include/block/block_ladder.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#pragma once

#include <string>

#include "block/block.h"
#include "block/block_component.h"
#include "block/block_property.h"
#include "json.hpp"

namespace adk {
/**
Expand All @@ -15,11 +10,8 @@ namespace adk {
public:
/**
* @brief Construct a new Ladder Block object
*
* @param property BlockProperty
*/
BlockLadder(BlockProperty property) : Block(property) {}

BlockLadder() {}
/**
* @brief Generates the json object
*
Expand All @@ -29,62 +21,6 @@ namespace adk {
*
* @return nlohmann::json
*/
nlohmann::json Generate(std::string mod_id, std::string id) {
output_ = Block::Generate(mod_id, id);

output_["minecraft:block"]["description"]["traits"]["minecraft:placement_position"]["enabled_states"] = { "minecraft:block_face" };
nlohmann::json::object_t temp = {
{"condition",
"q.block_state('minecraft:block_face') == 'north'"} };
temp["components"].update(
helper_.Rotation(
std::vector<int>{0, 0, 0},
id
)
);
output_["minecraft:block"]["permutations"].push_back(temp);
temp = {
{"condition",
"q.block_state('minecraft:block_face') == 'east'"} };
temp["components"].update(
helper_.Rotation(
std::vector<int>{0, 270, 0},
id
)
);
output_["minecraft:block"]["permutations"].push_back(temp);
temp = {
{"condition",
"q.block_state('minecraft:block_face') == 'south'"} };
temp["components"].update(
helper_.Rotation(
std::vector<int>{0, 180, 0},
id
)
);
output_["minecraft:block"]["permutations"].push_back(temp);
temp = {
{"condition",
"q.block_state('minecraft:block_face') == 'west'"} };
temp["components"].update(
helper_.Rotation(
std::vector<int>{0, 90, 0},
id
)
);
output_["minecraft:block"]["permutations"].push_back(temp);
output_["minecraft:block"]["components"].update(
helper_.BoxCollision(false)
);
output_["minecraft:block"]["components"].update(
helper_.BoxSelection(
std::vector<int>{8, 0, 8},
std::vector<int>{-16, 16, -3},
id
)
);

return output_;
}
nlohmann::json Generate(std::string mod_id, std::string id);
};
} // namespace adk
28 changes: 3 additions & 25 deletions adk/data/include/block/block_mushroom.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
#pragma once

#include <string>

#include "block/block_component.h"
#include "block/block_plant.h"
#include "block/block_property.h"
#include "json.hpp"

namespace adk {
/**
* @brief Represents a Mushroom Block
*/
class BlockMushroom: public BlockPlant {
class BlockMushroom : public BlockPlant {
public:
/**
* @brief Construct a new Mushroom Block object
*
* @param property BlockProperty
*/
BlockMushroom(BlockProperty property) : BlockPlant(property) {}
BlockMushroom() {}

/**
* @brief Generates the json object
Expand All @@ -29,21 +22,6 @@ namespace adk {
*
* @return nlohmann::json
*/
nlohmann::json Generate(std::string mod_id, std::string id) {
output_ = BlockPlant::Generate(mod_id, id);

output_["minecraft:block"]["components"].update(
helper_.BoxCollision(false)
);
output_["minecraft:block"]["components"].update(
helper_.BoxSelection(
std::vector<int>{-3, 0, -3},
std::vector<int>{6, 6, 6},
id
)
);

return output_;
}
nlohmann::json Generate(std::string mod_id, std::string id) override;
};
} // namespace adk
37 changes: 2 additions & 35 deletions adk/data/include/block/block_pillar.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#pragma once

#include <string>

#include "block/block.h"
#include "block/block_component.h"
#include "block/block_property.h"
#include "json.hpp"

namespace adk {
/**
Expand All @@ -15,10 +10,8 @@ namespace adk {
public:
/**
* @brief Construct a new Pillar Block object
*
* @param property BlockProperty
*/
BlockPillar(BlockProperty property) : Block(property) {}
BlockPillar() {}

/**
* @brief Generates the json object
Expand All @@ -29,32 +22,6 @@ namespace adk {
*
* @return nlohmann::json
*/
nlohmann::json Generate(std::string mod_id, std::string id) {
output_ = Block::Generate(mod_id, id);

output_["minecraft:block"]["description"]["traits"]["minecraft:placement_position"]["enabled_states"] = { "minecraft:block_face" };
nlohmann::json::object_t temp = {
{"condition",
"q.block_state('minecraft:block_face') == 'north' || q.block_state('minecraft:block_face') == 'south'"} };
temp["components"].update(
helper_.Rotation(
std::vector<int>{90, 0, 0},
id
)
);
output_["minecraft:block"]["permutations"].push_back(temp);
temp = {
{"condition",
"q.block_state('minecraft:block_face') == 'east' || q.block_state('minecraft:block_face') == 'west'"} };
temp["components"].update(
helper_.Rotation(
std::vector<int>{0, 0, 270},
id
)
);
output_["minecraft:block"]["permutations"].push_back(temp);

return output_;
}
nlohmann::json Generate(std::string mod_id, std::string id) override;
};
} // namespace adk
27 changes: 2 additions & 25 deletions adk/data/include/block/block_plant.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
#pragma once

#include <string>

#include "block/block.h"
#include "block/block_component.h"
#include "block/block_property.h"
#include "json.hpp"
#include "shared_construct.h"

namespace adk {
/**
* @brief Represents a Plant Block
*/
class BlockPlant : public Block {
public:
BlockPlant() {};
/**
* @brief Construct a new Plant Block object
*
* @param property BlockProperty
*/
BlockPlant(BlockProperty property) : Block(property) {}
BlockPlant() {}

/**
* @brief Generates the json object
Expand All @@ -31,20 +22,6 @@ namespace adk {
*
* @return nlohmann::json
*/
nlohmann::json Generate(std::string mod_id, std::string id) {
output_ = Block::Generate(mod_id, id);

BlockPlacementFilter filter;
filter.allowed_faces.push_back(BlockAllowedFaces::UP);
BlockDescriptor block_descriptor;
block_descriptor.tags = { "dirt", "farmland" };
filter.block_filter.push_back(block_descriptor);

output_["minecraft:block"]["components"].update(
helper_.PlacementFilter(filter)
);

return output_;
}
nlohmann::json Generate(std::string mod_id, std::string id) override;
};
} // namespace adk
Loading

0 comments on commit 7f7d2ea

Please sign in to comment.