-
Notifications
You must be signed in to change notification settings - Fork 1
Events
KubeJS TFC adds several JS events
- Rock Settings
- Limiting Containers
- Register Climate Model
- Select Climate Model
- Start Fire
- Prospect
- Logging
- Animal Product
- Collapse
ProbeJS is highly recommended when working with these
This event goes in the startup_scripts
folder.
TFC has an item size feature which it uses to limit which items can go into its containers. KubeJS TFC allows you to somewhat replicate this for other mod's containers, with some limitations:
- It will only be able to apply to a container which registers a MenuType
- It only applies to player interactions
- It only applies upon closing a menu
The basic functionality of this is based off of a 1.12 addon that did much the same. It is licensed under the BSD License
Upon a player closing a limited container any items that are (1) in the limited slots and (2) greater than the provided size will be removed from the container and spawned in world around the player
This is available through a new startup event, tfc.limit_container_size
, with a single method, limitContainerSize
, available
- 1st argument: A string, the registry name of a menu
- A full list of available menus can be found by running the command
/kubejs dump_registry minecraft:menu
in-game
- A full list of available menus can be found by running the command
- 2nd argument: A string, the maximum size of items allowed in the declared slots
- Valid values:
- tiny
- very_small
- small
- normal
- large
- very_large
- huge
- Valid values:
-
optional 3rd argument: An integer array, representing the specific range of indexes of the container's slots which should be limited, defaults to all slots in the container
- This will accept any multiple of 2 number of integers (i.e. {0, 2} or {1, 3, 5, 7})
onEvent('tfc.limit_container_size', event => {
// Limits the hopper to only have normal or smaller item sizes
event.limitContainerSize('minecraft:hopper', 'normal')
// Limits shulker boxes to very small or smaller items for slots 0 through 8 and 18 through 26
event.limitContainerSize('minecraft:shulker_box', 'very_small', 0, 8, 18, 26)
})
This event goes in the startup_scripts
folder
TFC implements local temperature and rainfall, this is done through the use of climate models. This event has two methods registerClimateModel
and registerAdvancedClimateModel
. Both events take a resource location, the name of the model being registered, and a climate model consumer, which defines how your custom model behaves; the second method has the ability to set custom behaviors on world and chunk load in its consumer.
-
setCurrentTemperatureCalculation(callback)
: Sets the calculation for current temperature at a position. The callback provides:- A
LevelReader
, the level - A
BlockPos
, the position - A
Long
, the calendar ticks - An
Integer
, the number of days in a month - And expects a number
- A
-
setAverageTemperatureCalculation(callback)
: Sets the calculation for the average temperature at a position. The callback provides:- A
LevelReader
, the level - A
BlockPos
, the position - And expects a number
- A
-
setAverageRainfallCalculation(callback)
: Sets the calculation for the average rainfall at a position. The callback provides:- A
LevelReader
, the level - A
BlockPos
, the position - And expects a number between 0 and 500
- A
-
setAirFog(callback)
: Sets the fogginess at a position and time. The callback provides:- A
LevelReader
, the level - A
BlockPos
, the position - A
Long
, the calendar ticks - And expects a number between 0 and 1
- A
-
setWaterFog(callback)
: Sets the water fogginess at a position and time. The callback provides:- A
LevelReader
, the level - A
BlockPos
, the position - A
Long
, the calendar ticks - And expects a number between 0 and 1
- A
-
getClimateSeed()
: Returns the climate seed, a number based on the level's seed -
getNewnoise()
: Returns an OpenSimplex2D noise generator. -
getTemperatureSettings()
: Returns the level's temperature climate settings, or the default if none -
getRainfallSettings()
: Returns the level's rainfall climate settings, or default if none -
averageTemperature
: Returns a reference to the model's average temperature calculation, usegetValue(LevelReader, BlockPos)
to get its value -
averageRainfall
: Returns a reference to the model's average rainfall calculation, usegetValue(LevelReader, BlockPos)
to get its value -
currentTemperature
: Returns a reference to the model's current temperature calculation, use `getValue(LevelReader, BlockPos, Long, Int) to get its value -
airFog
: Returns a reference to the model's air fog calculation, usegetValue(LevelReader, BlockPos, Long)
to get its value -
waterFog
: Returns a reference to the model's water fog calculation, usegetValue(LevelReader, BlockPos, Long)
to get its value
If registering an advanced model the following are also available
-
setOnWorldLoad(callback)
: Sets what should be done upon the world loading. The callback provides:- A
ServerLevel
, the level
- A
-
setOnChunkLoad(callback)
: Sets what should be done upon a chunk loading, by default this is only called during world generation and TFC's update climate command. The callback provides:- A
WorldGenLevel
, the level - A
ChunkAccess
, the chunk - A
ChunkData
, the chunk's TFC data
- A
onEvent('tfc.climate_model.register', event => {
event.registerClimateModel('kubejs:my_model', model => {
model.setAverageTemperatureCalculation((level, pos) => {
return (pos.x + pos.z) / 2000 + (pos.y / 60)
})
model.setAirFog((level, pos, calendarTicks) => {
return JavaMath.sin(Calendar.getCalendar(level).getCalendarDayTime() / 12000 * JavaMath.PI);
})
})
event.registerAdvancedClimateModel('kubejs:my_advanced_model', model => {
model.setOnWorldLoad(level => {
console.log(`Loading into dimension: ${level.dimension}`)
})
})
})
This event goes in the startup_scripts
or server_scripts
folders. It can be reloaded at any time.
TFC implements local temperature and rainfall, this is done through the use of climate models. Whenever a world is loading or selecting its climate model, this event is fired. It is only fired on the server.
Returns the level
Returns the climate model that applies to the level, defaults to BiomeBasedClimateModel. TFC sets the Overworld to use the OverworldCliamteModel.
Returns the climate model's id
Sets the climate model to use for the associated level. This will accept the name of a climate model or a direct reference to a climate model object
onEvent('tfc.climate_model.select', event => {
event.getLevel()
event.getModel()
event.setModel('kubejs:my_model')
})
This event goes in the startup_scripts
or server_scripts
folders. It can be reloaded at any time. It can be cancelled.
TFC uses this event for lighting fires or optionally light-able blocks. This event should be cancelled if it was handled here. If you want your items to act like Flint and Steel or Torches, add them to either the tfc:starts_fires_with_items
tag or the tfc:starts_fires_with_durability
tags.
Returns the level
Returns a BlockContainerJS of the clicked position
Returns the block face that was clicked
Returns the ItemStackJS representing the item used
Returns the FireResult of the event. Defaults to FireResult.IF_FAILED.
Sets the event's FireResult
Returns a boolean indicating if the event's FireStrength is strong
Returns the EntityJS of the player that performed the fire start, may be null
Returns the ServerJS of the level, may be null
onEvent('tfc.start_fire', event => {
if (event.getBlock().getCanSeeLight() && event.getFireResult() === FireResult.IF_FAILED) {
console.info(event.getFireResult())
event.setFireResult(FireResult.ALWAYS)
event.cancel()
}
})
This event goes in the startup_scripts
or server_scripts
folders. It can be reloaded at any time.
Whenever a prospector's pick used this event is fired. It is purely informational and cannot change anything.
Returns the EntityJS of the player that prospected
Returns the PlayerJS of the player that prospected
Returns the Player of the player that prospected
Returns the LevelJS of the player that prospected
Returns the ServerJS of the level, may be null
Returns the ProspectResult of the event
onEvent('tfc.prospect', event => {
event.getPlayer().addItemCooldown(event.getPlayer().getInventory().get(event.getPlayer().getSelectedSlot()).getitem(), 2000)
})
This event goes in the startup_scripts
or server_scripts
folders. It can be reloaded at any time. It can be cancelled.
This event is fired when a tree is about to be felled by an axe. Cancelling it will cause the block to be broken normally.
Returns the LevelJS of the event
Returns the ItemStackJS of the axe used
Returns the BlockContainerJS of the block broken
onEvent('tfc.logging', event => {
if (event.getAxe().hasTag('kubejs:logging_deny_list')) {
event.cancel()
}
})
This event goes in the startup_scripts
or server_scripts
folders. It can be reloaded at any time. It can be cancelled.
This event is fired whenever a sheep is sheared, a cow is milked, or similar action happens, cancelling it will prevent the default behavior, which is controlled by each entity's implementation. This event does not control if an entity can give products, it is for the sole purpose of modifying/blocking what happens when products are made.
This event has a product, it may either be an ItemStackJS or a FluidStackJS, not both. Only the non-empty type will retain modifications, attempting to change the type will void the the original product.
Returns the EntityJS that the product comes from
Returns the PlayerJS that used the tool
Returns the LevelJS of the event
Returns the BlockContainerJS at the position of the animal
Returns the TFCAnimalProperties of the animal
Returns the ItemStackJS of the held item, usually a bucket or shears
Returns the ItemStackJS of the product, may be empty
Returns the FluidStackJS of the product, may be empty
Returns true if the item product isn't empty
Sets the item product
Sets the fluid product
Returns the amount of wear the animal will take from this happening
Sets the amount of wear the animal will take from this happening
Returns the Player of the player that used the tool, may be null
Returns the ServerJS of the level
onEvent('tfc.animal_product', event => {
if (event.getAnimalProperties().getGender() === AnimalGender.FEMALE) {
event.cancel()
}
})
This event goes in the startup_scripts
or server_scripts
folders. It can be reloaded at any time.
This event is fired whenever a collapse happens, including fake/visual-only collapses.
Returns the BlockContainerJS of the center block
Returns the LevelJS of the event
Returns the squared radius of the collapse, will be 0 if the collapse is fake
Returns a list containing the positions of blocks also effected by the collapse
Returns true if the collapse is fake
onEvent('tfc.collapse', event -> {
event.secondaryPositions.forEach(pos -> {
event.level.minecraftLevel.playSound(null, pos, 'minecraft:block.wood.break', 'blocks', 1.0, 1.0)
})
})