Additional APIs
All checks were successful
ScriptCraft/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-04-26 18:07:01 -04:00
parent d73e2bc1af
commit 7adfaa0119
4 changed files with 59 additions and 3 deletions

View File

@ -30,5 +30,8 @@ class ItemStackBridges {
((ItemStack) args[0]).setTag((CompoundTag) args[1]); ((ItemStack) args[0]).setTag((CompoundTag) args[1]);
return null; return null;
}); });
Bridges.addBridge("ItemStack.toTag", args -> ((ItemStack) args[0]).toTag(new CompoundTag()));
Bridges.addBridge("ItemStack.fromTag", args -> ItemStack.fromTag((CompoundTag) args[1]));
} }
} }

View File

@ -9,6 +9,8 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.Objects;
class WorldBridges { class WorldBridges {
static void register() { static void register() {
Bridges.addBridge("World.getBlockState", args -> ((World) args[0]).getBlockState(new BlockPos((double) args[1], (double) args[2], (double) args[3]))); Bridges.addBridge("World.getBlockState", args -> ((World) args[0]).getBlockState(new BlockPos((double) args[1], (double) args[2], (double) args[3])));
@ -34,5 +36,16 @@ class WorldBridges {
} }
return null; return null;
}); });
Bridges.addBridge("World.getBlockEntity", args -> {
World world = (World) args[0];
BlockPos pos = new BlockPos(Util.toDouble(args[1], 0), Util.toDouble(args[2], 0), Util.toDouble(args[3], 0));
BlockEntity entity = world.getBlockEntity(pos);
if (entity != null) {
return Objects.requireNonNull(Registry.BLOCK_ENTITY_TYPE.getId(entity.getType())).toString();
} else {
return null;
}
});
} }
} }

View File

@ -114,6 +114,33 @@ export class ItemStack {
setTag(tag: CompoundTag) { setTag(tag: CompoundTag) {
useBridge('ItemStack.setTag', this.javaObject, tag.javaObject); useBridge('ItemStack.setTag', this.javaObject, tag.javaObject);
} }
/**
* Convert To Tag
* @returns Item Tag
*/
toTag(): CompoundTag {
const obj = useBridge('ItemStack.toTag', this.javaObject) as JavaObject;
if (obj) {
return new CompoundTag(obj);
} else {
return null;
}
}
/**
* Create From Tag
* @param tag Item Tag
* @returns Item Stack
*/
static fromTag(tag: CompoundTag): ItemStack {
const obj = useBridge('ItemStack.fromTag', tag.javaObject) as JavaObject;
if (obj) {
return new ItemStack(obj);
} else {
return null;
}
}
} }
/** /**

View File

@ -57,10 +57,9 @@ export class World {
} }
/** /**
* Get All Custom Block Entities * @internal
* @returns All Custom Block Entities
*/ */
getCustomBlockEntities(): CustomBlockEntity[] { private getCustomBlockEntities(): CustomBlockEntity[] {
return BlockRegistry.INSTANCE.getBlockEntities(); return BlockRegistry.INSTANCE.getBlockEntities();
} }
@ -78,4 +77,18 @@ export class World {
} }
return null; return null;
} }
/**
* Get Block Entity ID At Position
* @param pos Position
* @returns Block Entity ID At Position
*/
getBlockEntity(pos: Pos): Identifier {
const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as string;
if (obj) {
return new Identifier(obj);
} else {
return null;
}
}
} }