13
13
#include " Utils/Convert.h"
14
14
15
15
#include < mc/common/Brightness.h>
16
+ #include < mc/deps/core/string/HashedString.h>
16
17
17
18
using namespace Komomo ;
18
19
@@ -22,7 +23,6 @@ ClassDefine<BlockClass> blockClassBuilder =
22
23
23
24
.instanceProperty(" allowsRunes" , &BlockClass::getAllowsRunes)
24
25
.instanceProperty(" blockEntityType" , &BlockClass::getBlockEntityType)
25
- // .instanceProperty("blockState", &BlockClass::getBlockState)
26
26
.instanceProperty(" blockTintType" , &BlockClass::getBlockTintType)
27
27
.instanceProperty(" blockItemId" , &BlockClass::getBlockItemId)
28
28
.instanceProperty(" burnOdds" , &BlockClass::getBurnOdds)
@@ -80,7 +80,7 @@ ClassDefine<BlockClass> blockClassBuilder =
80
80
81
81
.InstanceFunction(addAABBs, BlockClass)
82
82
// .InstanceFunction(addCollisionShapes, BlockClass)
83
- // .InstanceFunction(addTags , BlockClass)
83
+ .InstanceFunction(addTag , BlockClass)
84
84
.InstanceFunction(allowStateMismatchOnPlacement, BlockClass)
85
85
// .InstanceFunction(asItemInstance, BlockClass)
86
86
.InstanceFunction(attack, BlockClass)
@@ -109,6 +109,7 @@ ClassDefine<BlockClass> blockClassBuilder =
109
109
// .InstanceFunction(executeItemEvent, BlockClass)
110
110
// .InstanceFunction(executeTrigger, BlockClass)
111
111
// .InstanceFunction(forEachState, BlockClass)
112
+ .InstanceFunction(getBlockState, BlockClass)
112
113
// .InstanceFunction(getClientPredictionOverride, BlockClass)
113
114
// .InstanceFunction(getCollisionShape, BlockClass)
114
115
// .InstanceFunction(getCollisionShapeForCamera, BlockClass)
@@ -126,12 +127,12 @@ ClassDefine<BlockClass> blockClassBuilder =
126
127
.InstanceFunction(getSecondPart, BlockClass)
127
128
.InstanceFunction(getVisualShape, BlockClass)
128
129
// .InstanceFunction(getVisualShapeInWorld, BlockClass)
129
- // .InstanceFunction(hasProperty, BlockClass)
130
- // .InstanceFunction(hasState, BlockClass)
130
+ .InstanceFunction(hasProperty, BlockClass)
131
+ .InstanceFunction(hasState, BlockClass)
131
132
.InstanceFunction(hasTag, BlockClass)
132
133
.InstanceFunction(ignoreEntitiesOnPistonMove, BlockClass)
133
134
.InstanceFunction(isAttachedTo, BlockClass)
134
- // .InstanceFunction(isFilteredOut, BlockClass)
135
+ .InstanceFunction(isFilteredOut, BlockClass)
135
136
.InstanceFunction(isObstructingChests, BlockClass)
136
137
.InstanceFunction(isPartialBlock, BlockClass)
137
138
.InstanceFunction(isPreservingMediumWhenPlaced, BlockClass)
@@ -145,7 +146,7 @@ ClassDefine<BlockClass> blockClassBuilder =
145
146
.InstanceFunction(neighborChanged, BlockClass)
146
147
.InstanceFunction(onExploded, BlockClass)
147
148
.InstanceFunction(onFallOn, BlockClass)
148
- // .InstanceFunction(onFertilized, BlockClass)
149
+ .InstanceFunction(onFertilized, BlockClass)
149
150
.InstanceFunction(onHitByActivatingAttack, BlockClass)
150
151
.InstanceFunction(onLightningHit, BlockClass)
151
152
.InstanceFunction(onPlace, BlockClass)
@@ -337,7 +338,16 @@ Local<Value> BlockClass::addAABBs(const Arguments& args) {
337
338
// Local<Value> BlockClass::addCollisionShapes(const Arguments& args) { CallVoidMethod(addCollisionShapes, shapes); }
338
339
339
340
// MCAPI class Block& addTag(class HashedString const& tag);
340
- // Local<Value> BlockClass::addTag(const Arguments& args) { }
341
+ Local<Value> BlockClass::addTag (const Arguments& args) {
342
+ CheckArgsCount (args, 1 );
343
+ CheckArgType (args[0 ], ValueKind::kString );
344
+ try {
345
+ if (!mBlock ) return Local<Value>();
346
+ auto tag = HashedString (args[0 ].asString ().toString ());
347
+ return BlockClass::newBlock (&mBlock ->addTag (tag));
348
+ }
349
+ Catch;
350
+ }
341
351
342
352
Local<Value> BlockClass::allowStateMismatchOnPlacement (const Arguments& args) {
343
353
CheckArgsCount (args, 1 );
@@ -611,12 +621,21 @@ Local<Value> BlockClass::entityInside(const Arguments& args) {
611
621
// ) const;
612
622
// Local<Value> BlockClass::executeItemEvent(const Arguments& args) {}
613
623
614
- // BlockState not implemented
615
624
// MCAPI void forEachState(std::function<bool(class BlockState const&, int)> callback) const;
616
625
// Local<Value> BlockClass::forEachState(const Arguments& args) {}
617
626
618
627
// MCAPI ::BlockState const* getBlockState(::HashedString const& name) const;
619
- // Local<Value> getBlockState(const Arguments& args) {}
628
+ Local<Value> BlockClass::getBlockState (const Arguments& args) {
629
+ CheckArgsCount (args, 1 );
630
+ CheckArgType (args[0 ], ValueKind::kString );
631
+ try {
632
+ if (!mBlock ) return Local<Value>();
633
+ auto name = HashedString (args[0 ].asString ().toString ());
634
+ auto result = const_cast <BlockState*>(mBlock ->getBlockState (name));
635
+ return BlockStateClass::newBlockState (result);
636
+ }
637
+ Catch;
638
+ }
620
639
621
640
// MCAPI bool getClientPredictionOverride(::BlockClientPredictionOverrides) const;
622
641
// Local<Value> getClientPredictionOverride(const Arguments& args) {}
@@ -771,23 +790,39 @@ Local<Value> BlockClass::getVisualShape(const Arguments& args) {
771
790
// getVisualShapeInWorld(::IConstBlockSource const& region, ::BlockPos const& pos, ::AABB& bufferAABB) const;
772
791
// Local<Value> BlockClass::getVisualShapeInWorld(const Arguments& args) {}
773
792
774
- // BlockProperty not implemented
775
793
// MCAPI bool hasProperty(::BlockProperty type) const;
776
- // Local<Value> BlockClass::hasProperty(const Arguments& args) {}
794
+ Local<Value> BlockClass::hasProperty (const Arguments& args) {
795
+ CheckArgsCount (args, 1 );
796
+ CheckArgType (args[0 ], ValueKind::kNumber );
797
+ try {
798
+ if (!mBlock ) return Local<Value>();
799
+ auto type = ConvertFromScriptX<BlockProperty>(args[0 ]);
800
+ return Boolean::newBoolean (mBlock ->hasProperty (type));
801
+ }
802
+ Catch;
803
+ }
804
+
777
805
778
- // BlockState not implemented
779
806
// MCAPI bool hasState(::BlockState const& stateType) const;
780
- // Local<Value> BlockClass::hasState(const Arguments& args) {}
807
+ Local<Value> BlockClass::hasState (const Arguments& args) {
808
+ CheckArgsCount (args, 1 );
809
+ CheckInstanceType (args[0 ], BlockStateClass);
810
+ try {
811
+ if (!mBlock ) return Local<Value>();
812
+ auto state = EngineScope::currentEngine ()->getNativeInstance <BlockStateClass>(args[0 ])->mBlockState ;
813
+ return Boolean::newBoolean (mBlock ->hasState (*state));
814
+ }
815
+ Catch;
816
+ }
781
817
782
- // another overload: HashedString not implemented
783
818
// MCAPI bool hasTag(::HashedString const& tagName) const;
784
819
Local<Value> BlockClass::hasTag (const Arguments& args) {
785
820
CheckArgsCount (args, 1 );
786
- CheckArgType (args[0 ], ValueKind::kNumber );
821
+ CheckArgType (args[0 ], ValueKind::kString );
787
822
try {
788
823
if (!mBlock ) return Local<Value>();
789
- auto hash = static_cast <uint64> (args[0 ].asNumber ().toInt64 ());
790
- return Boolean::newBoolean (mBlock ->hasTag (hash ));
824
+ auto tagName = HashedString (args[0 ].asString ().toString ());
825
+ return Boolean::newBoolean (mBlock ->hasTag (tagName ));
791
826
}
792
827
Catch;
793
828
}
@@ -810,9 +845,18 @@ Local<Value> BlockClass::isAttachedTo(const Arguments& args) {
810
845
Catch;
811
846
}
812
847
813
- // BlockRenderLayer not implemented
848
+
814
849
// MCAPI bool isFilteredOut(::BlockRenderLayer heldItemRenderLayer) const;
815
- // Local<Value> BlockClass::isFaceSturdy(const Arguments& args) {}
850
+ Local<Value> BlockClass::isFilteredOut (const Arguments& args) {
851
+ CheckArgsCount (args, 1 );
852
+ CheckArgType (args[0 ], ValueKind::kNumber );
853
+ try {
854
+ if (!mBlock ) return Local<Value>();
855
+ auto heldItemRenderLayer = ConvertFromScriptX<BlockRenderLayer>(args[0 ]);
856
+ return Boolean::newBoolean (mBlock ->isFilteredOut (heldItemRenderLayer));
857
+ }
858
+ Catch;
859
+ }
816
860
817
861
Local<Value> BlockClass::isObstructingChests (const Arguments& args) {
818
862
CheckArgsCount (args, 2 );
@@ -1012,10 +1056,25 @@ Local<Value> BlockClass::onFallOn(const Arguments& args) {
1012
1056
CatchReturn (Boolean::newBoolean (false ));
1013
1057
}
1014
1058
1015
- // FertilizerType not implemented
1016
1059
// MCAPI bool
1017
1060
// onFertilized(::BlockSource& region, ::BlockPos const& pos, ::Actor* entity, ::FertilizerType fType) const;
1018
- // Local<Value> BlockClass::onFertilized(const Arguments& args) {}
1061
+ Local<Value> BlockClass::onFertilized (const Arguments& args) {
1062
+ CheckArgsCount (args, 4 );
1063
+ CheckInstanceType (args[0 ], BlockSourceClass);
1064
+ CheckInstanceType (args[1 ], BlockPosClass);
1065
+ CheckInstanceType (args[2 ], ActorClass);
1066
+ CheckArgType (args[3 ], ValueKind::kNumber );
1067
+ try {
1068
+ if (!mBlock ) return Local<Value>();
1069
+ auto engine = EngineScope::currentEngine ();
1070
+ auto region = engine->getNativeInstance <BlockSourceClass>(args[0 ])->mBlockSource ;
1071
+ auto pos = engine->getNativeInstance <BlockPosClass>(args[1 ])->mBlockPos ;
1072
+ auto entity = engine->getNativeInstance <ActorClass>(args[2 ])->mActor ;
1073
+ auto fertilizerId = ConvertFromScriptX<FertilizerType>(args[3 ]);
1074
+ return Boolean::newBoolean (mBlock ->onFertilized (*region, pos, entity, fertilizerId));
1075
+ }
1076
+ Catch;
1077
+ }
1019
1078
1020
1079
Local<Value> BlockClass::onHitByActivatingAttack (const Arguments& args) {
1021
1080
CheckArgsCountReturn (args, 3 , Boolean::newBoolean (false ));
0 commit comments