Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic BlockState Support and Misc Delegate Methods to LevelJS #464

Merged
merged 12 commits into from
Aug 29, 2022

Conversation

Hunter19823
Copy link
Contributor

@Hunter19823 Hunter19823 commented Aug 25, 2022

Added BlockState Support to Custom Blocks
--Modifications--
BuiltinKubeJSPlugin:

  • Added "BlockProperties" binding to BlockStateProperties class.

LevelJS:

  • Added Delegate Methods for the following:
    • getWorldBorder()
    • getDifficulty()
    • getMoonPhase()
    • getMoonBrightness()

BlockBuilder:

  • Added set of BlockState properties
  • Added defaultStateModification callback, usable with defaultState
  • Added placementStateModification callback, usable with placementState
  • Added "BlockBuilder.property(Property)" for use with "BlockProperties" binding or any BlockstateProperty
  • Deprecated waterlogged and removed all usages of waterlogged.

BasicBlockJS

  • Implemented BlockBuilder.defaultState
  • Implemented BlockBuilder.placementState
  • Removed usages of BlockBuilder.waterlogged in a handful of places without removing functionality.
  • Added private method safeCallback for catching and logging exceptions in callback functions to startup script console.
  • Fixed waterlogged not being bucket friendly.

Additions:

  • BlockStateModifyCallbackJS (Used for registering default state)
  • BlockStateModifyPlacementCallbackJS (Used for modifying blockstate on placement, extension of BlockStateModifyCallbackJS)

Example Startup Script:

global["defaultStateHandler"] = function(event) {
	let prop = BlockProperties.NOTEBLOCK_INSTRUMENT;
	// console.log(BlockProperties.NOTEBLOCK_INSTRUMENT.getPossibleValues());
	// console.log(BlockProperties.NOTEBLOCK_INSTRUMENT.getValue("bell"))

	event.set(prop, "bell");
}

global["placementStateHandler"] = function(event) {
	if(event.clickedPos.x % 2 ==0) {
		//event.set(BlockProperties.WATERLOGGED, true);
		event.waterlogged(true);
	}else {
		//event.set(BlockProperties.WATERLOGGED, false);
		event.waterlogged(false);
		
	}
}
onEvent('block.registry', event => {
	event.create('example_block')
			.material('wood')
			.hardness(1.0)
			.displayName('Example Block')
			.property(BlockProperties.NOTEBLOCK_INSTRUMENT)
			.property(BlockProperties.WATERLOGGED)
			.property(BlockProperties.BITES)
			.defaultState((event) => {global["defaultStateHandler"](event);})
			.placementState((event) => {global["placementStateHandler"](event);})
	;
})

Hunter19823 and others added 7 commits August 22, 2022 16:08
--Modifications--
BuiltinKubeJSPlugin:
- Added "Properties" and "Property" binding to startup scripts for use with BlockStates

BlockBuilder:
- Added defaultState callback
- Added placementState callback
- Added BlockBuilder.property
- Added BlockBuilder.boolProperty
- Added BlockBuilder.enumProperty
- Added BlockBuilder.dirProperty
- Deprecated waterlogged

BasicBlockJS
- Implemented BlockBuilder.defaultState
- Implemented BlockBuilder.placementState
- Removed usages of BlockBuilder.waterlogged in a handful of places without removing functionality.
- Added private method safeCallback for catching and logging exceptions in callback functions to startup script console.

Additions:
- BlockStateModifyCallbackJS (Used for registering default state)
- BlockStateModifyPlacementCallbackJS (Used for modifying blockstate on placement)
… BlockBuilder to encourage reflective use instead.
- Fixed safeCallbackLogic
- Made BlockBuilder.blockStateProperties immutable after creation.
- Removed the last remaining uses of waterlogged
- Fixed WaterLogged logic by implementing SimpleWaterloggedBlock

BlockBuilder:
- BlockBuilder.blockStateProperties is now a set for quick lookup times.
- Added get and set methods to BlockStateModifyCallbackJS for simpler syntax and to clear rhino un-boxing issues.
Hunter19823 and others added 5 commits August 25, 2022 18:23
…StateModifyPlacementCallbackJS.getItem() for use in beans
 - Added BlockStateModifyPlacementCallbackJS.waterlogged()
 - Added BlockStateModifyPlacementCallbackJS.isWaterLogged()
 - BlockStateModifyPlacementCallbackJS.isWaterLogged() is now BlockStateModifyPlacementCallbackJS.isInWater
 - Added BlockStateModifyPlacementCallbackJS.waterlogged(boolean)
@MaxNeedsSnacks MaxNeedsSnacks merged commit 2f5a6dd into KubeJS-Mods:1.18/dev Aug 29, 2022
@Hunter19823 Hunter19823 deleted the misc_additions branch March 4, 2024 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants