Compare commits
No commits in common. "624193103e870f8b5bab037c0d93043128b95ec4" and "fa825173f92c7f48bd4fa1885e4ebb43dbfd2260" have entirely different histories.
624193103e
...
fa825173f9
@ -3,13 +3,11 @@
|
||||
## Create Your Block Class
|
||||
JavaScript:
|
||||
```javascript
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlock, BuiltinRegistry } from 'minecraft';
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlock } from 'minecraft';
|
||||
|
||||
class MyBlock extends CustomBlock {
|
||||
constructor() {
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
}
|
||||
|
||||
onUse(world, blockState, blockPos, side, player, hand) {
|
||||
@ -21,13 +19,11 @@ class MyBlock extends CustomBlock {
|
||||
|
||||
TypeScript:
|
||||
```typescript
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock, BuiltinRegistry } from 'minecraft';
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock } from 'minecraft';
|
||||
|
||||
class MyBlock extends CustomBlock {
|
||||
constructor() {
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
}
|
||||
|
||||
onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
@ -49,4 +45,4 @@ Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlo
|
||||
import { Registry, Identifier, BlockItem, ItemSettings } from 'minecraft';
|
||||
|
||||
Registry.register(Registry.ITEM, new Identifier('modid', 'my_block'), new BlockItem(new Identifier('modid', 'my_block'), new ItemSettings().setItemGroup('building_blocks')));
|
||||
```
|
||||
```
|
@ -63,13 +63,11 @@ class MyBlockEntity extends CustomBlockEntity {
|
||||
## Create Your Block Class
|
||||
JavaScript:
|
||||
```javascript
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlockWithEntity, BuiltinRegistry } from 'minecraft';
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlockWithEntity } from 'minecraft';
|
||||
|
||||
class MyBlock extends CustomBlockWithEntity {
|
||||
constructor() {
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
}
|
||||
|
||||
onUse(world, blockState, blockPos, side, player, hand) {
|
||||
@ -85,13 +83,11 @@ class MyBlock extends CustomBlockWithEntity {
|
||||
|
||||
TypeScript:
|
||||
```typescript
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock, BuiltinRegistry } from 'minecraft';
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock } from 'minecraft';
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
|
||||
class MyBlock extends CustomBlockWithEntity {
|
||||
class MyBlock extends CustomBlock {
|
||||
constructor() {
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
}
|
||||
|
||||
onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
@ -113,4 +109,4 @@ Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlo
|
||||
import { Registry, Identifier, BlockItem, ItemSettings } from 'minecraft';
|
||||
|
||||
Registry.register(Registry.ITEM, new Identifier('modid', 'my_block'), new BlockItem(new Identifier('modid', 'my_block'), new ItemSettings().setItemGroup('building_blocks')));
|
||||
```
|
||||
```
|
@ -3,9 +3,9 @@ org.gradle.jvmargs = -Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version = 1.16.2
|
||||
yarn_build = 21
|
||||
fabric_loader_version = 0.9.2+build.206
|
||||
minecraft_version = 1.16-pre3
|
||||
yarn_build = 1
|
||||
fabric_loader_version = 0.8.7+build.201
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
|
@ -1,12 +1,36 @@
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, BlockItem, ItemSettings, BuiltinRegistry } from 'minecraft';
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, BlockItem, ItemSettings, CustomItem, CustomBlockWithEntity, CustomBlockEntity, CompoundTag, NumberType } from 'minecraft';
|
||||
|
||||
console.log('hello');
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
class MyBlockEntity extends CustomBlockEntity {
|
||||
constructor() {
|
||||
super();
|
||||
this.ticks = 0;
|
||||
}
|
||||
|
||||
toTag(tag) {
|
||||
tag.set('MyTicks', this.ticks, NumberType.INT);
|
||||
return tag;
|
||||
}
|
||||
|
||||
fromTag(tag) {
|
||||
const obj = tag.get('MyTicks');
|
||||
if (typeof obj === 'number') {
|
||||
this.ticks = obj;
|
||||
} else {
|
||||
this.ticks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
tick() {
|
||||
this.ticks++;
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
class MyBlock extends CustomBlockWithEntity {
|
||||
constructor() {
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
}
|
||||
|
||||
onUse(world, blockState, blockPos, side, player, hand) {
|
||||
@ -25,3 +49,28 @@ class MyBlock extends CustomBlockWithEntity {
|
||||
|
||||
Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlock());
|
||||
Registry.register(Registry.ITEM, new Identifier('modid', 'my_block'), new BlockItem(new Identifier('modid', 'my_block'), new ItemSettings()));
|
||||
|
||||
class MyItem extends CustomItem {
|
||||
constructor() {
|
||||
super(new ItemSettings().setItemGroup('building_blocks').setMaxCount(128));
|
||||
}
|
||||
|
||||
onUse(world, player, hand) {
|
||||
console.log('Item Use: Normal');
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
onUseOnBlock(world, blockPos, side, player, hand) {
|
||||
console.log('Item Use: Block ' + blockPos.toString());
|
||||
world.spawnEntity(new Identifier('minecraft:cow'), blockPos.offset(side).add(new Pos(0.5, 0, 0.5))).toString();
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
onUseOnEntity(player, target, hand) {
|
||||
console.log('Item Use: Entity ' + target.toTag().toString());
|
||||
console.log('Health: ' + target.toTag().get('Health').toString());
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Registry.register(Registry.ITEM, new Identifier('modid', 'my_item'), new MyItem());
|
||||
|
@ -17,10 +17,9 @@ minecraft {
|
||||
}
|
||||
|
||||
repositories {
|
||||
//maven {
|
||||
// url = uri("https://maven.thebrokenrail.com/")
|
||||
//}
|
||||
mavenLocal()
|
||||
maven {
|
||||
url = uri("https://maven.thebrokenrail.com/")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -3,9 +3,9 @@ org.gradle.jvmargs = -Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version = 1.16.2
|
||||
yarn_build = 21
|
||||
fabric_loader_version = 0.9.2+build.206
|
||||
minecraft_version = 1.16-pre3
|
||||
yarn_build = 1
|
||||
fabric_loader_version = 0.8.7+build.201
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
|
@ -1,12 +1,33 @@
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, Direction, BuiltinRegistry } from 'minecraft';
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, CustomItem, Direction, LivingEntity, CustomBlockWithEntity, CustomBlockEntity, CompoundTag, NumberType } from 'minecraft';
|
||||
|
||||
console.log('hello');
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
class MyBlockEntity extends CustomBlockEntity {
|
||||
ticks = 0;
|
||||
|
||||
toTag(tag: CompoundTag): CompoundTag {
|
||||
tag.set('MyTicks', this.ticks, NumberType.INT);
|
||||
return tag;
|
||||
}
|
||||
|
||||
fromTag(tag: CompoundTag): void {
|
||||
const obj = tag.get('MyTicks');
|
||||
if (typeof obj === 'number') {
|
||||
this.ticks = obj;
|
||||
} else {
|
||||
this.ticks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
tick(): void {
|
||||
this.ticks++;
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
class MyBlock extends CustomBlockWithEntity {
|
||||
constructor() {
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
}
|
||||
|
||||
onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
@ -25,3 +46,28 @@ class MyBlock extends CustomBlockWithEntity {
|
||||
|
||||
Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlock());
|
||||
Registry.register(Registry.ITEM, new Identifier('modid', 'my_block'), new BlockItem(new Identifier('modid', 'my_block'), new ItemSettings()));
|
||||
|
||||
class MyItem extends CustomItem {
|
||||
constructor() {
|
||||
super(new ItemSettings().setItemGroup('building_blocks').setMaxCount(128));
|
||||
}
|
||||
|
||||
onUse(world: World, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
console.log('Item Use: Normal');
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
onUseOnBlock(world: World, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
console.log('Item Use: Block ' + blockPos.toString());
|
||||
world.spawnEntity(new Identifier('minecraft:cow'), blockPos.offset(side).add(new Pos(0.5, 0, 0.5))).toString();
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand): ActionResult {
|
||||
console.log('Item Use: Entity ' + target.toTag().toString());
|
||||
console.log('Health: ' + target.toTag().get('Health').toString());
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Registry.register(Registry.ITEM, new Identifier('modid', 'my_item'), new MyItem());
|
||||
|
@ -3,9 +3,9 @@ org.gradle.jvmargs = -Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version = 1.16.2
|
||||
yarn_build = 21
|
||||
fabric_loader_version = 0.9.2+build.206
|
||||
minecraft_version = 1.16-pre3
|
||||
yarn_build = 1
|
||||
fabric_loader_version = 0.8.7+build.201
|
||||
|
||||
# Mod Properties
|
||||
maven_group = com.thebrokenrail
|
||||
@ -13,4 +13,4 @@ org.gradle.jvmargs = -Xmx1G
|
||||
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_api_version = 0.19.0+build.398-1.16
|
||||
fabric_api_version = 0.11.8+build.357-1.16
|
||||
|
@ -1,13 +0,0 @@
|
||||
package com.thebrokenrail.scriptcraft.api.bridge;
|
||||
|
||||
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Material;
|
||||
|
||||
class BlockBridges {
|
||||
static void register() {
|
||||
ScriptCraftCore.addBridge("Block.getMaterial", args -> ((Block) args[0]).getDefaultState().getMaterial());
|
||||
ScriptCraftCore.addBridge("Block.getMaterialColor", args -> ((Block) args[0]).getDefaultState().getTopMaterialColor(null, null));
|
||||
ScriptCraftCore.addBridge("Block.isValid", args -> args[0] instanceof Block);
|
||||
}
|
||||
}
|
@ -10,14 +10,26 @@ import java.util.Locale;
|
||||
class BlockSettingsBridges {
|
||||
static void register() {
|
||||
ScriptCraftCore.addBridge("BlockSettings.create", args -> {
|
||||
Material material = (Material) args[0];
|
||||
MaterialColor materialColor = (MaterialColor) args[1];
|
||||
try {
|
||||
String materialID = ((String) args[0]).toUpperCase(Locale.ROOT);
|
||||
Material material = (Material) Material.class.getField(materialID).get(null);
|
||||
|
||||
AbstractBlock.Settings settings = AbstractBlock.Settings.of(material, materialColor);
|
||||
MaterialColor materialColor;
|
||||
if (args[1] != null) {
|
||||
String materialColorID = ((String) args[1]).toUpperCase(Locale.ROOT);
|
||||
materialColor = (MaterialColor) MaterialColor.class.getField(materialColorID).get(null);
|
||||
} else {
|
||||
materialColor = material.getColor();
|
||||
}
|
||||
|
||||
settings.strength(((Double) args[2]).floatValue(), ((Double) args[3]).floatValue());
|
||||
AbstractBlock.Settings settings = AbstractBlock.Settings.of(material, materialColor);
|
||||
|
||||
return settings;
|
||||
settings.strength(((Double) args[2]).floatValue(), ((Double) args[3]).floatValue());
|
||||
|
||||
return settings;
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.thebrokenrail.scriptcraft.api.bridge;
|
||||
public class Bridges {
|
||||
public static void init() {
|
||||
BlockSettingsBridges.register();
|
||||
RegistryBridges.register();
|
||||
RegistryBridge.register();
|
||||
ItemStackBridges.register();
|
||||
LivingEntityBridges.register();
|
||||
BlockStateBridges.register();
|
||||
@ -16,9 +16,5 @@ public class Bridges {
|
||||
PlayerEntityBridges.register();
|
||||
BlockEntityBridges.register();
|
||||
EventBridges.register();
|
||||
MaterialBridges.register();
|
||||
MaterialColorBridges.register();
|
||||
BlockBridges.register();
|
||||
BuiltinRegistryBridges.register();
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
package com.thebrokenrail.scriptcraft.api.bridge;
|
||||
|
||||
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
class BuiltinRegistryBridges {
|
||||
static void register() {
|
||||
ScriptCraftCore.addBridge("BuiltinRegistry.getBlock", args -> Registry.BLOCK.get(new Identifier((String) args[0])));
|
||||
}
|
||||
}
|
@ -5,15 +5,21 @@ import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
class DamageSourceBridges {
|
||||
static void register() {
|
||||
ScriptCraftCore.addBridge("DamageSource.getGeneric", args -> DamageSource.GENERIC);
|
||||
ScriptCraftCore.addBridge("DamageSource.getOutOfWorld", args -> DamageSource.OUT_OF_WORLD);
|
||||
ScriptCraftCore.addBridge("DamageSource.create", args -> {
|
||||
try {
|
||||
String id = ((String) args[0]).toUpperCase(Locale.ROOT);
|
||||
return DamageSource.class.getField(id).get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
ScriptCraftCore.addBridge("DamageSource.createFromExplosion", args -> DamageSource.explosion((LivingEntity) args[0]));
|
||||
|
||||
ScriptCraftCore.addBridge("DamageSource.createFromPlayer", args -> DamageSource.player((PlayerEntity) args[0]));
|
||||
ScriptCraftCore.addBridge("DamageSource.createFromMob", args -> DamageSource.mob((LivingEntity) args[0]));
|
||||
ScriptCraftCore.addBridge("DamageSource.createFromPlayer", args -> DamageSource.player((PlayerEntity) args[1]));
|
||||
ScriptCraftCore.addBridge("DamageSource.createFromMob", args -> DamageSource.mob((LivingEntity) args[1]));
|
||||
|
||||
ScriptCraftCore.addBridge("DamageSource.isValid", args -> args[0] instanceof DamageSource);
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
package com.thebrokenrail.scriptcraft.api.bridge;
|
||||
|
||||
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
|
||||
import net.minecraft.block.Material;
|
||||
|
||||
class MaterialBridges {
|
||||
static void register() {
|
||||
ScriptCraftCore.addBridge("Material.getColor", args -> ((Material) args[0]).getColor());
|
||||
ScriptCraftCore.addBridge("Material.isValid", args -> args[0] instanceof Material);
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.thebrokenrail.scriptcraft.api.bridge;
|
||||
|
||||
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
|
||||
class MaterialColorBridges {
|
||||
static void register() {
|
||||
ScriptCraftCore.addBridge("MaterialColor.isValid", args -> args[0] instanceof MaterialColor);
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
class RegistryBridges {
|
||||
class RegistryBridge {
|
||||
static void register() {
|
||||
ScriptCraftCore.addBridge("Registry.registerBlock", args -> {
|
||||
Registry.register(Registry.BLOCK, new Identifier((String) args[0]), new CustomBlock((Block.Settings) args[1], new Identifier((String) args[0])));
|
@ -1,57 +1,16 @@
|
||||
import { World } from './world';
|
||||
import { PlayerEntity } from './entity';
|
||||
import { Identifier, Hand, Pos, ActionResult, Direction, SimpleRegistry, JavaObjectWrapper, SimpleBuiltinRegistry } from './core';
|
||||
import { Identifier, Hand, Pos, ActionResult, Direction, SimpleRegistry, JavaObjectWrapper } from './core';
|
||||
import { CompoundTag } from './tag';
|
||||
import { useBridge, addBridge } from 'scriptcraft-core';
|
||||
import { Inventory } from './inventory';
|
||||
|
||||
/**
|
||||
* Block Material
|
||||
*/
|
||||
class Material extends JavaObjectWrapper {
|
||||
/**
|
||||
* Create Material Wrapper From Java Object
|
||||
* @param javaObject Java Object
|
||||
*/
|
||||
constructor(javaObject: JavaObject | JavaObjectWrapper) {
|
||||
super(javaObject);
|
||||
this.assertValidJavaObject('Material');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Associated Material Color
|
||||
* @returns Material Color
|
||||
*/
|
||||
getColor(): MaterialColor {
|
||||
const obj = useBridge('Material.getColor', this.getJavaObject()) as JavaObject;
|
||||
if (obj) {
|
||||
return new MaterialColor(obj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Block Material Color
|
||||
*/
|
||||
class MaterialColor extends JavaObjectWrapper {
|
||||
/**
|
||||
* Create Material Color Wrapper From Java Object
|
||||
* @param javaObject Java Object
|
||||
*/
|
||||
constructor(javaObject: JavaObject | JavaObjectWrapper) {
|
||||
super(javaObject);
|
||||
this.assertValidJavaObject('MaterialColor');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings for {@link CustomBlock}
|
||||
*/
|
||||
export class BlockSettings {
|
||||
#material: Material;
|
||||
#materialColor: MaterialColor;
|
||||
#material: string;
|
||||
#materialColor: string;
|
||||
|
||||
#resistance: number;
|
||||
#hardness: number;
|
||||
@ -61,11 +20,11 @@ export class BlockSettings {
|
||||
* @param material Material
|
||||
* @param materialColor Material Color
|
||||
*/
|
||||
constructor(material: Material);
|
||||
constructor(material: Material, materialColor: MaterialColor);
|
||||
constructor(material: Material, materialColor?: MaterialColor) {
|
||||
constructor(material: string);
|
||||
constructor(material: string, materialColor: string);
|
||||
constructor(material: string, materialColor?: string) {
|
||||
this.#material = material;
|
||||
this.#materialColor = materialColor !== null ? materialColor : material.getColor();
|
||||
this.#materialColor = materialColor;
|
||||
|
||||
this.#resistance = 0;
|
||||
this.#hardness = 0;
|
||||
@ -104,7 +63,7 @@ export class BlockSettings {
|
||||
* Get Material
|
||||
* @returns Material
|
||||
*/
|
||||
getMaterial(): Material {
|
||||
getMaterial(): string {
|
||||
return this.#material;
|
||||
}
|
||||
|
||||
@ -112,7 +71,7 @@ export class BlockSettings {
|
||||
* Set Material
|
||||
* @param material Material
|
||||
*/
|
||||
setMaterial(material: Material): BlockSettings {
|
||||
setMaterial(material: string): BlockSettings {
|
||||
this.#material = material;
|
||||
return this;
|
||||
}
|
||||
@ -121,7 +80,7 @@ export class BlockSettings {
|
||||
* Set Material Color
|
||||
* @param materialColor Material Color
|
||||
*/
|
||||
setMaterialColor(materialColor: MaterialColor): BlockSettings {
|
||||
setMaterialColor(materialColor: string): BlockSettings {
|
||||
this.#materialColor = materialColor;
|
||||
return this;
|
||||
}
|
||||
@ -130,7 +89,7 @@ export class BlockSettings {
|
||||
* Get Material Color
|
||||
* @returns Material Color
|
||||
*/
|
||||
getMaterialColor(): MaterialColor {
|
||||
getMaterialColor(): string {
|
||||
return this.#materialColor;
|
||||
}
|
||||
|
||||
@ -155,7 +114,7 @@ export class BlockSettings {
|
||||
* @returns Java Object
|
||||
*/
|
||||
createJavaObject(): JavaObject {
|
||||
return useBridge('BlockSettings.create', this.getMaterial().getJavaObject(), this.getMaterialColor().getJavaObject(), this.getHardness(), this.getResistance()) as JavaObject;
|
||||
return useBridge('BlockSettings.create', this.getMaterial(), this.getMaterialColor(), this.getHardness(), this.getResistance()) as JavaObject;
|
||||
}
|
||||
}
|
||||
|
||||
@ -378,44 +337,6 @@ export class CustomBlockWithEntity extends CustomBlock {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Built-In Block
|
||||
*/
|
||||
export class Block extends JavaObjectWrapper {
|
||||
/**
|
||||
* Create Built-In Block Wrapper From Java Object
|
||||
* @param javaObject Java Object
|
||||
*/
|
||||
constructor(javaObject: JavaObject | JavaObjectWrapper) {
|
||||
super(javaObject);
|
||||
this.assertValidJavaObject('Block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Block Material
|
||||
*/
|
||||
getMaterial(): Material {
|
||||
const obj = useBridge('Block.getMaterial', this.getJavaObject()) as JavaObject;
|
||||
if (obj) {
|
||||
return new Material(obj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Block MaterialColor
|
||||
*/
|
||||
getMaterialColor(): MaterialColor {
|
||||
const obj = useBridge('Block.getMaterialColor', this.getJavaObject()) as JavaObject;
|
||||
if (obj) {
|
||||
return new MaterialColor(obj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@ -498,22 +419,3 @@ addBridge('CustomBlockEntity.free', (i: number) => {
|
||||
addBridge('CustomBlock.onUse', (id: string, world: JavaObject, state: JavaObject, x: number, y: number, z: number, side: keyof typeof Direction, player: JavaObject, hand: keyof typeof Hand): string => {
|
||||
return BlockRegistry.INSTANCE.get(new Identifier(id)).onUse(new World(world), new BlockState(state), new Pos(x, y, z), Direction[side], new PlayerEntity(player), Hand[hand]);
|
||||
});
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export class BlockBuiltinRegistry implements SimpleBuiltinRegistry<Block> {
|
||||
static readonly INSTANCE = new BlockBuiltinRegistry();
|
||||
|
||||
private constructor() {
|
||||
}
|
||||
|
||||
get(id: Identifier): Block {
|
||||
const obj = useBridge('BuiltinRegistry.getBlock', id.toString()) as JavaObject;
|
||||
if (obj) {
|
||||
return new Block(obj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
import { Block, BlockBuiltinRegistry } from './block';
|
||||
import { SimpleBuiltinRegistry } from './core';
|
||||
|
||||
/**
|
||||
* Builtin Registry
|
||||
*/
|
||||
export class BuiltinRegistry {
|
||||
/**
|
||||
* Block Builtin Registry
|
||||
*/
|
||||
static BLOCK: SimpleBuiltinRegistry<Block> = BlockBuiltinRegistry.INSTANCE;
|
||||
}
|
@ -335,15 +335,3 @@ export interface SimpleRegistry<T> {
|
||||
*/
|
||||
getID(obj: T): Identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Builtin Registry
|
||||
*/
|
||||
export interface SimpleBuiltinRegistry<T> {
|
||||
/**
|
||||
* Get Object From ID
|
||||
* @param id ID
|
||||
* @returns Object
|
||||
*/
|
||||
get(id: Identifier): T;
|
||||
}
|
||||
|
@ -5,16 +5,7 @@ import { CompoundTag } from './tag';
|
||||
import { useBridge } from 'scriptcraft-core';
|
||||
import { Inventory } from './inventory';
|
||||
|
||||
function buildDamageSource(bridge: string): DamageSource {
|
||||
const obj = useBridge(bridge) as JavaObject;
|
||||
if (obj !== null) {
|
||||
return new DamageSource(obj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function buildDamageSourceWithValue(bridge: string, value: BridgeValueType): DamageSource {
|
||||
function buildDamageSource(bridge: string, value: BridgeValueType): DamageSource {
|
||||
const obj = useBridge(bridge, value) as JavaObject;
|
||||
if (obj !== null) {
|
||||
return new DamageSource(obj);
|
||||
@ -27,15 +18,6 @@ function buildDamageSourceWithValue(bridge: string, value: BridgeValueType): Dam
|
||||
* Damage Source
|
||||
*/
|
||||
export class DamageSource extends JavaObjectWrapper {
|
||||
/**
|
||||
* Generic Damage Source
|
||||
*/
|
||||
static GENERIC = buildDamageSource('DamageSource.getGeneric');
|
||||
/**
|
||||
* Void Damage Source
|
||||
*/
|
||||
static OUT_OF_WORLD = buildDamageSource('DamageSource.getOutOfWorld');
|
||||
|
||||
/**
|
||||
* Create Damage Source Wrapper From Java Object
|
||||
* @param javaObject Java Object
|
||||
@ -46,12 +28,12 @@ export class DamageSource extends JavaObjectWrapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Damage Source from an explosion
|
||||
* @param value Explosion Source
|
||||
* Create Damage Source from type
|
||||
* @param value Type
|
||||
* @returns Damage Source
|
||||
*/
|
||||
static createFromExplosion(value: LivingEntity): DamageSource {
|
||||
return buildDamageSourceWithValue('DamageSource.explosion', value.getJavaObject());
|
||||
static create(value: string): DamageSource {
|
||||
return buildDamageSource('DamageSource.create', value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,7 +42,7 @@ export class DamageSource extends JavaObjectWrapper {
|
||||
* @returns Damage Source
|
||||
*/
|
||||
static createFromPlayer(value: PlayerEntity): DamageSource {
|
||||
return buildDamageSourceWithValue('DamageSource.createFromPlayer', value.getJavaObject());
|
||||
return buildDamageSource('DamageSource.createFromPlayer', value.getJavaObject());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +51,7 @@ export class DamageSource extends JavaObjectWrapper {
|
||||
* @returns Damage Source
|
||||
*/
|
||||
static createFromMob(value: LivingEntity): DamageSource {
|
||||
return buildDamageSourceWithValue('DamageSource.createFromMob', value.getJavaObject());
|
||||
return buildDamageSource('DamageSource.createFromMob', value.getJavaObject());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,4 +17,3 @@ export { CompoundTag, ListTag, NumberType } from './tag';
|
||||
export { Registry } from './registry';
|
||||
export { Inventory } from './inventory';
|
||||
export { Events, Event, BlockEvent, ItemEvent, WorldEvent } from './event';
|
||||
export { BuiltinRegistry } from './builtin-registry';
|
||||
|
Reference in New Issue
Block a user