├── .github └── workflows │ └── gradle.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── dev │ └── latvian │ └── kubejs │ ├── CommonProperties.java │ ├── KubeJS.java │ ├── KubeJSCommon.java │ ├── KubeJSEvents.java │ ├── KubeJSInitializer.java │ ├── KubeJSObjects.java │ ├── KubeJSOtherEventHandler.java │ ├── KubeJSPaths.java │ ├── NonnullByDefault.java │ ├── bindings │ ├── BlockWrapper.java │ ├── DefaultBindings.java │ ├── FacingWrapper.java │ ├── IngredientWrapper.java │ ├── ItemWrapper.java │ ├── JsonWrapper.java │ ├── NBTWrapper.java │ ├── ScriptEventsWrapper.java │ ├── TextWrapper.java │ ├── TradeWrapper.java │ ├── UUIDWrapper.java │ └── UtilsWrapper.java │ ├── block │ ├── BlockBreakEventJS.java │ ├── BlockBuilder.java │ ├── BlockDropsEventJS.java │ ├── BlockItemBuilder.java │ ├── BlockJS.java │ ├── BlockLeftClickEventJS.java │ ├── BlockPlaceEventJS.java │ ├── BlockRegistryEventJS.java │ ├── BlockRightClickEventJS.java │ ├── KubeJSBlockEventHandler.java │ ├── MaterialJS.java │ ├── MaterialListJS.java │ ├── package-info.java │ └── predicate │ │ ├── BlockEntityPredicate.java │ │ ├── BlockEntityPredicateDataCheck.java │ │ ├── BlockIDPredicate.java │ │ ├── BlockPredicate.java │ │ └── package-info.java │ ├── callback │ └── item │ │ ├── EmptyLeftClickAirCallback.java │ │ ├── EmptyRightClickAirCallback.java │ │ ├── ItemCraftCallback.java │ │ ├── ItemDestroyCallback.java │ │ ├── ItemEntityPickupCallback.java │ │ ├── ItemEntityTossCallback.java │ │ ├── ItemRightClickAirCallback.java │ │ ├── ItemRightClickEntityCallback.java │ │ └── ItemSmeltCallback.java │ ├── client │ ├── ClientItemTooltipEventJS.java │ ├── ClientLoggedInEventJS.java │ ├── ClientProperties.java │ ├── ClientTickEventJS.java │ ├── ClientWrapper.java │ ├── DebugInfoEventJS.java │ ├── KubeJSClient.java │ ├── KubeJSClientEventHandler.java │ ├── KubeJSResourcePackFinder.java │ ├── SoundRegistryEventJS.java │ └── package-info.java │ ├── command │ ├── CommandRegistryEventJS.java │ ├── KubeJSCommands.java │ └── package-info.java │ ├── compat │ ├── AstromineRecipeEventHandler.java │ └── TechRebornRecipeEventHandler.java │ ├── core │ ├── AfterScriptLoadCallback.java │ ├── BlockKJS.java │ ├── CompoundNBTKJS.java │ ├── DataPackRegistriesHelper.java │ ├── DataPackRegistriesKJS.java │ ├── FireworkRocketEntityKJS.java │ ├── ImageButtonKJS.java │ ├── LivingEntityKJS.java │ ├── PlayerInteractionManagerKJS.java │ ├── ResourcePackManagerKJS.java │ ├── SimpleReloadableResourceManagerKJS.java │ ├── TagBuilderKJS.java │ ├── TagCollectionKJS.java │ ├── TradeOfferKJS.java │ ├── mixin │ │ ├── AbstractBlockMixin.java │ │ ├── AbstractFurnaceBlockEntityMixin.java │ │ ├── ClientPlayNetworkHandlerMixin.java │ │ ├── ClientRecipeBookMixin.java │ │ ├── CompoundNBTMixin.java │ │ ├── CraftingResultSlotMixin.java │ │ ├── DataPackRegistriesMixin.java │ │ ├── DebugHudMixin.java │ │ ├── EntityMixin.java │ │ ├── FireworkRocketEntityMixin.java │ │ ├── ImageButtonMixin.java │ │ ├── ItemStackMixin.java │ │ ├── LivingEntityMixin.java │ │ ├── MainWindowMixin.java │ │ ├── MinecraftClientMixin.java │ │ ├── PlayerInteractionManagerMixin.java │ │ ├── RecipeManagerMixin.java │ │ ├── ResourcePackManagerMixin.java │ │ ├── ServerPlayerInteractionManagerMixin.java │ │ ├── SimpleReloadableResourceManagerMixin.java │ │ ├── SplashScreenMixin.java │ │ ├── TagBuilderMixin.java │ │ ├── TagCollectionMixin.java │ │ ├── TradeOfferMixin.java │ │ └── package-info.java │ └── package-info.java │ ├── docs │ ├── DocumentationEvent.java │ ├── FieldDefinition.java │ ├── ID.java │ ├── KubeJSDocs.java │ ├── MemberDefinition.java │ ├── MethodDefinition.java │ ├── MinecraftClass.java │ ├── TypeDefinition.java │ └── package-info.java │ ├── entity │ ├── CheckLivingEntitySpawnEventJS.java │ ├── DamageSourceJS.java │ ├── EntityEventJS.java │ ├── EntityJS.java │ ├── EntityPotionEffectsJS.java │ ├── EntitySpawnedEventJS.java │ ├── ItemEntityJS.java │ ├── ItemFrameEntityJS.java │ ├── KubeJSEntityEventHandler.java │ ├── LivingEntityAttackEventJS.java │ ├── LivingEntityDeathEventJS.java │ ├── LivingEntityDropsEventJS.java │ ├── LivingEntityEventJS.java │ ├── LivingEntityJS.java │ └── package-info.java │ ├── event │ ├── DataEvent.java │ ├── EventJS.java │ ├── EventsJS.java │ ├── IEventHandler.java │ └── package-info.java │ ├── fluid │ ├── BoundFluidStackJS.java │ ├── BucketItemJS.java │ ├── EmptyFluidStackJS.java │ ├── FluidBuilder.java │ ├── FluidRegistryEventJS.java │ ├── FluidStackJS.java │ ├── FluidWrapper.java │ ├── KubeJSFluidEventHandler.java │ ├── UnboundFluidStackJS.java │ └── package-info.java │ ├── item │ ├── BlockItemJS.java │ ├── BoundItemStackJS.java │ ├── EmptyItemStackJS.java │ ├── FoodBuilder.java │ ├── InventoryJS.java │ ├── ItemBuilder.java │ ├── ItemCraftedEventJS.java │ ├── ItemDestroyedEventJS.java │ ├── ItemEntityInteractEventJS.java │ ├── ItemFoodEatenEventJS.java │ ├── ItemJS.java │ ├── ItemLeftClickEventJS.java │ ├── ItemPickupEventJS.java │ ├── ItemRegistryEventJS.java │ ├── ItemRightClickEmptyEventJS.java │ ├── ItemRightClickEventJS.java │ ├── ItemSmeltedEventJS.java │ ├── ItemStackJS.java │ ├── ItemTossEventJS.java │ ├── KubeJSItemEventHandler.java │ ├── UnboundItemStackJS.java │ ├── ingredient │ │ ├── FilteredIngredientJS.java │ │ ├── GroupIngredientJS.java │ │ ├── IgnoreNBTIngredientJS.java │ │ ├── IngredientJS.java │ │ ├── IngredientStackJS.java │ │ ├── MatchAllIngredientJS.java │ │ ├── MatchAnyIngredientJS.java │ │ ├── ModIngredientJS.java │ │ ├── NotIngredientJS.java │ │ ├── RegexIngredientJS.java │ │ ├── TagIngredientJS.java │ │ ├── VanillaPredicate.java │ │ └── package-info.java │ └── package-info.java │ ├── net │ ├── KubeJSNet.java │ ├── MessageCloseOverlay.java │ ├── MessageOpenOverlay.java │ ├── MessageSendDataFromClient.java │ ├── MessageSendDataFromServer.java │ ├── NetworkEventJS.java │ └── package-info.java │ ├── package-info.java │ ├── player │ ├── AdvancementJS.java │ ├── AttachPlayerDataEvent.java │ ├── ChestEventJS.java │ ├── ClientPlayerDataJS.java │ ├── ClientPlayerJS.java │ ├── EntityArrayList.java │ ├── FakeServerPlayerDataJS.java │ ├── InventoryChangedEventJS.java │ ├── InventoryEventJS.java │ ├── InventoryListener.java │ ├── KubeJSPlayerEventHandler.java │ ├── PlayerAdvancementEventJS.java │ ├── PlayerChatEventJS.java │ ├── PlayerDataJS.java │ ├── PlayerEventJS.java │ ├── PlayerJS.java │ ├── PlayerStatsJS.java │ ├── ServerPlayerDataJS.java │ ├── ServerPlayerJS.java │ ├── SimplePlayerEventJS.java │ └── package-info.java │ ├── recipe │ ├── ConditionalRecipeJS.java │ ├── CustomRecipeTypeJS.java │ ├── KubeJSRecipeEventHandler.java │ ├── RecipeEventJS.java │ ├── RecipeExceptionJS.java │ ├── RecipeFunction.java │ ├── RecipeJS.java │ ├── RecipeTypeJS.java │ ├── RegisterRecipeHandlersEvent.java │ ├── filter │ │ ├── AndFilter.java │ │ ├── GroupFilter.java │ │ ├── IDFilter.java │ │ ├── InputFilter.java │ │ ├── ModFilter.java │ │ ├── OrFilter.java │ │ ├── OutputFilter.java │ │ ├── RecipeFilter.java │ │ └── TypeFilter.java │ ├── minecraft │ │ ├── CookingRecipeJS.java │ │ ├── CustomRecipeJS.java │ │ ├── ShapedRecipeJS.java │ │ ├── ShapelessRecipeJS.java │ │ ├── SmithingRecipeJS.java │ │ └── StonecuttingRecipeJS.java │ └── package-info.java │ ├── rei │ ├── AddREIEventJS.java │ ├── HideREIEventJS.java │ ├── InformationREIEventJS.java │ ├── REIIntegration.java │ └── REIPlugin.java │ ├── script │ ├── AttachDataEvent.java │ ├── BindingsEvent.java │ ├── DataType.java │ ├── ScriptFile.java │ ├── ScriptFileInfo.java │ ├── ScriptManager.java │ ├── ScriptModData.java │ ├── ScriptPack.java │ ├── ScriptPackInfo.java │ ├── ScriptSource.java │ ├── ScriptType.java │ ├── ScriptsLoadedEvent.java │ ├── data │ │ ├── DataPackEventJS.java │ │ ├── KubeJSResourcePack.java │ │ ├── VirtualKubeJSDataPack.java │ │ └── package-info.java │ └── package-info.java │ ├── server │ ├── AttachServerDataEvent.java │ ├── CommandEventJS.java │ ├── GameRulesJS.java │ ├── IScheduledEventCallback.java │ ├── KubeJSServerEventHandler.java │ ├── ScheduledEvent.java │ ├── ServerCommandSender.java │ ├── ServerEventJS.java │ ├── ServerJS.java │ ├── ServerScriptManager.java │ ├── ServerSettings.java │ ├── TagEventJS.java │ └── package-info.java │ ├── text │ ├── Text.java │ ├── TextColor.java │ ├── TextString.java │ ├── TextTranslate.java │ └── package-info.java │ ├── trade │ ├── TradeOfferFactory.java │ └── TradeRegistryEventJS.java │ ├── util │ ├── AttachedData.java │ ├── BuilderBase.java │ ├── ConsoleJS.java │ ├── Copyable.java │ ├── CountingMap.java │ ├── FieldJS.java │ ├── JSObjectType.java │ ├── JsonSerializable.java │ ├── JsonUtilsJS.java │ ├── ListJS.java │ ├── MapJS.java │ ├── MessageSender.java │ ├── NBTSerializable.java │ ├── NBTUtilsJS.java │ ├── Overlay.java │ ├── TradeUtils.java │ ├── UUIDUtilsJS.java │ ├── UtilsJS.java │ ├── WithAttachedData.java │ ├── WrappedJS.java │ ├── WrappedJSObject.java │ ├── WrappedJSObjectChangeListener.java │ └── package-info.java │ └── world │ ├── AttachWorldDataEvent.java │ ├── BlockContainerJS.java │ ├── ClientWorldJS.java │ ├── ExplosionEventJS.java │ ├── ExplosionJS.java │ ├── FireworksJS.java │ ├── KubeJSWorldEventHandler.java │ ├── ServerWorldJS.java │ ├── SimpleWorldEventJS.java │ ├── WorldCommandSender.java │ ├── WorldEventJS.java │ ├── WorldJS.java │ └── package-info.java └── resources ├── assets └── kubejs │ ├── models │ └── item │ │ └── generated_bucket.json │ └── textures │ ├── fluid │ ├── fluid_thick.png │ ├── fluid_thick.png.mcmeta │ ├── fluid_thick_flow.png │ ├── fluid_thick_flow.png.mcmeta │ ├── fluid_thin.png │ ├── fluid_thin.png.mcmeta │ ├── fluid_thin_flow.png │ └── fluid_thin_flow.png.mcmeta │ └── item │ ├── bucket.png │ └── fluid.png ├── data └── kubejs │ ├── example_block_texture.png │ ├── example_client_script.js │ ├── example_item_texture.png │ ├── example_server_script.js │ └── example_startup_script.js ├── fabric.mod.json ├── kubejs.accessWidener ├── kubejs.mixins.json ├── kubejs_logo.png └── pack.mcmeta /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Set up JDK 1.8 13 | uses: actions/setup-java@v1 14 | with: 15 | java-version: 1.8 16 | - name: Build with Gradle 17 | run: | 18 | chmod +x gradlew 19 | ./gradlew build 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # eclipse 2 | bin 3 | *.launch 4 | .settings 5 | .metadata 6 | .classpath 7 | .project 8 | 9 | # idea 10 | out 11 | *.ipr 12 | *.iws 13 | *.iml 14 | .idea 15 | 16 | # gradle 17 | build 18 | .gradle 19 | 20 | # other 21 | eclipse 22 | run 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [KubeJS-Fabric](https://kubejs.latvian.dev/) 2 | Fabric version of KubeJS 3 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx3G 2 | mod_name=kubejs-fabric 3 | mod_package=dev.latvian.mods 4 | mod_version=1.6.0 5 | mod_author=LatvianModder 6 | curseforge_id=395864 7 | minecraft_version=1.16.4 8 | supported_version=1.16.2/3/4 9 | fabric_version=0.9.1+build.205 10 | fabric_api_version=0.17.2+build.396-1.16 11 | rhino_file=3097962 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jul 02 21:37:15 HKT 2020 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | jcenter() 4 | maven { 5 | name = 'Fabric' 6 | url = 'https://maven.fabricmc.net/' 7 | } 8 | gradlePluginPortal() 9 | } 10 | } 11 | rootProject.name = "KubeJS-Fabric" -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/KubeJSCommon.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs; 2 | 3 | import dev.latvian.kubejs.script.BindingsEvent; 4 | import dev.latvian.kubejs.util.Overlay; 5 | import dev.latvian.kubejs.world.WorldJS; 6 | import net.minecraft.nbt.CompoundTag; 7 | import net.minecraft.world.entity.player.Player; 8 | 9 | import javax.annotation.Nullable; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class KubeJSCommon { 15 | public void init() { 16 | } 17 | 18 | public void clientBindings(BindingsEvent event) { 19 | } 20 | 21 | public void handleDataToClientPacket(String channel, @Nullable CompoundTag data) { 22 | } 23 | 24 | @Nullable 25 | public Player getClientPlayer() { 26 | return null; 27 | } 28 | 29 | public void openOverlay(Overlay o) { 30 | } 31 | 32 | public void closeOverlay(String id) { 33 | } 34 | 35 | public WorldJS getClientWorld() { 36 | throw new IllegalStateException("Can't access client world from server side!"); 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/KubeJSInitializer.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs; 2 | 3 | @FunctionalInterface 4 | public interface KubeJSInitializer { 5 | void onKubeJSInitialization(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/KubeJSObjects.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs; 2 | 3 | import dev.latvian.kubejs.block.BlockBuilder; 4 | import dev.latvian.kubejs.fluid.FluidBuilder; 5 | import dev.latvian.kubejs.item.ItemBuilder; 6 | import dev.latvian.kubejs.util.BuilderBase; 7 | import net.minecraft.resources.ResourceLocation; 8 | 9 | import java.util.ArrayList; 10 | import java.util.LinkedHashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author LatvianModder 16 | */ 17 | public class KubeJSObjects { 18 | public static final List ALL = new ArrayList<>(); 19 | public static final Map ITEMS = new LinkedHashMap<>(); 20 | public static final Map BLOCKS = new LinkedHashMap<>(); 21 | public static final Map FLUIDS = new LinkedHashMap<>(); 22 | 23 | public static void register() { 24 | ALL.clear(); 25 | ITEMS.clear(); 26 | BLOCKS.clear(); 27 | FLUIDS.clear(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/KubeJSOtherEventHandler.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs; 2 | 3 | import dev.latvian.kubejs.client.SoundRegistryEventJS; 4 | import dev.latvian.kubejs.core.AfterScriptLoadCallback; 5 | import dev.latvian.kubejs.script.ScriptType; 6 | import net.minecraft.core.Registry; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class KubeJSOtherEventHandler implements KubeJSInitializer { 12 | @Override 13 | public void onKubeJSInitialization() { 14 | AfterScriptLoadCallback.EVENT.register(this::registry); 15 | } 16 | 17 | private void registry() { 18 | new SoundRegistryEventJS(Registry.SOUND_EVENT).post(ScriptType.STARTUP, KubeJSEvents.SOUND_REGISTRY); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/KubeJSPaths.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs; 2 | 3 | import dev.latvian.kubejs.util.UtilsJS; 4 | import net.fabricmc.loader.api.FabricLoader; 5 | import net.minecraft.server.packs.PackType; 6 | 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class KubeJSPaths { 14 | public static final Path DIRECTORY = FabricLoader.getInstance().getGameDir().resolve("kubejs").normalize(); 15 | public static final Path DATA = DIRECTORY.resolve("data"); 16 | public static final Path ASSETS = DIRECTORY.resolve("assets"); 17 | public static final Path STARTUP_SCRIPTS = DIRECTORY.resolve("startup_scripts"); 18 | public static final Path SERVER_SCRIPTS = DIRECTORY.resolve("server_scripts"); 19 | public static final Path CLIENT_SCRIPTS = DIRECTORY.resolve("client_scripts"); 20 | public static final Path CONFIG = DIRECTORY.resolve("config"); 21 | public static final Path EXPORTED = DIRECTORY.resolve("exported"); 22 | public static final Path README = DIRECTORY.resolve("README.txt"); 23 | 24 | static { 25 | if (Files.notExists(DIRECTORY)) { 26 | UtilsJS.tryIO(() -> Files.createDirectories(DIRECTORY)); 27 | } 28 | 29 | if (Files.notExists(CONFIG)) { 30 | UtilsJS.tryIO(() -> Files.createDirectories(CONFIG)); 31 | } 32 | 33 | if (Files.notExists(EXPORTED)) { 34 | UtilsJS.tryIO(() -> Files.createDirectories(EXPORTED)); 35 | } 36 | } 37 | 38 | public static Path get(PackType type) { 39 | return type == PackType.CLIENT_RESOURCES ? ASSETS : DATA; 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/NonnullByDefault.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs; 2 | 3 | import javax.annotation.Nonnull; 4 | import javax.annotation.meta.TypeQualifierDefault; 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | 10 | /** 11 | * @author LatvianModder 12 | * This annotation combines method and parameter nonnullability 13 | */ 14 | @Documented 15 | @Nonnull 16 | @TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER}) 17 | @Retention(RetentionPolicy.RUNTIME) 18 | public @interface NonnullByDefault { 19 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/bindings/FacingWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.bindings; 2 | 3 | import net.minecraft.core.Direction; 4 | 5 | import java.util.Collections; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class FacingWrapper { 13 | public final Direction down; 14 | public final Direction up; 15 | public final Direction north; 16 | public final Direction south; 17 | public final Direction west; 18 | public final Direction east; 19 | public final Map map; 20 | 21 | public FacingWrapper() { 22 | down = Direction.DOWN; 23 | up = Direction.UP; 24 | north = Direction.NORTH; 25 | south = Direction.SOUTH; 26 | west = Direction.WEST; 27 | east = Direction.EAST; 28 | HashMap map0 = new HashMap<>(); 29 | 30 | for (Direction facing : Direction.values()) { 31 | map0.put(facing.getName(), facing); 32 | } 33 | 34 | map = Collections.unmodifiableMap(map0); 35 | } 36 | 37 | public Direction opposite(Direction facing) { 38 | return facing.getOpposite(); 39 | } 40 | 41 | public int x(Direction facing) { 42 | return facing.getStepX(); 43 | } 44 | 45 | public int y(Direction facing) { 46 | return facing.getStepY(); 47 | } 48 | 49 | public int z(Direction facing) { 50 | return facing.getStepZ(); 51 | } 52 | 53 | public int getIndex(Direction facing) { 54 | return facing.get3DDataValue(); 55 | } 56 | 57 | public int getHorizontalIndex(Direction facing) { 58 | return facing.get2DDataValue(); 59 | } 60 | 61 | public float getYaw(Direction facing) { 62 | return facing.toYRot(); 63 | } 64 | 65 | public float getPitch(Direction facing) { 66 | return facing == up ? 180F : facing == down ? 0F : 90F; 67 | } 68 | 69 | public Direction rotateY(Direction facing) { 70 | return facing.getClockWise(); 71 | } 72 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/bindings/IngredientWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.bindings; 2 | 3 | import dev.latvian.kubejs.docs.ID; 4 | import dev.latvian.kubejs.item.EmptyItemStackJS; 5 | import dev.latvian.kubejs.item.ItemStackJS; 6 | import dev.latvian.kubejs.item.ingredient.*; 7 | import dev.latvian.kubejs.util.UtilsJS; 8 | 9 | import java.util.function.Predicate; 10 | import java.util.regex.Pattern; 11 | 12 | /** 13 | * @author LatvianModder 14 | */ 15 | public class IngredientWrapper { 16 | public IngredientJS getNone() { 17 | return EmptyItemStackJS.INSTANCE; 18 | } 19 | 20 | public IngredientJS getAll() { 21 | return MatchAllIngredientJS.INSTANCE; 22 | } 23 | 24 | public IngredientJS of(Object object) { 25 | return IngredientJS.of(object); 26 | } 27 | 28 | public IngredientJS custom(Predicate predicate) { 29 | return predicate::test; 30 | } 31 | 32 | public IngredientJS matchAny(Object[] objects) { 33 | MatchAnyIngredientJS ingredient = new MatchAnyIngredientJS(); 34 | ingredient.addAll(objects); 35 | return ingredient; 36 | } 37 | 38 | public IngredientJS tag(@ID String tag) { 39 | return TagIngredientJS.createTag(UtilsJS.getMCID(tag).toString()); 40 | } 41 | 42 | public IngredientJS tag(@ID String tag, int count) { 43 | return tag(tag).count(count); 44 | } 45 | 46 | public IngredientJS mod(String modId) { 47 | return new ModIngredientJS(modId); 48 | } 49 | 50 | public IngredientJS regex(Pattern pattern) { 51 | return new RegexIngredientJS(pattern); 52 | } 53 | 54 | public IngredientJS regex(String pattern) { 55 | return regex(Pattern.compile(pattern)); 56 | } 57 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/bindings/ItemWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.bindings; 2 | 3 | import dev.latvian.kubejs.docs.ID; 4 | import dev.latvian.kubejs.docs.MinecraftClass; 5 | import dev.latvian.kubejs.item.EmptyItemStackJS; 6 | import dev.latvian.kubejs.item.ItemStackJS; 7 | import dev.latvian.kubejs.util.ListJS; 8 | import dev.latvian.kubejs.util.UtilsJS; 9 | import dev.latvian.kubejs.world.FireworksJS; 10 | import net.minecraft.core.Registry; 11 | import net.minecraft.world.item.CreativeModeTab; 12 | import net.minecraft.world.item.Item; 13 | import net.minecraft.world.item.Items; 14 | 15 | import javax.annotation.Nullable; 16 | import java.util.Map; 17 | 18 | /** 19 | * @author LatvianModder 20 | */ 21 | public class ItemWrapper { 22 | public ItemStackJS of(Object object) { 23 | return ItemStackJS.of(object); 24 | } 25 | 26 | public ItemStackJS of(Object object, Object countOrNBT) { 27 | return ItemStackJS.of(object, countOrNBT); 28 | } 29 | 30 | public ItemStackJS of(Object object, int count, Object nbt) { 31 | return ItemStackJS.of(object, count, nbt); 32 | } 33 | 34 | public ListJS getList() { 35 | return ListJS.of(ItemStackJS.getList()); 36 | } 37 | 38 | public ListJS getTypeList() { 39 | return ItemStackJS.getTypeList(); 40 | } 41 | 42 | public ItemStackJS getEmpty() { 43 | return EmptyItemStackJS.INSTANCE; 44 | } 45 | 46 | public void clearListCache() { 47 | ItemStackJS.clearListCache(); 48 | } 49 | 50 | public FireworksJS fireworks(Map properties) { 51 | return FireworksJS.of(properties); 52 | } 53 | 54 | @MinecraftClass 55 | public Item getItem(@ID String id) { 56 | Item i = Registry.ITEM.get(UtilsJS.getMCID(id)); 57 | return i == null ? Items.AIR : i; 58 | } 59 | 60 | @Nullable 61 | @MinecraftClass 62 | public CreativeModeTab findGroup(String id) 63 | { 64 | return ItemStackJS.findGroup(id); 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/bindings/JsonWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.bindings; 2 | 3 | import com.google.gson.JsonElement; 4 | import dev.latvian.kubejs.util.JSObjectType; 5 | import dev.latvian.kubejs.util.JsonUtilsJS; 6 | import dev.latvian.kubejs.util.MapJS; 7 | import dev.latvian.kubejs.util.UtilsJS; 8 | 9 | import javax.annotation.Nullable; 10 | import java.io.File; 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author LatvianModder 15 | */ 16 | public class JsonWrapper { 17 | public JsonElement copy(JsonElement json) { 18 | return JsonUtilsJS.copy(json); 19 | } 20 | 21 | public String toString(JsonElement json) { 22 | return JsonUtilsJS.toString(json); 23 | } 24 | 25 | public String toPrettyString(JsonElement json) { 26 | return JsonUtilsJS.toPrettyString(json); 27 | } 28 | 29 | public Object parse(String string) { 30 | return UtilsJS.wrap(JsonUtilsJS.fromString(string), JSObjectType.ANY); 31 | } 32 | 33 | @Nullable 34 | public MapJS read(File file) throws IOException { 35 | return JsonUtilsJS.read(file); 36 | } 37 | 38 | public void write(File file, Object json) throws IOException { 39 | JsonUtilsJS.write(file, MapJS.of(json)); 40 | } 41 | 42 | @Nullable 43 | public MapJS read(String file) throws IOException { 44 | return JsonUtilsJS.read(file); 45 | } 46 | 47 | public void write(String file, Object json) throws IOException { 48 | JsonUtilsJS.write(file, MapJS.of(json)); 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/bindings/NBTWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.bindings; 2 | 3 | import dev.latvian.kubejs.util.MapJS; 4 | import dev.latvian.kubejs.util.NBTUtilsJS; 5 | 6 | import javax.annotation.Nullable; 7 | import java.io.File; 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class NBTWrapper { 14 | @Nullable 15 | public MapJS read(File file) throws IOException { 16 | return NBTUtilsJS.read(file); 17 | } 18 | 19 | public void write(File file, Object nbt) throws IOException { 20 | NBTUtilsJS.write(file, MapJS.of(nbt)); 21 | } 22 | 23 | @Nullable 24 | public Object read(String file) throws IOException { 25 | return NBTUtilsJS.read(file); 26 | } 27 | 28 | public void write(String file, Object nbt) throws IOException { 29 | NBTUtilsJS.write(file, MapJS.of(nbt)); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/bindings/ScriptEventsWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.bindings; 2 | 3 | import dev.latvian.kubejs.event.DataEvent; 4 | import dev.latvian.kubejs.event.EventsJS; 5 | import dev.latvian.kubejs.event.IEventHandler; 6 | import dev.latvian.kubejs.util.ListJS; 7 | 8 | import javax.annotation.Nullable; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class ScriptEventsWrapper { 14 | private final EventsJS events; 15 | 16 | public ScriptEventsWrapper(EventsJS e) { 17 | events = e; 18 | } 19 | 20 | public void listen(Object id, IEventHandler handler) { 21 | for (Object o : ListJS.orSelf(id)) { 22 | events.listen(String.valueOf(o), handler); 23 | } 24 | } 25 | 26 | public void post(String id, @Nullable Object data) { 27 | events.postToHandlers(id, events.handlers(id), new DataEvent(false, data)); 28 | } 29 | 30 | public void post(String id) { 31 | post(id, null); 32 | } 33 | 34 | public boolean postCancellable(String id, @Nullable Object data) { 35 | return events.postToHandlers(id, events.handlers(id), new DataEvent(true, data)); 36 | } 37 | 38 | public boolean postCancellable(String id) { 39 | return postCancellable(id, null); 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/bindings/TradeWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.bindings; 2 | 3 | import dev.latvian.kubejs.util.TradeUtils; 4 | import net.minecraft.world.entity.npc.VillagerTrades; 5 | 6 | public class TradeWrapper { 7 | public VillagerTrades.ItemListing of(Object data) { 8 | return TradeUtils.of(data); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/bindings/UUIDWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.bindings; 2 | 3 | import dev.latvian.kubejs.util.UUIDUtilsJS; 4 | 5 | import javax.annotation.Nullable; 6 | import java.util.UUID; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class UUIDWrapper { 12 | public String toString(UUID id) { 13 | return UUIDUtilsJS.toString(id); 14 | } 15 | 16 | @Nullable 17 | public UUID fromString(Object string) { 18 | return UUIDUtilsJS.fromString(String.valueOf(string)); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/BlockBreakEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class BlockBreakEventJS {} 7 | //public class BlockBreakEventJS extends PlayerEventJS 8 | //{ 9 | // public final BlockEvent.BreakEvent event; 10 | // 11 | // public BlockBreakEventJS(BlockEvent.BreakEvent e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public boolean canCancel() 18 | // { 19 | // return true; 20 | // } 21 | // 22 | // @Override 23 | // public EntityJS getEntity() 24 | // { 25 | // return entityOf(event.getPlayer()); 26 | // } 27 | // 28 | // public BlockContainerJS getBlock() 29 | // { 30 | // return new BlockContainerJS(event.getWorld(), event.getPos()) 31 | // { 32 | // @Override 33 | // public BlockState getBlockState() 34 | // { 35 | // return event.getState(); 36 | // } 37 | // }; 38 | // } 39 | // 40 | // public int getXp() 41 | // { 42 | // return event.getExpToDrop(); 43 | // } 44 | // 45 | // public void setXp(int xp) 46 | // { 47 | // event.setExpToDrop(xp); 48 | // } 49 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/BlockItemBuilder.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block; 2 | 3 | import dev.latvian.kubejs.item.BlockItemJS; 4 | import dev.latvian.kubejs.item.ItemBuilder; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class BlockItemBuilder extends ItemBuilder { 10 | public BlockBuilder blockBuilder; 11 | public BlockItemJS blockItem; 12 | 13 | public BlockItemBuilder(String i) { 14 | super(i); 15 | } 16 | 17 | @Override 18 | public String getType() { 19 | return "block"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/BlockLeftClickEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import dev.latvian.kubejs.player.PlayerEventJS; 6 | import dev.latvian.kubejs.world.BlockContainerJS; 7 | import net.minecraft.core.BlockPos; 8 | import net.minecraft.core.Direction; 9 | import net.minecraft.world.InteractionHand; 10 | import net.minecraft.world.entity.player.Player; 11 | import net.minecraft.world.level.Level; 12 | 13 | import javax.annotation.Nullable; 14 | 15 | /** 16 | * @author LatvianModder 17 | */ 18 | public class BlockLeftClickEventJS extends PlayerEventJS { 19 | public final Player player; 20 | public final Level world; 21 | public final BlockPos pos; 22 | public final InteractionHand hand; 23 | public final Direction direction; 24 | 25 | public BlockLeftClickEventJS(Player player, Level world, InteractionHand hand, BlockPos pos, Direction direction) { 26 | this.player = player; 27 | this.world = world; 28 | this.pos = pos; 29 | this.hand = hand; 30 | this.direction = direction; 31 | } 32 | 33 | @Override 34 | public boolean canCancel() { 35 | return true; 36 | } 37 | 38 | @Override 39 | public EntityJS getEntity() { 40 | return entityOf(player); 41 | } 42 | 43 | public BlockContainerJS getBlock() { 44 | return new BlockContainerJS(world, pos); 45 | } 46 | 47 | public ItemStackJS getItem() { 48 | return ItemStackJS.of(player.getItemInHand(hand)); 49 | } 50 | 51 | @Nullable 52 | public Direction getFacing() { 53 | return direction; 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/BlockPlaceEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class BlockPlaceEventJS {} 7 | //public class BlockPlaceEventJS extends EntityEventJS 8 | //{ 9 | // public final BlockEvent.EntityPlaceEvent event; 10 | // 11 | // public BlockPlaceEventJS(BlockEvent.EntityPlaceEvent e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public boolean canCancel() 18 | // { 19 | // return true; 20 | // } 21 | // 22 | // @Override 23 | // public EntityJS getEntity() 24 | // { 25 | // return entityOf(event.getEntity()); 26 | // } 27 | // 28 | // public BlockContainerJS getBlock() 29 | // { 30 | // return new BlockContainerJS(event.getWorld(), event.getPos()) 31 | // { 32 | // @Override 33 | // public BlockState getBlockState() 34 | // { 35 | // return event.getState(); 36 | // } 37 | // }; 38 | // } 39 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/BlockRegistryEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block; 2 | 3 | import dev.latvian.kubejs.KubeJSObjects; 4 | import dev.latvian.kubejs.event.EventJS; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class BlockRegistryEventJS extends EventJS { 10 | public BlockBuilder create(String name) { 11 | BlockBuilder builder = new BlockBuilder(name); 12 | KubeJSObjects.BLOCKS.put(builder.id, builder); 13 | KubeJSObjects.ALL.add(builder); 14 | return builder; 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/BlockRightClickEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import dev.latvian.kubejs.player.PlayerEventJS; 6 | import dev.latvian.kubejs.world.BlockContainerJS; 7 | import net.minecraft.core.Direction; 8 | import net.minecraft.world.InteractionHand; 9 | import net.minecraft.world.entity.player.Player; 10 | import net.minecraft.world.level.Level; 11 | import net.minecraft.world.phys.BlockHitResult; 12 | 13 | /** 14 | * @author LatvianModder 15 | */ 16 | public class BlockRightClickEventJS extends PlayerEventJS { 17 | public final Player player; 18 | public final Level world; 19 | public final InteractionHand hand; 20 | public final BlockHitResult blockHitResult; 21 | private BlockContainerJS block; 22 | private ItemStackJS item; 23 | 24 | public BlockRightClickEventJS(Player player, Level world, InteractionHand hand, BlockHitResult hitResult) { 25 | this.player = player; 26 | this.world = world; 27 | this.hand = hand; 28 | this.blockHitResult = hitResult; 29 | } 30 | 31 | @Override 32 | public boolean canCancel() { 33 | return true; 34 | } 35 | 36 | @Override 37 | public EntityJS getEntity() { 38 | return entityOf(player); 39 | } 40 | 41 | public BlockContainerJS getBlock() { 42 | if (block == null) { 43 | block = new BlockContainerJS(world, blockHitResult.getBlockPos()); 44 | } 45 | 46 | return block; 47 | } 48 | 49 | public InteractionHand getHand() { 50 | return hand; 51 | } 52 | 53 | public ItemStackJS getItem() { 54 | if (item == null) { 55 | item = ItemStackJS.of(player.getItemInHand(hand)); 56 | } 57 | 58 | return item; 59 | } 60 | 61 | public Direction getFacing() { 62 | return blockHitResult.getDirection(); 63 | } 64 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/MaterialJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block; 2 | 3 | import dev.latvian.kubejs.docs.MinecraftClass; 4 | import net.minecraft.world.level.block.SoundType; 5 | import net.minecraft.world.level.material.Material; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class MaterialJS { 11 | private final String id; 12 | private final Material minecraftMaterial; 13 | private final SoundType sound; 14 | 15 | public MaterialJS(String i, Material m, SoundType s) { 16 | id = i; 17 | minecraftMaterial = m; 18 | sound = s; 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | @MinecraftClass 26 | public Material getMinecraftMaterial() { 27 | return minecraftMaterial; 28 | } 29 | 30 | @MinecraftClass 31 | public SoundType getSound() { 32 | return sound; 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.block; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/predicate/BlockEntityPredicate.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block.predicate; 2 | 3 | import dev.latvian.kubejs.docs.ID; 4 | import dev.latvian.kubejs.util.UtilsJS; 5 | import dev.latvian.kubejs.world.BlockContainerJS; 6 | import net.minecraft.core.Registry; 7 | import net.minecraft.resources.ResourceLocation; 8 | import net.minecraft.world.level.block.entity.BlockEntity; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class BlockEntityPredicate implements BlockPredicate { 14 | private final ResourceLocation id; 15 | private BlockEntityPredicateDataCheck checkData; 16 | 17 | public BlockEntityPredicate(@ID String i) { 18 | id = UtilsJS.getMCID(i); 19 | } 20 | 21 | public BlockEntityPredicate data(BlockEntityPredicateDataCheck cd) { 22 | checkData = cd; 23 | return this; 24 | } 25 | 26 | @Override 27 | public boolean check(BlockContainerJS block) { 28 | BlockEntity blockEntity = block.getEntity(); 29 | return blockEntity != null && id.equals(Registry.BLOCK_ENTITY_TYPE.getKey(blockEntity.getType())) && (checkData == null || checkData.checkData(block.getEntityData())); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "{entity=" + id + "}"; 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/predicate/BlockEntityPredicateDataCheck.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block.predicate; 2 | 3 | import dev.latvian.kubejs.util.MapJS; 4 | 5 | import javax.annotation.Nullable; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | @FunctionalInterface 11 | public interface BlockEntityPredicateDataCheck { 12 | boolean checkData(@Nullable MapJS data); 13 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/predicate/BlockPredicate.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.block.predicate; 2 | 3 | import dev.latvian.kubejs.world.BlockContainerJS; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public interface BlockPredicate { 9 | boolean check(BlockContainerJS block); 10 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/block/predicate/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.block.predicate; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/callback/item/EmptyLeftClickAirCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.callback.item; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.world.InteractionHand; 7 | import net.minecraft.world.entity.player.Player; 8 | 9 | public interface EmptyLeftClickAirCallback { 10 | Event EVENT = EventFactory.createArrayBacked(EmptyLeftClickAirCallback.class, (listeners) -> { 11 | return (player, hand, position) -> { 12 | for (EmptyLeftClickAirCallback listener : listeners) { 13 | listener.leftClickEmpty(player, hand, position); 14 | } 15 | }; 16 | }); 17 | 18 | void leftClickEmpty(Player player, InteractionHand hand, BlockPos position); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/callback/item/EmptyRightClickAirCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.callback.item; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.world.InteractionHand; 7 | import net.minecraft.world.entity.player.Player; 8 | 9 | public interface EmptyRightClickAirCallback { 10 | Event EVENT = EventFactory.createArrayBacked(EmptyRightClickAirCallback.class, (listeners) -> { 11 | return (player, hand, position) -> { 12 | for (EmptyRightClickAirCallback listener : listeners) { 13 | listener.rightClickEmpty(player, hand, position); 14 | } 15 | }; 16 | }); 17 | 18 | void rightClickEmpty(Player player, InteractionHand hand, BlockPos position); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/callback/item/ItemCraftCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.callback.item; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.world.Container; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.item.ItemStack; 8 | 9 | public interface ItemCraftCallback { 10 | Event EVENT = EventFactory.createArrayBacked(ItemCraftCallback.class, (listeners) -> { 11 | return (player, inventory, result) -> { 12 | for (ItemCraftCallback listener : listeners) { 13 | listener.craft(player, inventory, result); 14 | } 15 | }; 16 | }); 17 | 18 | void craft(Player player, Container inventory, ItemStack result); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/callback/item/ItemDestroyCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.callback.item; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.world.InteractionHand; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.item.ItemStack; 8 | 9 | import javax.annotation.Nonnull; 10 | import javax.annotation.Nullable; 11 | 12 | public interface ItemDestroyCallback { 13 | Event EVENT = EventFactory.createArrayBacked(ItemDestroyCallback.class, (listeners) -> { 14 | return (player, original, hand) -> { 15 | for (ItemDestroyCallback listener : listeners) { 16 | listener.destroy(player, original, hand); 17 | } 18 | }; 19 | }); 20 | 21 | void destroy(Player player, @Nonnull ItemStack original, @Nullable InteractionHand hand); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/callback/item/ItemEntityPickupCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.callback.item; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.world.entity.item.ItemEntity; 6 | import net.minecraft.world.entity.player.Player; 7 | 8 | public interface ItemEntityPickupCallback { 9 | Event EVENT = EventFactory.createArrayBacked(ItemEntityPickupCallback.class, (listeners) -> { 10 | return (player, entity) -> { 11 | for (ItemEntityPickupCallback listener : listeners) { 12 | listener.pickup(player, entity); 13 | } 14 | }; 15 | }); 16 | 17 | void pickup(Player player, ItemEntity entity); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/callback/item/ItemEntityTossCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.callback.item; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.world.entity.item.ItemEntity; 6 | import net.minecraft.world.entity.player.Player; 7 | 8 | public interface ItemEntityTossCallback { 9 | Event EVENT = EventFactory.createArrayBacked(ItemEntityTossCallback.class, (listeners) -> { 10 | return (player, entity) -> { 11 | for (ItemEntityTossCallback listener : listeners) { 12 | listener.toss(player, entity); 13 | } 14 | }; 15 | }); 16 | 17 | void toss(Player player, ItemEntity entity); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/callback/item/ItemRightClickAirCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.callback.item; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.world.InteractionHand; 7 | import net.minecraft.world.entity.player.Player; 8 | import net.minecraft.world.item.ItemStack; 9 | 10 | public interface ItemRightClickAirCallback { 11 | Event EVENT = EventFactory.createArrayBacked(ItemRightClickAirCallback.class, (listeners) -> { 12 | return (player, stack, hand, position) -> { 13 | for (ItemRightClickAirCallback listener : listeners) { 14 | listener.rightClick(player, stack, hand, position); 15 | } 16 | }; 17 | }); 18 | 19 | void rightClick(Player player, ItemStack stack, InteractionHand hand, BlockPos position); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/callback/item/ItemRightClickEntityCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.callback.item; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.world.InteractionHand; 7 | import net.minecraft.world.entity.Entity; 8 | import net.minecraft.world.entity.player.Player; 9 | 10 | public interface ItemRightClickEntityCallback { 11 | Event EVENT = EventFactory.createArrayBacked(ItemRightClickEntityCallback.class, (listeners) -> { 12 | return (player, entity, hand, position) -> { 13 | for (ItemRightClickEntityCallback listener : listeners) { 14 | listener.interact(player, entity, hand, position); 15 | } 16 | }; 17 | }); 18 | 19 | void interact(Player player, Entity entity, InteractionHand hand, BlockPos position); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/callback/item/ItemSmeltCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.callback.item; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.world.Container; 6 | import net.minecraft.world.item.ItemStack; 7 | 8 | public interface ItemSmeltCallback { 9 | Event EVENT = EventFactory.createArrayBacked(ItemSmeltCallback.class, (listeners) -> { 10 | return (inventory, result) -> { 11 | for (ItemSmeltCallback listener : listeners) { 12 | listener.smelt(inventory, result); 13 | } 14 | }; 15 | }); 16 | 17 | void smelt(Container inventory, ItemStack result); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/client/ClientItemTooltipEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.client; 2 | 3 | import dev.latvian.kubejs.event.EventJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import dev.latvian.kubejs.text.Text; 6 | import net.minecraft.world.item.ItemStack; 7 | import net.minecraft.world.item.TooltipFlag; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class ClientItemTooltipEventJS extends EventJS { 15 | private final ItemStack stack; 16 | private final List lines; 17 | 18 | public ClientItemTooltipEventJS(ItemStack stack, TooltipFlag context, List lines) { 19 | this.stack = stack; 20 | this.lines = lines; 21 | } 22 | 23 | public ItemStackJS getItem() { 24 | return ItemStackJS.of(stack); 25 | } 26 | 27 | public void add(Object text) { 28 | lines.add(Text.of(text).component()); 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/client/ClientLoggedInEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.client; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.ClientPlayerJS; 5 | import dev.latvian.kubejs.player.PlayerEventJS; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class ClientLoggedInEventJS extends PlayerEventJS { 11 | private final ClientPlayerJS player; 12 | 13 | public ClientLoggedInEventJS(ClientPlayerJS p) { 14 | player = p; 15 | } 16 | 17 | @Override 18 | public EntityJS getEntity() { 19 | return player; 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/client/ClientTickEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.client; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.ClientPlayerJS; 5 | import dev.latvian.kubejs.player.PlayerEventJS; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class ClientTickEventJS extends PlayerEventJS { 11 | private final ClientPlayerJS player; 12 | 13 | public ClientTickEventJS(ClientPlayerJS p) { 14 | player = p; 15 | } 16 | 17 | @Override 18 | public EntityJS getEntity() { 19 | return player; 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/client/ClientWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.client; 2 | 3 | import com.mojang.blaze3d.platform.InputConstants; 4 | import dev.latvian.kubejs.docs.MinecraftClass; 5 | import dev.latvian.kubejs.player.ClientPlayerJS; 6 | import dev.latvian.kubejs.world.ClientWorldJS; 7 | import net.fabricmc.api.EnvType; 8 | import net.fabricmc.api.Environment; 9 | import net.minecraft.client.Minecraft; 10 | import net.minecraft.client.gui.screens.Screen; 11 | 12 | import javax.annotation.Nullable; 13 | 14 | /** 15 | * @author LatvianModder 16 | */ 17 | @Environment(EnvType.CLIENT) 18 | public class ClientWrapper { 19 | @MinecraftClass 20 | public Minecraft getMinecraft() { 21 | return Minecraft.getInstance(); 22 | } 23 | 24 | @Nullable 25 | public ClientWorldJS getWorld() { 26 | return ClientWorldJS.instance; 27 | } 28 | 29 | @Nullable 30 | public ClientPlayerJS getPlayer() { 31 | if (ClientWorldJS.instance == null) { 32 | return null; 33 | } 34 | 35 | return ClientWorldJS.instance.clientPlayerData.getPlayer(); 36 | } 37 | 38 | @Nullable 39 | public Screen getCurrentGui() { 40 | return getMinecraft().screen; 41 | } 42 | 43 | public void setCurrentGui(Screen gui) { 44 | getMinecraft().setScreen(gui); 45 | } 46 | 47 | public void setTitle(String t) { 48 | ClientProperties.get().title = t.trim(); 49 | getMinecraft().updateTitle(); 50 | } 51 | 52 | public String getCurrentWorldName() { 53 | if (getMinecraft().getCurrentServer() != null) { 54 | return getMinecraft().getCurrentServer().name; 55 | } 56 | 57 | return "Singleplayer"; 58 | } 59 | 60 | public boolean isKeyDown(int key) { 61 | return InputConstants.isKeyDown(getMinecraft().getWindow().getWindow(), key); 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/client/DebugInfoEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.client; 2 | 3 | import dev.latvian.kubejs.event.EventJS; 4 | import net.fabricmc.api.EnvType; 5 | import net.fabricmc.api.Environment; 6 | import net.minecraft.client.Minecraft; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | @Environment(EnvType.CLIENT) 14 | public class DebugInfoEventJS extends EventJS { 15 | public final List lines; 16 | 17 | public DebugInfoEventJS(List lines) { 18 | this.lines = lines; 19 | } 20 | 21 | public boolean getShowDebug() { 22 | return Minecraft.getInstance().options.renderDebug; 23 | } 24 | 25 | public List getLines() { 26 | return lines; 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/client/SoundRegistryEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.client; 2 | 3 | import dev.latvian.kubejs.KubeJS; 4 | import dev.latvian.kubejs.docs.ID; 5 | import dev.latvian.kubejs.event.EventJS; 6 | import dev.latvian.kubejs.util.UtilsJS; 7 | import net.minecraft.core.Registry; 8 | import net.minecraft.resources.ResourceLocation; 9 | import net.minecraft.sounds.SoundEvent; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class SoundRegistryEventJS extends EventJS { 15 | public final Registry registry; 16 | 17 | public SoundRegistryEventJS(Registry r) { 18 | registry = r; 19 | } 20 | 21 | public void register(@ID String id) { 22 | ResourceLocation r = UtilsJS.getMCID(KubeJS.appendModId(id)); 23 | Registry.register(registry, r, new SoundEvent(r)); 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/client/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.client; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/command/CommandRegistryEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.command; 2 | 3 | import com.mojang.brigadier.CommandDispatcher; 4 | import dev.latvian.kubejs.server.ServerEventJS; 5 | import net.minecraft.commands.CommandSourceStack; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class CommandRegistryEventJS extends ServerEventJS { 11 | private final boolean singlePlayer; 12 | private final CommandDispatcher dispatcher; 13 | 14 | public CommandRegistryEventJS(boolean s, CommandDispatcher c) { 15 | singlePlayer = s; 16 | dispatcher = c; 17 | } 18 | 19 | public boolean isSinglePlayer() { 20 | return singlePlayer; 21 | } 22 | 23 | public CommandDispatcher getDispatcher() { 24 | return dispatcher; 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/command/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.command; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/AfterScriptLoadCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | 6 | @FunctionalInterface 7 | public interface AfterScriptLoadCallback { 8 | Event EVENT = EventFactory.createArrayBacked(AfterScriptLoadCallback.class, callbacks -> () -> { 9 | for (AfterScriptLoadCallback callback : callbacks) { 10 | callback.afterLoad(); 11 | } 12 | }); 13 | 14 | void afterLoad(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/BlockKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | /** 4 | * @author LatvianModder/ 5 | */ 6 | public interface BlockKJS { 7 | /* FIXME 8 | void setHardnessKJS(float hardness); 9 | 10 | void setResistanceKJS(float resistance); 11 | 12 | void setLightLevelKJS(int lightLevel); 13 | 14 | void setHarvestToolKJS(ToolType type); 15 | 16 | void setHarvestLevelKJS(int level); 17 | */ 18 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/CompoundNBTKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import net.minecraft.nbt.Tag; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public interface CompoundNBTKJS { 11 | Map getTagsKJS(); 12 | 13 | void setTagsKJS(Map map); 14 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/DataPackRegistriesHelper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import dev.latvian.kubejs.KubeJSPaths; 4 | import dev.latvian.kubejs.script.data.KubeJSResourcePack; 5 | import dev.latvian.kubejs.server.ServerScriptManager; 6 | import dev.latvian.kubejs.util.UtilsJS; 7 | import net.minecraft.server.packs.PackResources; 8 | import net.minecraft.server.packs.PackType; 9 | 10 | import java.nio.file.Files; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * @author LatvianModder 16 | */ 17 | public class DataPackRegistriesHelper { 18 | public static List getResourcePackListKJS(List list0) { 19 | if (Files.notExists(KubeJSPaths.DATA)) { 20 | UtilsJS.tryIO(() -> Files.createDirectories(KubeJSPaths.DATA)); 21 | } 22 | List list = new ArrayList<>(); 23 | list.add(ServerScriptManager.instance.virtualDataPackLast); 24 | list.addAll(list0); 25 | list.add(new KubeJSResourcePack(PackType.SERVER_DATA)); 26 | list.add(ServerScriptManager.instance.virtualDataPackFirst); 27 | return list; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/DataPackRegistriesKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import dev.latvian.kubejs.server.ServerScriptManager; 4 | import net.minecraft.server.ServerResources; 5 | import net.minecraft.server.packs.resources.PreparableReloadListener; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public interface DataPackRegistriesKJS { 11 | default void initKJS() { 12 | try { 13 | ServerScriptManager.instance = new ServerScriptManager(); 14 | SimpleReloadableResourceManagerKJS manager = (SimpleReloadableResourceManagerKJS) (((ServerResources) this).getResourceManager()); 15 | PreparableReloadListener reloadListener = ServerScriptManager.instance.createReloadListener(); 16 | manager.getReloadListenersKJS().add(0, reloadListener); 17 | manager.getInitTaskQueueKJS().add(0, reloadListener); 18 | } catch (Exception ex) { 19 | throw new RuntimeException("KubeJS failed to register it's script loader!"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/FireworkRocketEntityKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public interface FireworkRocketEntityKJS { 7 | void setLifetimeKJS(int lifetime); 8 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/ImageButtonKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import net.minecraft.resources.ResourceLocation; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public interface ImageButtonKJS { 9 | ResourceLocation getButtonTextureKJS(); 10 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/LivingEntityKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import dev.latvian.kubejs.KubeJSEvents; 4 | import dev.latvian.kubejs.item.ItemFoodEatenEventJS; 5 | import dev.latvian.kubejs.item.ItemJS; 6 | import dev.latvian.kubejs.script.ScriptType; 7 | import net.minecraft.server.level.ServerPlayer; 8 | import net.minecraft.world.item.Item; 9 | import net.minecraft.world.item.ItemStack; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public interface LivingEntityKJS { 15 | default void foodEatenKJS(ItemStack is) { 16 | if (this instanceof ServerPlayer) { 17 | ItemFoodEatenEventJS event = new ItemFoodEatenEventJS((ServerPlayer) this, is); 18 | Item i = is.getItem(); 19 | 20 | if (i instanceof ItemJS) { 21 | ItemJS j = (ItemJS) i; 22 | 23 | if (j.properties.foodBuilder != null && j.properties.foodBuilder.eaten != null) { 24 | j.properties.foodBuilder.eaten.accept(event); 25 | } 26 | } 27 | 28 | event.post(ScriptType.SERVER, KubeJSEvents.ITEM_FOOD_EATEN); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/PlayerInteractionManagerKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public interface PlayerInteractionManagerKJS { 7 | boolean isDestroyingBlockKJS(); 8 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/ResourcePackManagerKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import net.minecraft.server.packs.repository.RepositorySource; 4 | 5 | public interface ResourcePackManagerKJS { 6 | void addProviderKJS(RepositorySource provider); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/SimpleReloadableResourceManagerKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import net.minecraft.server.packs.resources.FallbackResourceManager; 4 | import net.minecraft.server.packs.resources.PreparableReloadListener; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public interface SimpleReloadableResourceManagerKJS { 13 | Map getNamespaceResourceManagersKJS(); 14 | 15 | List getReloadListenersKJS(); 16 | 17 | List getInitTaskQueueKJS(); 18 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/TagBuilderKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import net.minecraft.tags.Tag; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public interface TagBuilderKJS { 11 | List getProxyListKJS(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/TagCollectionKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import dev.latvian.kubejs.item.ingredient.TagIngredientJS; 4 | import dev.latvian.kubejs.server.TagEventJS; 5 | import net.minecraft.resources.ResourceLocation; 6 | import net.minecraft.tags.Tag; 7 | 8 | import java.util.Map; 9 | import java.util.Optional; 10 | import java.util.function.Function; 11 | 12 | /** 13 | * @author LatvianModder 14 | */ 15 | public interface TagCollectionKJS { 16 | default void customTagsKJS(Map map) { 17 | TagIngredientJS.clearTagCache(); 18 | String c = getResourceLocationPrefixKJS().substring(5); 19 | String t = getItemTypeNameKJS(); 20 | new TagEventJS<>(c, map, getRegistryGetterKJS()).post(t + ".tags"); 21 | } 22 | 23 | Function> getRegistryGetterKJS(); 24 | 25 | String getResourceLocationPrefixKJS(); 26 | 27 | String getItemTypeNameKJS(); 28 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/TradeOfferKJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core; 2 | 3 | import net.minecraft.world.item.ItemStack; 4 | 5 | public interface TradeOfferKJS { 6 | ItemStack getFirstBuyItem(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/AbstractBlockMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.BlockKJS; 4 | import net.minecraft.world.level.block.state.BlockBehaviour; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | @Mixin(BlockBehaviour.class) 11 | public abstract class AbstractBlockMixin implements BlockKJS { 12 | /* FIXME 13 | @Override 14 | @Accessor("blockHardness") 15 | public abstract void setHardnessKJS(float f); 16 | 17 | @Override 18 | @Accessor(value = "field_235689_au_") 19 | public abstract void setResistanceKJS(float f); 20 | 21 | @Override 22 | @Accessor("lightValue") 23 | public abstract void setLightLevelKJS(int f); 24 | 25 | @Override 26 | @Accessor(value = "harvestTool") 27 | public abstract void setHarvestToolKJS(ToolType v); 28 | 29 | @Override 30 | @Accessor(value = "harvestLevel") 31 | public abstract void setHarvestLevelKJS(int v); 32 | */ 33 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/AbstractFurnaceBlockEntityMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.callback.item.ItemSmeltCallback; 4 | import net.minecraft.world.item.ItemStack; 5 | import net.minecraft.world.item.crafting.Recipe; 6 | import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; 7 | import net.minecraft.world.level.block.entity.BlockEntity; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 12 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 13 | 14 | @Mixin(AbstractFurnaceBlockEntity.class) 15 | public class AbstractFurnaceBlockEntityMixin { 16 | @Inject(locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;isEmpty()Z", ordinal = 0), method = "burn") 17 | void onSmelt(Recipe recipe, CallbackInfo ci, ItemStack itemStack, ItemStack itemStack2, ItemStack itemStack3) { 18 | if (((BlockEntity) (Object) this).getLevel().isClientSide()) return; 19 | 20 | ItemSmeltCallback.EVENT.invoker().smelt((AbstractFurnaceBlockEntity) (Object) this, itemStack2.copy()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/ClientRecipeBookMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import net.minecraft.client.ClientRecipeBook; 4 | import net.minecraft.client.RecipeBookCategories; 5 | import net.minecraft.world.item.crafting.Recipe; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 10 | 11 | @Mixin(ClientRecipeBook.class) 12 | public class ClientRecipeBookMixin { 13 | @Inject(method = "getCategory", 14 | at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;warn(Ljava/lang/String;[Lorg/apache/logging/log4j/util/Supplier;)V", 15 | ordinal = 0), cancellable = true) 16 | private static void getCategory(Recipe recipe, CallbackInfoReturnable cir) { 17 | cir.setReturnValue(RecipeBookCategories.UNKNOWN); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/CompoundNBTMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.CompoundNBTKJS; 4 | import net.minecraft.nbt.CompoundTag; 5 | import net.minecraft.nbt.Tag; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.gen.Accessor; 8 | 9 | import java.util.Map; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | @Mixin(CompoundTag.class) 15 | public abstract class CompoundNBTMixin implements CompoundNBTKJS { 16 | @Override 17 | @Accessor("tags") 18 | public abstract Map getTagsKJS(); 19 | 20 | @Override 21 | @Accessor("tags") 22 | public abstract void setTagsKJS(Map map); 23 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/CraftingResultSlotMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.callback.item.ItemCraftCallback; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.CraftingContainer; 6 | import net.minecraft.world.inventory.ResultSlot; 7 | import net.minecraft.world.item.ItemStack; 8 | import org.spongepowered.asm.mixin.Final; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Shadow; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 | 15 | @Mixin(ResultSlot.class) 16 | public class CraftingResultSlotMixin { 17 | @Shadow @Final private Player player; 18 | 19 | @Shadow @Final private CraftingContainer craftSlots; 20 | 21 | @Inject(at = @At("HEAD"), method = "checkTakeAchievements") 22 | void onCraftKJS(ItemStack stack, CallbackInfo ci) { 23 | ItemCraftCallback.EVENT.invoker().craft(this.player, craftSlots, stack); 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/DataPackRegistriesMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.DataPackRegistriesHelper; 4 | import dev.latvian.kubejs.core.DataPackRegistriesKJS; 5 | import net.minecraft.server.ServerResources; 6 | import net.minecraft.server.packs.PackResources; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.ModifyArg; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * @author LatvianModder 17 | */ 18 | @Mixin(ServerResources.class) 19 | public abstract class DataPackRegistriesMixin implements DataPackRegistriesKJS { 20 | @Inject(method = "", at = @At("RETURN")) 21 | private void initKJS(CallbackInfo ci) { 22 | initKJS(); 23 | } 24 | 25 | @ModifyArg(method = "loadResources", at = @At(value = "INVOKE", ordinal = 0, 26 | target = "Lnet/minecraft/server/packs/resources/ReloadableResourceManager;reload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/List;Ljava/util/concurrent/CompletableFuture;)Ljava/util/concurrent/CompletableFuture;"), 27 | index = 2) 28 | private static List resourcePackListKJS(List list) { 29 | return DataPackRegistriesHelper.getResourcePackListKJS(list); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/DebugHudMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.client.KubeJSClientEventHandler; 4 | import net.fabricmc.api.EnvType; 5 | import net.fabricmc.api.Environment; 6 | import net.minecraft.client.gui.components.DebugScreenOverlay; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 11 | 12 | import java.util.List; 13 | 14 | @Mixin(DebugScreenOverlay.class) 15 | @Environment(EnvType.CLIENT) 16 | public class DebugHudMixin { 17 | @Inject(at = @At("RETURN"), method = "getGameInformation") 18 | protected void getLeftTextKJS(CallbackInfoReturnable> info) { 19 | KubeJSClientEventHandler.ON_DEBUG_TEXT.invoker().accept(true, info.getReturnValue()); 20 | } 21 | 22 | @Inject(at = @At("RETURN"), method = "getSystemInformation") 23 | protected void getRightTextKJS(CallbackInfoReturnable> info) { 24 | KubeJSClientEventHandler.ON_DEBUG_TEXT.invoker().accept(false, info.getReturnValue()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/EntityMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.callback.item.ItemEntityTossCallback; 4 | import dev.latvian.kubejs.callback.item.ItemRightClickEntityCallback; 5 | import net.minecraft.world.InteractionHand; 6 | import net.minecraft.world.InteractionResult; 7 | import net.minecraft.world.entity.Entity; 8 | import net.minecraft.world.entity.item.ItemEntity; 9 | import net.minecraft.world.entity.player.Player; 10 | import net.minecraft.world.item.ItemStack; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 15 | 16 | @Mixin(Entity.class) 17 | public class EntityMixin { 18 | @Inject(at = @At("RETURN"), method = "spawnAtLocation(Lnet/minecraft/world/item/ItemStack;F)Lnet/minecraft/world/entity/item/ItemEntity;") 19 | void onToss(ItemStack stack, float yOffset, CallbackInfoReturnable callbackInformationReturnable) { 20 | if (!((Object) this instanceof Player) || callbackInformationReturnable.getReturnValue() == null) return; 21 | 22 | ItemEntityTossCallback.EVENT.invoker().toss((Player) (Object) this, callbackInformationReturnable.getReturnValue()); 23 | } 24 | 25 | @Inject(at = @At("RETURN"), method = "interact") 26 | void onInteract(Player player, InteractionHand hand, CallbackInfoReturnable cir) { 27 | ItemRightClickEntityCallback.EVENT.invoker().interact(player, (Entity) (Object) this, hand, player.blockPosition()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/FireworkRocketEntityMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.FireworkRocketEntityKJS; 4 | import net.minecraft.world.entity.projectile.FireworkRocketEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.gen.Accessor; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | @Mixin(FireworkRocketEntity.class) 12 | public abstract class FireworkRocketEntityMixin implements FireworkRocketEntityKJS { 13 | @Override 14 | @Accessor("lifetime") 15 | public abstract void setLifetimeKJS(int lifetime); 16 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/ImageButtonMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.ImageButtonKJS; 4 | import net.minecraft.client.gui.components.ImageButton; 5 | import net.minecraft.resources.ResourceLocation; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.gen.Accessor; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | @Mixin(ImageButton.class) 13 | public abstract class ImageButtonMixin implements ImageButtonKJS { 14 | @Override 15 | @Accessor("resourceLocation") 16 | public abstract ResourceLocation getButtonTextureKJS(); 17 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/ItemStackMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.callback.item.ItemDestroyCallback; 4 | import net.minecraft.world.entity.LivingEntity; 5 | import net.minecraft.world.entity.player.Player; 6 | import net.minecraft.world.item.ItemStack; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 12 | 13 | import java.util.function.Consumer; 14 | 15 | @Mixin(ItemStack.class) 16 | public abstract class ItemStackMixin { 17 | @Shadow 18 | public abstract ItemStack copy(); 19 | 20 | @Inject(at = @At(value = "RETURN", target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V"), 21 | method = "hurtAndBreak") 22 | void onBreak(int amount, T entity, Consumer breakCallback, CallbackInfo ci) { 23 | if (!(entity instanceof Player)) return; 24 | ItemDestroyCallback.EVENT.invoker().destroy((Player) entity, this.copy(), entity.getUsedItemHand()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/LivingEntityMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.callback.item.ItemEntityPickupCallback; 4 | import dev.latvian.kubejs.core.LivingEntityKJS; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.entity.LivingEntity; 7 | import net.minecraft.world.entity.item.ItemEntity; 8 | import net.minecraft.world.entity.player.Player; 9 | import net.minecraft.world.item.ItemStack; 10 | import net.minecraft.world.level.Level; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 16 | 17 | /** 18 | * @author LatvianModder 19 | */ 20 | @Mixin(LivingEntity.class) 21 | public abstract class LivingEntityMixin implements LivingEntityKJS { 22 | @Inject(method = "eat", at = @At("HEAD")) 23 | private void foodEaten(Level world, ItemStack item, CallbackInfoReturnable ci) { 24 | foodEatenKJS(item); 25 | } 26 | 27 | @Inject(at = @At("HEAD"), method = "take") 28 | void onPickupStack(Entity entity, int count, CallbackInfo callbackInformation) { 29 | if (!((Object) this instanceof Player) || !(entity instanceof ItemEntity)) return; 30 | 31 | ItemEntityPickupCallback.EVENT.invoker().pickup((Player) (Object) this, (ItemEntity) entity); 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/MainWindowMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import com.mojang.blaze3d.platform.Window; 4 | import dev.latvian.kubejs.client.ClientProperties; 5 | import net.fabricmc.api.EnvType; 6 | import net.fabricmc.api.Environment; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 11 | 12 | import java.io.InputStream; 13 | 14 | /** 15 | * @author LatvianModder 16 | */ 17 | @Environment(EnvType.CLIENT) 18 | @Mixin(Window.class) 19 | public class MainWindowMixin { 20 | @Inject(method = "setIcon", at = @At("HEAD"), cancellable = true) 21 | private void setWindowIcon(InputStream icon16, InputStream icon32, CallbackInfo ci) { 22 | if (ClientProperties.get().cancelIconUpdate()) { 23 | ci.cancel(); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/PlayerInteractionManagerMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.PlayerInteractionManagerKJS; 4 | import net.minecraft.server.level.ServerPlayerGameMode; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.gen.Accessor; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | @Mixin(ServerPlayerGameMode.class) 12 | public abstract class PlayerInteractionManagerMixin implements PlayerInteractionManagerKJS { 13 | @Override 14 | @Accessor("isDestroyingBlock") 15 | public abstract boolean isDestroyingBlockKJS(); 16 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/RecipeManagerMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import com.google.gson.JsonObject; 4 | import dev.latvian.kubejs.recipe.RecipeEventJS; 5 | import net.minecraft.resources.ResourceLocation; 6 | import net.minecraft.server.packs.resources.ResourceManager; 7 | import net.minecraft.util.profiling.ProfilerFiller; 8 | import net.minecraft.world.item.crafting.RecipeManager; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | import java.util.Map; 15 | 16 | /** 17 | * @author LatvianModder 18 | */ 19 | @Mixin(value = RecipeManager.class, priority = 1100) 20 | public abstract class RecipeManagerMixin { 21 | @Inject(method = "apply", at = @At("HEAD"), cancellable = true) 22 | private void customRecipesHead(Map map, ResourceManager resourceManager, ProfilerFiller profiler, CallbackInfo ci) { 23 | if (RecipeEventJS.instance != null) { 24 | RecipeEventJS.instance.post((RecipeManager) (Object) this, map); 25 | RecipeEventJS.instance = null; 26 | } 27 | ci.cancel(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/ResourcePackManagerMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import com.google.common.collect.Sets; 5 | import dev.latvian.kubejs.core.ResourcePackManagerKJS; 6 | import net.minecraft.server.packs.repository.PackRepository; 7 | import net.minecraft.server.packs.repository.RepositorySource; 8 | import org.spongepowered.asm.mixin.Final; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Mutable; 11 | import org.spongepowered.asm.mixin.Shadow; 12 | 13 | import java.util.LinkedHashSet; 14 | import java.util.Set; 15 | 16 | @Mixin(PackRepository.class) 17 | public class ResourcePackManagerMixin implements ResourcePackManagerKJS { 18 | @Mutable @Shadow @Final private Set sources; 19 | 20 | @Override 21 | public void addProviderKJS(RepositorySource provider) { 22 | LinkedHashSet set = Sets.newLinkedHashSet(sources); 23 | set.add(provider); 24 | sources = ImmutableSet.copyOf(set); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/ServerPlayerInteractionManagerMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.callback.item.ItemRightClickAirCallback; 4 | import net.minecraft.server.level.ServerPlayer; 5 | import net.minecraft.server.level.ServerPlayerGameMode; 6 | import net.minecraft.world.InteractionHand; 7 | import net.minecraft.world.InteractionResult; 8 | import net.minecraft.world.item.ItemStack; 9 | import net.minecraft.world.level.Level; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Shadow; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 15 | 16 | @Mixin(ServerPlayerGameMode.class) 17 | public class ServerPlayerInteractionManagerMixin { 18 | @Shadow public ServerPlayer player; 19 | 20 | @Inject(at = @At("HEAD"), cancellable = true, 21 | method = "useItem") 22 | void onUseItem(ServerPlayer player, Level world, ItemStack stack, InteractionHand hand, CallbackInfoReturnable callbackInformationReturnable) { 23 | ItemRightClickAirCallback.EVENT.invoker().rightClick(player, stack, hand, player.blockPosition()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/SimpleReloadableResourceManagerMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.SimpleReloadableResourceManagerKJS; 4 | import net.minecraft.server.packs.resources.FallbackResourceManager; 5 | import net.minecraft.server.packs.resources.PreparableReloadListener; 6 | import net.minecraft.server.packs.resources.SimpleReloadableResourceManager; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.gen.Accessor; 9 | 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * @author LatvianModder 15 | */ 16 | @Mixin(SimpleReloadableResourceManager.class) 17 | public abstract class SimpleReloadableResourceManagerMixin implements SimpleReloadableResourceManagerKJS { 18 | @Override 19 | @Accessor("namespacedPacks") 20 | public abstract Map getNamespaceResourceManagersKJS(); 21 | 22 | @Override 23 | @Accessor("listeners") 24 | public abstract List getReloadListenersKJS(); 25 | 26 | @Override 27 | @Accessor("recentlyRegistered") 28 | public abstract List getInitTaskQueueKJS(); 29 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/TagBuilderMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.TagBuilderKJS; 4 | import net.minecraft.tags.Tag; 5 | import org.spongepowered.asm.mixin.Final; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.gen.Accessor; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | @Mixin(Tag.Builder.class) 15 | public abstract class TagBuilderMixin implements TagBuilderKJS { 16 | @Override 17 | @Accessor(value = "entries") 18 | @Final 19 | public abstract List getProxyListKJS(); 20 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/TagCollectionMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.TagCollectionKJS; 4 | import net.minecraft.resources.ResourceLocation; 5 | import net.minecraft.tags.Tag; 6 | import net.minecraft.tags.TagCollection; 7 | import net.minecraft.tags.TagLoader; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.gen.Accessor; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 13 | 14 | import java.util.Map; 15 | import java.util.Optional; 16 | import java.util.function.Function; 17 | 18 | /** 19 | * @author LatvianModder 20 | */ 21 | @Mixin(TagLoader.class) 22 | public abstract class TagCollectionMixin implements TagCollectionKJS { 23 | @Inject(method = "load", at = @At("HEAD")) 24 | private void customTags(Map tags, CallbackInfoReturnable> cir) { 25 | customTagsKJS(tags); 26 | } 27 | 28 | @Override 29 | @Accessor("idToValue") 30 | public abstract Function> getRegistryGetterKJS(); 31 | 32 | @Override 33 | @Accessor("directory") 34 | public abstract String getResourceLocationPrefixKJS(); 35 | 36 | @Override 37 | @Accessor("name") 38 | public abstract String getItemTypeNameKJS(); 39 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/TradeOfferMixin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.core.mixin; 2 | 3 | import dev.latvian.kubejs.core.TradeOfferKJS; 4 | import net.minecraft.world.item.ItemStack; 5 | import net.minecraft.world.item.trading.MerchantOffer; 6 | import org.spongepowered.asm.mixin.Final; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | 10 | @Mixin(MerchantOffer.class) 11 | public class TradeOfferMixin implements TradeOfferKJS { 12 | @Shadow @Final private ItemStack baseCostA; 13 | 14 | @Override 15 | public ItemStack getFirstBuyItem() { 16 | return baseCostA; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/mixin/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.core.mixin; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/core/package-info.java: -------------------------------------------------------------------------------- 1 | @NonnullByDefault 2 | package dev.latvian.kubejs.core; 3 | 4 | import dev.latvian.kubejs.NonnullByDefault; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/docs/DocumentationEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.docs; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.function.Consumer; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class DocumentationEvent { 14 | public static final Event> EVENT = EventFactory.createArrayBacked(Consumer.class, consumers -> event -> { 15 | for (Consumer consumer : consumers) { 16 | consumer.accept(event); 17 | } 18 | }); 19 | private final Map, TypeDefinition> types; 20 | 21 | public DocumentationEvent() { 22 | types = new HashMap<>(); 23 | } 24 | 25 | public TypeDefinition type(Class c) { 26 | return types.computeIfAbsent(c, c1 -> new TypeDefinition(this, c1)); 27 | } 28 | 29 | public void createFile() { 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/docs/FieldDefinition.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.docs; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class FieldDefinition extends MemberDefinition { 7 | public interface Factory { 8 | FieldDefinition create(FieldDefinition f); 9 | } 10 | 11 | public boolean isFinal; 12 | 13 | FieldDefinition(TypeDefinition p, String n) { 14 | super(p, n); 15 | isFinal = true; 16 | } 17 | 18 | public FieldDefinition mutable() { 19 | isFinal = false; 20 | return this; 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/docs/ID.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.docs; 2 | 3 | import javax.annotation.meta.TypeQualifierDefault; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | 9 | /** 10 | * @author LatvianModder 11 | * This annotation indicates that type is Identifier, a.k.a minecraft styled namespace:path string. Value is default namespace 12 | */ 13 | @Documented 14 | @TypeQualifierDefault({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface ID { 17 | String value() default "minecraft"; 18 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/docs/KubeJSDocs.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.docs; 2 | 3 | import dev.latvian.kubejs.event.EventJS; 4 | import net.fabricmc.api.ModInitializer; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class KubeJSDocs implements ModInitializer { 10 | public static void documentation(DocumentationEvent event) { 11 | event.type(Object.class) 12 | .field("class", f -> f 13 | .type(Class.class) 14 | .comment("Returns the runtime class of this object") 15 | ) 16 | .method("hashCode", m -> m 17 | .type(int.class) 18 | .comment("Returns a hash code value for the object", "This method is supported for the benefit of hash tables such as those provided by HashMap") 19 | ) 20 | .method("equals", m -> m 21 | .type(boolean.class) 22 | .param("obj", Object.class) 23 | .comment("Indicates whether some other object is \"equal to\" this one") 24 | ) 25 | .method("toString", m -> m 26 | .type(String.class) 27 | .comment("Returns a string representation of the object, useful for logging") 28 | ) 29 | ; 30 | 31 | event.type(EventJS.class) 32 | .method("cancel", m -> m 33 | .comment("Stop event") 34 | ) 35 | ; 36 | } 37 | 38 | @Override 39 | public void onInitialize() { 40 | DocumentationEvent.EVENT.register(KubeJSDocs::documentation); 41 | } 42 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/docs/MemberDefinition.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.docs; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class MemberDefinition> { 11 | public final TypeDefinition parent; 12 | public final String name; 13 | public TypeDefinition type; 14 | public final List comment; 15 | 16 | MemberDefinition(TypeDefinition p, String n) { 17 | parent = p; 18 | name = n; 19 | type = parent.event.type(void.class); 20 | comment = new ArrayList<>(); 21 | } 22 | 23 | public T comment(String... c) { 24 | comment.addAll(Arrays.asList(c)); 25 | return (T) this; 26 | } 27 | 28 | public T type(Class t) { 29 | type = parent.event.type(t); 30 | return (T) this; 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/docs/MethodDefinition.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.docs; 2 | 3 | import org.apache.commons.lang3.tuple.Pair; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class MethodDefinition extends MemberDefinition { 12 | public interface Factory { 13 | MethodDefinition create(MethodDefinition m); 14 | } 15 | 16 | public final List> params; 17 | 18 | MethodDefinition(TypeDefinition p, String n) { 19 | super(p, n); 20 | params = new ArrayList<>(); 21 | } 22 | 23 | public MethodDefinition param(String name, Class c) { 24 | params.add(Pair.of(name, parent.event.type(c))); 25 | return this; 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/docs/MinecraftClass.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.docs; 2 | 3 | import javax.annotation.meta.TypeQualifierDefault; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | 9 | /** 10 | * @author LatvianModder 11 | * This annotation indicates that field type or method return type is a minecraft class and shouldn't be relied on 12 | */ 13 | @Documented 14 | @TypeQualifierDefault({ElementType.METHOD, ElementType.FIELD}) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface MinecraftClass { 17 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/docs/TypeDefinition.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.docs; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class TypeDefinition { 10 | public final DocumentationEvent event; 11 | public final Class type; 12 | public final List> members; 13 | public final List parents; 14 | 15 | TypeDefinition(DocumentationEvent e, Class c) { 16 | event = e; 17 | type = c; 18 | members = new ArrayList<>(); 19 | parents = new ArrayList<>(); 20 | 21 | if (c != Object.class) { 22 | parents.add(e.type(c.getSuperclass())); 23 | 24 | for (Class i : c.getInterfaces()) { 25 | parents.add(e.type(i)); 26 | } 27 | } 28 | } 29 | 30 | public TypeDefinition field(String name, FieldDefinition.Factory method) { 31 | members.add(method.create(new FieldDefinition(this, name))); 32 | return this; 33 | } 34 | 35 | public TypeDefinition field(String name, Class type, String... comment) { 36 | return field(name, t -> t.type(type).comment(comment)); 37 | } 38 | 39 | public TypeDefinition method(String name, MethodDefinition.Factory method) { 40 | members.add(method.create(new MethodDefinition(this, name))); 41 | return this; 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/docs/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.docs; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/CheckLivingEntitySpawnEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.entity; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class CheckLivingEntitySpawnEventJS {} 7 | //public class CheckLivingEntitySpawnEventJS extends LivingEntityEventJS 8 | //{ 9 | // public final LivingSpawnEvent.CheckSpawn event; 10 | // 11 | // public CheckLivingEntitySpawnEventJS(LivingSpawnEvent.CheckSpawn e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public boolean canCancel() 18 | // { 19 | // return true; 20 | // } 21 | // 22 | // @Override 23 | // public WorldJS getWorld() 24 | // { 25 | // return worldOf((World) event.getWorld()); 26 | // } 27 | // 28 | // @Override 29 | // public EntityJS getEntity() 30 | // { 31 | // return entityOf(event); 32 | // } 33 | // 34 | // public double getX() 35 | // { 36 | // return event.getX(); 37 | // } 38 | // 39 | // public double getY() 40 | // { 41 | // return event.getY(); 42 | // } 43 | // 44 | // public double getZ() 45 | // { 46 | // return event.getZ(); 47 | // } 48 | // 49 | // public BlockContainerJS getBlock() 50 | // { 51 | // return new BlockContainerJS(event.getWorld(), new BlockPos(getX(), getY(), getZ())); 52 | // } 53 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/DamageSourceJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.entity; 2 | 3 | import dev.latvian.kubejs.world.WorldJS; 4 | import net.minecraft.world.damagesource.DamageSource; 5 | 6 | import javax.annotation.Nullable; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class DamageSourceJS { 12 | private final WorldJS world; 13 | public final DamageSource source; 14 | 15 | public DamageSourceJS(WorldJS w, DamageSource s) { 16 | world = w; 17 | source = s; 18 | } 19 | 20 | public WorldJS getWorld() { 21 | return world; 22 | } 23 | 24 | public String getType() { 25 | return source.msgId; 26 | } 27 | 28 | @Nullable 29 | public EntityJS getImmediate() { 30 | return getWorld().getEntity(source.getDirectEntity()); 31 | } 32 | 33 | @Nullable 34 | public EntityJS getActual() { 35 | return getWorld().getEntity(source.getEntity()); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/EntityEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.entity; 2 | 3 | import dev.latvian.kubejs.world.WorldEventJS; 4 | import dev.latvian.kubejs.world.WorldJS; 5 | import net.minecraft.world.entity.Entity; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public abstract class EntityEventJS extends WorldEventJS { 11 | private EntityJS cachedEntity; 12 | 13 | public abstract EntityJS getEntity(); 14 | 15 | @Override 16 | public WorldJS getWorld() { 17 | return getEntity().getWorld(); 18 | } 19 | 20 | protected EntityJS entityOf(Entity entity) { 21 | if (cachedEntity == null) { 22 | cachedEntity = worldOf(entity).getEntity(entity); 23 | 24 | if (cachedEntity == null) { 25 | throw new IllegalStateException("Entity can't be null!"); 26 | } 27 | } 28 | 29 | return cachedEntity; 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/EntitySpawnedEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.entity; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class EntitySpawnedEventJS {} 7 | //public class EntitySpawnedEventJS extends EntityEventJS 8 | //{ 9 | // public final EntityJoinWorldEvent event; 10 | // 11 | // public EntitySpawnedEventJS(EntityJoinWorldEvent e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public boolean canCancel() 18 | // { 19 | // return true; 20 | // } 21 | // 22 | // @Override 23 | // public WorldJS getWorld() 24 | // { 25 | // return worldOf(event.getWorld()); 26 | // } 27 | // 28 | // @Override 29 | // public EntityJS getEntity() 30 | // { 31 | // return entityOf(event); 32 | // } 33 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/ItemEntityJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.entity; 2 | 3 | import dev.latvian.kubejs.item.ItemStackJS; 4 | import dev.latvian.kubejs.world.WorldJS; 5 | import net.minecraft.world.entity.item.ItemEntity; 6 | import net.minecraft.world.item.ItemStack; 7 | 8 | import javax.annotation.Nullable; 9 | import java.util.UUID; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class ItemEntityJS extends EntityJS { 15 | private final ItemEntity itemEntity; 16 | 17 | public ItemEntityJS(WorldJS w, ItemEntity e) { 18 | super(w, e); 19 | itemEntity = e; 20 | } 21 | 22 | @Override 23 | @Nullable 24 | public ItemStackJS getItem() { 25 | ItemStack stack = itemEntity.getItem(); 26 | return stack.isEmpty() ? null : ItemStackJS.of(stack); 27 | } 28 | 29 | public void setItem(Object item) { 30 | itemEntity.setItem(ItemStackJS.of(item).getItemStack()); 31 | } 32 | 33 | public int getLifespan() { 34 | return itemEntity.age; 35 | } 36 | 37 | public void setLifespan(int lifespan) { 38 | itemEntity.age = lifespan; 39 | } 40 | 41 | @Nullable 42 | public UUID getOwner() { 43 | return itemEntity.getOwner(); 44 | } 45 | 46 | public void setOwner(UUID owner) { 47 | itemEntity.setOwner(owner); 48 | } 49 | 50 | @Nullable 51 | public UUID getThrower() { 52 | return itemEntity.getThrower(); 53 | } 54 | 55 | public void setThrower(UUID thrower) { 56 | itemEntity.setThrower(thrower); 57 | } 58 | 59 | public void setDefaultPickupDelay() { 60 | setPickupDelay(10); 61 | } 62 | 63 | public void setNoPickupDelay() { 64 | setPickupDelay(0); 65 | } 66 | 67 | public void setInfinitePickupDelay() { 68 | setPickupDelay(Short.MAX_VALUE); 69 | } 70 | 71 | public void setPickupDelay(int ticks) { 72 | itemEntity.setPickUpDelay(ticks); 73 | } 74 | 75 | public void setNoDespawn() { 76 | itemEntity.setExtendedLifetime(); 77 | } 78 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/ItemFrameEntityJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.entity; 2 | 3 | import dev.latvian.kubejs.item.ItemStackJS; 4 | import dev.latvian.kubejs.world.WorldJS; 5 | import net.minecraft.world.entity.decoration.ItemFrame; 6 | import net.minecraft.world.item.ItemStack; 7 | 8 | import javax.annotation.Nullable; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class ItemFrameEntityJS extends EntityJS { 14 | private final ItemFrame itemFrameEntity; 15 | 16 | public ItemFrameEntityJS(WorldJS w, ItemFrame e) { 17 | super(w, e); 18 | itemFrameEntity = e; 19 | } 20 | 21 | @Override 22 | public boolean isFrame() { 23 | return true; 24 | } 25 | 26 | @Override 27 | @Nullable 28 | public ItemStackJS getItem() { 29 | ItemStack stack = itemFrameEntity.getItem(); 30 | return stack.isEmpty() ? null : ItemStackJS.of(stack); 31 | } 32 | 33 | public void setItem(Object item) { 34 | itemFrameEntity.setItem(ItemStackJS.of(item).getItemStack()); 35 | } 36 | 37 | public int getFrameRotation() { 38 | return itemFrameEntity.getRotation(); 39 | } 40 | 41 | public void setFrameRotation(int rotation) { 42 | itemFrameEntity.setRotation(rotation); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/LivingEntityAttackEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.entity; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class LivingEntityAttackEventJS {} 7 | //public class LivingEntityAttackEventJS extends LivingEntityEventJS 8 | //{ 9 | // public final LivingAttackEvent event; 10 | // 11 | // public LivingEntityAttackEventJS(LivingAttackEvent e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public boolean canCancel() 18 | // { 19 | // return true; 20 | // } 21 | // 22 | // @Override 23 | // public EntityJS getEntity() 24 | // { 25 | // return entityOf(event); 26 | // } 27 | // 28 | // public DamageSourceJS getSource() 29 | // { 30 | // return new DamageSourceJS(getWorld(), event.getSource()); 31 | // } 32 | // 33 | // public float getDamage() 34 | // { 35 | // return event.getAmount(); 36 | // } 37 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/LivingEntityDeathEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.entity; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class LivingEntityDeathEventJS {} 7 | //public class LivingEntityDeathEventJS extends LivingEntityEventJS 8 | //{ 9 | // public final LivingDeathEvent event; 10 | // 11 | // public LivingEntityDeathEventJS(LivingDeathEvent e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public boolean canCancel() 18 | // { 19 | // return true; 20 | // } 21 | // 22 | // @Override 23 | // public EntityJS getEntity() 24 | // { 25 | // return entityOf(event); 26 | // } 27 | // 28 | // public DamageSourceJS getSource() 29 | // { 30 | // return new DamageSourceJS(getWorld(), event.getSource()); 31 | // } 32 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/LivingEntityEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.entity; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public abstract class LivingEntityEventJS extends EntityEventJS { 7 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/entity/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.entity; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/event/DataEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.event; 2 | 3 | import javax.annotation.Nullable; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public class DataEvent extends EventJS { 9 | private final boolean canCancel; 10 | private final Object data; 11 | 12 | public DataEvent(boolean c, @Nullable Object d) { 13 | canCancel = c; 14 | data = d; 15 | } 16 | 17 | @Override 18 | public boolean canCancel() { 19 | return canCancel; 20 | } 21 | 22 | @Nullable 23 | public Object getData() { 24 | return data; 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/event/EventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.event; 2 | 3 | import dev.latvian.kubejs.script.ScriptType; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public class EventJS { 9 | private boolean cancelled = false; 10 | 11 | public boolean canCancel() { 12 | return false; 13 | } 14 | 15 | public final void cancel() { 16 | cancelled = true; 17 | } 18 | 19 | public final boolean isCancelled() { 20 | return cancelled; 21 | } 22 | 23 | protected void afterPosted(boolean result) { 24 | } 25 | 26 | public final boolean post(ScriptType t, String id) { 27 | if (t != ScriptType.STARTUP && post(ScriptType.STARTUP, id) && canCancel()) { 28 | return true; 29 | } 30 | 31 | EventsJS e = t.manager.get().events; 32 | boolean b = e.postToHandlers(id, e.handlers(id), this); 33 | afterPosted(b); 34 | return b; 35 | } 36 | 37 | public final boolean post(ScriptType t, String id, String sub) { 38 | String id1 = id + '.' + sub; 39 | 40 | if (t != ScriptType.STARTUP) { 41 | EventsJS e = ScriptType.STARTUP.manager.get().events; 42 | if ((e.postToHandlers(id1, e.handlers(id1), this) || e.postToHandlers(id, e.handlers(id), this)) && canCancel()) { 43 | afterPosted(true); 44 | return true; 45 | } 46 | } 47 | 48 | EventsJS e = t.manager.get().events; 49 | boolean b = e.postToHandlers(id1, e.handlers(id1), this) || e.postToHandlers(id, e.handlers(id), this); 50 | afterPosted(b); 51 | return b; 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/event/IEventHandler.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.event; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | @FunctionalInterface 7 | public interface IEventHandler { 8 | void onEvent(EventJS event); 9 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/event/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.event; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/fluid/BoundFluidStackJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.fluid; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class BoundFluidStackJS {} 7 | //public class BoundFluidStackJS extends FluidStackJS 8 | //{ 9 | // private final FluidStack fluidStack; 10 | // 11 | // public BoundFluidStackJS(FluidStack fs) 12 | // { 13 | // fluidStack = fs; 14 | // } 15 | // 16 | // @Override 17 | // public String getId() 18 | // { 19 | // return fluidStack.getFluid().getRegistryName().toString(); 20 | // } 21 | // 22 | // @Override 23 | // public Fluid getFluid() 24 | // { 25 | // return fluidStack.getFluid(); 26 | // } 27 | // 28 | // @Override 29 | // public FluidStack getFluidStack() 30 | // { 31 | // return fluidStack; 32 | // } 33 | // 34 | // @Override 35 | // public int getAmount() 36 | // { 37 | // return fluidStack.getAmount(); 38 | // } 39 | // 40 | // @Override 41 | // public void setAmount(int amount) 42 | // { 43 | // fluidStack.setAmount(amount); 44 | // } 45 | // 46 | // @Override 47 | // @Nullable 48 | // public MapJS getNbt() 49 | // { 50 | // return MapJS.of(fluidStack.getTag()); 51 | // } 52 | // 53 | // @Override 54 | // public void setNbt(@Nullable Object nbt) 55 | // { 56 | // fluidStack.setTag(MapJS.nbt(nbt)); 57 | // } 58 | // 59 | // @Override 60 | // public FluidStackJS copy() 61 | // { 62 | // return new BoundFluidStackJS(fluidStack.copy()); 63 | // } 64 | // 65 | // @Override 66 | // public void onChanged(@Nullable MapJS o) 67 | // { 68 | // setNbt(o); 69 | // } 70 | //} 71 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/fluid/BucketItemJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.fluid; 2 | 3 | import net.minecraft.world.item.BucketItem; 4 | import net.minecraft.world.item.CreativeModeTab; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class BucketItemJS extends BucketItem { 10 | public final FluidBuilder properties; 11 | 12 | public BucketItemJS(FluidBuilder b) { 13 | super(b.stillFluid, new Properties().stacksTo(1).tab(CreativeModeTab.TAB_MISC)); 14 | properties = b; 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/fluid/EmptyFluidStackJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.fluid; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class EmptyFluidStackJS {} 7 | //public class EmptyFluidStackJS extends FluidStackJS 8 | //{ 9 | // public static final EmptyFluidStackJS INSTANCE = new EmptyFluidStackJS(); 10 | // 11 | // @Override 12 | // public boolean isEmpty() 13 | // { 14 | // return true; 15 | // } 16 | // 17 | // @Override 18 | // public String getId() 19 | // { 20 | // return "minecraft:empty"; 21 | // } 22 | // 23 | // @Override 24 | // public Fluid getFluid() 25 | // { 26 | // return Fluids.EMPTY; 27 | // } 28 | // 29 | // @Nullable 30 | // @Override 31 | // public FluidStack getFluidStack() 32 | // { 33 | // return null; 34 | // } 35 | // 36 | // @Override 37 | // public int getAmount() 38 | // { 39 | // return 0; 40 | // } 41 | // 42 | // @Override 43 | // public void setAmount(int amount) 44 | // { 45 | // } 46 | // 47 | // @Override 48 | // @Nullable 49 | // public MapJS getNbt() 50 | // { 51 | // return null; 52 | // } 53 | // 54 | // @Override 55 | // public void setNbt(@Nullable Object nbt) 56 | // { 57 | // } 58 | // 59 | // @Override 60 | // public FluidStackJS copy() 61 | // { 62 | // return this; 63 | // } 64 | // 65 | // @Override 66 | // public boolean equals(Object o) 67 | // { 68 | // return FluidStackJS.of(o).isEmpty(); 69 | // } 70 | // 71 | // @Override 72 | // public boolean strongEquals(Object o) 73 | // { 74 | // return FluidStackJS.of(o).isEmpty(); 75 | // } 76 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/fluid/FluidRegistryEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.fluid; 2 | 3 | import dev.latvian.kubejs.KubeJSObjects; 4 | import dev.latvian.kubejs.event.EventJS; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class FluidRegistryEventJS extends EventJS { 10 | public FluidBuilder create(String name) { 11 | FluidBuilder builder = new FluidBuilder(name); 12 | KubeJSObjects.FLUIDS.put(builder.id, builder); 13 | KubeJSObjects.ALL.add(builder); 14 | return builder; 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/fluid/FluidWrapper.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.fluid; 2 | 3 | import dev.latvian.kubejs.docs.ID; 4 | import dev.latvian.kubejs.docs.MinecraftClass; 5 | import dev.latvian.kubejs.util.UtilsJS; 6 | import net.minecraft.core.Registry; 7 | import net.minecraft.resources.ResourceLocation; 8 | import net.minecraft.world.level.material.Fluid; 9 | import net.minecraft.world.level.material.Fluids; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * @author LatvianModder 16 | */ 17 | public class FluidWrapper { 18 | // public FluidStackJS of(@ID Object o) 19 | // { 20 | // return FluidStackJS.of(o); 21 | // } 22 | // 23 | // public FluidStackJS of(@ID Object o, Object amountOrNBT) 24 | // { 25 | // return FluidStackJS.of(o, amountOrNBT); 26 | // } 27 | // 28 | // public FluidStackJS of(@ID Object o, int amount, Object nbt) 29 | // { 30 | // return FluidStackJS.of(o, amount, nbt); 31 | // } 32 | 33 | @MinecraftClass 34 | public Fluid getType(@ID String id) { 35 | Fluid f = Registry.FLUID.get(UtilsJS.getMCID(id)); 36 | return f == null ? Fluids.EMPTY : f; 37 | } 38 | 39 | public List getTypes() { 40 | List set = new ArrayList<>(); 41 | 42 | for (ResourceLocation id : Registry.FLUID.keySet()) { 43 | set.add(id.toString()); 44 | } 45 | 46 | return set; 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/fluid/KubeJSFluidEventHandler.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.fluid; 2 | 3 | import dev.latvian.kubejs.KubeJSInitializer; 4 | import dev.latvian.kubejs.core.AfterScriptLoadCallback; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class KubeJSFluidEventHandler implements KubeJSInitializer { 10 | @Override 11 | public void onKubeJSInitialization() { 12 | AfterScriptLoadCallback.EVENT.register(this::registry); 13 | } 14 | 15 | private void registry() { 16 | // TODO 17 | // for (FluidBuilder builder : KubeJSObjects.FLUIDS.values()) 18 | // { 19 | // builder.stillFluid = new ForgeFlowingFluid.Source(builder.createProperties()); 20 | // builder.stillFluid.setRegistryName(builder.id); 21 | // event.getRegistry().register(builder.stillFluid); 22 | // 23 | // builder.flowingFluid = new ForgeFlowingFluid.Flowing(builder.createProperties()); 24 | // builder.flowingFluid.setRegistryName(builder.id.getNamespace() + ":flowing_" + builder.id.getPath()); 25 | // event.getRegistry().register(builder.flowingFluid); 26 | // } 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/fluid/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.fluid; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/BlockItemJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.block.BlockItemBuilder; 4 | import net.minecraft.world.item.BlockItem; 5 | import net.minecraft.world.item.ItemStack; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class BlockItemJS extends BlockItem { 11 | public final BlockItemBuilder properties; 12 | 13 | public BlockItemJS(BlockItemBuilder p) { 14 | super(p.blockBuilder.block, p.createItemProperties()); 15 | properties = p; 16 | } 17 | 18 | @Override 19 | public boolean isFoil(ItemStack stack) { 20 | return properties.glow || super.isFoil(stack); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemCraftedEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import net.minecraft.world.Container; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.item.ItemStack; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class ItemCraftedEventJS extends PlayerEventJS { 13 | public final Player player; 14 | public final Container inventory; 15 | public final ItemStack result; 16 | 17 | public ItemCraftedEventJS(Player player, Container inventory, ItemStack result) { 18 | this.player = player; 19 | this.inventory = inventory; 20 | this.result = result; 21 | } 22 | 23 | @Override 24 | public EntityJS getEntity() { 25 | return entityOf(player); 26 | } 27 | 28 | public ItemStackJS getItem() { 29 | return ItemStackJS.of(result); 30 | } 31 | 32 | public InventoryJS getInventory() { 33 | return new InventoryJS(inventory); 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemDestroyedEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import net.minecraft.world.InteractionHand; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.item.ItemStack; 8 | 9 | import javax.annotation.Nullable; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class ItemDestroyedEventJS extends PlayerEventJS { 15 | public final Player player; 16 | public final ItemStack original; 17 | public final InteractionHand hand; 18 | 19 | public ItemDestroyedEventJS(Player player, ItemStack original, InteractionHand hand) { 20 | this.player = player; 21 | this.original = original; 22 | this.hand = hand; 23 | } 24 | 25 | @Override 26 | public boolean canCancel() { 27 | return true; 28 | } 29 | 30 | @Override 31 | public EntityJS getEntity() { 32 | return entityOf(player); 33 | } 34 | 35 | @Nullable 36 | public InteractionHand getHand() { 37 | return hand; 38 | } 39 | 40 | public ItemStackJS getItem() { 41 | return ItemStackJS.of(original); 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemEntityInteractEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.world.InteractionHand; 7 | import net.minecraft.world.entity.Entity; 8 | import net.minecraft.world.entity.player.Player; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class ItemEntityInteractEventJS extends PlayerEventJS { 14 | public final Player player; 15 | public final Entity entity; 16 | public final InteractionHand hand; 17 | public final BlockPos position; 18 | 19 | public ItemEntityInteractEventJS(Player player, Entity entity, InteractionHand hand, BlockPos position) { 20 | this.player = player; 21 | this.entity = entity; 22 | this.hand = hand; 23 | this.position = position; 24 | } 25 | 26 | @Override 27 | public boolean canCancel() { 28 | return true; 29 | } 30 | 31 | @Override 32 | public EntityJS getEntity() { 33 | return entityOf(player); 34 | } 35 | 36 | public InteractionHand getHand() { 37 | return hand; 38 | } 39 | 40 | public ItemStackJS getItem() { 41 | return ItemStackJS.of(player.getItemInHand(hand)); 42 | } 43 | 44 | public EntityJS getTarget() { 45 | return getWorld().getEntity(entity); 46 | } 47 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemFoodEatenEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import net.minecraft.server.level.ServerPlayer; 6 | import net.minecraft.world.item.ItemStack; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class ItemFoodEatenEventJS extends PlayerEventJS { 12 | private final ServerPlayer player; 13 | public final ItemStackJS item; 14 | 15 | public ItemFoodEatenEventJS(ServerPlayer p, ItemStack is) { 16 | player = p; 17 | item = ItemStackJS.of(is); 18 | } 19 | 20 | @Override 21 | public boolean canCancel() { 22 | return true; 23 | } 24 | 25 | @Override 26 | public EntityJS getEntity() { 27 | return entityOf(player); 28 | } 29 | 30 | public ItemStackJS getItem() { 31 | return item; 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemLeftClickEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.world.InteractionHand; 7 | import net.minecraft.world.entity.player.Player; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class ItemLeftClickEventJS extends PlayerEventJS { 13 | public final Player player; 14 | public final InteractionHand hand; 15 | public final BlockPos position; 16 | 17 | public ItemLeftClickEventJS(Player player, InteractionHand hand, BlockPos position) { 18 | this.player = player; 19 | this.hand = hand; 20 | this.position = position; 21 | } 22 | 23 | @Override 24 | public EntityJS getEntity() { 25 | return entityOf(player); 26 | } 27 | 28 | public ItemStackJS getItem() { 29 | return ItemStackJS.of(player.getItemInHand(hand)); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemPickupEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import net.minecraft.world.entity.item.ItemEntity; 6 | import net.minecraft.world.entity.player.Player; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class ItemPickupEventJS extends PlayerEventJS { 12 | public final Player player; 13 | public final ItemEntity entity; 14 | 15 | public ItemPickupEventJS(Player player, ItemEntity entity) { 16 | this.player = player; 17 | this.entity = entity; 18 | } 19 | 20 | @Override 21 | public boolean canCancel() { 22 | return true; 23 | } 24 | 25 | @Override 26 | public EntityJS getEntity() { 27 | return entityOf(player); 28 | } 29 | 30 | public EntityJS getItemEntity() { 31 | return entityOf(entity); 32 | } 33 | 34 | public ItemStackJS getItem() { 35 | return ItemStackJS.of(entity.getItem()); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemRegistryEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.KubeJS; 4 | import dev.latvian.kubejs.KubeJSObjects; 5 | import dev.latvian.kubejs.block.BlockItemBuilder; 6 | import dev.latvian.kubejs.event.EventJS; 7 | 8 | import java.util.function.Supplier; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class ItemRegistryEventJS extends EventJS { 14 | public ItemBuilder create(String name) { 15 | ItemBuilder builder = new ItemBuilder(name); 16 | KubeJSObjects.ITEMS.put(builder.id, builder); 17 | KubeJSObjects.ALL.add(builder); 18 | return builder; 19 | } 20 | 21 | @Deprecated 22 | public BlockItemBuilder createBlockItem(String name) { 23 | KubeJS.LOGGER.error("This method is deprecated! Replaced by block registry .item(function(item) { /*chained item functions here*/ }) or .noItem()"); 24 | return new BlockItemBuilder(name); 25 | } 26 | 27 | public Supplier createFood(Supplier builder) { 28 | return builder; 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemRightClickEmptyEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.world.InteractionHand; 7 | import net.minecraft.world.entity.player.Player; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class ItemRightClickEmptyEventJS extends PlayerEventJS { 13 | public final Player player; 14 | public final InteractionHand hand; 15 | public final BlockPos position; 16 | 17 | public ItemRightClickEmptyEventJS(Player player, InteractionHand hand, BlockPos position) { 18 | this.player = player; 19 | this.hand = hand; 20 | this.position = position; 21 | } 22 | 23 | @Override 24 | public EntityJS getEntity() { 25 | return entityOf(player); 26 | } 27 | 28 | public InteractionHand getHand() { 29 | return hand; 30 | } 31 | 32 | public ItemStackJS getItem() { 33 | return EmptyItemStackJS.INSTANCE; 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemRightClickEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.world.InteractionHand; 7 | import net.minecraft.world.entity.player.Player; 8 | import net.minecraft.world.item.ItemStack; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class ItemRightClickEventJS extends PlayerEventJS { 14 | public final Player player; 15 | public final InteractionHand hand; 16 | public final ItemStack stack; 17 | public final BlockPos position; 18 | 19 | public ItemRightClickEventJS(Player player, ItemStack stack, InteractionHand hand, BlockPos position) { 20 | this.player = player; 21 | this.stack = stack; 22 | this.hand = hand; 23 | this.position = position; 24 | } 25 | 26 | @Override 27 | public boolean canCancel() { 28 | return true; 29 | } 30 | 31 | @Override 32 | public EntityJS getEntity() { 33 | return entityOf(player); 34 | } 35 | 36 | public InteractionHand getHand() { 37 | return hand; 38 | } 39 | 40 | public ItemStackJS getItem() { 41 | return ItemStackJS.of(stack); 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemSmeltedEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.event.EventJS; 4 | import net.minecraft.world.Container; 5 | import net.minecraft.world.item.ItemStack; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class ItemSmeltedEventJS extends EventJS { 11 | public final Container inventory; 12 | public final ItemStack result; 13 | 14 | public ItemSmeltedEventJS(Container inventory, ItemStack result) { 15 | this.inventory = inventory; 16 | this.result = result; 17 | } 18 | 19 | public ItemStackJS getItem() { 20 | return ItemStackJS.of(result); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ItemTossEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import net.minecraft.world.entity.item.ItemEntity; 6 | import net.minecraft.world.entity.player.Player; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class ItemTossEventJS extends PlayerEventJS { 12 | public final Player player; 13 | public final ItemEntity entity; 14 | 15 | public ItemTossEventJS(Player player, ItemEntity entity) { 16 | this.player = player; 17 | this.entity = entity; 18 | } 19 | 20 | @Override 21 | public boolean canCancel() { 22 | return true; 23 | } 24 | 25 | @Override 26 | public EntityJS getEntity() { 27 | return entityOf(player); 28 | } 29 | 30 | public EntityJS getItemEntity() { 31 | return getWorld().getEntity(entity); 32 | } 33 | 34 | public ItemStackJS getItem() { 35 | return ItemStackJS.of(entity.getItem()); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ingredient/FilteredIngredientJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item.ingredient; 2 | 3 | import dev.latvian.kubejs.item.ItemStackJS; 4 | 5 | import java.util.LinkedHashSet; 6 | import java.util.Set; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public final class FilteredIngredientJS implements IngredientJS { 12 | private final IngredientJS ingredient; 13 | private final IngredientJS filter; 14 | 15 | public FilteredIngredientJS(IngredientJS i, IngredientJS f) { 16 | ingredient = i; 17 | filter = f; 18 | } 19 | 20 | @Override 21 | public boolean test(ItemStackJS stack) { 22 | return ingredient.test(stack) && filter.test(stack); 23 | } 24 | 25 | @Override 26 | public Set getStacks() { 27 | Set set = new LinkedHashSet<>(); 28 | 29 | for (ItemStackJS stack : ingredient.getStacks()) { 30 | if (filter.test(stack)) { 31 | set.add(stack); 32 | } 33 | } 34 | 35 | return set; 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ingredient/GroupIngredientJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item.ingredient; 2 | 3 | import dev.latvian.kubejs.docs.MinecraftClass; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import net.minecraft.world.item.CreativeModeTab; 6 | import net.minecraft.world.item.ItemStack; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class GroupIngredientJS implements IngredientJS { 12 | private final CreativeModeTab group; 13 | 14 | public GroupIngredientJS(CreativeModeTab m) { 15 | group = m; 16 | } 17 | 18 | @MinecraftClass 19 | public CreativeModeTab getGroup() { 20 | return group; 21 | } 22 | 23 | public String getGroupId() { 24 | return group.getRecipeFolderName(); 25 | } 26 | 27 | @Override 28 | public boolean test(ItemStackJS stack) { 29 | return !stack.isEmpty() && stack.getItem().getItemCategory() == group; 30 | } 31 | 32 | @Override 33 | public boolean testVanilla(ItemStack stack) { 34 | return !stack.isEmpty() && stack.getItem().getItemCategory() == group; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "%" + group.getRecipeFolderName(); 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ingredient/IgnoreNBTIngredientJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item.ingredient; 2 | 3 | import dev.latvian.kubejs.item.ItemStackJS; 4 | import net.minecraft.world.item.ItemStack; 5 | 6 | import java.util.Set; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public final class IgnoreNBTIngredientJS implements IngredientJS { 12 | private final ItemStackJS item; 13 | 14 | public IgnoreNBTIngredientJS(ItemStackJS i) { 15 | item = i; 16 | } 17 | 18 | @Override 19 | public boolean test(ItemStackJS stack) { 20 | return item.areItemsEqual(stack); 21 | } 22 | 23 | @Override 24 | public boolean testVanilla(ItemStack stack) { 25 | return item.getItem() == stack.getItem(); 26 | } 27 | 28 | @Override 29 | public Set getStacks() { 30 | return item.getStacks(); 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ingredient/MatchAllIngredientJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item.ingredient; 2 | 3 | import dev.latvian.kubejs.item.EmptyItemStackJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import net.minecraft.world.item.ItemStack; 6 | 7 | import java.util.LinkedHashSet; 8 | import java.util.List; 9 | import java.util.Set; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class MatchAllIngredientJS implements IngredientJS { 15 | public static MatchAllIngredientJS INSTANCE = new MatchAllIngredientJS(); 16 | 17 | private MatchAllIngredientJS() { 18 | } 19 | 20 | @Override 21 | public boolean test(ItemStackJS stack) { 22 | return !stack.isEmpty(); 23 | } 24 | 25 | @Override 26 | public boolean testVanilla(ItemStack stack) { 27 | return !stack.isEmpty(); 28 | } 29 | 30 | @Override 31 | public Set getStacks() { 32 | Set set = new LinkedHashSet<>(); 33 | 34 | for (ItemStackJS stack : ItemStackJS.getList()) { 35 | set.add(stack.getCopy()); 36 | } 37 | 38 | return set; 39 | } 40 | 41 | @Override 42 | public ItemStackJS getFirst() { 43 | List list = ItemStackJS.getList(); 44 | return list.isEmpty() ? EmptyItemStackJS.INSTANCE : list.get(0).getCopy(); 45 | } 46 | 47 | @Override 48 | public IngredientJS not() { 49 | return EmptyItemStackJS.INSTANCE; 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ingredient/ModIngredientJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item.ingredient; 2 | 3 | import dev.latvian.kubejs.item.EmptyItemStackJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import net.minecraft.core.Registry; 6 | import net.minecraft.world.item.ItemStack; 7 | 8 | import java.util.LinkedHashSet; 9 | import java.util.Set; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class ModIngredientJS implements IngredientJS { 15 | private final String mod; 16 | 17 | public ModIngredientJS(String m) { 18 | mod = m; 19 | } 20 | 21 | public String getMod() { 22 | return mod; 23 | } 24 | 25 | @Override 26 | public boolean test(ItemStackJS stack) { 27 | return !stack.isEmpty() && mod.equals(stack.getMod()); 28 | } 29 | 30 | @Override 31 | public boolean testVanilla(ItemStack stack) { 32 | return !stack.isEmpty() && mod.equals(Registry.ITEM.getKey(stack.getItem()).getNamespace()); 33 | } 34 | 35 | @Override 36 | public Set getStacks() { 37 | Set set = new LinkedHashSet<>(); 38 | 39 | for (ItemStackJS stack : ItemStackJS.getList()) { 40 | if (mod.equals(stack.getMod())) { 41 | set.add(stack); 42 | } 43 | } 44 | 45 | return set; 46 | } 47 | 48 | @Override 49 | public ItemStackJS getFirst() { 50 | for (ItemStackJS stack : ItemStackJS.getList()) { 51 | if (mod.equals(stack.getMod())) { 52 | return stack.getCopy(); 53 | } 54 | } 55 | 56 | return EmptyItemStackJS.INSTANCE; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "mod:" + mod; 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ingredient/NotIngredientJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item.ingredient; 2 | 3 | import dev.latvian.kubejs.item.ItemStackJS; 4 | import net.minecraft.world.item.ItemStack; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public final class NotIngredientJS implements IngredientJS { 10 | private final IngredientJS ingredientJS; 11 | 12 | public NotIngredientJS(IngredientJS i) { 13 | ingredientJS = i; 14 | } 15 | 16 | @Override 17 | public boolean test(ItemStackJS stack) { 18 | return !ingredientJS.test(stack); 19 | } 20 | 21 | @Override 22 | public boolean testVanilla(ItemStack stack) { 23 | return !ingredientJS.testVanilla(stack); 24 | } 25 | 26 | @Override 27 | public IngredientJS not() { 28 | return ingredientJS; 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ingredient/RegexIngredientJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item.ingredient; 2 | 3 | import dev.latvian.kubejs.item.ItemStackJS; 4 | import net.minecraft.core.Registry; 5 | import net.minecraft.world.item.ItemStack; 6 | 7 | import java.util.regex.Pattern; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class RegexIngredientJS implements IngredientJS { 13 | private final Pattern pattern; 14 | 15 | public RegexIngredientJS(Pattern p) { 16 | pattern = p; 17 | } 18 | 19 | public Pattern getPattern() { 20 | return pattern; 21 | } 22 | 23 | @Override 24 | public boolean test(ItemStackJS stack) { 25 | return !stack.isEmpty() && pattern.matcher(stack.getId()).find(); 26 | } 27 | 28 | @Override 29 | public boolean testVanilla(ItemStack stack) { 30 | return !stack.isEmpty() && pattern.matcher(Registry.ITEM.getKey(stack.getItem()).toString()).find(); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "regex:" + pattern; 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ingredient/VanillaPredicate.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.item.ingredient; 2 | 3 | import net.minecraft.world.item.ItemStack; 4 | 5 | import java.util.function.Predicate; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class VanillaPredicate implements Predicate { 11 | private final IngredientJS ingredient; 12 | 13 | public VanillaPredicate(IngredientJS i) { 14 | ingredient = i; 15 | } 16 | 17 | @Override 18 | public boolean test(ItemStack stack) { 19 | return ingredient.testVanilla(stack); 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/ingredient/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.item.ingredient; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/item/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.item; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/net/MessageCloseOverlay.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.net; 2 | 3 | import dev.latvian.kubejs.KubeJS; 4 | import net.fabricmc.fabric.api.network.PacketContext; 5 | import net.minecraft.network.FriendlyByteBuf; 6 | 7 | import java.util.function.Supplier; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class MessageCloseOverlay { 13 | private final String overlay; 14 | 15 | public MessageCloseOverlay(String o) { 16 | overlay = o; 17 | } 18 | 19 | public MessageCloseOverlay(FriendlyByteBuf buf) { 20 | overlay = buf.readUtf(5000); 21 | } 22 | 23 | public void write(FriendlyByteBuf buf) { 24 | buf.writeUtf(overlay, 5000); 25 | } 26 | 27 | public void handle(Supplier context) { 28 | context.get().getTaskQueue().execute(() -> KubeJS.instance.proxy.closeOverlay(overlay)); 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/net/MessageOpenOverlay.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.net; 2 | 3 | import dev.latvian.kubejs.KubeJS; 4 | import dev.latvian.kubejs.text.Text; 5 | import dev.latvian.kubejs.util.Overlay; 6 | import net.fabricmc.fabric.api.network.PacketContext; 7 | import net.minecraft.network.FriendlyByteBuf; 8 | 9 | import java.util.function.Supplier; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class MessageOpenOverlay { 15 | private final Overlay overlay; 16 | 17 | public MessageOpenOverlay(Overlay o) { 18 | overlay = o; 19 | } 20 | 21 | public MessageOpenOverlay(FriendlyByteBuf buffer) { 22 | overlay = new Overlay(buffer.readUtf(5000)); 23 | overlay.color = buffer.readInt(); 24 | overlay.alwaysOnTop = buffer.readBoolean(); 25 | int s = buffer.readUnsignedByte(); 26 | 27 | for (int i = 0; i < s; i++) { 28 | overlay.add(Text.read(buffer)); 29 | } 30 | } 31 | 32 | public void write(FriendlyByteBuf buffer) { 33 | buffer.writeUtf(overlay.id, 5000); 34 | buffer.writeInt(overlay.color); 35 | buffer.writeBoolean(overlay.alwaysOnTop); 36 | buffer.writeByte(overlay.text.size()); 37 | 38 | for (Text t : overlay.text) { 39 | t.write(buffer); 40 | } 41 | } 42 | 43 | public void handle(Supplier context) { 44 | context.get().getTaskQueue().execute(() -> KubeJS.instance.proxy.openOverlay(overlay)); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/net/MessageSendDataFromClient.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.net; 2 | 3 | import dev.latvian.kubejs.KubeJSEvents; 4 | import dev.latvian.kubejs.util.MapJS; 5 | import net.fabricmc.fabric.api.network.PacketContext; 6 | import net.minecraft.nbt.CompoundTag; 7 | import net.minecraft.network.FriendlyByteBuf; 8 | import net.minecraft.world.entity.player.Player; 9 | 10 | import javax.annotation.Nullable; 11 | import java.util.function.Supplier; 12 | 13 | /** 14 | * @author LatvianModder 15 | */ 16 | public class MessageSendDataFromClient { 17 | private final String channel; 18 | private final CompoundTag data; 19 | 20 | public MessageSendDataFromClient(String c, @Nullable CompoundTag d) { 21 | channel = c; 22 | data = d; 23 | } 24 | 25 | MessageSendDataFromClient(FriendlyByteBuf buf) { 26 | channel = buf.readUtf(120); 27 | data = buf.readNbt(); 28 | } 29 | 30 | public void write(FriendlyByteBuf buf) { 31 | buf.writeUtf(channel, 120); 32 | buf.writeNbt(data); 33 | } 34 | 35 | public void handle(Supplier context) { 36 | if (!channel.isEmpty()) { 37 | final Player player = context.get().getPlayer(); 38 | 39 | if (player != null) { 40 | context.get().getTaskQueue().execute(() -> new NetworkEventJS(player, channel, MapJS.of(data)).post(KubeJSEvents.PLAYER_DATA_FROM_CLIENT, channel)); 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/net/MessageSendDataFromServer.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.net; 2 | 3 | import dev.latvian.kubejs.KubeJS; 4 | import net.fabricmc.fabric.api.network.PacketContext; 5 | import net.minecraft.nbt.CompoundTag; 6 | import net.minecraft.network.FriendlyByteBuf; 7 | 8 | import javax.annotation.Nullable; 9 | import java.util.function.Supplier; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class MessageSendDataFromServer { 15 | private final String channel; 16 | private final CompoundTag data; 17 | 18 | public MessageSendDataFromServer(String c, @Nullable CompoundTag d) { 19 | channel = c; 20 | data = d; 21 | } 22 | 23 | public MessageSendDataFromServer(FriendlyByteBuf buf) { 24 | channel = buf.readUtf(120); 25 | data = buf.readNbt(); 26 | } 27 | 28 | public void write(FriendlyByteBuf buf) { 29 | buf.writeUtf(channel, 120); 30 | buf.writeNbt(data); 31 | } 32 | 33 | public void handle(Supplier context) { 34 | if (!channel.isEmpty()) { 35 | context.get().getTaskQueue().execute(() -> KubeJS.instance.proxy.handleDataToClientPacket(channel, data)); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/net/NetworkEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.net; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.player.PlayerEventJS; 5 | import dev.latvian.kubejs.util.MapJS; 6 | import net.minecraft.world.entity.player.Player; 7 | 8 | import javax.annotation.Nullable; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class NetworkEventJS extends PlayerEventJS { 14 | private final Player player; 15 | private final String channel; 16 | private final MapJS data; 17 | 18 | public NetworkEventJS(Player p, String c, @Nullable MapJS d) { 19 | player = p; 20 | channel = c; 21 | data = d; 22 | } 23 | 24 | @Override 25 | public boolean canCancel() { 26 | return true; 27 | } 28 | 29 | @Override 30 | public EntityJS getEntity() { 31 | return entityOf(player); 32 | } 33 | 34 | public String getChannel() { 35 | return channel; 36 | } 37 | 38 | @Nullable 39 | public MapJS getData() { 40 | return data; 41 | } 42 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/net/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.net; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/package-info.java: -------------------------------------------------------------------------------- 1 | @NonnullByDefault 2 | package dev.latvian.kubejs; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/AttachPlayerDataEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | import dev.latvian.kubejs.script.AttachDataEvent; 4 | import dev.latvian.kubejs.script.DataType; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class AttachPlayerDataEvent extends AttachDataEvent { 10 | public AttachPlayerDataEvent(PlayerDataJS p) { 11 | super(DataType.PLAYER, p); 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/ChestEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class ChestEventJS {} 7 | //public class ChestEventJS extends InventoryEventJS 8 | //{ 9 | // private InventoryJS inventory; 10 | // 11 | // public ChestEventJS(PlayerContainerEvent e) 12 | // { 13 | // super(e); 14 | // } 15 | // 16 | // @MinecraftClass 17 | // public IInventory getWrappedInventory() 18 | // { 19 | // return ((ChestContainer) getInventoryContainer()).getLowerChestInventory(); 20 | // } 21 | // 22 | // public InventoryJS getInventory() 23 | // { 24 | // if (inventory == null) 25 | // { 26 | // inventory = new InventoryJS(getWrappedInventory()); 27 | // } 28 | // 29 | // return inventory; 30 | // } 31 | // 32 | // @Nullable 33 | // public BlockContainerJS getBlock() 34 | // { 35 | // if (getWrappedInventory() instanceof BlockEntity) 36 | // { 37 | // return getWorld().getBlock((BlockEntity) getWrappedInventory()); 38 | // } 39 | // 40 | // return null; 41 | // } 42 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/ClientPlayerDataJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import dev.latvian.kubejs.world.ClientWorldJS; 5 | import dev.latvian.kubejs.world.WorldJS; 6 | import net.minecraft.world.entity.player.Player; 7 | 8 | import javax.annotation.Nullable; 9 | import java.util.UUID; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class ClientPlayerDataJS extends PlayerDataJS { 15 | private final ClientWorldJS world; 16 | private final ClientPlayerJS player; 17 | private final Player minecraftPlayer; 18 | 19 | public ClientPlayerDataJS(ClientWorldJS w, Player p, boolean s) { 20 | world = w; 21 | minecraftPlayer = p; 22 | player = new ClientPlayerJS(this, minecraftPlayer, s); 23 | } 24 | 25 | public ClientWorldJS getWorld() { 26 | return world; 27 | } 28 | 29 | @Override 30 | public UUID getId() { 31 | return player.getId(); 32 | } 33 | 34 | @Override 35 | public String getName() { 36 | return player.getProfile().getName(); 37 | } 38 | 39 | @Override 40 | public GameProfile getProfile() { 41 | return player.getProfile(); 42 | } 43 | 44 | @Override 45 | public WorldJS getOverworld() { 46 | return world; 47 | } 48 | 49 | @Nullable 50 | @Override 51 | public Player getMinecraftPlayer() { 52 | return minecraftPlayer; 53 | } 54 | 55 | @Override 56 | public ClientPlayerJS getPlayer() { 57 | return player; 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/FakeServerPlayerDataJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | import dev.latvian.kubejs.server.ServerJS; 4 | import dev.latvian.kubejs.world.WorldJS; 5 | import net.minecraft.server.level.ServerPlayer; 6 | 7 | import javax.annotation.Nullable; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class FakeServerPlayerDataJS extends ServerPlayerDataJS { 13 | public ServerPlayer player; 14 | 15 | public FakeServerPlayerDataJS(ServerJS s, ServerPlayer p) { 16 | super(s, p.getUUID(), p.getGameProfile().getName(), true); 17 | player = p; 18 | } 19 | 20 | @Override 21 | public WorldJS getOverworld() { 22 | return getServer().getOverworld(); 23 | } 24 | 25 | @Override 26 | @Nullable 27 | public ServerPlayer getMinecraftPlayer() { 28 | return player; 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/InventoryChangedEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import net.minecraft.server.level.ServerPlayer; 6 | import net.minecraft.world.item.ItemStack; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class InventoryChangedEventJS extends PlayerEventJS { 12 | private final ServerPlayer player; 13 | private final ItemStack item; 14 | private final int slot; 15 | 16 | public InventoryChangedEventJS(ServerPlayer p, ItemStack is, int s) { 17 | player = p; 18 | item = is; 19 | slot = s; 20 | } 21 | 22 | @Override 23 | public EntityJS getEntity() { 24 | return entityOf(player); 25 | } 26 | 27 | public ItemStackJS getItem() { 28 | return ItemStackJS.of(item); 29 | } 30 | 31 | public int getSlot() { 32 | return slot; 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/InventoryEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class InventoryEventJS {} 7 | //public class InventoryEventJS extends PlayerEventJS 8 | //{ 9 | // private final PlayerContainerEvent event; 10 | // 11 | // public InventoryEventJS(PlayerContainerEvent e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public EntityJS getEntity() 18 | // { 19 | // return entityOf(event); 20 | // } 21 | // 22 | // @MinecraftClass 23 | // public Container getInventoryContainer() 24 | // { 25 | // return event.getContainer(); 26 | // } 27 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/InventoryListener.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | import dev.latvian.kubejs.KubeJSEvents; 4 | import net.minecraft.core.NonNullList; 5 | import net.minecraft.server.level.ServerPlayer; 6 | import net.minecraft.world.inventory.AbstractContainerMenu; 7 | import net.minecraft.world.inventory.ContainerListener; 8 | import net.minecraft.world.item.ItemStack; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class InventoryListener implements ContainerListener { 14 | public final ServerPlayer player; 15 | 16 | public InventoryListener(ServerPlayer p) { 17 | player = p; 18 | } 19 | 20 | @Override 21 | public void refreshContainer(AbstractContainerMenu container, NonNullList itemsList) { 22 | new InventoryChangedEventJS(player, ItemStack.EMPTY, -1).post(KubeJSEvents.PLAYER_INVENTORY_CHANGED); 23 | } 24 | 25 | @Override 26 | public void slotChanged(AbstractContainerMenu container, int index, ItemStack stack) { 27 | if (!stack.isEmpty() && container.getSlot(index).container == player.inventory) { 28 | new InventoryChangedEventJS(player, stack, index).post(KubeJSEvents.PLAYER_INVENTORY_CHANGED); 29 | } 30 | } 31 | 32 | @Override 33 | public void setContainerData(AbstractContainerMenu container, int id, int value) { 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/PlayerAdvancementEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class PlayerAdvancementEventJS {} 7 | //public class PlayerAdvancementEventJS extends PlayerEventJS 8 | //{ 9 | // public final AdvancementEvent event; 10 | // 11 | // public PlayerAdvancementEventJS(AdvancementEvent e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public boolean canCancel() 18 | // { 19 | // return true; 20 | // } 21 | // 22 | // @Override 23 | // public EntityJS getEntity() 24 | // { 25 | // return entityOf(event); 26 | // } 27 | // 28 | // public AdvancementJS getAdvancement() 29 | // { 30 | // return new AdvancementJS(event.getAdvancement()); 31 | // } 32 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/PlayerChatEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class PlayerChatEventJS {} 7 | //public class PlayerChatEventJS extends PlayerEventJS 8 | //{ 9 | // public final ServerChatEvent event; 10 | // 11 | // public PlayerChatEventJS(ServerChatEvent e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public boolean canCancel() 18 | // { 19 | // return true; 20 | // } 21 | // 22 | // @Override 23 | // public EntityJS getEntity() 24 | // { 25 | // return entityOf(event.getPlayer()); 26 | // } 27 | // 28 | // public String getUsername() 29 | // { 30 | // return event.getUsername(); 31 | // } 32 | // 33 | // public String getMessage() 34 | // { 35 | // return event.getMessage(); 36 | // } 37 | // 38 | // public void setMessage(Text text) 39 | // { 40 | // event.setComponent(text.component()); 41 | // } 42 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/PlayerDataJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import dev.latvian.kubejs.docs.MinecraftClass; 5 | import dev.latvian.kubejs.util.AttachedData; 6 | import dev.latvian.kubejs.util.WithAttachedData; 7 | import dev.latvian.kubejs.world.WorldJS; 8 | import net.minecraft.world.entity.player.Player; 9 | 10 | import javax.annotation.Nullable; 11 | import java.util.UUID; 12 | 13 | /** 14 | * @author LatvianModder 15 | */ 16 | public abstract class PlayerDataJS> implements WithAttachedData { 17 | private AttachedData data; 18 | 19 | public abstract UUID getId(); 20 | 21 | public abstract String getName(); 22 | 23 | @MinecraftClass 24 | public GameProfile getProfile() { 25 | return new GameProfile(getId(), getName()); 26 | } 27 | 28 | @Override 29 | public AttachedData getData() { 30 | if (data == null) { 31 | data = new AttachedData(this); 32 | } 33 | 34 | return data; 35 | } 36 | 37 | public boolean hasClientMod() { 38 | return true; 39 | } 40 | 41 | public abstract WorldJS getOverworld(); 42 | 43 | @Nullable 44 | @MinecraftClass 45 | public abstract E getMinecraftPlayer(); 46 | 47 | public abstract P getPlayer(); 48 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/PlayerEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import dev.latvian.kubejs.entity.LivingEntityEventJS; 5 | 6 | import javax.annotation.Nullable; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public abstract class PlayerEventJS extends LivingEntityEventJS { 12 | @Nullable 13 | public PlayerJS getPlayer() { 14 | EntityJS e = getEntity(); 15 | 16 | if (e instanceof PlayerJS) { 17 | return (PlayerJS) e; 18 | } 19 | 20 | return null; 21 | } 22 | 23 | // Helper methods for Game Stages 24 | 25 | public boolean hasGameStage(String stage) { 26 | // if (getPlayer() != null && ModList.get().isLoaded("gamestages")) 27 | // { 28 | // return GameStageKJSHelper.hasStage(getPlayer().minecraftPlayer, stage); 29 | // } 30 | 31 | return false; 32 | } 33 | 34 | public void addGameStage(String stage) { 35 | // if (ModList.get().isLoaded("gamestages")) 36 | // { 37 | // if (getPlayer() instanceof ServerPlayerJS) 38 | // { 39 | // GameStageKJSHelper.addStage(((ServerPlayerJS) getPlayer()).minecraftPlayer, stage); 40 | // } 41 | // } 42 | // else 43 | // { 44 | getWorld().getSide().console.error("Can't add gamestage " + stage + ", GameStages mod isn't loaded!"); 45 | // } 46 | } 47 | 48 | public void removeGameStage(String stage) { 49 | // if (ModList.get().isLoaded("gamestages")) 50 | // { 51 | // if (getPlayer() instanceof ServerPlayerJS) 52 | // { 53 | // GameStageKJSHelper.removeStage(((ServerPlayerJS) getPlayer()).minecraftPlayer, stage); 54 | // } 55 | // } 56 | // else 57 | // { 58 | getWorld().getSide().console.error("Can't remove gamestage " + stage + ", GameStages mod isn't loaded!"); 59 | // } 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/PlayerStatsJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | import dev.latvian.kubejs.docs.ID; 4 | import dev.latvian.kubejs.util.UtilsJS; 5 | import net.minecraft.stats.StatsCounter; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class PlayerStatsJS { 11 | private final PlayerJS player; 12 | private final StatsCounter statFile; 13 | 14 | public PlayerStatsJS(PlayerJS p, StatsCounter s) { 15 | player = p; 16 | statFile = s; 17 | } 18 | 19 | public PlayerJS getPlayer() { 20 | return player; 21 | } 22 | 23 | public int get(@ID String id) { 24 | return statFile.getValue(UtilsJS.getStat(id)); 25 | } 26 | 27 | public void set(@ID String id, int value) { 28 | statFile.setValue(player.minecraftPlayer, UtilsJS.getStat(id), value); 29 | } 30 | 31 | public void add(@ID String id, int value) { 32 | statFile.increment(player.minecraftPlayer, UtilsJS.getStat(id), value); 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/SimplePlayerEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.player; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import net.minecraft.world.entity.player.Player; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class SimplePlayerEventJS extends PlayerEventJS { 10 | private final Player player; 11 | 12 | public SimplePlayerEventJS(Player p) { 13 | player = p; 14 | } 15 | 16 | @Override 17 | public EntityJS getEntity() { 18 | return entityOf(player); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/player/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.player; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/ConditionalRecipeJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe; 2 | 3 | import dev.latvian.kubejs.util.ListJS; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public class ConditionalRecipeJS extends RecipeJS { 9 | @Override 10 | public void create(ListJS args) { 11 | } 12 | 13 | @Override 14 | public void deserialize() { 15 | } 16 | 17 | @Override 18 | public void serialize() { 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/CustomRecipeTypeJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe; 2 | 3 | import dev.latvian.kubejs.recipe.minecraft.CustomRecipeJS; 4 | import net.minecraft.world.item.crafting.RecipeSerializer; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class CustomRecipeTypeJS extends RecipeTypeJS { 10 | public CustomRecipeTypeJS(RecipeSerializer s) { 11 | super(s, CustomRecipeJS::new); 12 | } 13 | 14 | @Override 15 | public boolean isCustom() { 16 | return true; 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/KubeJSRecipeEventHandler.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe; 2 | 3 | import dev.latvian.kubejs.KubeJSInitializer; 4 | import dev.latvian.kubejs.recipe.minecraft.*; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class KubeJSRecipeEventHandler implements KubeJSInitializer { 10 | @Override 11 | public void onKubeJSInitialization() { 12 | RegisterRecipeHandlersEvent.EVENT.register(event -> { 13 | event.register("minecraft:crafting_shaped", ShapedRecipeJS::new); 14 | event.register("minecraft:crafting_shapeless", ShapelessRecipeJS::new); 15 | event.register("minecraft:stonecutting", StonecuttingRecipeJS::new); 16 | event.register("minecraft:smelting", CookingRecipeJS::new); 17 | event.register("minecraft:blasting", CookingRecipeJS::new); 18 | event.register("minecraft:smoking", CookingRecipeJS::new); 19 | event.register("minecraft:campfire_cooking", CookingRecipeJS::new); 20 | event.register("minecraft:smithing", SmithingRecipeJS::new); 21 | }); 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/RecipeExceptionJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class RecipeExceptionJS extends IllegalArgumentException { 7 | public RecipeExceptionJS(String m) { 8 | super(m); 9 | } 10 | 11 | @Override 12 | public String toString() { 13 | return getLocalizedMessage(); 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/RecipeTypeJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe; 2 | 3 | import dev.latvian.kubejs.docs.ID; 4 | import dev.latvian.kubejs.util.UtilsJS; 5 | import net.minecraft.core.Registry; 6 | import net.minecraft.world.item.crafting.RecipeSerializer; 7 | 8 | import java.util.Objects; 9 | import java.util.function.Supplier; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class RecipeTypeJS { 15 | public final RecipeSerializer serializer; 16 | public final Supplier factory; 17 | private final String string; 18 | 19 | public RecipeTypeJS(RecipeSerializer s, @ID String id, Supplier f) { 20 | serializer = s; 21 | factory = f; 22 | string = UtilsJS.getID(id); 23 | } 24 | 25 | public RecipeTypeJS(RecipeSerializer s, Supplier f) { 26 | this(s, Objects.requireNonNull(Registry.RECIPE_SERIALIZER.getKey(s)).toString(), f); 27 | } 28 | 29 | public boolean isCustom() { 30 | return false; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return string; 36 | } 37 | 38 | public String getId() { 39 | return string; 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | return string.hashCode(); 45 | } 46 | 47 | @Override 48 | public boolean equals(Object obj) { 49 | return string.equals(obj.toString()); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/RegisterRecipeHandlersEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe; 2 | 3 | import dev.latvian.kubejs.docs.ID; 4 | import dev.latvian.kubejs.util.UtilsJS; 5 | import net.fabricmc.fabric.api.event.Event; 6 | import net.fabricmc.fabric.api.event.EventFactory; 7 | import net.minecraft.core.Registry; 8 | import net.minecraft.resources.ResourceLocation; 9 | 10 | import java.util.Map; 11 | import java.util.Objects; 12 | import java.util.function.Consumer; 13 | import java.util.function.Supplier; 14 | 15 | /** 16 | * @author LatvianModder 17 | */ 18 | public class RegisterRecipeHandlersEvent { 19 | public static final Event> EVENT = EventFactory.createArrayBacked(Consumer.class, consumers -> event -> { 20 | for (Consumer consumer : consumers) { 21 | consumer.accept(event); 22 | } 23 | }); 24 | private final Map map; 25 | 26 | public RegisterRecipeHandlersEvent(Map m) { 27 | map = m; 28 | } 29 | 30 | public void register(RecipeTypeJS type) { 31 | map.put(UtilsJS.getMCID(type.toString()), type); 32 | } 33 | 34 | public void register(@ID String id, Supplier f) 35 | { 36 | register(new RecipeTypeJS(Objects.requireNonNull(Registry.RECIPE_SERIALIZER.get(UtilsJS.getMCID(id))), f)); 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/filter/AndFilter.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe.filter; 2 | 3 | import dev.latvian.kubejs.recipe.RecipeJS; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class AndFilter implements RecipeFilter { 12 | public final List list = new ArrayList<>(2); 13 | 14 | @Override 15 | public boolean test(RecipeJS r) { 16 | for (RecipeFilter p : list) { 17 | if (!p.test(r)) { 18 | return false; 19 | } 20 | } 21 | 22 | return true; 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/filter/GroupFilter.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe.filter; 2 | 3 | import dev.latvian.kubejs.recipe.RecipeJS; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public class GroupFilter implements RecipeFilter { 9 | private final String group; 10 | 11 | public GroupFilter(String g) { 12 | group = g; 13 | } 14 | 15 | @Override 16 | public boolean test(RecipeJS r) { 17 | return r.getGroup().equals(group); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/filter/IDFilter.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe.filter; 2 | 3 | import dev.latvian.kubejs.recipe.RecipeJS; 4 | import net.minecraft.resources.ResourceLocation; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class IDFilter implements RecipeFilter { 10 | private final ResourceLocation id; 11 | 12 | public IDFilter(ResourceLocation i) { 13 | id = i; 14 | } 15 | 16 | @Override 17 | public boolean test(RecipeJS r) { 18 | return r.id.equals(id); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/filter/InputFilter.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe.filter; 2 | 3 | import dev.latvian.kubejs.item.ingredient.IngredientJS; 4 | import dev.latvian.kubejs.recipe.RecipeJS; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class InputFilter implements RecipeFilter { 10 | private final IngredientJS in; 11 | private final boolean exact; 12 | 13 | public InputFilter(IngredientJS i, boolean e) { 14 | in = i; 15 | exact = e; 16 | } 17 | 18 | @Override 19 | public boolean test(RecipeJS r) { 20 | return r.hasInput(in, exact); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/filter/ModFilter.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe.filter; 2 | 3 | import dev.latvian.kubejs.recipe.RecipeJS; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public class ModFilter implements RecipeFilter { 9 | private final String mod; 10 | 11 | public ModFilter(String m) { 12 | mod = m; 13 | } 14 | 15 | @Override 16 | public boolean test(RecipeJS r) { 17 | return r.getMod().equals(mod); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/filter/OrFilter.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe.filter; 2 | 3 | import dev.latvian.kubejs.recipe.RecipeJS; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class OrFilter implements RecipeFilter { 12 | public final List list = new ArrayList<>(2); 13 | 14 | @Override 15 | public boolean test(RecipeJS r) { 16 | for (RecipeFilter p : list) { 17 | if (p.test(r)) { 18 | return true; 19 | } 20 | } 21 | 22 | return false; 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/filter/OutputFilter.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe.filter; 2 | 3 | import dev.latvian.kubejs.item.ingredient.IngredientJS; 4 | import dev.latvian.kubejs.recipe.RecipeJS; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class OutputFilter implements RecipeFilter { 10 | private final IngredientJS out; 11 | private final boolean exact; 12 | 13 | public OutputFilter(IngredientJS o, boolean e) { 14 | out = o; 15 | exact = e; 16 | } 17 | 18 | @Override 19 | public boolean test(RecipeJS r) { 20 | return r.hasOutput(out, exact); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/filter/TypeFilter.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe.filter; 2 | 3 | import dev.latvian.kubejs.recipe.RecipeJS; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public class TypeFilter implements RecipeFilter { 9 | private final String type; 10 | 11 | public TypeFilter(String t) { 12 | type = t; 13 | } 14 | 15 | @Override 16 | public boolean test(RecipeJS r) { 17 | return r.type.toString().equals(type); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/minecraft/StonecuttingRecipeJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.recipe.minecraft; 2 | 3 | import dev.latvian.kubejs.item.ItemStackJS; 4 | import dev.latvian.kubejs.item.ingredient.IngredientJS; 5 | import dev.latvian.kubejs.recipe.RecipeJS; 6 | import dev.latvian.kubejs.util.ListJS; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class StonecuttingRecipeJS extends RecipeJS { 12 | @Override 13 | public void create(ListJS args) { 14 | ItemStackJS result = ItemStackJS.of(args.get(0)); 15 | outputItems.add(result); 16 | IngredientJS ingredient = IngredientJS.of(args.get(1)); 17 | inputItems.add(ingredient); 18 | } 19 | 20 | @Override 21 | public void deserialize() { 22 | ItemStackJS result = ItemStackJS.resultFromRecipeJson(json.get("result")).count(json.get("count").getAsInt()); 23 | outputItems.add(result); 24 | 25 | IngredientJS ingredient = IngredientJS.ingredientFromRecipeJson(json.get("ingredient")); 26 | inputItems.add(ingredient); 27 | } 28 | 29 | @Override 30 | public void serialize() { 31 | json.add("ingredient", inputItems.get(0).toJson()); 32 | json.addProperty("result", outputItems.get(0).getId()); 33 | json.addProperty("count", outputItems.get(0).getCount()); 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/recipe/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.recipe; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/rei/AddREIEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.rei; 2 | 3 | import com.google.common.collect.Lists; 4 | import dev.latvian.kubejs.event.EventJS; 5 | import dev.latvian.kubejs.util.ListJS; 6 | import me.shedaniel.rei.api.EntryRegistry; 7 | import me.shedaniel.rei.api.EntryStack; 8 | 9 | import java.util.List; 10 | import java.util.function.Function; 11 | 12 | public class AddREIEventJS extends EventJS { 13 | private final EntryRegistry registry; 14 | private final Function function; 15 | private final List added = Lists.newArrayList(); 16 | 17 | public AddREIEventJS(EntryRegistry registry, Function function) { 18 | this.registry = registry; 19 | this.function = function; 20 | } 21 | 22 | public void add(Object o) { 23 | for (Object o1 : ListJS.orSelf(o)) { 24 | EntryStack stack = function.apply(o1); 25 | 26 | if (stack != null && !stack.isEmpty()) { 27 | added.add(stack); 28 | } 29 | } 30 | } 31 | 32 | @Override 33 | protected void afterPosted(boolean result) { 34 | if (!added.isEmpty()) { 35 | registry.registerEntriesAfter(null, added); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/rei/HideREIEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.rei; 2 | 3 | import dev.latvian.kubejs.event.EventJS; 4 | import it.unimi.dsi.fastutil.longs.LongOpenHashSet; 5 | import it.unimi.dsi.fastutil.longs.LongSet; 6 | import me.shedaniel.rei.api.EntryRegistry; 7 | import me.shedaniel.rei.api.EntryStack; 8 | 9 | import java.util.Collection; 10 | import java.util.function.Function; 11 | import java.util.stream.Collectors; 12 | 13 | public class HideREIEventJS extends EventJS { 14 | private final EntryRegistry registry; 15 | private final EntryStack.Type type; 16 | private final Function> serializer; 17 | private final LongSet hidden = new LongOpenHashSet(); 18 | private boolean hideAll = false; 19 | 20 | public HideREIEventJS(EntryRegistry registry, EntryStack.Type type, Function> serializer) { 21 | this.registry = registry; 22 | this.type = type; 23 | this.serializer = serializer; 24 | } 25 | 26 | public Collection getAllIngredients() { 27 | return (Collection) registry.getEntryStacks().filter(this::filterType).map(EntryStack::getObject).collect(Collectors.toList()); 28 | } 29 | 30 | private boolean filterType(EntryStack stack) { 31 | return stack.getType() == type; 32 | } 33 | 34 | public void hide(Object o) { 35 | if (!hideAll) { 36 | for (EntryStack stack : serializer.apply(o)) { 37 | hidden.add(stack.hashIgnoreAmount()); 38 | } 39 | } 40 | } 41 | 42 | public void hideAll() { 43 | hideAll = true; 44 | } 45 | 46 | @Override 47 | protected void afterPosted(boolean result) { 48 | if (!hidden.isEmpty()) { 49 | registry.removeEntryIf(stack -> { 50 | if (filterType(stack)) { 51 | return hideAll || hidden.contains(stack.hashIgnoreAmount()); 52 | } 53 | 54 | return false; 55 | }); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/rei/InformationREIEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.rei; 2 | 3 | import dev.latvian.kubejs.event.EventJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import dev.latvian.kubejs.item.ingredient.IngredientJS; 6 | import dev.latvian.kubejs.text.Text; 7 | import dev.latvian.kubejs.util.ListJS; 8 | import me.shedaniel.rei.api.BuiltinPlugin; 9 | import me.shedaniel.rei.api.EntryStack; 10 | 11 | import java.util.stream.Collectors; 12 | 13 | public class InformationREIEventJS extends EventJS { 14 | public void add(Object stacks, Object title, Object description) { 15 | BuiltinPlugin.getInstance().registerInformation( 16 | EntryStack.ofItemStacks(IngredientJS.of(stacks).getStacks().stream().map(ItemStackJS::getItemStack).collect(Collectors.toList())), 17 | Text.of(title).component(), 18 | components -> { 19 | ListJS.orSelf(description).stream().map(Text::of).map(Text::component).collect(Collectors.toCollection(() -> components)); 20 | return components; 21 | } 22 | ); 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/rei/REIIntegration.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.rei; 2 | 3 | public class REIIntegration { 4 | public static final String REI_HIDE_ITEMS = "rei.hide.items"; 5 | public static final String REI_ADD_ITEMS = "rei.add.items"; 6 | public static final String REI_INFORMATION = "rei.information"; 7 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/rei/REIPlugin.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.rei; 2 | 3 | import dev.latvian.kubejs.KubeJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import dev.latvian.kubejs.item.ingredient.IngredientJS; 6 | import dev.latvian.kubejs.script.ScriptType; 7 | import me.shedaniel.rei.api.EntryRegistry; 8 | import me.shedaniel.rei.api.EntryStack; 9 | import me.shedaniel.rei.api.RecipeHelper; 10 | import me.shedaniel.rei.api.plugins.REIPluginV0; 11 | import net.minecraft.resources.ResourceLocation; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class REIPlugin implements REIPluginV0 { 17 | @Override 18 | public ResourceLocation getPluginIdentifier() { 19 | return new ResourceLocation(KubeJS.MOD_ID, "rei"); 20 | } 21 | 22 | @Override 23 | public void registerEntries(EntryRegistry entryRegistry) { 24 | new HideREIEventJS<>(entryRegistry, EntryStack.Type.ITEM, object -> { 25 | List list = new ArrayList<>(); 26 | 27 | for (ItemStackJS stack : IngredientJS.of(object).getStacks()) { 28 | list.add(EntryStack.create(stack.getItemStack())); 29 | } 30 | 31 | return list; 32 | }).post(ScriptType.CLIENT, REIIntegration.REI_HIDE_ITEMS); 33 | 34 | new AddREIEventJS(entryRegistry, o -> EntryStack.create(ItemStackJS.of(o).getItemStack())).post(ScriptType.CLIENT, REIIntegration.REI_ADD_ITEMS); 35 | } 36 | 37 | @Override 38 | public void registerRecipeDisplays(RecipeHelper recipeHelper) { 39 | new InformationREIEventJS().post(ScriptType.CLIENT, REIIntegration.REI_INFORMATION); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/AttachDataEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | import dev.latvian.kubejs.util.WithAttachedData; 4 | import net.fabricmc.fabric.api.event.Event; 5 | import net.fabricmc.fabric.api.event.EventFactory; 6 | 7 | import java.util.function.Consumer; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class AttachDataEvent { 13 | public static final Event> EVENT = EventFactory.createArrayBacked(Consumer.class, consumers -> event -> { 14 | for (Consumer consumer : consumers) { 15 | consumer.accept(event); 16 | } 17 | }); 18 | private final DataType type; 19 | private final T parent; 20 | 21 | public AttachDataEvent(DataType t, T p) { 22 | type = t; 23 | parent = p; 24 | } 25 | 26 | public DataType getType() { 27 | return type; 28 | } 29 | 30 | public T getParent() { 31 | return parent; 32 | } 33 | 34 | public void add(String id, Object object) { 35 | parent.getData().put(id, object); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/BindingsEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | import dev.latvian.mods.rhino.*; 4 | import dev.latvian.mods.rhino.util.DynamicFunction; 5 | import net.fabricmc.fabric.api.event.Event; 6 | import net.fabricmc.fabric.api.event.EventFactory; 7 | 8 | import java.util.function.Consumer; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class BindingsEvent { 14 | public static final Event> EVENT = EventFactory.createArrayBacked(Consumer.class, consumers -> event -> { 15 | for (Consumer consumer : consumers) { 16 | consumer.accept(event); 17 | } 18 | }); 19 | 20 | public final ScriptType type; 21 | public Scriptable scope; 22 | 23 | public BindingsEvent(ScriptType t, Scriptable s) { 24 | type = t; 25 | scope = s; 26 | } 27 | 28 | public ScriptType getType() { 29 | return type; 30 | } 31 | 32 | public void add(String name, Object value) { 33 | ScriptableObject.putProperty(scope, name, Context.javaToJS(value, scope)); 34 | } 35 | 36 | public void addClass(String name, Class clazz) { 37 | add(name, new NativeJavaClass(scope, clazz)); 38 | } 39 | 40 | public void addFunction(String name, DynamicFunction.Callback function) { 41 | add(name, new DynamicFunction(function)); 42 | } 43 | 44 | public void addConstant(String name, Object value) { 45 | add(name, value); 46 | } 47 | 48 | public void addFunction(String name, BaseFunction function) { 49 | add(name, function); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/DataType.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | import dev.latvian.kubejs.player.PlayerDataJS; 4 | import dev.latvian.kubejs.player.PlayerJS; 5 | import dev.latvian.kubejs.server.ServerJS; 6 | import dev.latvian.kubejs.world.WorldJS; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public final class DataType { 12 | public static DataType SERVER = new DataType<>("server", ServerJS.class); 13 | public static DataType WORLD = new DataType<>("world", WorldJS.class); 14 | public static DataType PLAYER = new DataType<>("player", PlayerDataJS.class, PlayerJS.class); 15 | 16 | public final String name; 17 | public final Class parent; 18 | public final Class actualParent; 19 | 20 | public DataType(String s, Class c, Class a) { 21 | name = s; 22 | parent = c; 23 | actualParent = a; 24 | } 25 | 26 | public DataType(String s, Class c) { 27 | this(s, c, c); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/ScriptFile.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | import net.minecraft.util.LazyLoadedValue; 4 | import org.apache.commons.io.IOUtils; 5 | 6 | import javax.annotation.Nullable; 7 | import java.io.BufferedInputStream; 8 | import java.io.InputStream; 9 | import java.nio.charset.StandardCharsets; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class ScriptFile implements Comparable { 15 | public final ScriptPack pack; 16 | public final ScriptFileInfo info; 17 | public final ScriptSource source; 18 | public final LazyLoadedValue content = new LazyLoadedValue<>(this::loadContent); 19 | 20 | private Throwable error; 21 | 22 | public ScriptFile(ScriptPack p, ScriptFileInfo i, ScriptSource s) { 23 | pack = p; 24 | info = i; 25 | source = s; 26 | } 27 | 28 | @Nullable 29 | public Throwable getError() { 30 | return error; 31 | } 32 | 33 | private String loadContent() { 34 | error = null; 35 | 36 | try (InputStream stream = source.createStream(info)) { 37 | return new String(IOUtils.toByteArray(new BufferedInputStream(stream)), StandardCharsets.UTF_8); 38 | } catch (Throwable ex) { 39 | error = ex; 40 | return null; 41 | } 42 | } 43 | 44 | public boolean load() { 45 | error = null; 46 | 47 | String script = content.get(); 48 | if (script != null) { 49 | try { 50 | pack.context.evaluateString(pack.scope, script, info.location.toString(), 1, null); 51 | return true; 52 | } catch (Throwable ex) { 53 | error = ex; 54 | } 55 | } 56 | return false; 57 | } 58 | 59 | @Override 60 | public int compareTo(ScriptFile o) { 61 | return Integer.compare(o.info.getPriority(), info.getPriority()); 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/ScriptFileInfo.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | import net.minecraft.resources.ResourceLocation; 4 | 5 | import javax.annotation.Nullable; 6 | import java.io.BufferedReader; 7 | import java.io.InputStreamReader; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author LatvianModder 14 | */ 15 | public class ScriptFileInfo { 16 | public final ScriptPackInfo pack; 17 | public final String file; 18 | public final ResourceLocation location; 19 | private final Map properties; 20 | private int priority; 21 | 22 | public ScriptFileInfo(ScriptPackInfo p, String f) { 23 | pack = p; 24 | file = f; 25 | location = new ResourceLocation(pack.namespace, pack.pathStart + file); 26 | properties = new HashMap<>(); 27 | priority = 0; 28 | } 29 | 30 | @Nullable 31 | public Throwable preload(ScriptSource source) { 32 | properties.clear(); 33 | 34 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(source.createStream(this), StandardCharsets.UTF_8))) { 35 | String line; 36 | 37 | while ((line = reader.readLine()) != null) { 38 | line = line.trim(); 39 | 40 | if (line.startsWith("//")) { 41 | String[] s = line.substring(2).split(":", 2); 42 | 43 | if (s.length == 2) { 44 | properties.put(s[0].trim().toLowerCase(), s[1].trim()); 45 | } 46 | } else { 47 | break; 48 | } 49 | } 50 | 51 | priority = Integer.parseInt(getProperty("priority", "0")); 52 | 53 | return null; 54 | } catch (Throwable ex) { 55 | return ex; 56 | } 57 | } 58 | 59 | public String getProperty(String s, String def) { 60 | return properties.getOrDefault(s, def); 61 | } 62 | 63 | public int getPriority() { 64 | return priority; 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/ScriptPack.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | import dev.latvian.mods.rhino.Context; 4 | import dev.latvian.mods.rhino.Scriptable; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class ScriptPack { 13 | public final ScriptManager manager; 14 | public final ScriptPackInfo info; 15 | public final List scripts; 16 | 17 | public Context context; 18 | public Scriptable scope; 19 | 20 | public ScriptPack(ScriptManager m, ScriptPackInfo i) { 21 | manager = m; 22 | info = i; 23 | scripts = new ArrayList<>(); 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/ScriptPackInfo.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | import net.minecraft.network.chat.Component; 4 | import net.minecraft.network.chat.TextComponent; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class ScriptPackInfo { 13 | public final String namespace; 14 | public final Component displayName; 15 | public final List scripts; 16 | public final String pathStart; 17 | 18 | public ScriptPackInfo(String n, String p) { 19 | namespace = n; 20 | scripts = new ArrayList<>(); 21 | pathStart = p; 22 | displayName = new TextComponent(namespace); // Load custom properties 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/ScriptSource.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | import net.minecraft.server.packs.resources.Resource; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | @FunctionalInterface 14 | public interface ScriptSource { 15 | InputStream createStream(ScriptFileInfo info) throws IOException; 16 | 17 | interface FromPath extends ScriptSource { 18 | Path getPath(ScriptFileInfo info); 19 | 20 | @Override 21 | default InputStream createStream(ScriptFileInfo info) throws IOException { 22 | return Files.newInputStream(getPath(info)); 23 | } 24 | } 25 | 26 | interface FromResource extends ScriptSource { 27 | Resource getResource(ScriptFileInfo info) throws IOException; 28 | 29 | @Override 30 | default InputStream createStream(ScriptFileInfo info) throws IOException { 31 | return getResource(info).getInputStream(); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/ScriptType.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | import dev.latvian.kubejs.KubeJS; 4 | import dev.latvian.kubejs.server.ServerScriptManager; 5 | import dev.latvian.kubejs.util.ConsoleJS; 6 | import net.minecraft.world.level.LevelReader; 7 | import org.apache.logging.log4j.LogManager; 8 | 9 | import java.util.function.Supplier; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public enum ScriptType { 15 | STARTUP("startup", "KubeJS Startup", () -> KubeJS.startupScriptManager), 16 | SERVER("server", "KubeJS Server", () -> ServerScriptManager.instance.scriptManager), 17 | CLIENT("client", "KubeJS Client", () -> KubeJS.clientScriptManager); 18 | 19 | public static ScriptType of(LevelReader world) { 20 | return world.isClientSide() ? CLIENT : SERVER; 21 | } 22 | 23 | public final String name; 24 | public final ConsoleJS console; 25 | public final Supplier manager; 26 | 27 | ScriptType(String n, String cname, Supplier m) { 28 | name = n; 29 | console = new ConsoleJS(this, LogManager.getLogger(cname)); 30 | manager = m; 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/ScriptsLoadedEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script; 2 | 3 | 4 | import net.fabricmc.fabric.api.event.Event; 5 | import net.fabricmc.fabric.api.event.EventFactory; 6 | 7 | import java.util.function.Consumer; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class ScriptsLoadedEvent { 13 | public static final Event> EVENT = EventFactory.createArrayBacked(Consumer.class, consumers -> event -> { 14 | for (Consumer consumer : consumers) { 15 | consumer.accept(event); 16 | } 17 | }); 18 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/data/DataPackEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.script.data; 2 | 3 | import dev.latvian.kubejs.docs.ID; 4 | import dev.latvian.kubejs.server.ServerEventJS; 5 | import dev.latvian.kubejs.util.JsonUtilsJS; 6 | import dev.latvian.kubejs.util.MapJS; 7 | import dev.latvian.kubejs.util.UtilsJS; 8 | 9 | /** 10 | * @author LatvianModder 11 | */ 12 | public class DataPackEventJS extends ServerEventJS { 13 | private final VirtualKubeJSDataPack virtualDataPack; 14 | 15 | public DataPackEventJS(VirtualKubeJSDataPack d) { 16 | virtualDataPack = d; 17 | } 18 | 19 | public void add(@ID String id, String content) { 20 | virtualDataPack.addData(UtilsJS.getMCID(id), content); 21 | } 22 | 23 | public void addJson(@ID String id, Object json) { 24 | MapJS map = MapJS.of(json); 25 | 26 | if (map != null) { 27 | add(id, JsonUtilsJS.toString(map.toJson())); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/data/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.script.data; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/script/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.script; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/server/AttachServerDataEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.server; 2 | 3 | import dev.latvian.kubejs.script.AttachDataEvent; 4 | import dev.latvian.kubejs.script.DataType; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class AttachServerDataEvent extends AttachDataEvent { 10 | public AttachServerDataEvent(ServerJS s) { 11 | super(DataType.SERVER, s); 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/server/CommandEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.server; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class CommandEventJS {} 7 | //public class CommandEventJS extends ServerEventJS 8 | //{ 9 | // public final CommandEvent event; 10 | // 11 | // public CommandEventJS(CommandEvent e) 12 | // { 13 | // event = e; 14 | // } 15 | // 16 | // @Override 17 | // public boolean canCancel() 18 | // { 19 | // return true; 20 | // } 21 | // 22 | // public ParseResults getParseResults() 23 | // { 24 | // return event.getParseResults(); 25 | // } 26 | // 27 | // public void setParseResults(ParseResults parse) 28 | // { 29 | // event.setParseResults(parse); 30 | // } 31 | // 32 | // public Throwable getException() 33 | // { 34 | // return event.getException(); 35 | // } 36 | // 37 | // public void setException(Throwable exception) 38 | // { 39 | // event.setException(exception); 40 | // } 41 | //} -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/server/GameRulesJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.server; 2 | 3 | import com.mojang.serialization.Dynamic; 4 | import net.minecraft.nbt.CompoundTag; 5 | import net.minecraft.nbt.NbtOps; 6 | import net.minecraft.world.level.GameRules; 7 | 8 | import javax.annotation.Nullable; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author LatvianModder 14 | */ 15 | public class GameRulesJS { 16 | private GameRules rules; 17 | private Map cache; 18 | 19 | public GameRulesJS(GameRules r) { 20 | rules = r; 21 | } 22 | 23 | @Nullable 24 | private GameRules.Key getKey(String rule) { 25 | if (cache == null) { 26 | cache = new HashMap<>(); 27 | 28 | GameRules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor() { 29 | @Override 30 | public > void visit(GameRules.Key key, GameRules.Type type) { 31 | cache.put(key.toString(), key); 32 | } 33 | }); 34 | } 35 | 36 | return cache.get(rule); 37 | } 38 | 39 | @Nullable 40 | private Object get(String rule) { 41 | GameRules.Key key = getKey(rule); 42 | return key == null ? null : rules.getRule(key); 43 | } 44 | 45 | public String getString(String rule) { 46 | Object o = get(rule); 47 | return o == null ? "" : String.valueOf(o); 48 | } 49 | 50 | public boolean getBoolean(String rule) { 51 | Object o = get(rule); 52 | return o instanceof Boolean && (Boolean) o; 53 | } 54 | 55 | public int getInt(String rule) { 56 | Object o = get(rule); 57 | return o instanceof Number ? ((Number) o).intValue() : 0; 58 | } 59 | 60 | public void set(String rule, Object value) { 61 | CompoundTag nbt = rules.createTag(); 62 | nbt.putString(rule, String.valueOf(value)); 63 | rules = new GameRules(new Dynamic<>(NbtOps.INSTANCE, nbt)); //TODO: Check if works 64 | } 65 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/server/IScheduledEventCallback.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.server; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | @FunctionalInterface 7 | public interface IScheduledEventCallback { 8 | void onCallback(ScheduledEvent callback); 9 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/server/ScheduledEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.server; 2 | 3 | import dev.latvian.kubejs.script.ScriptFile; 4 | 5 | import javax.annotation.Nullable; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class ScheduledEvent { 11 | public final ScriptFile file; 12 | 13 | private final ServerJS server; 14 | private final boolean usingTicks; 15 | private final long timer; 16 | private final long endTime; 17 | private final Object data; 18 | private final IScheduledEventCallback callback; 19 | 20 | ScheduledEvent(ServerJS s, boolean ut, long t, long e, @Nullable Object d, IScheduledEventCallback c) { 21 | file = s.serverScriptManager.scriptManager.currentFile; 22 | usingTicks = ut; 23 | server = s; 24 | timer = t; 25 | endTime = e; 26 | data = d; 27 | callback = c; 28 | } 29 | 30 | public boolean isUsingTicks() { 31 | return usingTicks; 32 | } 33 | 34 | public ServerJS getServer() { 35 | return server; 36 | } 37 | 38 | public long getTimer() { 39 | return timer; 40 | } 41 | 42 | public long getEndTime() { 43 | return endTime; 44 | } 45 | 46 | @Nullable 47 | public Object getData() { 48 | return data; 49 | } 50 | 51 | public void reschedule() { 52 | reschedule(timer); 53 | } 54 | 55 | public long getTimerDuration() { 56 | return endTime - timer; 57 | } 58 | 59 | public ScheduledEvent reschedule(long timer) { 60 | if (isUsingTicks()) { 61 | return server.scheduleInTicks(timer, data, callback); 62 | } else { 63 | return server.schedule(timer, data, callback); 64 | } 65 | } 66 | 67 | void call() { 68 | callback.onCallback(this); 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/server/ServerCommandSender.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.server; 2 | 3 | import net.minecraft.commands.CommandSource; 4 | import net.minecraft.commands.CommandSourceStack; 5 | import net.minecraft.commands.arguments.EntityAnchorArgument; 6 | import net.minecraft.network.chat.TextComponent; 7 | import net.minecraft.server.level.ServerLevel; 8 | import net.minecraft.world.phys.Vec2; 9 | import net.minecraft.world.phys.Vec3; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class ServerCommandSender extends CommandSourceStack { 15 | public ServerCommandSender(ServerJS w) { 16 | super(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, (ServerLevel) w.getOverworld().minecraftWorld, 4, "Server", new TextComponent("Server"), w.minecraftServer, null, true, (context, success, result) -> {}, EntityAnchorArgument.Anchor.FEET); 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/server/ServerEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.server; 2 | 3 | import dev.latvian.kubejs.event.EventJS; 4 | 5 | import javax.annotation.Nullable; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class ServerEventJS extends EventJS { 11 | @Nullable 12 | public ServerJS getServer() { 13 | return ServerJS.instance; 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/server/ServerSettings.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.server; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class ServerSettings { 7 | public static ServerSettings instance; 8 | 9 | public boolean dataPackOutput = false; 10 | public boolean logAddedRecipes = false; 11 | public boolean logRemovedRecipes = false; 12 | public boolean betterRecipeErrorLogging = true; 13 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/server/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.server; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/text/TextColor.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.text; 2 | 3 | import net.minecraft.ChatFormatting; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public enum TextColor { 12 | BLACK("black", '0', 0x000000, ChatFormatting.BLACK), 13 | DARK_BLUE("dark_blue", '1', 0x0000AA, ChatFormatting.DARK_BLUE), 14 | DARK_GREEN("dark_green", '2', 0x00AA00, ChatFormatting.DARK_GREEN), 15 | DARK_AQUA("dark_aqua", '3', 0x00AAAA, ChatFormatting.DARK_AQUA), 16 | DARK_RED("dark_red", '4', 0xAA0000, ChatFormatting.DARK_RED), 17 | DARK_PURPLE("dark_purple", '5', 0xAA00AA, ChatFormatting.DARK_PURPLE), 18 | GOLD("gold", '6', 0xFFAA00, ChatFormatting.GOLD), 19 | GRAY("gray", '7', 0xAAAAAA, ChatFormatting.GRAY), 20 | DARK_GRAY("dark_gray", '8', 0x555555, ChatFormatting.DARK_GRAY), 21 | BLUE("blue", '9', 0x5555FF, ChatFormatting.BLUE), 22 | GREEN("green", 'a', 0x55FF55, ChatFormatting.GREEN), 23 | AQUA("aqua", 'b', 0x55FFFF, ChatFormatting.AQUA), 24 | RED("red", 'c', 0xFF5555, ChatFormatting.RED), 25 | LIGHT_PURPLE("light_purple", 'd', 0xFF55FF, ChatFormatting.LIGHT_PURPLE), 26 | YELLOW("yellow", 'e', 0xFFFF55, ChatFormatting.YELLOW), 27 | WHITE("white", 'f', 0xFFFFFF, ChatFormatting.WHITE); 28 | 29 | public static final Map MAP = new HashMap<>(); 30 | 31 | static { 32 | for (TextColor color : values()) { 33 | MAP.put(color.name, color); 34 | } 35 | } 36 | 37 | public final String name; 38 | public final char code; 39 | public final int color; 40 | public final ChatFormatting textFormatting; 41 | 42 | TextColor(String n, char c, int h, ChatFormatting f) { 43 | name = n; 44 | code = c; 45 | color = 0xFF000000 | h; 46 | textFormatting = f; 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/text/TextString.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.text; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.JsonObject; 5 | import com.google.gson.JsonPrimitive; 6 | import net.minecraft.network.chat.MutableComponent; 7 | import net.minecraft.network.chat.TextComponent; 8 | 9 | import javax.annotation.Nullable; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class TextString extends Text { 15 | private final String string; 16 | 17 | public TextString(@Nullable Object text) { 18 | string = String.valueOf(text); 19 | } 20 | 21 | public String getRawString() { 22 | return string; 23 | } 24 | 25 | @Override 26 | public MutableComponent rawComponent() { 27 | return new TextComponent(string); 28 | } 29 | 30 | @Override 31 | public Text rawCopy() { 32 | return new TextString(string); 33 | } 34 | 35 | @Override 36 | public JsonElement toJson() { 37 | JsonObject o = getPropertiesAsJson(); 38 | 39 | if (o.size() == 0) { 40 | return new JsonPrimitive(string); 41 | } 42 | 43 | o.addProperty("text", string); 44 | return o; 45 | } 46 | 47 | @Override 48 | public boolean equals(Object obj) { 49 | if (obj == this) { 50 | return true; 51 | } else if (!(obj instanceof TextString) || !string.equals(((TextString) obj).string)) { 52 | return false; 53 | } 54 | 55 | return super.equals(obj); 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return string.hashCode() * 31 + super.hashCode(); 61 | } 62 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/text/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.text; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/trade/TradeOfferFactory.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.trade; 2 | 3 | import net.minecraft.world.entity.Entity; 4 | import net.minecraft.world.entity.npc.VillagerTrades; 5 | import net.minecraft.world.item.Item; 6 | import net.minecraft.world.item.ItemStack; 7 | import net.minecraft.world.item.Items; 8 | import net.minecraft.world.item.trading.MerchantOffer; 9 | import net.minecraft.world.level.block.Block; 10 | 11 | import java.util.Random; 12 | 13 | public class TradeOfferFactory implements VillagerTrades.ItemListing { 14 | private final ItemStack sell; 15 | private final int price; 16 | private final int count; 17 | private final int maxUses; 18 | private final int experience; 19 | private final float multiplier; 20 | 21 | public TradeOfferFactory(Block block, int price, int count, int maxUses, int experience) { 22 | this(new ItemStack(block), price, count, maxUses, experience); 23 | } 24 | 25 | public TradeOfferFactory(Item item, int price, int count, int maxUses, int experience) { 26 | this(new ItemStack(item), price, count, maxUses, experience); 27 | } 28 | 29 | public TradeOfferFactory(ItemStack stack, int price, int count, int maxUses, int experience) { 30 | this(stack, price, count, maxUses, experience, 0.05F); 31 | } 32 | 33 | public TradeOfferFactory(ItemStack stack, int price, int count, int maxUses, int experience, float multiplier) { 34 | this.sell = stack; 35 | this.price = price; 36 | this.count = count; 37 | this.maxUses = maxUses; 38 | this.experience = experience; 39 | this.multiplier = multiplier; 40 | } 41 | 42 | @Override 43 | public MerchantOffer getOffer(Entity entity, Random random) { 44 | return new MerchantOffer(new ItemStack(Items.EMERALD, this.price), new ItemStack(this.sell.getItem(), this.count), this.maxUses, this.experience, this.multiplier); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/AttachedData.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public class AttachedData extends HashMap { 9 | private final Object parent; 10 | 11 | public AttachedData(Object p) { 12 | parent = p; 13 | } 14 | 15 | public Object getParent() { 16 | return parent; 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/BuilderBase.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | import dev.latvian.kubejs.KubeJS; 4 | import dev.latvian.kubejs.script.ScriptType; 5 | import net.minecraft.resources.ResourceLocation; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public abstract class BuilderBase { 11 | public final ResourceLocation id; 12 | public String translationKey; 13 | public String displayName; 14 | 15 | public BuilderBase(String s) { 16 | id = UtilsJS.getMCID(KubeJS.appendModId(s)); 17 | translationKey = getType() + "." + id.getNamespace() + "." + id.getPath(); 18 | displayName = ""; 19 | } 20 | 21 | public abstract String getType(); 22 | 23 | @Deprecated 24 | public void add() { 25 | ScriptType.STARTUP.console.setLineNumber(true); 26 | ScriptType.STARTUP.console.log("You no longer need to use .add() at end of " + getType() + " builder!"); 27 | ScriptType.STARTUP.console.setLineNumber(false); 28 | } 29 | 30 | public BuilderBase translationKey(String key) { 31 | translationKey = key; 32 | return this; 33 | } 34 | 35 | public BuilderBase displayName(String name) { 36 | displayName = name; 37 | return this; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/Copyable.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public interface Copyable { 7 | Copyable copy(); 8 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/FieldJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | import javax.annotation.Nullable; 4 | import java.lang.reflect.Field; 5 | import java.util.Optional; 6 | 7 | /** 8 | * @author LatvianModder 9 | */ 10 | public class FieldJS { 11 | private final Field field; 12 | 13 | public FieldJS(@Nullable Field f) { 14 | field = f; 15 | } 16 | 17 | public Optional get(@Nullable Object object) { 18 | if (field == null) { 19 | return Optional.empty(); 20 | } 21 | 22 | try { 23 | if (!field.isAccessible()) { 24 | field.setAccessible(true); 25 | } 26 | 27 | return Optional.ofNullable(UtilsJS.cast(field.get(object))); 28 | } catch (Exception ex) { 29 | return Optional.empty(); 30 | } 31 | } 32 | 33 | @Nullable 34 | public Optional staticGet() { 35 | return get(null); 36 | } 37 | 38 | public boolean set(@Nullable Object object, @Nullable Object value) { 39 | if (field == null) { 40 | return false; 41 | } 42 | 43 | try { 44 | if (!field.isAccessible()) { 45 | field.setAccessible(true); 46 | } 47 | 48 | field.set(object, value); 49 | return true; 50 | } catch (Exception ex) { 51 | return false; 52 | } 53 | } 54 | 55 | public boolean staticSet(@Nullable Object value) { 56 | return set(null, value); 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/JSObjectType.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public enum JSObjectType { 7 | ANY, 8 | MAP, 9 | LIST; 10 | 11 | public boolean checkMap() { 12 | return this == ANY || this == MAP; 13 | } 14 | 15 | public boolean checkList() { 16 | return this == ANY || this == LIST; 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/JsonSerializable.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | import com.google.gson.JsonElement; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | @FunctionalInterface 9 | public interface JsonSerializable { 10 | JsonElement toJson(); 11 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/MessageSender.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | import dev.latvian.kubejs.text.Text; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public interface MessageSender { 9 | Text getName(); 10 | 11 | default Text getDisplayName() { 12 | return getName(); 13 | } 14 | 15 | void tell(Object message); 16 | 17 | default void setStatusMessage(Object message) { 18 | } 19 | 20 | int runCommand(String command); 21 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/NBTSerializable.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | import net.minecraft.nbt.Tag; 4 | 5 | /** 6 | * @author LatvianModder 7 | */ 8 | public interface NBTSerializable { 9 | Tag toNBT(); 10 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/Overlay.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | import dev.latvian.kubejs.item.EmptyItemStackJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import dev.latvian.kubejs.text.Text; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class Overlay { 14 | public final String id; 15 | public final List text; 16 | public int color; 17 | public boolean alwaysOnTop; 18 | public ItemStackJS icon; 19 | 20 | public Overlay(String i) { 21 | id = i; 22 | text = new ArrayList<>(1); 23 | color = 0x101010; 24 | alwaysOnTop = false; 25 | icon = EmptyItemStackJS.INSTANCE; 26 | } 27 | 28 | public Overlay add(Object o) { 29 | text.add(Text.of(o)); 30 | return this; 31 | } 32 | 33 | public Overlay alwaysOnTop() { 34 | alwaysOnTop = true; 35 | return this; 36 | } 37 | 38 | public Overlay color(int col) { 39 | color = col; 40 | return this; 41 | } 42 | 43 | public Overlay color(String col) { 44 | return color(Long.decode(col).intValue()); 45 | } 46 | 47 | public Overlay icon(Object o) { 48 | icon = ItemStackJS.of(o); 49 | return this; 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/TradeUtils.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | import dev.latvian.kubejs.item.EmptyItemStackJS; 4 | import dev.latvian.kubejs.item.ItemStackJS; 5 | import dev.latvian.kubejs.trade.TradeOfferFactory; 6 | import net.minecraft.world.entity.npc.VillagerTrades; 7 | import net.minecraft.world.item.Item; 8 | import net.minecraft.world.item.ItemStack; 9 | import net.minecraft.world.level.block.Block; 10 | 11 | public class TradeUtils { 12 | public static VillagerTrades.ItemListing of(Object data) { 13 | MapJS mapJS = MapJS.of(data); 14 | 15 | ItemStack stack = ItemStackJS.of(mapJS.getOrDefault("stack", EmptyItemStackJS.INSTANCE)).getItemStack(); 16 | Block block = (Block) mapJS.get("block"); 17 | Item item = (Item) mapJS.get("item"); 18 | Integer price = (Integer) mapJS.get("price"); 19 | Integer count = (Integer) mapJS.get("count"); 20 | Integer uses = (Integer) mapJS.get("uses"); 21 | Integer experience = (Integer) mapJS.get("experience"); 22 | Float multiplier = ((Number) mapJS.get("multiplier")).floatValue(); 23 | 24 | price = price == null ? 1 : price; 25 | count = count == null ? 1 : count; 26 | uses = uses == null ? 1 : uses; 27 | experience = experience == null ? 8 : experience; 28 | multiplier = multiplier == null ? 1F : multiplier; 29 | 30 | if (!stack.isEmpty()) { 31 | return new TradeOfferFactory(stack, price, count, uses, experience, multiplier); 32 | } else if (item != null) { 33 | return new TradeOfferFactory(new ItemStack(item), price, count, uses, experience, multiplier); 34 | } else if (block != null) { 35 | return new TradeOfferFactory(new ItemStack(block), price, count, uses, experience, multiplier); 36 | } else { 37 | return null; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/UUIDUtilsJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | import javax.annotation.Nullable; 4 | import java.util.UUID; 5 | 6 | /** 7 | * @author LatvianModder 8 | */ 9 | public class UUIDUtilsJS { 10 | public static String toString(@Nullable UUID id) { 11 | if (id != null) { 12 | long msb = id.getMostSignificantBits(); 13 | long lsb = id.getLeastSignificantBits(); 14 | StringBuilder sb = new StringBuilder(32); 15 | digits(sb, msb >> 32, 8); 16 | digits(sb, msb >> 16, 4); 17 | digits(sb, msb, 4); 18 | digits(sb, lsb >> 48, 4); 19 | digits(sb, lsb, 12); 20 | return sb.toString(); 21 | } 22 | 23 | return ""; 24 | } 25 | 26 | private static void digits(StringBuilder sb, long val, int digits) { 27 | long hi = 1L << (digits * 4); 28 | String s = Long.toHexString(hi | (val & (hi - 1))); 29 | sb.append(s, 1, s.length()); 30 | } 31 | 32 | @Nullable 33 | public static UUID fromString(@Nullable Object o) { 34 | String s = String.valueOf(o); 35 | 36 | if (o == null || !(s.length() == 32 || s.length() == 36)) { 37 | return null; 38 | } 39 | 40 | try { 41 | if (s.indexOf('-') != -1) { 42 | return UUID.fromString(s); 43 | } 44 | 45 | int l = s.length(); 46 | StringBuilder sb = new StringBuilder(36); 47 | for (int i = 0; i < l; i++) { 48 | sb.append(s.charAt(i)); 49 | if (i == 7 || i == 11 || i == 15 || i == 19) { 50 | sb.append('-'); 51 | } 52 | } 53 | 54 | return UUID.fromString(sb.toString()); 55 | } catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | 59 | return null; 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/WithAttachedData.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public interface WithAttachedData { 7 | AttachedData getData(); 8 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/WrappedJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public interface WrappedJS { 7 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/WrappedJSObject.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public interface WrappedJSObject extends WrappedJS { 7 | void toString(StringBuilder builder); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/WrappedJSObjectChangeListener.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.util; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | @FunctionalInterface 7 | public interface WrappedJSObjectChangeListener { 8 | void onChanged(T o); 9 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/util/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.util; -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/world/AttachWorldDataEvent.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.world; 2 | 3 | import dev.latvian.kubejs.script.AttachDataEvent; 4 | import dev.latvian.kubejs.script.DataType; 5 | import net.fabricmc.fabric.api.event.Event; 6 | import net.fabricmc.fabric.api.event.EventFactory; 7 | 8 | import java.util.function.Consumer; 9 | 10 | /** 11 | * @author LatvianModder 12 | */ 13 | public class AttachWorldDataEvent extends AttachDataEvent { 14 | public static final Event> EVENT = EventFactory.createArrayBacked(Consumer.class, consumers -> event -> { 15 | for (Consumer consumer : consumers) { 16 | consumer.accept(event); 17 | } 18 | }); 19 | 20 | public AttachWorldDataEvent(WorldJS w) { 21 | super(DataType.WORLD, w); 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/world/ExplosionJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.world; 2 | 3 | import dev.latvian.kubejs.entity.EntityJS; 4 | import net.minecraft.world.level.Explosion; 5 | import net.minecraft.world.level.Level; 6 | import net.minecraft.world.level.LevelAccessor; 7 | 8 | /** 9 | * @author LatvianModder 10 | */ 11 | public class ExplosionJS { 12 | private final LevelAccessor world; 13 | public final double x, y, z; 14 | public EntityJS exploder; 15 | public float strength; 16 | public boolean causesFire; 17 | public Explosion.BlockInteraction explosionMode; 18 | 19 | public ExplosionJS(LevelAccessor w, double _x, double _y, double _z) { 20 | world = w; 21 | x = _x; 22 | y = _y; 23 | z = _z; 24 | exploder = null; 25 | strength = 3F; 26 | causesFire = false; 27 | explosionMode = Explosion.BlockInteraction.BREAK; 28 | } 29 | 30 | public ExplosionJS exploder(EntityJS entity) { 31 | exploder = entity; 32 | return this; 33 | } 34 | 35 | public ExplosionJS strength(float f) { 36 | strength = f; 37 | return this; 38 | } 39 | 40 | public ExplosionJS causesFire(boolean b) { 41 | causesFire = b; 42 | return this; 43 | } 44 | 45 | public ExplosionJS damagesTerrain(boolean b) { 46 | explosionMode = b ? Explosion.BlockInteraction.BREAK : Explosion.BlockInteraction.NONE; 47 | return this; 48 | } 49 | 50 | public ExplosionJS destroysTerrain(boolean b) { 51 | explosionMode = b ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.NONE; 52 | return this; 53 | } 54 | 55 | public void explode() { 56 | if (world instanceof Level) { 57 | ((Level) world).explode(exploder == null ? null : exploder.minecraftEntity, x, y, z, strength, causesFire, explosionMode); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/world/SimpleWorldEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.world; 2 | 3 | /** 4 | * @author LatvianModder 5 | */ 6 | public class SimpleWorldEventJS extends WorldEventJS { 7 | private final WorldJS world; 8 | 9 | public SimpleWorldEventJS(WorldJS w) { 10 | world = w; 11 | } 12 | 13 | @Override 14 | public WorldJS getWorld() { 15 | return world; 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/world/WorldCommandSender.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.world; 2 | 3 | import net.minecraft.commands.CommandSource; 4 | import net.minecraft.commands.CommandSourceStack; 5 | import net.minecraft.commands.arguments.EntityAnchorArgument; 6 | import net.minecraft.network.chat.TextComponent; 7 | import net.minecraft.server.level.ServerLevel; 8 | import net.minecraft.world.phys.Vec2; 9 | import net.minecraft.world.phys.Vec3; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public class WorldCommandSender extends CommandSourceStack { 15 | public WorldCommandSender(ServerWorldJS w) { 16 | super(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, (ServerLevel) w.minecraftWorld, 4, "World", new TextComponent("World"), w.getServer().minecraftServer, null, true, (context, success, result) -> {}, EntityAnchorArgument.Anchor.FEET); 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/world/WorldEventJS.java: -------------------------------------------------------------------------------- 1 | package dev.latvian.kubejs.world; 2 | 3 | import dev.latvian.kubejs.event.EventJS; 4 | import dev.latvian.kubejs.server.ServerJS; 5 | import dev.latvian.kubejs.util.UtilsJS; 6 | import net.minecraft.world.entity.Entity; 7 | import net.minecraft.world.level.Level; 8 | 9 | import javax.annotation.Nullable; 10 | 11 | /** 12 | * @author LatvianModder 13 | */ 14 | public abstract class WorldEventJS extends EventJS { 15 | public abstract WorldJS getWorld(); 16 | 17 | @Nullable 18 | public ServerJS getServer() { 19 | return getWorld().getServer(); 20 | } 21 | 22 | protected WorldJS worldOf(Level world) { 23 | return UtilsJS.getWorld(world); 24 | } 25 | 26 | protected WorldJS worldOf(Entity entity) { 27 | return worldOf(entity.level); 28 | } 29 | 30 | public final boolean post(String id) { 31 | return post(getWorld().getSide(), id); 32 | } 33 | 34 | public final boolean post(String id, String sub) { 35 | return post(getWorld().getSide(), id, sub); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/dev/latvian/kubejs/world/package-info.java: -------------------------------------------------------------------------------- 1 | @dev.latvian.kubejs.NonnullByDefault 2 | package dev.latvian.kubejs.world; -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/models/item/generated_bucket.json: -------------------------------------------------------------------------------- 1 | { 2 | "parent": "item/generated", 3 | "textures": { 4 | "layer0": "kubejs:item/bucket", 5 | "layer1": "kubejs:item/fluid" 6 | } 7 | } -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/fluid/fluid_thick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/src/main/resources/assets/kubejs/textures/fluid/fluid_thick.png -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/fluid/fluid_thick.png.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "animation": { 3 | "frametime": 2, 4 | "frames": [ 5 | 0, 6 | 1, 7 | 2, 8 | 3, 9 | 4, 10 | 5, 11 | 6, 12 | 7, 13 | 8, 14 | 9, 15 | 10, 16 | 11, 17 | 12, 18 | 13, 19 | 14, 20 | 15, 21 | 16, 22 | 17, 23 | 18, 24 | 19, 25 | 18, 26 | 17, 27 | 16, 28 | 15, 29 | 14, 30 | 13, 31 | 12, 32 | 11, 33 | 10, 34 | 9, 35 | 8, 36 | 7, 37 | 6, 38 | 5, 39 | 4, 40 | 3, 41 | 2, 42 | 1 43 | ] 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/fluid/fluid_thick_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/src/main/resources/assets/kubejs/textures/fluid/fluid_thick_flow.png -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/fluid/fluid_thick_flow.png.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "animation": { 3 | "frametime": 3 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/fluid/fluid_thin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/src/main/resources/assets/kubejs/textures/fluid/fluid_thin.png -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/fluid/fluid_thin.png.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "animation": { 3 | "frametime": 2 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/fluid/fluid_thin_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/src/main/resources/assets/kubejs/textures/fluid/fluid_thin_flow.png -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/fluid/fluid_thin_flow.png.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "animation": {} 3 | } -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/item/bucket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/src/main/resources/assets/kubejs/textures/item/bucket.png -------------------------------------------------------------------------------- /src/main/resources/assets/kubejs/textures/item/fluid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/src/main/resources/assets/kubejs/textures/item/fluid.png -------------------------------------------------------------------------------- /src/main/resources/data/kubejs/example_block_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/src/main/resources/data/kubejs/example_block_texture.png -------------------------------------------------------------------------------- /src/main/resources/data/kubejs/example_client_script.js: -------------------------------------------------------------------------------- 1 | // priority: 0 2 | 3 | console.info('Hello, World! (You will see this line every time client resources reload)') -------------------------------------------------------------------------------- /src/main/resources/data/kubejs/example_item_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/src/main/resources/data/kubejs/example_item_texture.png -------------------------------------------------------------------------------- /src/main/resources/data/kubejs/example_server_script.js: -------------------------------------------------------------------------------- 1 | // priority: 0 2 | 3 | console.info('Hello, World! (You will see this line every time server resources reload)') 4 | 5 | events.listen('recipes', event => { 6 | // Change recipes here 7 | }) 8 | 9 | events.listen('item.tags', event => { 10 | // Change item tags here 11 | }) -------------------------------------------------------------------------------- /src/main/resources/data/kubejs/example_startup_script.js: -------------------------------------------------------------------------------- 1 | // priority: 0 2 | 3 | console.info('Hello, World! (You will only see this line once in console, during startup)') 4 | 5 | events.listen('item.registry', event => { 6 | // Register new items here 7 | // event.create('example_item').displayName('Example Item') 8 | }) 9 | 10 | events.listen('block.registry', event => { 11 | // Register new blocks here 12 | // event.create('example_block').material('wood').hardness(1.0).displayName('Example Block') 13 | }) -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "kubejs", 4 | "version": "${version}", 5 | "name": "KubeJS", 6 | "description": "Allows you to tweak and customize modpack with JavaScript", 7 | "authors": [ 8 | "LatvianModder", 9 | "shedaniel", 10 | "vini2003" 11 | ], 12 | "license": "LGPL-2.1-or-later", 13 | "icon": "kubejs_logo.png", 14 | "environment": "*", 15 | "entrypoints": { 16 | "main": [ 17 | "dev.latvian.kubejs.KubeJS", 18 | "dev.latvian.kubejs.server.KubeJSServerEventHandler", 19 | "dev.latvian.kubejs.docs.KubeJSDocs" 20 | ], 21 | "kubejs-init": [ 22 | "dev.latvian.kubejs.KubeJSOtherEventHandler", 23 | "dev.latvian.kubejs.world.KubeJSWorldEventHandler", 24 | "dev.latvian.kubejs.player.KubeJSPlayerEventHandler", 25 | "dev.latvian.kubejs.entity.KubeJSEntityEventHandler", 26 | "dev.latvian.kubejs.block.KubeJSBlockEventHandler", 27 | "dev.latvian.kubejs.item.KubeJSItemEventHandler", 28 | "dev.latvian.kubejs.recipe.KubeJSRecipeEventHandler", 29 | "dev.latvian.kubejs.fluid.KubeJSFluidEventHandler", 30 | "dev.latvian.kubejs.compat.AstromineRecipeEventHandler", 31 | "dev.latvian.kubejs.compat.TechRebornRecipeEventHandler" 32 | ], 33 | "rei_plugins": [ 34 | "dev.latvian.kubejs.rei.REIPlugin" 35 | ] 36 | }, 37 | "accessWidener": "kubejs.accessWidener", 38 | "mixins": [ 39 | "kubejs.mixins.json" 40 | ], 41 | "depends": { 42 | "fabricloader": ">=0.9.0", 43 | "fabric": "*" 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/resources/kubejs.accessWidener: -------------------------------------------------------------------------------- 1 | accessWidener v1 named 2 | accessible field net/minecraft/world/entity/item/ItemEntity age I 3 | mutable field net/minecraft/world/entity/item/ItemEntity age I 4 | accessible field net/minecraft/world/item/crafting/RecipeManager recipes Ljava/util/Map; 5 | mutable field net/minecraft/world/item/crafting/RecipeManager recipes Ljava/util/Map; 6 | accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties requiresCorrectToolForDrops Z 7 | mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties requiresCorrectToolForDrops Z -------------------------------------------------------------------------------- /src/main/resources/kubejs.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "dev.latvian.kubejs.core.mixin", 4 | "compatibilityLevel": "JAVA_8", 5 | "mixins": [ 6 | "AbstractBlockMixin", "AbstractFurnaceBlockEntityMixin", "CompoundNBTMixin", 7 | "CraftingResultSlotMixin", "DataPackRegistriesMixin", "EntityMixin", "FireworkRocketEntityMixin", "ItemStackMixin", 8 | "LivingEntityMixin", "PlayerInteractionManagerMixin", 9 | "RecipeManagerMixin", "ResourcePackManagerMixin", "ServerPlayerInteractionManagerMixin", 10 | "SimpleReloadableResourceManagerMixin", "TagBuilderMixin", "TagCollectionMixin", "TradeOfferMixin" 11 | ], 12 | "client": [ 13 | "ClientPlayNetworkHandlerMixin", "ClientRecipeBookMixin", "DebugHudMixin", "ImageButtonMixin", "MainWindowMixin", "MinecraftClientMixin", 14 | "SplashScreenMixin" 15 | ], 16 | "injectors": { 17 | "defaultRequire": 1 18 | }, 19 | "minVersion": "0.8" 20 | } -------------------------------------------------------------------------------- /src/main/resources/kubejs_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KubeJS-Mods/KubeJS-Fabric/611979ca753c541d94d16fb8a00e164cde0058a0/src/main/resources/kubejs_logo.png -------------------------------------------------------------------------------- /src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "KubeJS Resources", 4 | "pack_format": 4 5 | } 6 | } 7 | --------------------------------------------------------------------------------