This commit is contained in:
parent
d73e2bc1af
commit
7adfaa0119
@ -30,5 +30,8 @@ class ItemStackBridges {
|
||||
((ItemStack) args[0]).setTag((CompoundTag) args[1]);
|
||||
return null;
|
||||
});
|
||||
|
||||
Bridges.addBridge("ItemStack.toTag", args -> ((ItemStack) args[0]).toTag(new CompoundTag()));
|
||||
Bridges.addBridge("ItemStack.fromTag", args -> ItemStack.fromTag((CompoundTag) args[1]));
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
class WorldBridges {
|
||||
static void register() {
|
||||
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;
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +114,33 @@ export class ItemStack {
|
||||
setTag(tag: CompoundTag) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,10 +57,9 @@ export class World {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All Custom Block Entities
|
||||
* @returns All Custom Block Entities
|
||||
* @internal
|
||||
*/
|
||||
getCustomBlockEntities(): CustomBlockEntity[] {
|
||||
private getCustomBlockEntities(): CustomBlockEntity[] {
|
||||
return BlockRegistry.INSTANCE.getBlockEntities();
|
||||
}
|
||||
|
||||
@ -78,4 +77,18 @@ export class World {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user