├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src └── main ├── java └── youyihj │ └── zenutils │ ├── Reference.java │ ├── ZenUtils.java │ ├── api │ ├── block │ │ ├── ZenUtilsBlock.java │ │ └── ZenUtilsBlockDefinition.java │ ├── command │ │ ├── DefaultGetTabCompletion.java │ │ ├── ExpandedCommandManager.java │ │ ├── ICommandExecute.java │ │ ├── IGetCommandUsage.java │ │ ├── IGetTabCompletion.java │ │ ├── IZenCommand.java │ │ ├── TabCompletion.java │ │ ├── TabCompletionCase.java │ │ ├── ZenCommand.java │ │ ├── ZenCommandRegisterAction.java │ │ ├── ZenCommandTree.java │ │ └── ZenUtilsCommandSender.java │ ├── cotx │ │ ├── ExpandHand.java │ │ ├── ExpandVanillaFactory.java │ │ ├── annotation │ │ │ └── ExpandContentTweakerEntry.java │ │ ├── block │ │ │ ├── CrTCoTBlockStateBridge.java │ │ │ ├── DirectionalBlockContent.java │ │ │ ├── DirectionalBlockRepresentation.java │ │ │ ├── ExpandBlockContent.java │ │ │ ├── ExpandBlockRepresentation.java │ │ │ ├── OmniDirectionalBlockContent.java │ │ │ └── OmniDirectionalTileEntityContent.java │ │ ├── brackets │ │ │ ├── BracketHandlerCoTBlock.java │ │ │ ├── BracketHandlerCoTItem.java │ │ │ ├── LateGetContentLookup.java │ │ │ └── TemplateBracketHandlerCoT.java │ │ ├── function │ │ │ ├── IBlockActivated.java │ │ │ ├── IEntityCollided.java │ │ │ ├── IEntityItemUpdate.java │ │ │ ├── IEntityWalk.java │ │ │ ├── IGetEntityLifeSpan.java │ │ │ ├── IPlacementChecker.java │ │ │ └── ITileEntityTick.java │ │ ├── item │ │ │ ├── EnergyItemContent.java │ │ │ ├── EnergyItemRepresentation.java │ │ │ ├── ExpandItemContent.java │ │ │ └── ExpandItemRepresentation.java │ │ └── tile │ │ │ ├── ExpandWorldForTile.java │ │ │ ├── TileData.java │ │ │ ├── TileEntityContent.java │ │ │ ├── TileEntityManager.java │ │ │ ├── TileEntityRegistryHandler.java │ │ │ └── TileEntityRepresentation.java │ ├── energy │ │ └── CrTEnergyStorage.java │ ├── entity │ │ ├── IEntityPredicate.java │ │ ├── IEntityTick.java │ │ ├── INearbyEntityList.java │ │ ├── ZenUtilsEntity.java │ │ └── ZenUtilsEntityDefinition.java │ ├── event │ │ ├── CTEventPriority.java │ │ ├── CTRandomTickEvent.java │ │ ├── EntityItemDeathEvent.java │ │ ├── EntityItemFallEvent.java │ │ ├── EntityRemoveEvent.java │ │ ├── ExpandEventManager.java │ │ ├── RandomTickEvent.java │ │ ├── WorldLoadEvent.java │ │ ├── WorldSaveEvent.java │ │ └── WorldUnloadEvent.java │ ├── ftbq │ │ ├── CTChapter.java │ │ ├── CTQuest.java │ │ ├── CTQuestObjectBase.java │ │ ├── CTReward.java │ │ ├── CTTask.java │ │ ├── FTBQEventManager.java │ │ └── event │ │ │ ├── CTChapterCompletedEvent.java │ │ │ ├── CTCustomRewardEvent.java │ │ │ ├── CTCustomTaskEvent.java │ │ │ ├── CTObjectCompletedEvent.java │ │ │ ├── CTQuestCompletedEvent.java │ │ │ ├── CTTaskCompletedEvent.java │ │ │ └── CTTaskStartedEvent.java │ ├── item │ │ ├── CrTItemHandler.java │ │ ├── ITooltipModifier.java │ │ ├── ItemTooltipModification.java │ │ └── ZenUtilsMutableItemStack.java │ ├── liquid │ │ ├── CrTLiquidHandler.java │ │ └── ILiquidTankProperties.java │ ├── logger │ │ ├── ICleanableLogger.java │ │ ├── ILogFilter.java │ │ ├── LogLevel.java │ │ ├── LogOption.java │ │ ├── RegexLogFilter.java │ │ ├── ScriptPosition.java │ │ └── ScriptSuppressLogFilter.java │ ├── network │ │ ├── IByteBuf.java │ │ ├── IByteBufWriter.java │ │ ├── IClientMessageHandler.java │ │ ├── IServerMessageHandler.java │ │ └── ZenNetworkHandler.java │ ├── player │ │ ├── BaublePlayerPatch.java │ │ ├── DefaultStatFormatters.java │ │ ├── IActionResult.java │ │ ├── IStatFormatter.java │ │ ├── PlayerStat.java │ │ └── ZenUtilsPlayer.java │ ├── preprocessor │ │ ├── DownloadReobfMappingPreprocessor.java │ │ ├── HardFailPreprocessor.java │ │ ├── NoFixRecipeBookPreprocessor.java │ │ ├── NotReloadablePreprocessor.java │ │ ├── ReloadablePreprocessor.java │ │ └── SuppressErrorPreprocessor.java │ ├── reload │ │ ├── ActionReloadCallback.java │ │ ├── IActionReloadCallbackFactory.java │ │ ├── Reloadable.java │ │ └── ScriptReloadEvent.java │ ├── util │ │ ├── CommandUtils.java │ │ ├── CrTI18n.java │ │ ├── CrTIntRange.java │ │ ├── CrTUUID.java │ │ ├── ExpandData.java │ │ ├── ExpandGame.java │ │ ├── ExpandPotion.java │ │ ├── HexHelper.java │ │ ├── JourneyMap.java │ │ ├── ReflectionInvoked.java │ │ ├── StaticString.java │ │ ├── StringList.java │ │ ├── StringPredicate.java │ │ ├── ZenUtilsClient.java │ │ ├── ZenUtilsGlobal.java │ │ ├── catenation │ │ │ ├── Catenation.java │ │ │ ├── CatenationContext.java │ │ │ ├── CatenationStatus.java │ │ │ ├── ICatenationBuilder.java │ │ │ ├── ICatenationTask.java │ │ │ ├── ICatenationTaskQueueBuilder.java │ │ │ ├── ICatenationTaskQueueBuilderConsumer.java │ │ │ ├── ITimerHandler.java │ │ │ ├── IWorldCondition.java │ │ │ ├── IWorldFunction.java │ │ │ ├── Timer.java │ │ │ └── persistence │ │ │ │ ├── BuiltinObjectHolderTypes.java │ │ │ │ ├── CatenationPersistenceAPI.java │ │ │ │ ├── CatenationPersistenceEntryBuilder.java │ │ │ │ ├── CatenationPersistenceRegisterAction.java │ │ │ │ ├── ICatenationFactory.java │ │ │ │ ├── ICatenationObjectHolder.java │ │ │ │ └── PersistedCatenationStarter.java │ │ └── delay │ │ │ ├── CTDelayManager.java │ │ │ ├── DelayRunnable.java │ │ │ └── IsExecute.java │ ├── world │ │ ├── GameRuleHelper.java │ │ └── ZenUtilsWorld.java │ └── zenscript │ │ ├── IMultilinePreprocessor.java │ │ ├── IMultilinePreprocessorFactory.java │ │ ├── INativeClassExclude.java │ │ ├── SidedZenRegister.java │ │ └── TemplateBracketHandler.java │ └── impl │ ├── capability │ ├── IZenWorldCapability.java │ ├── ZenWorldCapability.java │ ├── ZenWorldCapabilityHandler.java │ └── ZenWorldCapabilityProvider.java │ ├── command │ ├── CleanLogCommand.java │ └── StatCommand.java │ ├── core │ ├── Configuration.java │ ├── MixinInit.java │ └── ZenUtilsPlugin.java │ ├── entity │ ├── EntityTickDispatcher.java │ └── NearbyEntityList.java │ ├── event │ ├── EventHandler.java │ ├── EventHandlerRegisterAction.java │ ├── EventHandlerRegisterException.java │ └── GenericEventManagerImpl.java │ ├── fluid │ └── MCLiquidTankProperties.java │ ├── member │ ├── AnnotatedMember.java │ ├── ClassData.java │ ├── ClassDataFetcher.java │ ├── ExecutableData.java │ ├── FieldData.java │ ├── LiteralType.java │ ├── LookupRequester.java │ ├── TypeData.java │ ├── bytecode │ │ ├── BytecodeAnnotatedMember.java │ │ ├── BytecodeClassData.java │ │ ├── BytecodeClassDataFetcher.java │ │ ├── BytecodeFieldData.java │ │ ├── BytecodeMethodData.java │ │ ├── BytecodeTypeData.java │ │ └── MethodParameterParser.java │ └── reflect │ │ ├── ReflectionAnnotatedMember.java │ │ ├── ReflectionClassData.java │ │ ├── ReflectionClassDataFetcher.java │ │ ├── ReflectionExecutableData.java │ │ ├── ReflectionFieldData.java │ │ └── ReflectionTypeData.java │ ├── mixin │ ├── crafttweaker │ │ ├── CraftTweakerMixinPlugin.java │ │ ├── MixinBlockContent.java │ │ ├── MixinCoTItemBracketHandler.java │ │ ├── MixinCraftTweaker.java │ │ ├── MixinCraftTweakerAPI.java │ │ ├── MixinCraftTweakerImplementationAPI.java │ │ ├── MixinEnvironmentClass.java │ │ ├── MixinExpression.java │ │ ├── MixinExpressionMap.java │ │ ├── MixinItemContent.java │ │ ├── MixinMCEntity.java │ │ ├── MixinMCPlayerAnvilUpdateEvent.java │ │ ├── MixinParsedClassConstructor.java │ │ ├── MixinParsedExpression.java │ │ ├── MixinParsedExpressionFunction.java │ │ ├── MixinParsedZenClass.java │ │ ├── MixinParsedZenClassField.java │ │ ├── MixinParsedZenClassMethod.java │ │ ├── MixinPartialType.java │ │ ├── MixinPlayerAnvilUpdateEvent.java │ │ ├── MixinPreprocessorManager.java │ │ ├── MixinTemplateStringTokener.java │ │ ├── MixinTokenStream.java │ │ ├── MixinTypeRegistry.java │ │ ├── MixinZenTokener.java │ │ ├── MixinZenType.java │ │ ├── MixinZenTypeAssociate.java │ │ ├── MixinZenTypeNative.java │ │ └── TokenStreamAccessor.java │ ├── custom │ │ ├── CustomMixinErrorHandler.java │ │ └── CustomMixinPlugin.java │ ├── customscriptentrypoint │ │ └── MixinFMLModContainer.java │ ├── itf │ │ ├── IAnvilUpdateEventExtension.java │ │ ├── IEnvironmentClassExtension.java │ │ ├── IParsedClassConstructorExtension.java │ │ ├── IParsedZenClassExtension.java │ │ └── IParsedZenClassFieldExtension.java │ ├── simpledimensions │ │ └── MixinWorldCustom.java │ ├── vanilla │ │ ├── ContainerRepairAccessor.java │ │ ├── MixinAnvilUpdateEvent.java │ │ ├── MixinEntityItem.java │ │ ├── MixinForgeHooks.java │ │ ├── MixinWorldServer.java │ │ └── VanillaMixinPlugin.java │ └── zenbootstrap │ │ ├── MixinCleanroomLoadController.java │ │ ├── MixinForgeLoadController.java │ │ └── ZenMixinBootstrapPlugin.java │ ├── network │ ├── ByteAndDataConverter.java │ ├── PlayerScriptValidation.java │ ├── ValidateScriptMessage.java │ ├── ZenUtilsByteBuf.java │ ├── ZenUtilsMessage.java │ └── ZenUtilsNetworkHandler.java │ ├── player │ ├── ActionResult.java │ ├── DummyNetHandler.java │ ├── FakePlayerHolder.java │ ├── IStatFormatterAdapter.java │ ├── InteractBlockContext.java │ └── PlayerInteractionSimulation.java │ ├── reload │ ├── AnnotatedActionReloadCallback.java │ ├── ReloadCommand.java │ ├── ReloadEventHandler.java │ └── ScriptReloader.java │ ├── runtime │ ├── HardFailLogger.java │ ├── InvalidCraftTweakerVersionException.java │ ├── ScriptRunException.java │ ├── ScriptStatus.java │ ├── ZenUtilsFileLogger.java │ ├── ZenUtilsLogger.java │ └── ZenUtilsTweaker.java │ ├── util │ ├── DeepDataUpdater.java │ ├── Either.java │ ├── FireEntityRemoveEventListener.java │ ├── IVersionChecker.java │ ├── InternalUtils.java │ ├── JourneyMapPlugin.java │ ├── LogMTErrorRunnableWrapper.java │ ├── NoFeedbackCommandSender.java │ ├── ReflectUtils.java │ ├── SimpleCache.java │ ├── TotallyImmutableItemStack.java │ └── catenation │ │ ├── AbstractCatenationBuilder.java │ │ ├── CatenationBuilder.java │ │ ├── CatenationManager.java │ │ ├── CatenationTaskQueueBuilder.java │ │ ├── ClientCatenationBuilder.java │ │ ├── InstantTask.java │ │ ├── RepeatTask.java │ │ ├── SleepTask.java │ │ ├── SleepUntilTask.java │ │ ├── TimerTask.java │ │ └── persistence │ │ ├── BlockPosObjectHolder.java │ │ ├── CatenationPersistedObjects.java │ │ ├── CatenationPersistenceImpl.java │ │ ├── DataObjectHolder.java │ │ ├── EntityObjectHolder.java │ │ ├── ObjectHolderTypeRegistry.java │ │ └── PlayerObjectHolder.java │ └── zenscript │ ├── Defaults.java │ ├── ExpressionCallStaticThenCastWithStringArg.java │ ├── ExpressionDeepNull.java │ ├── ExpressionTemplateString.java │ ├── IOrderlyType.java │ ├── LiteralTokener.java │ ├── MixinPreprocessor.java │ ├── ParsedExpressionDeepNull.java │ ├── TemplateString.java │ ├── TemplateStringTokener.java │ ├── ZenTypeDeepNull.java │ ├── entrypoint │ └── CustomScriptEntrypoint.java │ ├── mixin │ ├── ExpressionMixinThis.java │ ├── MixinAnnotationTranslator.java │ ├── ZenMixin.java │ ├── ZenTypeMixinCallbackInfo.java │ └── ZenTypeMixinCallbackInfoReturnable.java │ └── nat │ ├── CastingRuleCoerced.java │ ├── CraftTweakerBridge.java │ ├── DelegatedExpressionCallStatic.java │ ├── ExpressionClassConstant.java │ ├── ExpressionNativeConstructorCall.java │ ├── ExpressionNativeGetter.java │ ├── ExpressionNativeSetter.java │ ├── ExpressionSuper.java │ ├── ExpressionSuperConstructorCall.java │ ├── JavaNativeMemberSymbol.java │ ├── MCPReobfuscation.java │ ├── NativeClassValidate.java │ ├── NativeMethod.java │ ├── ParsedZenClassCompile.java │ ├── PartialCallSuperConstructor.java │ ├── PartialJavaNativeClassOrPackage.java │ ├── PartialJavaNativeMember.java │ ├── SymbolCallSuperConstructor.java │ ├── ZenTypeClass.java │ ├── ZenTypeJavaNative.java │ ├── ZenTypeJavaNativeIterable.java │ └── ZenTypeJavaNativeSuper.java └── resources ├── META-INF └── zenutils_at.cfg ├── assets └── zenutils │ ├── lang │ ├── en_us.lang │ └── zh_cn.lang │ └── templates │ ├── all_directional_block.json │ ├── horizontal_directional_block.json │ ├── item_tool.json │ ├── plane_rotatable_all_directional_block.json │ ├── plane_rotatable_horizontal_direactional_block.json │ ├── plane_rotatable_vertical_directional_block.json │ └── vertical_directional_block.json ├── mcmod.info ├── mixins.zenutils.custom.json ├── mixins.zenutils.customscriptentrypoint.json ├── mixins.zenutils.json ├── mixins.zenutils.randomtickevent.json ├── mixins.zenutils.simpledimensions.json ├── mixins.zenutils.vanilla.json ├── mixins.zenutils.zenbootstrap.json └── pack.mcmeta /.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 | classes 24 | logs 25 | runServer 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 youyihj 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZenUtils 2 | 3 | A powerful CraftTweaker (for Minecraft 1.12) addon. The most important feature is the (partial) script reloading. Check [wiki](https://github.com/friendlyhj/ZenUtils/wiki) to view all features. 4 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Sets default memory used for gradle commands. Can be overridden by user or command line properties. 2 | # This is required to provide enough memory for the Minecraft decompilation process. 3 | org.gradle.jvmargs=-Xmx3G 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyhj/ZenUtils/20254afe86a61ac3841cab0602d522b45e4d635b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/Reference.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils; 2 | 3 | import org.apache.commons.lang3.SystemUtils; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public class Reference { 9 | public static final String MODID = "zenutils"; 10 | public static final String NAME = "ZenUtils"; 11 | public static final String VERSION = "1.22.4"; 12 | public static final String DEPENDENCIES = "required-after:crafttweaker;required-after:mixinbooter@[8.0,);required-after:configanytime;before:contenttweaker;after:ftbquests;"; 13 | public static final String MOD_COT = "contenttweaker"; 14 | public static final boolean IS_CLEANROOM = !SystemUtils.IS_JAVA_1_8; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/block/ZenUtilsBlock.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.block; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.block.IBlock; 5 | import crafttweaker.api.block.IBlockState; 6 | import crafttweaker.api.item.IItemStack; 7 | import crafttweaker.api.minecraft.CraftTweakerMC; 8 | import crafttweaker.api.world.IBlockPos; 9 | import crafttweaker.api.world.IWorld; 10 | import stanhebben.zenscript.annotations.ZenExpansion; 11 | import stanhebben.zenscript.annotations.ZenMethod; 12 | 13 | /** 14 | * @author youyihj 15 | */ 16 | @ZenRegister 17 | @ZenExpansion("crafttweaker.block.IBlock") 18 | @SuppressWarnings("unused") 19 | public class ZenUtilsBlock { 20 | @ZenMethod 21 | @SuppressWarnings("deprecation") 22 | public static IItemStack getItem(IBlock block, IWorld world, IBlockPos pos, IBlockState state) { 23 | return CraftTweakerMC.getIItemStack(CraftTweakerMC.getBlock(block).getItem( 24 | CraftTweakerMC.getWorld(world), 25 | CraftTweakerMC.getBlockPos(pos), 26 | CraftTweakerMC.getBlockState(state) 27 | )); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/block/ZenUtilsBlockDefinition.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.block; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.block.IBlockDefinition; 5 | import crafttweaker.api.minecraft.CraftTweakerMC; 6 | import net.minecraft.block.Block; 7 | import stanhebben.zenscript.annotations.ZenExpansion; 8 | import stanhebben.zenscript.annotations.ZenGetter; 9 | import stanhebben.zenscript.annotations.ZenMethodStatic; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @ZenRegister 15 | @ZenExpansion("crafttweaker.block.IBlockDefinition") 16 | public class ZenUtilsBlockDefinition { 17 | @ZenGetter("numericalId") 18 | public static int getNumericalId(IBlockDefinition definition) { 19 | return Block.getIdFromBlock(CraftTweakerMC.getBlock(definition)); 20 | } 21 | 22 | @ZenMethodStatic 23 | public static IBlockDefinition getFromNumericalId(int id) { 24 | return CraftTweakerMC.getBlockDefinition(Block.getBlockById(id)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/command/ExpandedCommandManager.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.command; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.command.ICommandManager; 5 | import crafttweaker.api.command.ICommandSender; 6 | import crafttweaker.api.minecraft.CraftTweakerMC; 7 | import crafttweaker.mc1120.CraftTweaker; 8 | import stanhebben.zenscript.annotations.ZenExpansion; 9 | import stanhebben.zenscript.annotations.ZenMethod; 10 | import youyihj.zenutils.impl.util.NoFeedbackCommandSender; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | @ZenRegister 16 | @ZenExpansion("crafttweaker.command.ICommandManager") 17 | public class ExpandedCommandManager { 18 | @ZenMethod 19 | public static int executeCommandSilent(ICommandManager commandManager, ICommandSender sender, String rawCommand) { 20 | return CraftTweaker.server.commandManager.executeCommand(new NoFeedbackCommandSender(CraftTweakerMC.getICommandSender(sender)), rawCommand); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/command/ICommandExecute.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.command; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.server.IServer; 5 | import net.minecraft.command.CommandException; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.command.ICommandExecute") 13 | public interface ICommandExecute { 14 | void execute(ZenCommand command, IServer server, ZenUtilsCommandSender sender, String[] args) throws CommandException; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/command/IGetCommandUsage.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.command; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | @FunctionalInterface 10 | @ZenRegister 11 | @ZenClass("mods.zenutils.command.IGetCommandUsage") 12 | public interface IGetCommandUsage { 13 | IGetCommandUsage UNDEFINED = (sender -> "commands.undefined.usage"); 14 | 15 | String getCommandUsage(ZenUtilsCommandSender sender); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/command/IGetTabCompletion.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.command; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.server.IServer; 5 | import crafttweaker.api.world.IBlockPos; 6 | import net.minecraft.command.CommandException; 7 | import stanhebben.zenscript.annotations.ZenClass; 8 | import youyihj.zenutils.api.util.StringList; 9 | 10 | import javax.annotation.Nullable; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | @FunctionalInterface 16 | @ZenRegister 17 | @ZenClass("mods.zenutils.command.IGetTabCompletion") 18 | public interface IGetTabCompletion { 19 | StringList get(IServer server, ZenUtilsCommandSender sender, @Nullable IBlockPos targetPos) throws CommandException; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/command/IZenCommand.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.command; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import net.minecraft.command.ICommand; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.command.IZenCommand") 13 | public interface IZenCommand extends ICommand { 14 | @ZenMethod 15 | default void register() { 16 | ZenCommandRegisterAction.ApplyLogic.INSTANCE.apply(new ZenCommandRegisterAction(this)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/command/TabCompletion.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.command; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | import stanhebben.zenscript.annotations.ZenMethod; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | @ZenRegister 11 | @ZenClass("mods.zenutils.command.TabCompletion") 12 | @Deprecated 13 | public class TabCompletion { 14 | private final String[] info; 15 | 16 | private TabCompletion(String[] info) { 17 | this.info = info; 18 | } 19 | 20 | @ZenMethod 21 | public static TabCompletion create(String[] info) { 22 | return new TabCompletion(info); 23 | } 24 | 25 | @ZenMethod 26 | public String[] getInfo() { 27 | return this.info; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/command/TabCompletionCase.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.command; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | import stanhebben.zenscript.annotations.ZenMethod; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenRegister 14 | @ZenClass("mods.zenutils.command.TabCompletionCase") 15 | @Deprecated 16 | public class TabCompletionCase { 17 | 18 | static final HashMap> cases = new HashMap<>(); 19 | 20 | @ZenMethod 21 | public static void add(String key, List value) { 22 | cases.put(key, value); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/command/ZenUtilsCommandSender.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.command; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.server.IServer; 5 | import crafttweaker.api.world.IBlockPos; 6 | import crafttweaker.api.world.IWorld; 7 | import crafttweaker.mc1120.server.MCServer; 8 | import crafttweaker.mc1120.world.MCBlockPos; 9 | import crafttweaker.mc1120.world.MCWorld; 10 | import net.minecraft.command.ICommandSender; 11 | import net.minecraft.util.text.TextComponentString; 12 | import stanhebben.zenscript.annotations.ZenClass; 13 | 14 | @ZenRegister 15 | @ZenClass("mods.zenutils.command.ZenUtilsCommandSender") 16 | public class ZenUtilsCommandSender implements crafttweaker.api.command.ICommandSender{ 17 | private final ICommandSender commandSender; 18 | 19 | public ZenUtilsCommandSender(ICommandSender commandSender) { 20 | this.commandSender = commandSender; 21 | } 22 | 23 | @Override 24 | public String getDisplayName() { 25 | return this.commandSender.getDisplayName().getFormattedText(); 26 | } 27 | 28 | @Override 29 | public IBlockPos getPosition() { 30 | return new MCBlockPos(this.commandSender.getPosition()); 31 | } 32 | 33 | @Override 34 | public IWorld getWorld() { 35 | return new MCWorld(this.commandSender.getEntityWorld()); 36 | } 37 | 38 | @Override 39 | public IServer getServer() { 40 | return new MCServer(this.commandSender.getServer()); 41 | } 42 | 43 | @Override 44 | public void sendMessage(String text) { 45 | this.commandSender.sendMessage(new TextComponentString(text)); 46 | } 47 | 48 | @Override 49 | public Object getInternal() { 50 | return this.commandSender; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/ExpandHand.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx; 2 | 3 | import com.teamacronymcoders.contenttweaker.api.ctobjects.enums.Hand; 4 | import crafttweaker.api.entity.IEntityEquipmentSlot; 5 | import crafttweaker.mc1120.entity.MCEntityEquipmentSlot; 6 | import net.minecraft.inventory.EntityEquipmentSlot; 7 | import stanhebben.zenscript.annotations.ZenCaster; 8 | import stanhebben.zenscript.annotations.ZenExpansion; 9 | import stanhebben.zenscript.annotations.ZenMethod; 10 | import youyihj.zenutils.Reference; 11 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 12 | 13 | /** 14 | * @author youyihj 15 | */ 16 | @SidedZenRegister(modDeps = Reference.MOD_COT) 17 | @ZenExpansion("mods.contenttweaker.Hand") 18 | public class ExpandHand { 19 | @ZenMethod 20 | @ZenCaster 21 | public static IEntityEquipmentSlot asEntityEquipmentSlot(Hand hand) { 22 | switch (hand.getInternal()) { 23 | case MAIN_HAND: 24 | return new MCEntityEquipmentSlot(EntityEquipmentSlot.MAINHAND); 25 | case OFF_HAND: 26 | return new MCEntityEquipmentSlot(EntityEquipmentSlot.OFFHAND); 27 | default: 28 | return null; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/annotation/ExpandContentTweakerEntry.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.annotation; 2 | 3 | import com.teamacronymcoders.contenttweaker.modules.vanilla.blocks.BlockContent; 4 | import com.teamacronymcoders.contenttweaker.modules.vanilla.blocks.BlockRepresentation; 5 | import com.teamacronymcoders.contenttweaker.modules.vanilla.items.ItemContent; 6 | import com.teamacronymcoders.contenttweaker.modules.vanilla.items.ItemRepresentation; 7 | 8 | import java.lang.annotation.*; 9 | 10 | /** 11 | * Mark a class as an expand ContentTweaker entry. The class should extend {@link BlockContent} or {@link ItemContent}. 12 | * 13 | * @author youyihj 14 | */ 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target(ElementType.TYPE) 17 | @Inherited 18 | public @interface ExpandContentTweakerEntry { 19 | 20 | /** 21 | * Mark a method as a representation getter. Used for late get ContentTweaker entries. 22 | *

23 | * The method should have zero parameters and return a class which extends {@link BlockRepresentation} or {@link ItemRepresentation}. 24 | * Moreover, the return type is exposed to zenscript. 25 | */ 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Target(ElementType.METHOD) 28 | @interface RepresentationGetter { 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/block/CrTCoTBlockStateBridge.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.block; 2 | 3 | import com.teamacronymcoders.contenttweaker.api.ctobjects.blockstate.ICTBlockState; 4 | import crafttweaker.api.block.IBlockState; 5 | import crafttweaker.mc1120.block.MCBlockState; 6 | import stanhebben.zenscript.annotations.ZenCaster; 7 | import stanhebben.zenscript.annotations.ZenExpansion; 8 | import youyihj.zenutils.Reference; 9 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @SidedZenRegister(modDeps = Reference.MOD_COT) 15 | @ZenExpansion("mods.contenttweaker.BlockState") 16 | public class CrTCoTBlockStateBridge { 17 | @ZenCaster 18 | public static IBlockState castToCrT(ICTBlockState state) { 19 | return new MCBlockState(state.getInternal()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/brackets/LateGetContentLookup.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.brackets; 2 | 3 | import com.teamacronymcoders.contenttweaker.modules.vanilla.blocks.BlockContent; 4 | import com.teamacronymcoders.contenttweaker.modules.vanilla.items.ItemContent; 5 | 6 | import java.util.HashSet; 7 | import java.util.Set; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public class LateGetContentLookup { 13 | private static final Set items = new HashSet<>(); 14 | private static final Set blocks = new HashSet<>(); 15 | 16 | public static void addItem(ItemContent item) { 17 | items.add(item); 18 | } 19 | 20 | public static void addBlock(BlockContent block) { 21 | blocks.add(block); 22 | } 23 | 24 | public static void refreshFields() { 25 | items.forEach(ItemContent::setFields); 26 | blocks.forEach(BlockContent::setFields); 27 | } 28 | 29 | public static void clear() { 30 | items.clear(); 31 | blocks.clear(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/function/IBlockActivated.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.function; 2 | 3 | import com.teamacronymcoders.contenttweaker.api.ctobjects.blockpos.IBlockPos; 4 | import com.teamacronymcoders.contenttweaker.api.ctobjects.blockstate.ICTBlockState; 5 | import com.teamacronymcoders.contenttweaker.api.ctobjects.entity.player.ICTPlayer; 6 | import com.teamacronymcoders.contenttweaker.api.ctobjects.enums.Facing; 7 | import com.teamacronymcoders.contenttweaker.api.ctobjects.enums.Hand; 8 | import com.teamacronymcoders.contenttweaker.api.ctobjects.world.IWorld; 9 | import crafttweaker.api.util.Position3f; 10 | import stanhebben.zenscript.annotations.ZenClass; 11 | import youyihj.zenutils.Reference; 12 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 13 | 14 | /** 15 | * @author youyihj 16 | */ 17 | @FunctionalInterface 18 | @SidedZenRegister(modDeps = Reference.MOD_COT) 19 | @ZenClass("mods.zenutils.cotx.IBlockActivated") 20 | public interface IBlockActivated { 21 | boolean activate(IWorld world, IBlockPos pos, ICTBlockState state, ICTPlayer player, Hand hand, Facing facing, Position3f blockHit); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/function/IEntityCollided.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.function; 2 | 3 | import com.teamacronymcoders.contenttweaker.api.ctobjects.blockpos.IBlockPos; 4 | import com.teamacronymcoders.contenttweaker.api.ctobjects.blockstate.ICTBlockState; 5 | import com.teamacronymcoders.contenttweaker.api.ctobjects.world.IWorld; 6 | import crafttweaker.api.entity.IEntity; 7 | import stanhebben.zenscript.annotations.ZenClass; 8 | import youyihj.zenutils.Reference; 9 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @FunctionalInterface 15 | @SidedZenRegister(modDeps = Reference.MOD_COT) 16 | @ZenClass("mods.zenutils.cotx.IEntityCollided") 17 | public interface IEntityCollided { 18 | void call(IWorld world, IBlockPos pos, ICTBlockState state, IEntity entity); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/function/IEntityItemUpdate.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.function; 2 | 3 | import crafttweaker.api.entity.IEntityItem; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | import youyihj.zenutils.Reference; 6 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @FunctionalInterface 12 | @SidedZenRegister(modDeps = Reference.MOD_COT) 13 | @ZenClass("mods.zenutils.cotx.IEntityItemUpdate") 14 | public interface IEntityItemUpdate { 15 | boolean update(IEntityItem entityItem); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/function/IEntityWalk.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.function; 2 | 3 | import com.teamacronymcoders.contenttweaker.api.ctobjects.blockpos.IBlockPos; 4 | import com.teamacronymcoders.contenttweaker.api.ctobjects.world.IWorld; 5 | import crafttweaker.api.entity.IEntity; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import youyihj.zenutils.Reference; 8 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @FunctionalInterface 14 | @SidedZenRegister(modDeps = Reference.MOD_COT) 15 | @ZenClass("mods.zenutils.cotx.IEntityWalk") 16 | public interface IEntityWalk { 17 | void call(IWorld world, IBlockPos pos, IEntity entity); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/function/IGetEntityLifeSpan.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.function; 2 | 3 | import com.teamacronymcoders.contenttweaker.api.ctobjects.world.IWorld; 4 | import crafttweaker.api.item.IItemStack; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import youyihj.zenutils.Reference; 7 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @FunctionalInterface 13 | @SidedZenRegister(modDeps = Reference.MOD_COT) 14 | @ZenClass("mods.zenutils.cotx.IGetEntityLifeSpan") 15 | public interface IGetEntityLifeSpan { 16 | int get(IItemStack iItemStack, IWorld world); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/function/IPlacementChecker.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.function; 2 | 3 | import com.teamacronymcoders.contenttweaker.api.ctobjects.blockpos.IBlockPos; 4 | import com.teamacronymcoders.contenttweaker.api.ctobjects.world.IWorld; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import youyihj.zenutils.Reference; 7 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @FunctionalInterface 13 | @SidedZenRegister(modDeps = Reference.MOD_COT) 14 | @ZenClass("mods.zenutils.cotx.IPlacementChecker") 15 | public interface IPlacementChecker { 16 | boolean canPlaceAt(IWorld world, IBlockPos pos); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/function/ITileEntityTick.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.function; 2 | 3 | import com.teamacronymcoders.contenttweaker.api.ctobjects.blockpos.IBlockPos; 4 | import com.teamacronymcoders.contenttweaker.api.ctobjects.world.IWorld; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import youyihj.zenutils.Reference; 7 | import youyihj.zenutils.api.cotx.tile.TileEntityContent; 8 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @SidedZenRegister(modDeps = Reference.MOD_COT) 14 | @ZenClass("mods.zenutils.cotx.ITileEntityTick") 15 | @FunctionalInterface 16 | public interface ITileEntityTick { 17 | void tick(TileEntityContent tileEntity, IWorld world, IBlockPos pos); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/item/EnergyItemRepresentation.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.item; 2 | 3 | import com.teamacronymcoders.base.registrysystem.ItemRegistry; 4 | import com.teamacronymcoders.contenttweaker.ContentTweaker; 5 | import net.minecraftforge.fml.common.Optional; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import youyihj.zenutils.Reference; 8 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @SidedZenRegister(modDeps = Reference.MOD_COT) 14 | @ZenClass("mods.zenutils.cotx.EnergyItem") 15 | public class EnergyItemRepresentation extends ExpandItemRepresentation { 16 | 17 | final int capacity; 18 | final int maxReceive; 19 | final int maxExtract; 20 | 21 | public EnergyItemRepresentation(String unlocalizedName, int capacity, int maxReceive, int maxExtract) { 22 | super(unlocalizedName); 23 | this.capacity = capacity; 24 | this.maxReceive = maxReceive; 25 | this.maxExtract = maxExtract; 26 | } 27 | 28 | @Override 29 | @Optional.Method(modid = "redstoneflux") 30 | public void register() { 31 | ContentTweaker.instance.getRegistry(ItemRegistry.class, "ITEM").register(new EnergyItemContent(this)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/tile/ExpandWorldForTile.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.tile; 2 | 3 | import crafttweaker.api.minecraft.CraftTweakerMC; 4 | import crafttweaker.api.world.IBlockPos; 5 | import crafttweaker.api.world.IWorld; 6 | import net.minecraft.tileentity.TileEntity; 7 | import stanhebben.zenscript.annotations.ZenExpansion; 8 | import stanhebben.zenscript.annotations.ZenMethod; 9 | import youyihj.zenutils.Reference; 10 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 11 | 12 | import javax.annotation.Nullable; 13 | 14 | /** 15 | * @author youyihj 16 | */ 17 | @SidedZenRegister(modDeps = Reference.MOD_COT) 18 | @ZenExpansion("crafttweaker.world.IWorld") 19 | public class ExpandWorldForTile { 20 | @ZenMethod 21 | @Nullable 22 | public static TileEntityContent getCustomTileEntity(IWorld world, IBlockPos pos) { 23 | TileEntity tileEntity = CraftTweakerMC.getWorld(world).getTileEntity(CraftTweakerMC.getBlockPos(pos)); 24 | if (tileEntity instanceof TileEntityContent) { 25 | return (TileEntityContent) tileEntity; 26 | } 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/tile/TileData.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.tile; 2 | 3 | import crafttweaker.api.data.IData; 4 | import crafttweaker.mc1120.data.NBTConverter; 5 | import net.minecraft.nbt.NBTTagCompound; 6 | import net.minecraftforge.common.util.INBTSerializable; 7 | import stanhebben.zenscript.annotations.ZenClass; 8 | import stanhebben.zenscript.annotations.ZenGetter; 9 | import stanhebben.zenscript.annotations.ZenSetter; 10 | import youyihj.zenutils.Reference; 11 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 12 | import youyihj.zenutils.impl.util.InternalUtils; 13 | 14 | /** 15 | * @author youyihj 16 | */ 17 | @SidedZenRegister(modDeps = Reference.MOD_COT) 18 | @ZenClass("mods.zenutils.cotx.TileData") 19 | public class TileData implements INBTSerializable { 20 | private final NBTTagCompound nbtTagCompound = new NBTTagCompound(); 21 | 22 | public void readFromNBT(NBTTagCompound nbt) { 23 | this.nbtTagCompound.merge(nbt); 24 | } 25 | 26 | public NBTTagCompound writeToNBT(NBTTagCompound nbt) { 27 | nbt.merge(this.nbtTagCompound); 28 | return nbt; 29 | } 30 | 31 | @ZenGetter("data") 32 | public IData getData() { 33 | return NBTConverter.from(this.writeToNBT(new NBTTagCompound()), true); 34 | } 35 | 36 | @ZenSetter("data") 37 | public void setData(IData data) { 38 | InternalUtils.checkDataMap(data); 39 | this.readFromNBT((NBTTagCompound) NBTConverter.from(data)); 40 | } 41 | 42 | @Override 43 | public NBTTagCompound serializeNBT() { 44 | return nbtTagCompound; 45 | } 46 | 47 | @Override 48 | public void deserializeNBT(NBTTagCompound nbt) { 49 | this.nbtTagCompound.merge(nbt); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/tile/TileEntityManager.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.tile; 2 | 3 | 4 | import com.google.common.base.Preconditions; 5 | import com.google.common.collect.Maps; 6 | import crafttweaker.CraftTweakerAPI; 7 | import youyihj.zenutils.api.cotx.function.ITileEntityTick; 8 | 9 | import java.util.Map; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | public final class TileEntityManager { 15 | private static final Map TICK_FUNCTIONS = Maps.newHashMap(); 16 | 17 | public static void registerTileEntity(TileEntityRepresentation tileEntityRepresentation) { 18 | int id = tileEntityRepresentation.getId(); 19 | if (TICK_FUNCTIONS.containsKey(id)) { 20 | CraftTweakerAPI.logError("Tile Entity ID: " + id + " has been used!"); 21 | return; 22 | } 23 | putTickFunction(id, tileEntityRepresentation.onTick); 24 | } 25 | 26 | public static ITileEntityTick getTickFunction(int id) { 27 | return TICK_FUNCTIONS.getOrDefault(id, ((tileEntity, world, pos) -> {})); 28 | } 29 | 30 | public static void putTickFunction(int id, ITileEntityTick tileEntityTick) { 31 | Preconditions.checkArgument(id != -1, "id -1 is reserved"); 32 | TICK_FUNCTIONS.put(id, tileEntityTick); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/tile/TileEntityRegistryHandler.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.tile; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.util.ResourceLocation; 5 | import net.minecraftforge.event.RegistryEvent; 6 | import net.minecraftforge.fml.common.Mod; 7 | import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 8 | import net.minecraftforge.fml.common.registry.GameRegistry; 9 | import youyihj.zenutils.Reference; 10 | import youyihj.zenutils.api.cotx.block.OmniDirectionalTileEntityContent; 11 | import youyihj.zenutils.impl.util.InternalUtils; 12 | 13 | /** 14 | * @author youyihj 15 | */ 16 | @Mod.EventBusSubscriber 17 | public class TileEntityRegistryHandler { 18 | @SubscribeEvent 19 | public static void handle(RegistryEvent.Register event) { 20 | if (InternalUtils.isContentTweakerInstalled()) { 21 | GameRegistry.registerTileEntity(TileEntityContent.class, new ResourceLocation(Reference.MODID, "tile_entity")); 22 | GameRegistry.registerTileEntity(OmniDirectionalTileEntityContent.class, new ResourceLocation(Reference.MODID, "omni_directional_tile_entity")); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/cotx/tile/TileEntityRepresentation.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.cotx.tile; 2 | 3 | import stanhebben.zenscript.annotations.ZenClass; 4 | import stanhebben.zenscript.annotations.ZenGetter; 5 | import stanhebben.zenscript.annotations.ZenMethod; 6 | import stanhebben.zenscript.annotations.ZenProperty; 7 | import youyihj.zenutils.Reference; 8 | import youyihj.zenutils.api.cotx.function.ITileEntityTick; 9 | import youyihj.zenutils.api.zenscript.SidedZenRegister; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @SidedZenRegister(modDeps = Reference.MOD_COT) 15 | @ZenClass("mods.zenutils.cotx.TileEntity") 16 | public class TileEntityRepresentation { 17 | private final int id; 18 | 19 | public TileEntityRepresentation(int id) { 20 | this.id = id; 21 | } 22 | 23 | @ZenProperty 24 | public ITileEntityTick onTick = ((tileEntity, world, pos) -> {}); 25 | 26 | @ZenGetter("id") 27 | public int getId() { 28 | return id; 29 | } 30 | 31 | @ZenMethod 32 | public void register() { 33 | TileEntityManager.registerTileEntity(this); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/energy/CrTEnergyStorage.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.energy; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import net.minecraftforge.energy.IEnergyStorage; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenGetter; 7 | import stanhebben.zenscript.annotations.ZenMethod; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @ZenClass("mods.zenutils.EnergyStorage") 13 | @ZenRegister 14 | public class CrTEnergyStorage { 15 | private final IEnergyStorage storage; 16 | 17 | private CrTEnergyStorage(IEnergyStorage storage) { 18 | this.storage = storage; 19 | } 20 | 21 | public static CrTEnergyStorage of(IEnergyStorage storage) { 22 | return storage == null ? null : new CrTEnergyStorage(storage); 23 | } 24 | 25 | @ZenMethod 26 | public int receiveEnergy(int maxReceive, boolean simulate) { 27 | return storage.receiveEnergy(maxReceive, simulate); 28 | } 29 | 30 | @ZenGetter("energyStored") 31 | public int getEnergyStored() { 32 | return storage.getEnergyStored(); 33 | } 34 | 35 | @ZenGetter 36 | public boolean canExtract() { 37 | return storage.canExtract(); 38 | } 39 | 40 | @ZenMethod 41 | public int extractEnergy(int maxExtract, boolean simulate) { 42 | return storage.extractEnergy(maxExtract, simulate); 43 | } 44 | 45 | @ZenGetter 46 | public boolean canReceive() { 47 | return storage.canReceive(); 48 | } 49 | 50 | @ZenGetter("maxEnergyStored") 51 | public int getMaxEnergyStored() { 52 | return storage.getMaxEnergyStored(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/entity/IEntityPredicate.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.entity; 2 | 3 | import com.google.common.base.Predicate; 4 | import crafttweaker.annotations.ZenRegister; 5 | import crafttweaker.api.entity.IEntity; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import stanhebben.zenscript.annotations.ZenMethod; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @ZenRegister 13 | @ZenClass("mods.zenutils.IEntityPredicate") 14 | public interface IEntityPredicate extends Predicate { 15 | @ZenMethod 16 | boolean test(IEntity entity); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/entity/IEntityTick.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.entity; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.entity.IEntity; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | @ZenRegister 11 | @FunctionalInterface 12 | @ZenClass("mods.zenutils.IEntityTick") 13 | public interface IEntityTick { 14 | void tick(IEntity entity); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/entity/INearbyEntityList.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.entity; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.entity.IEntity; 5 | import crafttweaker.api.entity.IEntityDefinition; 6 | import crafttweaker.api.entity.IEntityItem; 7 | import crafttweaker.api.entity.IEntityLivingBase; 8 | import crafttweaker.api.player.IPlayer; 9 | import stanhebben.zenscript.annotations.ZenClass; 10 | import stanhebben.zenscript.annotations.ZenGetter; 11 | import stanhebben.zenscript.annotations.ZenMethod; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * @author youyihj 17 | */ 18 | @ZenRegister 19 | @ZenClass("mods.zenutils.INearbyEntityList") 20 | public interface INearbyEntityList { 21 | @ZenMethod 22 | INearbyEntityList filterType(IEntityDefinition definition); 23 | 24 | @ZenMethod 25 | INearbyEntityList filter(IEntityPredicate predicate); 26 | 27 | @ZenMethod 28 | @ZenGetter 29 | List entities(); 30 | 31 | @ZenMethod 32 | @ZenGetter 33 | List livings(); 34 | 35 | @ZenMethod 36 | @ZenGetter 37 | List players(); 38 | 39 | @ZenMethod 40 | @ZenGetter 41 | List items(); 42 | 43 | @ZenMethod 44 | @ZenGetter 45 | IEntity closestEntity(); 46 | 47 | @ZenMethod 48 | @ZenGetter 49 | IEntityLivingBase closestLiving(); 50 | 51 | @ZenMethod 52 | @ZenGetter 53 | IPlayer closestPlayer(); 54 | 55 | @ZenMethod 56 | @ZenGetter 57 | IEntityItem closestItem(); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/entity/ZenUtilsEntityDefinition.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.entity; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.entity.IEntityDefinition; 5 | import net.minecraft.entity.Entity; 6 | import net.minecraftforge.fml.common.registry.EntityEntry; 7 | import stanhebben.zenscript.annotations.Optional; 8 | import stanhebben.zenscript.annotations.ZenExpansion; 9 | import stanhebben.zenscript.annotations.ZenMethod; 10 | import youyihj.zenutils.impl.entity.EntityTickDispatcher; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | @ZenRegister 16 | @ZenExpansion("crafttweaker.entity.IEntityDefinition") 17 | public class ZenUtilsEntityDefinition { 18 | @ZenMethod 19 | public static void onTick(IEntityDefinition definition, IEntityTick operation, @Optional int interval) { 20 | Class entityClass = ((EntityEntry) definition.getInternal()).getEntityClass(); 21 | EntityTickDispatcher.register(entityClass, operation, interval); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/event/CTEventPriority.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.event; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import net.minecraftforge.fml.common.eventhandler.EventPriority; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenClass("mods.zenutils.EventPriority") 12 | @ZenRegister 13 | public enum CTEventPriority { 14 | HIGHEST(EventPriority.HIGHEST), 15 | HIGH(EventPriority.HIGH), 16 | NORMAL(EventPriority.NORMAL), 17 | LOW(EventPriority.LOW), 18 | LOWEST(EventPriority.LOWEST); 19 | private final EventPriority priority; 20 | 21 | CTEventPriority(EventPriority priority) { 22 | this.priority = priority; 23 | } 24 | 25 | @ZenMethod 26 | public static CTEventPriority highest() { 27 | return HIGHEST; 28 | } 29 | 30 | @ZenMethod 31 | public static CTEventPriority high() { 32 | return HIGH; 33 | } 34 | 35 | @ZenMethod 36 | public static CTEventPriority normal() { 37 | return NORMAL; 38 | } 39 | 40 | @ZenMethod 41 | public static CTEventPriority low() { 42 | return LOW; 43 | } 44 | 45 | @ZenMethod 46 | public static CTEventPriority lowest() { 47 | return LOWEST; 48 | } 49 | 50 | public EventPriority getPriority() { 51 | return priority; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/event/CTRandomTickEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.event; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.block.IBlockState; 5 | import crafttweaker.api.event.IBlockEvent; 6 | import crafttweaker.api.event.IEventCancelable; 7 | import crafttweaker.api.minecraft.CraftTweakerMC; 8 | import crafttweaker.api.world.IBlockPos; 9 | import crafttweaker.api.world.IWorld; 10 | import stanhebben.zenscript.annotations.ZenClass; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | @ZenRegister 16 | @ZenClass("mods.zenutils.event.RandomTickEvent") 17 | public class CTRandomTickEvent implements IBlockEvent, IEventCancelable { 18 | private final RandomTickEvent event; 19 | 20 | public CTRandomTickEvent(RandomTickEvent event) { 21 | this.event = event; 22 | } 23 | 24 | @Override 25 | public IWorld getWorld() { 26 | return CraftTweakerMC.getIWorld(event.getWorld()); 27 | } 28 | 29 | @Override 30 | public IBlockState getBlockState() { 31 | return CraftTweakerMC.getBlockState(event.getState()); 32 | } 33 | 34 | @Override 35 | public IBlockPos getPosition() { 36 | return CraftTweakerMC.getIBlockPos(event.getPos()); 37 | } 38 | 39 | @Override 40 | public boolean isCanceled() { 41 | return event.isCanceled(); 42 | } 43 | 44 | @Override 45 | public void setCanceled(boolean canceled) { 46 | event.setCanceled(canceled); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/event/EntityItemDeathEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.event; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.damage.IDamageSource; 5 | import crafttweaker.api.entity.IEntity; 6 | import crafttweaker.api.entity.IEntityItem; 7 | import crafttweaker.api.event.IEntityEvent; 8 | import crafttweaker.api.minecraft.CraftTweakerMC; 9 | import net.minecraft.entity.item.EntityItem; 10 | import net.minecraft.util.DamageSource; 11 | import stanhebben.zenscript.annotations.ZenClass; 12 | import stanhebben.zenscript.annotations.ZenGetter; 13 | 14 | /** 15 | * @author youyihj 16 | */ 17 | @ZenClass("mods.zenutils.event.EntityItemDeathEvent") 18 | @ZenRegister 19 | public class EntityItemDeathEvent implements IEntityEvent { 20 | private final EntityItem entityItem; 21 | private final DamageSource damageSource; 22 | 23 | public EntityItemDeathEvent(EntityItem entityItem, DamageSource damageSource) { 24 | this.entityItem = entityItem; 25 | this.damageSource = damageSource; 26 | } 27 | 28 | @ZenGetter("item") 29 | public IEntityItem getEntityItem() { 30 | return CraftTweakerMC.getIEntityItem(entityItem); 31 | } 32 | 33 | @ZenGetter("damageSource") 34 | public IDamageSource getDamageSource() { 35 | return CraftTweakerMC.getIDamageSource(damageSource); 36 | } 37 | 38 | @Override 39 | public IEntity getEntity() { 40 | return getEntityItem(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/event/EntityRemoveEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.event; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.entity.IEntity; 5 | import crafttweaker.api.event.IEntityEvent; 6 | import crafttweaker.api.event.IWorldEvent; 7 | import crafttweaker.api.world.IWorld; 8 | import stanhebben.zenscript.annotations.ZenClass; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenRegister 14 | @ZenClass("mods.zenutils.event.EntityRemoveEvent") 15 | public class EntityRemoveEvent implements IEntityEvent, IWorldEvent { 16 | private final IEntity entity; 17 | private final IWorld world; 18 | 19 | public EntityRemoveEvent(IEntity entity, IWorld world) { 20 | this.entity = entity; 21 | this.world = world; 22 | } 23 | 24 | @Override 25 | public IEntity getEntity() { 26 | return entity; 27 | } 28 | 29 | @Override 30 | public IWorld getWorld() { 31 | return world; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/event/RandomTickEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.event; 2 | 3 | import net.minecraft.block.state.IBlockState; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.world.World; 6 | import net.minecraftforge.event.world.BlockEvent; 7 | import net.minecraftforge.fml.common.eventhandler.Cancelable; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @Cancelable 13 | public class RandomTickEvent extends BlockEvent { 14 | public RandomTickEvent(World world, BlockPos pos, IBlockState state) { 15 | super(world, pos, state); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/event/WorldLoadEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.event; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.event.IWorldEvent; 5 | import crafttweaker.api.minecraft.CraftTweakerMC; 6 | import crafttweaker.api.world.IWorld; 7 | import net.minecraftforge.event.world.WorldEvent; 8 | import stanhebben.zenscript.annotations.ZenClass; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenClass("mods.zenutils.event.WorldLoadEvent") 14 | @ZenRegister 15 | public class WorldLoadEvent implements IWorldEvent { 16 | private final WorldEvent.Load event; 17 | 18 | public WorldLoadEvent(WorldEvent.Load event) { 19 | this.event = event; 20 | } 21 | 22 | @Override 23 | public IWorld getWorld() { 24 | return CraftTweakerMC.getIWorld(event.getWorld()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/event/WorldSaveEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.event; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.event.IWorldEvent; 5 | import crafttweaker.api.minecraft.CraftTweakerMC; 6 | import crafttweaker.api.world.IWorld; 7 | import net.minecraftforge.event.world.WorldEvent; 8 | import stanhebben.zenscript.annotations.ZenClass; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenClass("mods.zenutils.event.WorldSaveEvent") 14 | @ZenRegister 15 | public class WorldSaveEvent implements IWorldEvent { 16 | private final WorldEvent.Save event; 17 | 18 | 19 | public WorldSaveEvent(WorldEvent.Save event) { 20 | this.event = event; 21 | } 22 | 23 | @Override 24 | public IWorld getWorld() { 25 | return CraftTweakerMC.getIWorld(event.getWorld()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/event/WorldUnloadEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.event; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.event.IWorldEvent; 5 | import crafttweaker.api.minecraft.CraftTweakerMC; 6 | import crafttweaker.api.world.IWorld; 7 | import net.minecraftforge.event.world.WorldEvent; 8 | import stanhebben.zenscript.annotations.ZenClass; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenClass("mods.zenutils.event.WorldUnloadEvent") 14 | @ZenRegister 15 | public class WorldUnloadEvent implements IWorldEvent { 16 | private final WorldEvent.Unload event; 17 | 18 | public WorldUnloadEvent(WorldEvent.Unload event) { 19 | this.event = event; 20 | } 21 | 22 | @Override 23 | public IWorld getWorld() { 24 | return CraftTweakerMC.getIWorld(event.getWorld()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/ftbq/CTChapter.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.ftbq; 2 | 3 | import com.feed_the_beast.ftbquests.quest.Chapter; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import stanhebben.zenscript.annotations.ZenGetter; 8 | 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | @ZenClass("mods.zenutils.ftbq.Chapter") 16 | @ZenRegister 17 | @ModOnly("ftbquests") 18 | public class CTChapter extends CTQuestObjectBase { 19 | private final Chapter chapter; 20 | 21 | public CTChapter(Chapter chapter) { 22 | super(chapter); 23 | this.chapter = chapter; 24 | } 25 | 26 | @ZenGetter("quests") 27 | public List getQuests() { 28 | return chapter.quests.stream().map(CTQuest::new).collect(Collectors.toList()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/ftbq/CTReward.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.ftbq; 2 | 3 | import com.feed_the_beast.ftbquests.quest.reward.Reward; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import stanhebben.zenscript.annotations.ZenGetter; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @ZenRegister 13 | @ZenClass("mods.zenutils.ftbq.Reward") 14 | @ModOnly("ftbquests") 15 | public class CTReward extends CTQuestObjectBase { 16 | private final Reward reward; 17 | 18 | public CTReward(Reward reward) { 19 | super(reward); 20 | this.reward = reward; 21 | } 22 | 23 | @ZenGetter("quest") 24 | public CTQuest getQuest() { 25 | return new CTQuest(reward.quest); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/ftbq/CTTask.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.ftbq; 2 | 3 | import com.feed_the_beast.ftbquests.quest.task.Task; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import stanhebben.zenscript.annotations.ZenGetter; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @ZenClass("mods.zenutils.ftbq.Task") 13 | @ZenRegister 14 | @ModOnly("ftbquests") 15 | public class CTTask extends CTQuestObjectBase { 16 | private final Task task; 17 | 18 | public CTTask(Task task) { 19 | super(task); 20 | this.task = task; 21 | } 22 | 23 | @ZenGetter("quest") 24 | public CTQuest getQuest() { 25 | return new CTQuest(task.quest); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/ftbq/event/CTChapterCompletedEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.ftbq.event; 2 | 3 | import com.feed_the_beast.ftbquests.events.ObjectCompletedEvent; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import stanhebben.zenscript.annotations.ZenGetter; 8 | import youyihj.zenutils.api.ftbq.CTChapter; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenRegister 14 | @ZenClass("mods.zenutils.ftbq.ChapterCompletedEvent") 15 | @ModOnly("ftbquests") 16 | public class CTChapterCompletedEvent extends CTObjectCompletedEvent { 17 | private final ObjectCompletedEvent.ChapterEvent event; 18 | 19 | public CTChapterCompletedEvent(ObjectCompletedEvent.ChapterEvent event) { 20 | super(event); 21 | this.event = event; 22 | } 23 | 24 | @ZenGetter("chapter") 25 | public CTChapter getChapter() { 26 | return new CTChapter(event.getChapter()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/ftbq/event/CTCustomRewardEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.ftbq.event; 2 | 3 | import com.feed_the_beast.ftbquests.events.CustomRewardEvent; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import crafttweaker.api.event.IEventCancelable; 7 | import crafttweaker.api.minecraft.CraftTweakerMC; 8 | import crafttweaker.api.player.IPlayer; 9 | import stanhebben.zenscript.annotations.ZenClass; 10 | import stanhebben.zenscript.annotations.ZenGetter; 11 | import youyihj.zenutils.api.ftbq.CTReward; 12 | 13 | /** 14 | * @author youyihj 15 | */ 16 | @ZenRegister 17 | @ZenClass("mods.zenutils.ftbq.CustomRewardEvent") 18 | @ModOnly("ftbquests") 19 | public class CTCustomRewardEvent implements IEventCancelable { 20 | private final CustomRewardEvent event; 21 | 22 | public CTCustomRewardEvent(CustomRewardEvent event) { 23 | this.event = event; 24 | } 25 | 26 | @ZenGetter("player") 27 | public IPlayer getPlayer() { 28 | return CraftTweakerMC.getIPlayer(event.getPlayer()); 29 | } 30 | 31 | @ZenGetter("notify") 32 | public boolean getNotify() { 33 | return event.getNotify(); 34 | } 35 | 36 | @ZenGetter("reward") 37 | public CTReward getReward() { 38 | return new CTReward(event.getReward()); 39 | } 40 | 41 | @Override 42 | public boolean isCanceled() { 43 | return event.isCanceled(); 44 | } 45 | 46 | @Override 47 | public void setCanceled(boolean canceled) { 48 | event.setCanceled(canceled); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/ftbq/event/CTObjectCompletedEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.ftbq.event; 2 | 3 | import com.feed_the_beast.ftbquests.events.ObjectCompletedEvent; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import crafttweaker.api.minecraft.CraftTweakerMC; 7 | import crafttweaker.api.player.IPlayer; 8 | import stanhebben.zenscript.annotations.ZenClass; 9 | import stanhebben.zenscript.annotations.ZenGetter; 10 | 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | 14 | /** 15 | * @author youyihj 16 | */ 17 | @ZenRegister 18 | @ZenClass("mods.zenutils.ftbq.ObjectCompletedEvent") 19 | @ModOnly("ftbquests") 20 | public class CTObjectCompletedEvent { 21 | public CTObjectCompletedEvent(ObjectCompletedEvent event) { 22 | this.event = event; 23 | } 24 | 25 | private final ObjectCompletedEvent event; 26 | 27 | @ZenGetter("onlineMembers") 28 | public List getOnlineMembers() { 29 | return event.getOnlineMembers().stream().map(CraftTweakerMC::getIPlayer).collect(Collectors.toList()); 30 | } 31 | 32 | @ZenGetter("notifyPlayers") 33 | public List getNotifyPlayers() { 34 | return event.getNotifiedPlayers().stream().map(CraftTweakerMC::getIPlayer).collect(Collectors.toList()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/ftbq/event/CTQuestCompletedEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.ftbq.event; 2 | 3 | import com.feed_the_beast.ftbquests.events.ObjectCompletedEvent; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import stanhebben.zenscript.annotations.ZenGetter; 8 | import youyihj.zenutils.api.ftbq.CTQuest; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenRegister 14 | @ZenClass("mods.zenutils.ftbq.QuestCompletedEvent") 15 | @ModOnly("ftbquests") 16 | public class CTQuestCompletedEvent extends CTObjectCompletedEvent { 17 | private final ObjectCompletedEvent.QuestEvent event; 18 | 19 | public CTQuestCompletedEvent(ObjectCompletedEvent.QuestEvent event) { 20 | super(event); 21 | this.event = event; 22 | } 23 | 24 | @ZenGetter("quest") 25 | public CTQuest getQuest() { 26 | return new CTQuest(event.getQuest()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/ftbq/event/CTTaskCompletedEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.ftbq.event; 2 | 3 | import com.feed_the_beast.ftbquests.events.ObjectCompletedEvent; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import stanhebben.zenscript.annotations.ZenGetter; 8 | import youyihj.zenutils.api.ftbq.CTTask; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenRegister 14 | @ZenClass("mods.zenutils.ftbq.TaskCompletedEvent") 15 | @ModOnly("ftbquests") 16 | public class CTTaskCompletedEvent extends CTObjectCompletedEvent { 17 | public final ObjectCompletedEvent.TaskEvent event; 18 | 19 | public CTTaskCompletedEvent(ObjectCompletedEvent.TaskEvent event) { 20 | super(event); 21 | this.event = event; 22 | } 23 | 24 | @ZenGetter("task") 25 | public CTTask getTask() { 26 | return new CTTask(event.getTask()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/ftbq/event/CTTaskStartedEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.ftbq.event; 2 | 3 | import com.feed_the_beast.ftbquests.events.TaskStartedEvent; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | import stanhebben.zenscript.annotations.ZenGetter; 8 | import youyihj.zenutils.api.ftbq.CTTask; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenRegister 14 | @ZenClass("mods.zenutils.ftbq.TaskStartedEvent") 15 | @ModOnly("ftbquests") 16 | public class CTTaskStartedEvent { 17 | public CTTaskStartedEvent(TaskStartedEvent event) { 18 | this.event = event; 19 | } 20 | 21 | private final TaskStartedEvent event; 22 | 23 | @ZenGetter("task") 24 | public CTTask getTask() { 25 | return new CTTask(event.getTaskData().task); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/item/ITooltipModifier.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.item; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.item.IItemStack; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import youyihj.zenutils.api.util.StringList; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.ITooltipModifier") 13 | @FunctionalInterface 14 | public interface ITooltipModifier { 15 | void apply(IItemStack stack, StringList tooltip, boolean shiftPressed, boolean advanced); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/item/ZenUtilsMutableItemStack.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.item; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.item.IMutableItemStack; 5 | import crafttweaker.api.minecraft.CraftTweakerMC; 6 | import net.minecraft.item.ItemStack; 7 | import net.minecraftforge.energy.CapabilityEnergy; 8 | import net.minecraftforge.fluids.FluidUtil; 9 | import stanhebben.zenscript.annotations.ZenExpansion; 10 | import stanhebben.zenscript.annotations.ZenGetter; 11 | import youyihj.zenutils.api.energy.CrTEnergyStorage; 12 | import youyihj.zenutils.api.liquid.CrTLiquidHandler; 13 | 14 | /** 15 | * @author youyihj 16 | */ 17 | @ZenRegister 18 | @ZenExpansion("crafttweaker.item.IMutableItemStack") 19 | public class ZenUtilsMutableItemStack { 20 | @ZenGetter("fluidHandler") 21 | public static CrTLiquidHandler getFluidHandler(IMutableItemStack item) { 22 | return CrTLiquidHandler.of(FluidUtil.getFluidHandler(CraftTweakerMC.getItemStack(item))); 23 | } 24 | 25 | @ZenGetter("energyStorage") 26 | public static CrTEnergyStorage getEnergyStorage(IMutableItemStack item) { 27 | ItemStack mcItem = CraftTweakerMC.getItemStack(item); 28 | if (mcItem.hasCapability(CapabilityEnergy.ENERGY, null)) { 29 | return CrTEnergyStorage.of(mcItem.getCapability(CapabilityEnergy.ENERGY, null)); 30 | } 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/logger/ICleanableLogger.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.logger; 2 | 3 | import crafttweaker.runtime.ILogger; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public interface ICleanableLogger extends ILogger { 9 | void clean(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/logger/ILogFilter.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.logger; 2 | 3 | import javax.annotation.Nullable; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public interface ILogFilter { 9 | /** 10 | * returns true to block the log message 11 | */ 12 | boolean isBlock(String message, LogLevel logLevel, @Nullable ScriptPosition scriptPosition); 13 | 14 | @Override 15 | int hashCode(); 16 | 17 | @Override 18 | boolean equals(Object obj); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/logger/LogLevel.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.logger; 2 | 3 | import net.minecraft.util.text.TextFormatting; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public enum LogLevel { 9 | TRACE, 10 | INFO, 11 | WARNING(TextFormatting.YELLOW), 12 | ERROR(TextFormatting.RED), 13 | FATAL(TextFormatting.DARK_RED); 14 | 15 | private final TextFormatting textFormatting; 16 | private final boolean logPlayer; 17 | 18 | LogLevel(TextFormatting textFormatting) { 19 | this.textFormatting = textFormatting; 20 | this.logPlayer = true; 21 | } 22 | 23 | LogLevel() { 24 | this.logPlayer = false; 25 | this.textFormatting = TextFormatting.RESET; 26 | } 27 | 28 | public boolean isLogPlayer() { 29 | return logPlayer; 30 | } 31 | 32 | public TextFormatting getTextFormatting() { 33 | return textFormatting; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/logger/LogOption.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.logger; 2 | 3 | import crafttweaker.CraftTweakerAPI; 4 | 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class LogOption { 12 | private LogLevel minLogLevel = LogLevel.TRACE; 13 | private final Set filters = new HashSet<>(); 14 | 15 | public LogLevel getMinLogLevel() { 16 | return minLogLevel; 17 | } 18 | 19 | public void setMinLogLevel(LogLevel minLogLevel) { 20 | this.minLogLevel = minLogLevel; 21 | } 22 | 23 | public void addFilter(ILogFilter filter) { 24 | filters.add(filter); 25 | } 26 | 27 | public boolean isBlock(LogLevel logLevel, String message) { 28 | fromCrTConfig(); 29 | if (logLevel.compareTo(minLogLevel) < 0) { 30 | return true; 31 | } 32 | ScriptPosition scriptPosition = ScriptPosition.current(); 33 | for (ILogFilter filter : filters) { 34 | if (filter.isBlock(message, logLevel, scriptPosition)) { 35 | return true; 36 | } 37 | } 38 | return false; 39 | } 40 | 41 | private void fromCrTConfig() { 42 | if (CraftTweakerAPI.isSuppressingErrors()) { 43 | minLogLevel = LogLevel.ERROR; 44 | } else if (CraftTweakerAPI.isSuppressingWarnings()) { 45 | minLogLevel = LogLevel.WARNING; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/logger/RegexLogFilter.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.logger; 2 | 3 | import javax.annotation.Nullable; 4 | import java.util.Objects; 5 | import java.util.regex.Pattern; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public class RegexLogFilter implements ILogFilter { 11 | private final Pattern regex; 12 | 13 | public RegexLogFilter(Pattern regex) { 14 | this.regex = regex; 15 | } 16 | 17 | @Override 18 | public boolean isBlock(String message, LogLevel logLevel, @Nullable ScriptPosition scriptPosition) { 19 | return regex.matcher(message).matches(); 20 | } 21 | 22 | @Override 23 | public boolean equals(Object o) { 24 | if (this == o) return true; 25 | if (o == null || getClass() != o.getClass()) return false; 26 | RegexLogFilter that = (RegexLogFilter) o; 27 | return Objects.equals(regex.pattern(), that.regex.pattern()); 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | return Objects.hash(regex.pattern()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/logger/ScriptPosition.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.logger; 2 | 3 | import crafttweaker.CraftTweakerAPI; 4 | 5 | import javax.annotation.Nullable; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public class ScriptPosition { 11 | private final String fileName; 12 | private final int line; 13 | 14 | public ScriptPosition(String fileName, int line) { 15 | this.fileName = fileName; 16 | this.line = line; 17 | } 18 | 19 | @Nullable 20 | public static ScriptPosition current() { 21 | String scriptFileAndLine = CraftTweakerAPI.getScriptFileAndLine(); 22 | if ("".equals(scriptFileAndLine)) { 23 | return null; 24 | } else { 25 | String[] split = scriptFileAndLine.split(":"); 26 | return new ScriptPosition(split[0], Integer.parseInt(split[1])); 27 | } 28 | } 29 | 30 | public String getFileName() { 31 | return fileName; 32 | } 33 | 34 | public int getLine() { 35 | return line; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return fileName + ":" + line; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/logger/ScriptSuppressLogFilter.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.logger; 2 | 3 | import javax.annotation.Nullable; 4 | import java.util.Objects; 5 | import java.util.Set; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public class ScriptSuppressLogFilter implements ILogFilter { 11 | private final String scriptName; 12 | private final Set suppressLevels; 13 | 14 | public ScriptSuppressLogFilter(String scriptName, Set suppressLevels) { 15 | this.scriptName = scriptName; 16 | this.suppressLevels = suppressLevels; 17 | } 18 | 19 | @Override 20 | public boolean isBlock(String message, LogLevel logLevel, @Nullable ScriptPosition scriptPosition) { 21 | return scriptPosition != null && scriptName.equals(scriptPosition.getFileName()) && suppressLevels.contains(logLevel); 22 | } 23 | 24 | @Override 25 | public boolean equals(Object o) { 26 | if (this == o) return true; 27 | if (o == null || getClass() != o.getClass()) return false; 28 | ScriptSuppressLogFilter that = (ScriptSuppressLogFilter) o; 29 | return Objects.equals(scriptName, that.scriptName) && Objects.equals(suppressLevels, that.suppressLevels); 30 | } 31 | 32 | @Override 33 | public int hashCode() { 34 | return Objects.hash(scriptName, suppressLevels); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/network/IByteBufWriter.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.network; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | @ZenRegister 10 | @ZenClass("mods.zenutils.IByteBufWriter") 11 | @FunctionalInterface 12 | public interface IByteBufWriter { 13 | 14 | void write(IByteBuf byteBuf); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/network/IClientMessageHandler.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.network; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.player.IPlayer; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | @ZenRegister 11 | @ZenClass("mods.zenutils.IClientMessageHandler") 12 | @FunctionalInterface 13 | public interface IClientMessageHandler { 14 | IClientMessageHandler NONE = ((player, byteBuf) -> {}); 15 | 16 | void handle(IPlayer player, IByteBuf byteBuf); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/network/IServerMessageHandler.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.network; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.player.IPlayer; 5 | import crafttweaker.api.server.IServer; 6 | import stanhebben.zenscript.annotations.ZenClass; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @FunctionalInterface 12 | @ZenRegister 13 | @ZenClass("mods.zenutils.IServerMessageHandler") 14 | public interface IServerMessageHandler { 15 | IServerMessageHandler NONE = (server, byteBuf, player) -> {}; 16 | 17 | void handle(IServer server, IByteBuf byteBuf, IPlayer player); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/player/BaublePlayerPatch.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.player; 2 | 3 | import baubles.api.cap.BaublesCapabilities; 4 | import crafttweaker.annotations.ModOnly; 5 | import crafttweaker.annotations.ZenRegister; 6 | import crafttweaker.api.minecraft.CraftTweakerMC; 7 | import crafttweaker.api.player.IPlayer; 8 | import stanhebben.zenscript.annotations.ZenExpansion; 9 | import stanhebben.zenscript.annotations.ZenMethod; 10 | import youyihj.zenutils.api.item.CrTItemHandler; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | @ZenRegister 16 | @ZenExpansion("crafttweaker.player.IPlayer") 17 | @ModOnly("baubles") 18 | public class BaublePlayerPatch { 19 | @ZenMethod 20 | public static CrTItemHandler getPlayerBaubleItemHandler(IPlayer player) { 21 | return CrTItemHandler.of(CraftTweakerMC.getPlayer(player).getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/player/IActionResult.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.player; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.item.IItemStack; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenGetter; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.IActionResult") 13 | public interface IActionResult { 14 | @ZenGetter("item") 15 | IItemStack getItem(); 16 | 17 | T getResult(); 18 | 19 | @ZenGetter("result") 20 | default String getResultString() { 21 | return String.valueOf(getResult()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/player/IStatFormatter.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.player; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import net.minecraft.stats.IStatType; 5 | import net.minecraftforge.fml.relauncher.Side; 6 | import net.minecraftforge.fml.relauncher.SideOnly; 7 | import stanhebben.zenscript.annotations.ZenClass; 8 | import stanhebben.zenscript.annotations.ZenMethod; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenRegister 14 | @ZenClass("mods.zenutils.IStatFormatter") 15 | public interface IStatFormatter { 16 | @ZenMethod 17 | String format(int number); 18 | 19 | default IStatType toType() { 20 | return new IStatType() { 21 | @SideOnly(Side.CLIENT) 22 | @Override 23 | public String format(int number) { 24 | return IStatFormatter.this.format(number); 25 | } 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/preprocessor/DownloadReobfMappingPreprocessor.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.preprocessor; 2 | 3 | import crafttweaker.preprocessor.PreprocessorActionBase; 4 | import crafttweaker.runtime.ScriptFile; 5 | import youyihj.zenutils.impl.zenscript.nat.MCPReobfuscation; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public class DownloadReobfMappingPreprocessor extends PreprocessorActionBase { 11 | public static final String NAME = "download_reobf_mapping"; 12 | 13 | public DownloadReobfMappingPreprocessor(String fileName, String preprocessorLine, int lineIndex) { 14 | super(fileName, preprocessorLine, lineIndex); 15 | } 16 | 17 | @Override 18 | public void executeActionOnFind(ScriptFile scriptFile) { 19 | MCPReobfuscation.INSTANCE.name(); 20 | } 21 | 22 | @Override 23 | public String getPreprocessorName() { 24 | return NAME; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/preprocessor/HardFailPreprocessor.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.preprocessor; 2 | 3 | import crafttweaker.preprocessor.PreprocessorActionBase; 4 | import crafttweaker.runtime.ScriptFile; 5 | import youyihj.zenutils.ZenUtils; 6 | import youyihj.zenutils.impl.runtime.HardFailLogger; 7 | 8 | public class HardFailPreprocessor extends PreprocessorActionBase { 9 | public static final String NAME = "hardfail"; 10 | private static boolean used; 11 | 12 | public HardFailPreprocessor(String fileName, String preprocessorLine, int lineIndex) { 13 | super(fileName, preprocessorLine, lineIndex); 14 | } 15 | 16 | @Override 17 | public void executeActionOnFind(ScriptFile scriptFile) { 18 | if (!used) { 19 | ZenUtils.crafttweakerLogger.addLogger(new HardFailLogger()); 20 | used = true; 21 | } 22 | } 23 | 24 | @Override 25 | public String getPreprocessorName() { 26 | return NAME; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/preprocessor/NoFixRecipeBookPreprocessor.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.preprocessor; 2 | 3 | import crafttweaker.CraftTweakerAPI; 4 | import crafttweaker.mc1120.CraftTweaker; 5 | import crafttweaker.preprocessor.PreprocessorActionBase; 6 | import crafttweaker.runtime.ScriptFile; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class NoFixRecipeBookPreprocessor extends PreprocessorActionBase { 12 | public static final String NAME = "no_fix_recipe_book"; 13 | 14 | public NoFixRecipeBookPreprocessor(String fileName, String preprocessorLine, int lineIndex) { 15 | super(fileName, preprocessorLine, lineIndex); 16 | } 17 | 18 | @Override 19 | public void executeActionOnFind(ScriptFile scriptFile) { 20 | CraftTweakerAPI.logWarning("no_fix_recipe_book preprocessor is deprecated now!"); 21 | CraftTweakerAPI.logWarning("You should install no recipe book mod instead. (https://www.curseforge.com/minecraft/mc-mods/no-recipe-book)"); 22 | CraftTweakerAPI.logWarning("CraftTweaker detects this mod. If the mod is found, CraftTweaker won't fix the recipe book."); 23 | CraftTweaker.alreadyChangedThePlayer = true; 24 | } 25 | 26 | @Override 27 | public String getPreprocessorName() { 28 | return NAME; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/preprocessor/NotReloadablePreprocessor.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.preprocessor; 2 | 3 | import crafttweaker.preprocessor.PreprocessorActionBase; 4 | import crafttweaker.runtime.ScriptFile; 5 | import youyihj.zenutils.impl.util.InternalUtils; 6 | import youyihj.zenutils.impl.runtime.ScriptStatus; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class NotReloadablePreprocessor extends PreprocessorActionBase { 12 | public static final String NAME = "notreloadable"; 13 | 14 | public NotReloadablePreprocessor(String fileName, String preprocessorLine, int lineIndex) { 15 | super(fileName, preprocessorLine, lineIndex); 16 | } 17 | 18 | @Override 19 | public void executeActionOnFind(ScriptFile scriptFile) { 20 | if (InternalUtils.getScriptStatus() == ScriptStatus.RELOAD) { 21 | scriptFile.setExecutionBlocked(true); 22 | } 23 | } 24 | 25 | @Override 26 | public String getPreprocessorName() { 27 | return NAME; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/preprocessor/ReloadablePreprocessor.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.preprocessor; 2 | 3 | import crafttweaker.preprocessor.PreprocessorActionBase; 4 | import crafttweaker.runtime.ScriptFile; 5 | import org.apache.commons.lang3.ArrayUtils; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public class ReloadablePreprocessor extends PreprocessorActionBase { 11 | public static final String NAME = "reloadable"; 12 | 13 | public ReloadablePreprocessor(String fileName, String preprocessorLine, int lineIndex) { 14 | super(fileName, preprocessorLine, lineIndex); 15 | } 16 | 17 | @Override 18 | public void executeActionOnFind(ScriptFile scriptFile) { 19 | scriptFile.setLoaderNames(ArrayUtils.add(scriptFile.getLoaderNames(), NAME)); 20 | } 21 | 22 | @Override 23 | public String getPreprocessorName() { 24 | return NAME; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/reload/ActionReloadCallback.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.reload; 2 | 3 | import crafttweaker.IAction; 4 | import youyihj.zenutils.impl.util.SimpleCache; 5 | 6 | 7 | /** 8 | * Handles an existed action reload callback behaviors. Each action object has a reload callback object. Extend it to describe 9 | * your reload behavior for an action. 10 | * 11 | * @see IActionReloadCallbackFactory 12 | */ 13 | public abstract class ActionReloadCallback { 14 | private static final SimpleCache, Boolean> HAS_UNDO_METHOD_CACHE = new SimpleCache<>(it -> { 15 | try { 16 | it.getDeclaredMethod("undo"); 17 | return true; 18 | } catch (NoSuchMethodException e) { 19 | return false; 20 | } 21 | }); 22 | 23 | protected final T action; 24 | 25 | public ActionReloadCallback(T action) { 26 | this.action = action; 27 | } 28 | 29 | /** 30 | * Same as {@link IAction#apply()} but will be called on reloading 31 | */ 32 | public void applyReload() { 33 | action.apply(); 34 | } 35 | 36 | /** 37 | * Rolls back changes carried by the action. 38 | */ 39 | public void undo() { 40 | 41 | } 42 | 43 | public void beforeApply(@SuppressWarnings("unused") boolean reload) { 44 | 45 | } 46 | 47 | public void afterApply(@SuppressWarnings("unused") boolean reload) { 48 | 49 | } 50 | 51 | /** 52 | * @return If the action requires some cleanup code 53 | * @implNote default implementation: if the class declares undo method 54 | */ 55 | public boolean hasUndoMethod() { 56 | return HAS_UNDO_METHOD_CACHE.get(this.getClass()); 57 | } 58 | 59 | public String describeAction() { 60 | return action.describe(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/reload/IActionReloadCallbackFactory.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.reload; 2 | 3 | import crafttweaker.IAction; 4 | import crafttweaker.mc1120.events.ScriptRunEvent; 5 | import youyihj.zenutils.ZenUtils; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | @FunctionalInterface 11 | public interface IActionReloadCallbackFactory { 12 | /** 13 | * Marks an action (and actions that extend it) is reloadable. 14 | * It should be used in {@link ScriptRunEvent.Pre} event listener 15 | * @param clazz the type of target action 16 | * @param callbackFactory describe how to create a reload callback object to the given action 17 | */ 18 | static void register(Class clazz, IActionReloadCallbackFactory callbackFactory) { 19 | ZenUtils.tweaker.addReloadCallback(clazz, callbackFactory); 20 | } 21 | 22 | ActionReloadCallback create(T action); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/reload/Reloadable.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.reload; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Marks an action that will not be affected by the action freezing. 7 | * In other words, it will be applied again when script reloading. 8 | *

9 | * If the action requires some cleanup code, please add a public method called undo that rolls back changes carried by the action. 10 | * If the action requires different apply logic when reloading, add a public method called applyReload which is invoked when the action is applied by reload command 11 | * It shouldn't have any arguments and return value. 12 | * It will be called before script reloading. 13 | *

14 | * Example:

{@code
15 |  * @Reloadable
16 |  * public class TestAction implements IAction {
17 |  *     public static final List CONTENTS = new ArrayList<>();
18 |  *
19 |  *     private final String content;
20 |  *
21 |  *     public TestAction(String content) {
22 |  *         this.content = content;
23 |  *     }
24 |  *
25 |  *     @Override
26 |  *     public void apply() {
27 |  *         CONTENTS.add(content);
28 |  *     }
29 |  *
30 |  *     @ReflectionInvoked
31 |  *     public void undo() {
32 |  *         CONTENTS.remove(content);
33 |  *     }
34 |  *
35 |  *     @Override
36 |  *     public String describe() {
37 |  *         return "Adding " + content + " to content list";
38 |  *     }
39 |  * }
40 |  * }
41 | * 42 | * @author youyihj 43 | */ 44 | @Retention(RetentionPolicy.RUNTIME) 45 | @Target(ElementType.TYPE) 46 | public @interface Reloadable { 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/reload/ScriptReloadEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.reload; 2 | 3 | import net.minecraft.command.ICommandSender; 4 | import net.minecraftforge.fml.common.eventhandler.Event; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | public class ScriptReloadEvent extends Event { 10 | private final ICommandSender requester; 11 | 12 | public ScriptReloadEvent(ICommandSender reloadRequester) { 13 | this.requester = reloadRequester; 14 | } 15 | 16 | public ICommandSender getRequester() { 17 | return requester; 18 | } 19 | 20 | public static class Pre extends ScriptReloadEvent { 21 | public Pre(ICommandSender reloadRequester) { 22 | super(reloadRequester); 23 | } 24 | } 25 | 26 | public static class Post extends ScriptReloadEvent { 27 | public Post(ICommandSender reloadRequester) { 28 | super(reloadRequester); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/CrTI18n.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import net.minecraft.util.text.translation.I18n; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.I18n") 13 | @SuppressWarnings({"unused", "deprecation"}) 14 | public class CrTI18n { 15 | 16 | @ZenMethod 17 | public static boolean hasKey(String key) { 18 | return I18n.canTranslate(key); 19 | } 20 | 21 | @ZenMethod 22 | public static String format(String format, Object... args) { 23 | return I18n.translateToLocalFormatted(format, args); 24 | } 25 | 26 | @ZenMethod 27 | public static String format(String format) { 28 | return I18n.translateToLocal(format); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/CrTIntRange.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenCaster; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | import stanhebben.zenscript.value.IntRange; 8 | 9 | @ZenRegister 10 | @ZenClass("mods.zenutils.IntRange") 11 | @SuppressWarnings("unused") 12 | public class CrTIntRange { 13 | private final IntRange intRange; 14 | 15 | private CrTIntRange(IntRange range) { 16 | this.intRange = range; 17 | } 18 | 19 | @ZenMethod 20 | public static CrTIntRange get(int from, int to) { 21 | return new CrTIntRange(new IntRange(from, to)); 22 | } 23 | 24 | @ZenMethod 25 | public static CrTIntRange get(IntRange range) { 26 | return new CrTIntRange(range); 27 | } 28 | 29 | @ZenCaster 30 | @ZenMethod 31 | public IntRange castToIntRange() { 32 | return this.intRange; 33 | } 34 | 35 | @ZenMethod 36 | public int getFrom() { 37 | return this.intRange.getFrom(); 38 | } 39 | 40 | @ZenMethod 41 | public int getTo() { 42 | return this.intRange.getTo(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/ExpandPotion.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.minecraft.CraftTweakerMC; 5 | import crafttweaker.api.potions.IPotion; 6 | import net.minecraft.potion.Potion; 7 | import stanhebben.zenscript.annotations.ZenExpansion; 8 | import stanhebben.zenscript.annotations.ZenGetter; 9 | import stanhebben.zenscript.annotations.ZenMethodStatic; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @ZenRegister 15 | @ZenExpansion("crafttweaker.potions.IPotion") 16 | public class ExpandPotion { 17 | @ZenGetter("numericalId") 18 | public static int getNumericalId(IPotion potion) { 19 | return Potion.getIdFromPotion(CraftTweakerMC.getPotion(potion)); 20 | } 21 | 22 | @ZenMethodStatic 23 | public static IPotion getFromNumericalId(int id) { 24 | return CraftTweakerMC.getIPotion(Potion.getPotionById(id)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/HexHelper.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | import stanhebben.zenscript.annotations.ZenMethod; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | @ZenRegister 11 | @ZenClass("mods.zenutils.HexHelper") 12 | @SuppressWarnings("unused") 13 | public class HexHelper { 14 | @ZenMethod 15 | public static String toHexString(int i) { 16 | return Integer.toHexString(i); 17 | } 18 | 19 | @ZenMethod 20 | public static int toDecInteger(String hex) { 21 | return Integer.parseInt(hex, 16); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/JourneyMap.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util; 2 | 3 | import crafttweaker.annotations.ModOnly; 4 | import crafttweaker.annotations.ZenRegister; 5 | import crafttweaker.api.world.IBlockPos; 6 | import crafttweaker.api.world.IWorld; 7 | import stanhebben.zenscript.annotations.ZenClass; 8 | import stanhebben.zenscript.annotations.ZenMethod; 9 | import youyihj.zenutils.impl.util.JourneyMapPlugin; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @ZenClass("mods.zenutils.JourneyMap") 15 | @ZenRegister 16 | @ModOnly("journeymap") 17 | public class JourneyMap { 18 | @ZenMethod 19 | public static void createWaypoint(String name, IBlockPos pos, IWorld world, int color) { 20 | JourneyMapPlugin.createWaypoint(name, pos, world, color); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/ReflectionInvoked.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PARAMETER}) 12 | @Retention(RetentionPolicy.SOURCE) 13 | public @interface ReflectionInvoked { 14 | boolean asm() default false; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/StringPredicate.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | 6 | import java.util.function.Predicate; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.StringPredicate") 13 | public interface StringPredicate extends Predicate { 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/ZenUtilsClient.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.client.IClient; 5 | import stanhebben.zenscript.annotations.ZenExpansion; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | import youyihj.zenutils.api.util.catenation.ICatenationBuilder; 8 | import youyihj.zenutils.impl.util.catenation.ClientCatenationBuilder; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenRegister 14 | @ZenExpansion("crafttweaker.api.IClient") 15 | public class ZenUtilsClient { 16 | @ZenMethod 17 | public static ICatenationBuilder catenation(IClient client) { 18 | return new ClientCatenationBuilder(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/ICatenationBuilder.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.data.IData; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.ICatenationBuilder") 13 | public interface ICatenationBuilder { 14 | ICatenationBuilder addTask(ICatenationTask task); 15 | 16 | @ZenMethod 17 | ICatenationBuilder run(IWorldFunction function); 18 | 19 | @ZenMethod 20 | ICatenationBuilder sleep(long ticks); 21 | 22 | @ZenMethod 23 | ICatenationBuilder sleepUntil(IWorldCondition condition); 24 | 25 | @ZenMethod 26 | ICatenationBuilder customTimer(long duration, ITimerHandler handler); 27 | 28 | @ZenMethod 29 | ICatenationBuilder repeat(int times, ICatenationTaskQueueBuilderConsumer builderConsumer); 30 | 31 | @ZenMethod 32 | ICatenationBuilder stopWhen(IWorldCondition condition); 33 | 34 | @ZenMethod 35 | ICatenationBuilder onStop(IWorldFunction function); 36 | 37 | @ZenMethod 38 | ICatenationBuilder data(IData data); 39 | 40 | @ZenMethod 41 | default ICatenationBuilder then(IWorldFunction function) { 42 | return run(function); 43 | } 44 | 45 | @ZenMethod 46 | default ICatenationBuilder alwaysUntil(IWorldCondition condition) { 47 | return sleepUntil(condition); 48 | } 49 | 50 | @ZenMethod 51 | Catenation start(); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/ICatenationTask.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation; 2 | 3 | import crafttweaker.api.data.IData; 4 | import crafttweaker.api.world.IWorld; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | public interface ICatenationTask { 10 | void run(IWorld world, CatenationContext context); 11 | 12 | boolean isComplete(); 13 | 14 | IData serializeToData(); 15 | 16 | void deserializeFromData(IData data); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/ICatenationTaskQueueBuilder.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | import stanhebben.zenscript.annotations.ZenMethod; 6 | 7 | import java.util.Queue; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @ZenRegister 13 | @ZenClass("mods.zenutils.ICatenationTaskQueueBuilder") 14 | public interface ICatenationTaskQueueBuilder { 15 | ICatenationTaskQueueBuilder addTask(ICatenationTask task); 16 | 17 | Queue build(); 18 | 19 | @ZenMethod 20 | ICatenationTaskQueueBuilder run(IWorldFunction function); 21 | 22 | @ZenMethod 23 | ICatenationTaskQueueBuilder sleep(long ticks); 24 | 25 | @ZenMethod 26 | ICatenationTaskQueueBuilder sleepUntil(IWorldCondition condition); 27 | 28 | @ZenMethod 29 | ICatenationTaskQueueBuilder customTimer(long duration, ITimerHandler handler); 30 | 31 | @ZenMethod 32 | ICatenationTaskQueueBuilder repeat(int times, ICatenationTaskQueueBuilderConsumer builderConsumer); 33 | 34 | @ZenMethod 35 | default ICatenationTaskQueueBuilder then(IWorldFunction function) { 36 | return run(function); 37 | } 38 | 39 | @ZenMethod 40 | default ICatenationTaskQueueBuilder alwaysUntil(IWorldCondition condition) { 41 | return sleepUntil(condition); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/ICatenationTaskQueueBuilderConsumer.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | import stanhebben.zenscript.annotations.ZenMethod; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | @ZenRegister 11 | @ZenClass("mods.zenutils.ICatenationTaskQueueBuilderConsumer") 12 | public interface ICatenationTaskQueueBuilderConsumer { 13 | @ZenMethod 14 | void apply(ICatenationTaskQueueBuilder builder); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/ITimerHandler.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.world.IWorld; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.ITimerHandler") 13 | public interface ITimerHandler { 14 | @ZenMethod 15 | void apply(Timer timer, IWorld world, CatenationContext context); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/IWorldCondition.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.world.IWorld; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.IWorldCondition") 13 | @FunctionalInterface 14 | public interface IWorldCondition { 15 | @ZenMethod 16 | boolean apply(IWorld world, CatenationContext context); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/IWorldFunction.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.world.IWorld; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.IWorldFunction") 13 | @FunctionalInterface 14 | public interface IWorldFunction { 15 | @ZenMethod 16 | void apply(IWorld world, CatenationContext context); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/Timer.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation; 2 | 3 | import com.google.common.base.Preconditions; 4 | import crafttweaker.annotations.ZenRegister; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenGetter; 7 | import stanhebben.zenscript.annotations.ZenMethod; 8 | import stanhebben.zenscript.annotations.ZenSetter; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ZenRegister 14 | @ZenClass("mods.zenutils.CatenationTimer") 15 | public class Timer { 16 | private final long duration; 17 | private long current; 18 | 19 | public Timer(long duration) { 20 | Preconditions.checkArgument(duration > 0, "duration must be positive."); 21 | this.duration = duration; 22 | } 23 | 24 | @ZenMethod 25 | public void update() { 26 | if (!isFinish()) { 27 | current++; 28 | } 29 | } 30 | 31 | @ZenMethod 32 | public void reset() { 33 | setCurrent(0); 34 | } 35 | 36 | @ZenGetter("current") 37 | public long getCurrent() { 38 | return current; 39 | } 40 | 41 | @ZenSetter("current") 42 | public void setCurrent(long current) { 43 | this.current = Math.min(duration, current); 44 | } 45 | 46 | @ZenGetter("duration") 47 | public long getDuration() { 48 | return duration; 49 | } 50 | 51 | @ZenGetter("finish") 52 | public boolean isFinish() { 53 | return current == duration; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/persistence/BuiltinObjectHolderTypes.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation.persistence; 2 | 3 | import crafttweaker.api.data.IData; 4 | import crafttweaker.api.entity.IEntity; 5 | import crafttweaker.api.player.IPlayer; 6 | import crafttweaker.api.world.IBlockPos; 7 | import youyihj.zenutils.impl.util.catenation.persistence.BlockPosObjectHolder; 8 | import youyihj.zenutils.impl.util.catenation.persistence.DataObjectHolder; 9 | import youyihj.zenutils.impl.util.catenation.persistence.EntityObjectHolder; 10 | import youyihj.zenutils.impl.util.catenation.persistence.PlayerObjectHolder; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | public class BuiltinObjectHolderTypes { 16 | public static final ICatenationObjectHolder.Type PLAYER = ICatenationObjectHolder.Type.of(PlayerObjectHolder::new, IPlayer.class); 17 | public static final ICatenationObjectHolder.Type POSITION = ICatenationObjectHolder.Type.of(BlockPosObjectHolder::new, IBlockPos.class); 18 | public static final ICatenationObjectHolder.Type DATA = ICatenationObjectHolder.Type.of(DataObjectHolder::new, IData.class); 19 | public static final ICatenationObjectHolder.Type ENTITY = ICatenationObjectHolder.Type.of(EntityObjectHolder::new, IEntity.class); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/persistence/CatenationPersistenceAPI.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation.persistence; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.world.IWorld; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import stanhebben.zenscript.annotations.ZenMethod; 7 | import youyihj.zenutils.impl.util.catenation.persistence.CatenationPersistenceImpl; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @ZenRegister 13 | @ZenClass("mods.zenutils.CatenationPersistence") 14 | public class CatenationPersistenceAPI { 15 | @ZenMethod 16 | public static CatenationPersistenceEntryBuilder registerPersistedCatenation(String key) { 17 | return new CatenationPersistenceEntryBuilder(key); 18 | } 19 | 20 | @ZenMethod 21 | public static PersistedCatenationStarter startPersistedCatenation(String key, IWorld world) { 22 | return new PersistedCatenationStarter(world, key); 23 | } 24 | 25 | public static void receiveObject(ICatenationObjectHolder.Type type, T object) { 26 | CatenationPersistenceImpl.receiveObject(type, object); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/persistence/CatenationPersistenceRegisterAction.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation.persistence; 2 | 3 | import crafttweaker.IAction; 4 | import youyihj.zenutils.api.reload.Reloadable; 5 | import youyihj.zenutils.impl.util.catenation.persistence.CatenationPersistenceImpl; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @Reloadable 13 | public class CatenationPersistenceRegisterAction implements IAction { 14 | private final String key; 15 | private final Map> objectHolderTypes; 16 | 17 | private final ICatenationFactory catenationSupplier; 18 | 19 | public CatenationPersistenceRegisterAction(String key, Map> objectHolderTypes, ICatenationFactory catenationSupplier) { 20 | this.key = key; 21 | this.objectHolderTypes = objectHolderTypes; 22 | this.catenationSupplier = catenationSupplier; 23 | } 24 | 25 | @Override 26 | public void apply() { 27 | CatenationPersistenceImpl.registerPersistCatenation(key, catenationSupplier, objectHolderTypes); 28 | } 29 | 30 | @Override 31 | public String describe() { 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/catenation/persistence/ICatenationFactory.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.catenation.persistence; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import crafttweaker.api.world.IWorld; 5 | import stanhebben.zenscript.annotations.ZenClass; 6 | import youyihj.zenutils.api.util.catenation.Catenation; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @ZenRegister 12 | @ZenClass("mods.zenutils.ICatenationFactory") 13 | @FunctionalInterface 14 | public interface ICatenationFactory { 15 | Catenation get(IWorld world); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/delay/CTDelayManager.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.delay; 2 | 3 | import crafttweaker.CraftTweakerAPI; 4 | import crafttweaker.annotations.ZenRegister; 5 | import crafttweaker.api.minecraft.CraftTweakerMC; 6 | import crafttweaker.mc1120.CraftTweaker; 7 | import stanhebben.zenscript.annotations.Optional; 8 | import stanhebben.zenscript.annotations.ZenClass; 9 | import stanhebben.zenscript.annotations.ZenMethod; 10 | import youyihj.zenutils.api.world.ZenUtilsWorld; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | @ZenRegister 16 | @ZenClass("mods.zenutils.DelayManager") 17 | @Deprecated 18 | public class CTDelayManager { 19 | 20 | @ZenMethod 21 | public static void addDelayWork(DelayRunnable runnable, @Optional(valueLong = 1L) long delay) { 22 | addDelayWork(runnable, IsExecute.of(true), delay); 23 | } 24 | 25 | @ZenMethod 26 | public static void addDelayWork(DelayRunnable runnable, IsExecute isExecute, @Optional(valueLong = 1L) long delay) { 27 | CraftTweakerAPI.logWarning("DelayManager is deprecated, use Catenation instead."); 28 | ZenUtilsWorld.catenation(CraftTweakerMC.getIWorld(CraftTweaker.server.getEntityWorld())) 29 | .sleep(delay) 30 | .then((world, context) -> runnable.run()) 31 | .stopWhen((world, context) -> !isExecute.isExec()) 32 | .start(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/delay/DelayRunnable.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.delay; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | import stanhebben.zenscript.annotations.ZenMethod; 6 | 7 | @FunctionalInterface 8 | @ZenRegister 9 | @ZenClass("mods.zenutils.DelayRunnable") 10 | @Deprecated 11 | public interface DelayRunnable extends Runnable { 12 | 13 | @Override 14 | @ZenMethod 15 | void run(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/util/delay/IsExecute.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.util.delay; 2 | 3 | import crafttweaker.annotations.ZenRegister; 4 | import stanhebben.zenscript.annotations.ZenClass; 5 | import stanhebben.zenscript.annotations.ZenMethod; 6 | import stanhebben.zenscript.annotations.ZenProperty; 7 | 8 | @ZenRegister 9 | @ZenClass("mods.zenutils.IsExecute") 10 | @Deprecated 11 | public class IsExecute { 12 | 13 | @ZenProperty 14 | private boolean exec; 15 | 16 | private IsExecute(boolean exec) { 17 | this.exec = exec; 18 | } 19 | 20 | @ZenMethod 21 | public boolean isExec() { 22 | return exec; 23 | } 24 | 25 | @ZenMethod 26 | public void setExec(boolean exec) { 27 | this.exec = exec; 28 | } 29 | 30 | @ZenMethod 31 | public static IsExecute of(boolean exec) { 32 | return new IsExecute(exec); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/zenscript/IMultilinePreprocessor.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.zenscript; 2 | 3 | import crafttweaker.preprocessor.IPreprocessor; 4 | import stanhebben.zenscript.value.IntRange; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public interface IMultilinePreprocessor extends IPreprocessor { 12 | IntRange getLineRange(); 13 | 14 | List getPreprocessorLines(); 15 | 16 | @Override 17 | default int getLineIndex() { 18 | return getLineRange().getFrom(); 19 | } 20 | 21 | @Override 22 | default String getPreprocessorLine() { 23 | return getPreprocessorLines().get(0); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/zenscript/IMultilinePreprocessorFactory.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.zenscript; 2 | 3 | import crafttweaker.preprocessor.PreprocessorFactory; 4 | import stanhebben.zenscript.value.IntRange; 5 | 6 | import java.util.Collections; 7 | import java.util.List; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public interface IMultilinePreprocessorFactory extends PreprocessorFactory { 13 | R createPreprocessor(String fileName, List preprocessorLines, IntRange lineRange); 14 | 15 | @Override 16 | default R createPreprocessor(String fileName, String preprocessorLine, int lineIndex) { 17 | return createPreprocessor(fileName, Collections.singletonList(preprocessorLine), new IntRange(lineIndex, lineIndex)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/zenscript/INativeClassExclude.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.zenscript; 2 | 3 | import youyihj.zenutils.impl.member.ClassData; 4 | import youyihj.zenutils.impl.zenscript.nat.NativeClassValidate; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | public interface INativeClassExclude { 10 | boolean shouldExclude(ClassData clazz); 11 | 12 | static void register(INativeClassExclude exclude) { 13 | NativeClassValidate.EXCLUDES.add(exclude); 14 | } 15 | 16 | static void filterPrefix(String prefix) { 17 | register(clazz -> clazz.name().startsWith(prefix)); 18 | } 19 | 20 | static void filterClass(Class clazz) { 21 | register(it -> it.name().equals(clazz.getCanonicalName())); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/api/zenscript/SidedZenRegister.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.api.zenscript; 2 | 3 | import net.minecraftforge.fml.relauncher.Side; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * Automatically register a class to zenscript on specific sides with specific mod dependencies. 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.TYPE) 15 | public @interface SidedZenRegister { 16 | Side[] value() default {Side.CLIENT, Side.SERVER}; 17 | 18 | /** 19 | * Only registers the class when all mod dependencies are installed 20 | * The difference of {@link crafttweaker.annotations.ModOnly} is it can define multiple dependencies 21 | * and doesn't try to load the class when dependencies are not satisfied 22 | */ 23 | String[] modDeps() default {}; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/capability/IZenWorldCapability.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.capability; 2 | 3 | import crafttweaker.api.data.IData; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | import net.minecraftforge.common.util.INBTSerializable; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public interface IZenWorldCapability extends INBTSerializable { 11 | 12 | IData getData(); 13 | 14 | void setData(IData data); 15 | 16 | void updateData(IData data); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/capability/ZenWorldCapability.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.capability; 2 | 3 | import com.google.common.collect.Maps; 4 | import crafttweaker.api.data.DataMap; 5 | import crafttweaker.api.data.IData; 6 | import crafttweaker.mc1120.data.NBTConverter; 7 | import net.minecraft.nbt.NBTTagCompound; 8 | import youyihj.zenutils.impl.util.InternalUtils; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | public class ZenWorldCapability implements IZenWorldCapability { 14 | private IData data = new DataMap(Maps.newHashMap(), false); 15 | 16 | @Override 17 | public IData getData() { 18 | return this.data; 19 | } 20 | 21 | @Override 22 | public void setData(IData data) { 23 | InternalUtils.checkDataMap(data); 24 | this.data = data; 25 | } 26 | 27 | @Override 28 | public void updateData(IData data) { 29 | this.data = this.data.update(data); 30 | } 31 | 32 | @Override 33 | public NBTTagCompound serializeNBT() { 34 | return ((NBTTagCompound) NBTConverter.from(data)); 35 | } 36 | 37 | @Override 38 | public void deserializeNBT(NBTTagCompound nbt) { 39 | this.data = NBTConverter.from(nbt, false); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/capability/ZenWorldCapabilityProvider.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.capability; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.util.EnumFacing; 5 | import net.minecraftforge.common.capabilities.Capability; 6 | import net.minecraftforge.common.capabilities.ICapabilityProvider; 7 | import net.minecraftforge.common.util.INBTSerializable; 8 | 9 | import javax.annotation.Nonnull; 10 | import javax.annotation.Nullable; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | public class ZenWorldCapabilityProvider implements ICapabilityProvider, INBTSerializable { 16 | private final IZenWorldCapability zenWorldCapability; 17 | 18 | public ZenWorldCapabilityProvider(IZenWorldCapability capability) { 19 | this.zenWorldCapability = capability; 20 | } 21 | 22 | @Override 23 | public boolean hasCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { 24 | return capability == ZenWorldCapabilityHandler.ZEN_WORLD_CAPABILITY; 25 | } 26 | 27 | @Nullable 28 | @Override 29 | public T getCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { 30 | if (capability == ZenWorldCapabilityHandler.ZEN_WORLD_CAPABILITY) { 31 | return ZenWorldCapabilityHandler.ZEN_WORLD_CAPABILITY.cast(this.zenWorldCapability); 32 | } 33 | return null; 34 | } 35 | 36 | @Override 37 | public NBTTagCompound serializeNBT() { 38 | return this.zenWorldCapability.serializeNBT(); 39 | } 40 | 41 | @Override 42 | public void deserializeNBT(NBTTagCompound nbt) { 43 | this.zenWorldCapability.deserializeNBT(nbt); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/command/CleanLogCommand.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.command; 2 | 3 | import crafttweaker.mc1120.commands.CraftTweakerCommand; 4 | import net.minecraft.command.ICommandSender; 5 | import net.minecraft.server.MinecraftServer; 6 | import net.minecraft.util.text.TextComponentString; 7 | import net.minecraft.util.text.TextFormatting; 8 | import youyihj.zenutils.ZenUtils; 9 | 10 | import static crafttweaker.mc1120.commands.SpecialMessagesChat.getClickableCommandText; 11 | import static crafttweaker.mc1120.commands.SpecialMessagesChat.getNormalMessage; 12 | 13 | /** 14 | * @author youyihj 15 | */ 16 | public class CleanLogCommand extends CraftTweakerCommand { 17 | public CleanLogCommand() { 18 | super("clean"); 19 | } 20 | 21 | @Override 22 | protected void init() { 23 | setDescription( 24 | getClickableCommandText(TextFormatting.DARK_GREEN + "/ct clean", "/ct clean", true), 25 | getNormalMessage(TextFormatting.DARK_AQUA + "Cleans crafttweaker log.") 26 | ); 27 | } 28 | 29 | @Override 30 | public void executeCommand(MinecraftServer server, ICommandSender sender, String[] args) { 31 | ZenUtils.crafttweakerLogger.clean(); 32 | sender.sendMessage(new TextComponentString("cleaned the log.")); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/command/StatCommand.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.command; 2 | 3 | import crafttweaker.CraftTweakerAPI; 4 | import crafttweaker.mc1120.commands.CraftTweakerCommand; 5 | import net.minecraft.command.ICommandSender; 6 | import net.minecraft.server.MinecraftServer; 7 | import net.minecraft.stats.StatBase; 8 | import net.minecraft.stats.StatList; 9 | import net.minecraft.util.text.TextFormatting; 10 | 11 | import static crafttweaker.mc1120.commands.SpecialMessagesChat.*; 12 | 13 | /** 14 | * @author youyihj 15 | */ 16 | public class StatCommand extends CraftTweakerCommand { 17 | public StatCommand() { 18 | super("stats"); 19 | } 20 | 21 | @Override 22 | protected void init() { 23 | setDescription( 24 | getClickableCommandText(TextFormatting.DARK_GREEN + "/ct stats", "/ct stats", true), 25 | getNormalMessage(TextFormatting.DARK_AQUA + "Outputs a list of all basic stats.") 26 | ); 27 | } 28 | 29 | @Override 30 | public void executeCommand(MinecraftServer server, ICommandSender sender, String[] args) { 31 | CraftTweakerAPI.logCommand("Basic Stats:"); 32 | for (StatBase stat : StatList.BASIC_STATS) { 33 | CraftTweakerAPI.logCommand(stat.statId); 34 | } 35 | sender.sendMessage(getLinkToCraftTweakerLog("Basic stat list generated", sender)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/core/MixinInit.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.core; 2 | 3 | import com.google.common.collect.Lists; 4 | import net.minecraftforge.fml.common.Loader; 5 | import youyihj.zenutils.api.util.ReflectionInvoked; 6 | import zone.rong.mixinbooter.ILateMixinLoader; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @ReflectionInvoked 14 | public class MixinInit implements ILateMixinLoader { 15 | @Override 16 | public List getMixinConfigs() { 17 | List config = Lists.newArrayList("mixins.zenutils.json"); 18 | if (Loader.isModLoaded("simpledimensions")) { 19 | config.add("mixins.zenutils.simpledimensions.json"); 20 | } 21 | return config; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/core/ZenUtilsPlugin.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.core; 2 | 3 | import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; 4 | import youyihj.zenutils.api.util.ReflectionInvoked; 5 | import zone.rong.mixinbooter.IEarlyMixinLoader; 6 | 7 | import javax.annotation.Nullable; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | @ReflectionInvoked 16 | @IFMLLoadingPlugin.MCVersion("1.12.2") 17 | public class ZenUtilsPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader { 18 | @Override 19 | public String[] getASMTransformerClass() { 20 | return new String[0]; 21 | } 22 | 23 | @Override 24 | public String getModContainerClass() { 25 | return null; 26 | } 27 | 28 | @Nullable 29 | @Override 30 | public String getSetupClass() { 31 | return null; 32 | } 33 | 34 | @Override 35 | public void injectData(Map data) { 36 | 37 | } 38 | 39 | @Override 40 | public String getAccessTransformerClass() { 41 | return null; 42 | } 43 | 44 | @Override 45 | public List getMixinConfigs() { 46 | List configs = new ArrayList<>(); 47 | configs.add("mixins.zenutils.vanilla.json"); 48 | if (Configuration.enableMixin) { 49 | configs.add("mixins.zenutils.zenbootstrap.json"); 50 | } 51 | if (Configuration.enableRandomTickEvent) { 52 | configs.add("mixins.zenutils.randomtickevent.json"); 53 | } 54 | if (Configuration.customScriptEntrypoint.length != 0) { 55 | configs.add("mixins.zenutils.customscriptentrypoint.json"); 56 | } 57 | return configs; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/event/EventHandlerRegisterAction.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.event; 2 | 3 | import crafttweaker.IAction; 4 | import net.minecraftforge.fml.common.eventhandler.EventPriority; 5 | import net.minecraftforge.fml.common.eventhandler.IEventListener; 6 | import net.minecraftforge.fml.common.eventhandler.ListenerList; 7 | import youyihj.zenutils.api.reload.Reloadable; 8 | import youyihj.zenutils.api.util.ReflectionInvoked; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @Reloadable 14 | public class EventHandlerRegisterAction implements IAction { 15 | private final IEventListener listener; 16 | private final ListenerList listenerList; 17 | private final EventPriority priority; 18 | private final int busID; 19 | private final String eventName; 20 | 21 | public EventHandlerRegisterAction(IEventListener listener, ListenerList listenerList, EventPriority priority, int busID, String eventName) { 22 | this.listener = listener; 23 | this.listenerList = listenerList; 24 | this.priority = priority; 25 | this.busID = busID; 26 | this.eventName = eventName; 27 | } 28 | 29 | @Override 30 | public void apply() { 31 | listenerList.register(busID, priority, listener); 32 | } 33 | 34 | @ReflectionInvoked 35 | public void undo() { 36 | listenerList.unregister(busID, listener); 37 | } 38 | 39 | @Override 40 | public String describe() { 41 | return "Registering an event listener for " + eventName; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/event/EventHandlerRegisterException.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.event; 2 | 3 | /** 4 | * @author youyihj 5 | */ 6 | public class EventHandlerRegisterException extends Exception { 7 | public EventHandlerRegisterException(String message) { 8 | super(message); 9 | } 10 | 11 | public EventHandlerRegisterException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/fluid/MCLiquidTankProperties.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.fluid; 2 | 3 | import crafttweaker.api.liquid.ILiquidStack; 4 | import crafttweaker.api.minecraft.CraftTweakerMC; 5 | import net.minecraftforge.fluids.capability.IFluidTankProperties; 6 | import youyihj.zenutils.api.liquid.ILiquidTankProperties; 7 | 8 | /** 9 | * @author various.authors 10 | */ 11 | public class MCLiquidTankProperties implements ILiquidTankProperties { 12 | private final IFluidTankProperties properties; 13 | 14 | public MCLiquidTankProperties(IFluidTankProperties properties) { 15 | this.properties = properties; 16 | } 17 | 18 | public ILiquidStack getContents() { 19 | return CraftTweakerMC.getILiquidStack(properties.getContents()); 20 | } 21 | 22 | public int getCapacity() { 23 | return properties.getCapacity(); 24 | } 25 | 26 | public boolean canFill() { 27 | return properties.canFill(); 28 | } 29 | 30 | public boolean canDrain() { 31 | return properties.canDrain(); 32 | } 33 | 34 | public boolean canFillFluidType(ILiquidStack liquidStack) { 35 | return properties.canFillFluidType(CraftTweakerMC.getLiquidStack(liquidStack)); 36 | } 37 | 38 | public boolean canDrainFluidType(ILiquidStack liquidStack) { 39 | return properties.canDrainFluidType(CraftTweakerMC.getLiquidStack(liquidStack)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/AnnotatedMember.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member; 2 | 3 | import java.lang.annotation.Annotation; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public interface AnnotatedMember { 9 | boolean isAnnotationPresent(Class annotationClass); 10 | 11 | A getAnnotation(Class annotationClass); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/ClassData.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member; 2 | 3 | import javax.annotation.Nullable; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public interface ClassData extends TypeData, AnnotatedMember { 11 | String name(); 12 | 13 | String internalName(); 14 | 15 | List fields(LookupRequester requester); 16 | 17 | List methods(LookupRequester requester); 18 | 19 | List constructors(LookupRequester requester); 20 | 21 | default List methods(String name, LookupRequester requester) { 22 | return methods(requester).stream().filter(it -> name.equals(it.name())).collect(Collectors.toList()); 23 | } 24 | 25 | boolean isInterface(); 26 | 27 | boolean isAssignableFrom(ClassData classData); 28 | 29 | @Nullable 30 | ClassData superClass(); 31 | 32 | List interfaces(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/ClassDataFetcher.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member; 2 | 3 | /** 4 | * @author youyihj 5 | */ 6 | public interface ClassDataFetcher { 7 | ClassData forName(String className) throws ClassNotFoundException; 8 | 9 | ClassData forClass(Class clazz); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/ExecutableData.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public interface ExecutableData extends AnnotatedMember { 9 | String name(); 10 | 11 | ClassData declaringClass(); 12 | 13 | int parameterCount(); 14 | 15 | int modifiers(); 16 | 17 | TypeData returnType(); 18 | 19 | List parameters(); 20 | 21 | boolean isVarArgs(); 22 | 23 | default String descriptor() { 24 | StringBuilder buf = new StringBuilder(); 25 | buf.append('('); 26 | for (TypeData parameter : parameters()) { 27 | buf.append(parameter.descriptor()); 28 | } 29 | buf.append(')'); 30 | buf.append(returnType().descriptor()); 31 | return buf.toString(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/FieldData.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member; 2 | 3 | /** 4 | * @author youyihj 5 | */ 6 | public interface FieldData extends AnnotatedMember { 7 | ClassData declaringClass(); 8 | 9 | String name(); 10 | 11 | int modifiers(); 12 | 13 | TypeData type(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/LiteralType.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public class LiteralType implements Type { 9 | private final String name; 10 | 11 | public LiteralType(TypeData typeData) { 12 | this.name = typeData.toString(); 13 | } 14 | 15 | public LiteralType(String name) { 16 | this.name = name; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return name; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/LookupRequester.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member; 2 | 3 | import java.lang.reflect.Modifier; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public enum LookupRequester { 9 | PUBLIC(Modifier.PUBLIC), 10 | SUBCLASS(Modifier.PUBLIC | Modifier.PROTECTED), 11 | SELF(0) { 12 | @Override 13 | public boolean allows(int modifier) { 14 | return true; 15 | } 16 | }; 17 | 18 | private final int modifierMask; 19 | 20 | LookupRequester(int modifierMask) { 21 | this.modifierMask = modifierMask; 22 | } 23 | 24 | public boolean allows(int modifier) { 25 | return (modifierMask & modifier) != 0; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/TypeData.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public interface TypeData { 9 | Type javaType(); 10 | 11 | String descriptor(); 12 | 13 | ClassData asClassData(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/bytecode/BytecodeFieldData.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member.bytecode; 2 | 3 | import org.objectweb.asm.tree.FieldNode; 4 | import youyihj.zenutils.impl.member.ClassData; 5 | import youyihj.zenutils.impl.member.FieldData; 6 | import youyihj.zenutils.impl.member.TypeData; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class BytecodeFieldData extends BytecodeAnnotatedMember implements FieldData { 12 | private final FieldNode fieldNode; 13 | private final BytecodeClassData declaringClass; 14 | 15 | public BytecodeFieldData(FieldNode fieldNode, BytecodeClassData declaringClass) { 16 | this.fieldNode = fieldNode; 17 | this.declaringClass = declaringClass; 18 | setAnnotationNodes(fieldNode.visibleAnnotations); 19 | setAnnotationNodes(fieldNode.invisibleAnnotations); 20 | } 21 | 22 | @Override 23 | public ClassData declaringClass() { 24 | return declaringClass; 25 | } 26 | 27 | @Override 28 | public String name() { 29 | return fieldNode.name; 30 | } 31 | 32 | @Override 33 | public int modifiers() { 34 | return fieldNode.access; 35 | } 36 | 37 | @Override 38 | public TypeData type() { 39 | return declaringClass.getClassDataFetcher().type(fieldNode.desc, fieldNode.signature); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/reflect/ReflectionAnnotatedMember.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member.reflect; 2 | 3 | import youyihj.zenutils.impl.member.AnnotatedMember; 4 | 5 | import java.lang.annotation.Annotation; 6 | import java.lang.reflect.AnnotatedElement; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class ReflectionAnnotatedMember implements AnnotatedMember { 12 | private final AnnotatedElement element; 13 | 14 | public ReflectionAnnotatedMember(AnnotatedElement element) { 15 | this.element = element; 16 | } 17 | 18 | @Override 19 | public A getAnnotation(Class annotationClass) { 20 | return element.getAnnotation(annotationClass); 21 | } 22 | 23 | @Override 24 | public boolean isAnnotationPresent(Class annotationClass) { 25 | return element.isAnnotationPresent(annotationClass); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/reflect/ReflectionClassDataFetcher.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member.reflect; 2 | 3 | import youyihj.zenutils.impl.member.ClassData; 4 | import youyihj.zenutils.impl.member.ClassDataFetcher; 5 | import youyihj.zenutils.impl.member.TypeData; 6 | 7 | import java.lang.reflect.Type; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public class ReflectionClassDataFetcher implements ClassDataFetcher { 13 | private final ClassLoader classLoader; 14 | 15 | public ReflectionClassDataFetcher(ClassLoader classLoader) { 16 | this.classLoader = classLoader; 17 | } 18 | 19 | public static TypeData type(Type type, Class clazz) { 20 | if (type instanceof Class) { 21 | return ReflectionClassData.of(clazz); 22 | } else { 23 | return new ReflectionTypeData(type, clazz); 24 | } 25 | } 26 | 27 | @Override 28 | public ClassData forName(String className) throws ClassNotFoundException { 29 | return ReflectionClassData.of(Class.forName(className, false, classLoader)); 30 | } 31 | 32 | @Override 33 | public ClassData forClass(Class clazz) { 34 | return ReflectionClassData.of(clazz); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/reflect/ReflectionFieldData.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member.reflect; 2 | 3 | import youyihj.zenutils.impl.member.ClassData; 4 | import youyihj.zenutils.impl.member.FieldData; 5 | import youyihj.zenutils.impl.member.TypeData; 6 | 7 | import java.lang.reflect.Field; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public class ReflectionFieldData extends ReflectionAnnotatedMember implements FieldData { 13 | private final Field field; 14 | 15 | public ReflectionFieldData(Field field) { 16 | super(field); 17 | this.field = field; 18 | } 19 | 20 | @Override 21 | public ClassData declaringClass() { 22 | return ReflectionClassData.of(field.getDeclaringClass()); 23 | } 24 | 25 | @Override 26 | public String name() { 27 | return field.getName(); 28 | } 29 | 30 | @Override 31 | public int modifiers() { 32 | return field.getModifiers(); 33 | } 34 | 35 | @Override 36 | public TypeData type() { 37 | return ReflectionClassDataFetcher.type(field.getGenericType(), field.getType()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/member/reflect/ReflectionTypeData.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.member.reflect; 2 | 3 | import youyihj.zenutils.impl.member.ClassData; 4 | import youyihj.zenutils.impl.member.TypeData; 5 | 6 | import java.lang.reflect.*; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class ReflectionTypeData implements TypeData { 12 | private final Type type; 13 | private final Class clazz; 14 | 15 | /* package-private */ ReflectionTypeData(Type type, Class clazz) { 16 | this.type = type; 17 | this.clazz = clazz; 18 | } 19 | 20 | @Override 21 | public Type javaType() { 22 | return type; 23 | } 24 | 25 | @Override 26 | public String descriptor() { 27 | return org.objectweb.asm.Type.getDescriptor(clazz); 28 | } 29 | 30 | @Override 31 | public ClassData asClassData() { 32 | return ReflectionClassData.of(clazz); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinBlockContent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import net.minecraft.block.material.Material; 4 | 5 | import com.teamacronymcoders.base.blocks.BlockBase; 6 | import com.teamacronymcoders.contenttweaker.modules.vanilla.blocks.BlockContent; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.ModifyArg; 10 | 11 | @Mixin(value = BlockContent.class, remap = false) 12 | public abstract class MixinBlockContent extends BlockBase { 13 | public MixinBlockContent(Material mat) { 14 | super(mat); 15 | } 16 | 17 | @ModifyArg(method = "setFields", at = @At(value = "INVOKE", target = "Lcom/teamacronymcoders/contenttweaker/modules/vanilla/blocks/BlockContent;setTranslationKey(Ljava/lang/String;)Lnet/minecraft/block/Block;", remap = true), index = 0) 18 | private String fixTranslationKey(String original) { 19 | if (this.getMod() == null || original.contains(this.getMod().getID())) return original; 20 | return this.getMod().getID() + "." + original; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinCoTItemBracketHandler.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import com.teamacronymcoders.contenttweaker.modules.vanilla.resources.ItemBracketHandler; 4 | import net.minecraftforge.oredict.OreDictionary; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Pseudo; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Redirect; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @Pseudo 14 | @Mixin(value = ItemBracketHandler.class, remap = false) 15 | public abstract class MixinCoTItemBracketHandler { 16 | @Redirect(method = "resolve", at = @At(value = "INVOKE", target = "Ljava/lang/Integer;parseInt(Ljava/lang/String;)I")) 17 | private int readMeta(String s) { 18 | return "*".equals(s) ? OreDictionary.WILDCARD_VALUE : Integer.parseInt(s); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinCraftTweaker.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import crafttweaker.mc1120.CraftTweaker; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | @Mixin(value = CraftTweaker.class, remap = false) 10 | public abstract class MixinCraftTweaker { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinCraftTweakerImplementationAPI.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import crafttweaker.CrafttweakerImplementationAPI; 4 | import crafttweaker.api.logger.MTLogger; 5 | import org.spongepowered.asm.mixin.Final; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.Mutable; 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 | import youyihj.zenutils.impl.runtime.ZenUtilsFileLogger; 13 | import youyihj.zenutils.impl.runtime.ZenUtilsLogger; 14 | 15 | import java.nio.file.FileSystems; 16 | 17 | /** 18 | * @author youyihj 19 | */ 20 | @Mixin(value = CrafttweakerImplementationAPI.class, remap = false) 21 | public abstract class MixinCraftTweakerImplementationAPI { 22 | @Mutable 23 | @Shadow @Final public static MTLogger logger; 24 | 25 | @Inject(method = "", at = @At("TAIL")) 26 | private static void redirectLogger(CallbackInfo ci) { 27 | logger = new ZenUtilsLogger(); 28 | logger.addLogger(new ZenUtilsFileLogger(FileSystems.getDefault().getPath("crafttweaker.log"))); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinEnvironmentClass.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import stanhebben.zenscript.compiler.EnvironmentClass; 5 | import youyihj.zenutils.impl.mixin.itf.IEnvironmentClassExtension; 6 | import youyihj.zenutils.impl.zenscript.nat.ZenTypeJavaNative; 7 | 8 | import java.util.Collections; 9 | import java.util.List; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @Mixin(EnvironmentClass.class) 15 | public abstract class MixinEnvironmentClass implements IEnvironmentClassExtension { 16 | private List targets; 17 | private List subClasses; 18 | 19 | @Override 20 | public List getMixinTargets() { 21 | return targets == null ? Collections.emptyList() : targets; 22 | } 23 | 24 | @Override 25 | public void setMixinTargets(List targets) { 26 | this.targets = targets; 27 | } 28 | 29 | @Override 30 | public List getSuperClasses() { 31 | return subClasses; 32 | } 33 | 34 | @Override 35 | public void setSubClasses(List superClasses) { 36 | this.subClasses = superClasses; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinExpressionMap.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.spongepowered.asm.mixin.Final; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.Shadow; 6 | import org.spongepowered.asm.mixin.injection.Constant; 7 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 8 | import stanhebben.zenscript.expression.ExpressionMap; 9 | import stanhebben.zenscript.type.ZenTypeAssociative; 10 | import youyihj.zenutils.impl.zenscript.IOrderlyType; 11 | 12 | import java.util.HashMap; 13 | import java.util.LinkedHashMap; 14 | 15 | /** 16 | * @author youyihj 17 | */ 18 | @Mixin(value = ExpressionMap.class, remap = false) 19 | public abstract class MixinExpressionMap { 20 | @Shadow 21 | @Final 22 | private ZenTypeAssociative type; 23 | 24 | @ModifyConstant( 25 | method = "compile", 26 | constant = @Constant(classValue = HashMap.class) 27 | ) 28 | private Class modifyCreateMapType(Class clazz) { 29 | return ((IOrderlyType) type).isOrderly() ? LinkedHashMap.class : HashMap.class; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinItemContent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import com.teamacronymcoders.base.items.ItemBase; 4 | import com.teamacronymcoders.contenttweaker.modules.vanilla.items.ItemContent; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.ModifyArg; 8 | 9 | @Mixin(value = ItemContent.class, remap = false) 10 | public abstract class MixinItemContent extends ItemBase { 11 | public MixinItemContent(String name) { 12 | super(name); 13 | } 14 | 15 | @ModifyArg(method = "setFields", at = @At(value = "INVOKE", target = "Lcom/teamacronymcoders/contenttweaker/modules/vanilla/items/ItemContent;setTranslationKey(Ljava/lang/String;)Lnet/minecraft/item/Item;", remap = true), index = 0) 16 | private String fixTranslationKey(String original) { 17 | if (this.getMod() == null || original.contains(this.getMod().getID())) return original; 18 | return this.getMod().getID() + "." + original; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinMCEntity.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import crafttweaker.api.entity.IEntityDefinition; 4 | import crafttweaker.mc1120.entity.MCEntity; 5 | import crafttweaker.mc1120.entity.MCEntityDefinition; 6 | import net.minecraft.entity.Entity; 7 | import net.minecraft.util.ResourceLocation; 8 | import net.minecraftforge.fml.common.registry.EntityEntry; 9 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Overwrite; 12 | import org.spongepowered.asm.mixin.Shadow; 13 | import org.spongepowered.asm.mixin.Unique; 14 | import youyihj.zenutils.impl.util.SimpleCache; 15 | 16 | import java.util.Map; 17 | 18 | /** 19 | * @author youyihj 20 | */ 21 | @Mixin(value = MCEntity.class, remap = false) 22 | public abstract class MixinMCEntity { 23 | 24 | @Unique 25 | private static final SimpleCache, IEntityDefinition> DEF_CACHE = new SimpleCache<>(it -> { 26 | for (Map.Entry entry : ForgeRegistries.ENTITIES.getEntries()) { 27 | if (entry.getValue().getEntityClass() == it) { 28 | return new MCEntityDefinition(entry.getValue()); 29 | } 30 | } 31 | return null; 32 | }); 33 | 34 | @Shadow 35 | private Entity entity; 36 | 37 | /** 38 | * @author youyihj 39 | * @reason improve performance using a cache 40 | */ 41 | @Overwrite 42 | public IEntityDefinition getDefinition() { 43 | return DEF_CACHE.get(entity.getClass()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinParsedExpressionFunction.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.objectweb.asm.Opcodes; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.injection.At; 6 | import org.spongepowered.asm.mixin.injection.Redirect; 7 | import stanhebben.zenscript.parser.expression.ParsedExpressionFunction; 8 | import stanhebben.zenscript.type.ZenTypeNative; 9 | import youyihj.zenutils.impl.zenscript.nat.ZenTypeJavaNative; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @Mixin(value = ParsedExpressionFunction.class, remap = false) 15 | public abstract class MixinParsedExpressionFunction { 16 | @Redirect(method = "compile", at = @At(value = "JUMP", opcode = Opcodes.IFEQ, ordinal = 0, shift = At.Shift.BEFORE)) 17 | private boolean canUseNativeType(Object obj, Class clazz) { 18 | return obj instanceof ZenTypeNative || obj instanceof ZenTypeJavaNative; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinPartialType.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import org.spongepowered.asm.mixin.injection.Constant; 5 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 6 | import stanhebben.zenscript.expression.partial.PartialType; 7 | import stanhebben.zenscript.type.ZenType; 8 | import stanhebben.zenscript.type.ZenTypeNative; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | @Mixin(value = PartialType.class, remap = false) 14 | public abstract class MixinPartialType { 15 | @SuppressWarnings("InvalidInjectorMethodSignature") 16 | @ModifyConstant(method = "call", constant = @Constant(classValue = ZenTypeNative.class)) 17 | private Class alwaysTryCallingType(Object obj, Class constant) { 18 | return ZenType.class; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinPlayerAnvilUpdateEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import crafttweaker.api.event.IPlayerEvent; 4 | import crafttweaker.api.event.PlayerAnvilUpdateEvent; 5 | import org.spongepowered.asm.mixin.Implements; 6 | import org.spongepowered.asm.mixin.Interface; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @Mixin(PlayerAnvilUpdateEvent.class) 13 | @Implements(@Interface(iface = IPlayerEvent.class, prefix = "zu$")) 14 | public interface MixinPlayerAnvilUpdateEvent { 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinTemplateStringTokener.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import youyihj.zenutils.impl.zenscript.TemplateStringTokener; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | @Mixin(TemplateStringTokener.class) 10 | public abstract class MixinTemplateStringTokener { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinTokenStream.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import org.spongepowered.asm.mixin.injection.Constant; 5 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 6 | import stanhebben.zenscript.parser.TokenStream; 7 | import youyihj.zenutils.impl.zenscript.TemplateStringTokener; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @Mixin(value = TokenStream.class, remap = false) 13 | public abstract class MixinTokenStream { 14 | @SuppressWarnings({"MixinAnnotationTarget", "ConstantValue", "EqualsBetweenInconvertibleTypes"}) 15 | @ModifyConstant(method = "advance", constant = @Constant(expandZeroConditions = Constant.Condition.LESS_THAN_ZERO)) 16 | private int skipWhitespaceCheck(int constant) { 17 | return this.getClass().equals(TemplateStringTokener.class) ? Integer.MIN_VALUE : 0; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinZenTokener.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.apache.commons.lang3.ArrayUtils; 4 | import org.spongepowered.asm.mixin.Final; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Mutable; 7 | import org.spongepowered.asm.mixin.Shadow; 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 | import stanhebben.zenscript.ZenTokener; 12 | import stanhebben.zenscript.parser.CompiledDFA; 13 | import stanhebben.zenscript.parser.NFA; 14 | import youyihj.zenutils.impl.zenscript.TemplateStringTokener; 15 | import youyihj.zenutils.impl.zenscript.TemplateString; 16 | 17 | /** 18 | * @author youyihj 19 | */ 20 | @Mixin(value = ZenTokener.class, remap = false) 21 | public abstract class MixinZenTokener { 22 | @Shadow 23 | @Final 24 | @Mutable 25 | private static String[] REGEXPS; 26 | 27 | @Shadow 28 | @Final 29 | @Mutable 30 | private static int[] FINALS; 31 | 32 | @Shadow 33 | @Final 34 | @Mutable 35 | private static CompiledDFA DFA; 36 | 37 | @Inject(method = "", at = @At("RETURN")) 38 | private static void zu$addTemplateStringToken(CallbackInfo ci) { 39 | FINALS = ArrayUtils.addAll(FINALS, TemplateString.T_TEMPLATE_STRING, TemplateString.T_ESCAPE_CHAR); 40 | REGEXPS = ArrayUtils.addAll(REGEXPS, TemplateString.T_TEMPLATE_STRING_REGEX, TemplateString.T_ESCAPE_CHAR_REGEX); 41 | DFA = new NFA(REGEXPS, FINALS).toDFA().optimize().compile(); 42 | TemplateStringTokener.setupDFAFromZenTokener(REGEXPS, FINALS); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinZenType.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import org.spongepowered.asm.mixin.injection.At; 5 | import org.spongepowered.asm.mixin.injection.Inject; 6 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 7 | import stanhebben.zenscript.ZenTokener; 8 | import stanhebben.zenscript.compiler.IEnvironmentGlobal; 9 | import stanhebben.zenscript.parser.Token; 10 | import stanhebben.zenscript.type.ZenType; 11 | import youyihj.zenutils.impl.zenscript.IOrderlyType; 12 | 13 | /** 14 | * @author youyihj 15 | */ 16 | @Mixin(value = ZenType.class, remap = false) 17 | public abstract class MixinZenType { 18 | @Inject(method = "read", at = @At("RETURN")) 19 | private static void readOrderlyTag(ZenTokener tokener, IEnvironmentGlobal environment, CallbackInfoReturnable cir) { 20 | ZenType returnValue = cir.getReturnValue(); 21 | if (returnValue instanceof IOrderlyType) { 22 | if (tokener.optional(ZenTokener.T_DOLLAR) != null) { 23 | Token orderlyToken = tokener.required(ZenTokener.T_ID, "orderly required"); 24 | if ("orderly".equals(orderlyToken.getValue())) { 25 | ((IOrderlyType) returnValue).setOrderly(); 26 | } else { 27 | environment.error("orderly required"); 28 | } 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/MixinZenTypeAssociate.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import stanhebben.zenscript.type.ZenType; 5 | import stanhebben.zenscript.type.ZenTypeAssociative; 6 | import youyihj.zenutils.impl.zenscript.IOrderlyType; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @Mixin(value = ZenTypeAssociative.class, remap = false) 12 | public abstract class MixinZenTypeAssociate extends ZenType implements IOrderlyType { 13 | private boolean orderly; 14 | 15 | @Override 16 | public boolean isOrderly() { 17 | return orderly; 18 | } 19 | 20 | @Override 21 | public void setOrderly() { 22 | this.orderly = true; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/crafttweaker/TokenStreamAccessor.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.crafttweaker; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import org.spongepowered.asm.mixin.gen.Accessor; 5 | import stanhebben.zenscript.parser.TokenStream; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | @Mixin(value = TokenStream.class, remap = false) 11 | public interface TokenStreamAccessor { 12 | @Accessor 13 | void setLine(int line); 14 | 15 | @Accessor 16 | void setLineOffset(int lineOffset); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/custom/CustomMixinErrorHandler.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.custom; 2 | 3 | import crafttweaker.CraftTweakerAPI; 4 | import org.spongepowered.asm.mixin.extensibility.IMixinConfig; 5 | import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler; 6 | import org.spongepowered.asm.mixin.extensibility.IMixinInfo; 7 | import youyihj.zenutils.api.util.ReflectionInvoked; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @ReflectionInvoked 13 | public class CustomMixinErrorHandler implements IMixinErrorHandler { 14 | @Override 15 | public ErrorAction onPrepareError(IMixinConfig config, Throwable th, IMixinInfo mixin, ErrorAction action) { 16 | return action; 17 | } 18 | 19 | @Override 20 | public ErrorAction onApplyError(String targetClassName, Throwable th, IMixinInfo mixin, ErrorAction action) { 21 | if ("mixins.zenutils.custom.json".equals(mixin.getConfig().getName())) { 22 | CraftTweakerAPI.logError("Error occurred when applying mixin " + mixin.getName() + " to class " + targetClassName, th); 23 | } 24 | return action; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/custom/CustomMixinPlugin.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.custom; 2 | 3 | import org.objectweb.asm.tree.ClassNode; 4 | import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; 5 | import org.spongepowered.asm.mixin.extensibility.IMixinInfo; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Set; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | public class CustomMixinPlugin implements IMixinConfigPlugin { 15 | private static final List mixins = new ArrayList<>(); 16 | 17 | public static void addMixinClass(String mixin) { 18 | mixins.add(mixin); 19 | } 20 | 21 | @Override 22 | public void onLoad(String mixinPackage) { 23 | 24 | } 25 | 26 | @Override 27 | public String getRefMapperConfig() { 28 | return ""; 29 | } 30 | 31 | @Override 32 | public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { 33 | return false; 34 | } 35 | 36 | @Override 37 | public void acceptTargets(Set myTargets, Set otherTargets) { 38 | 39 | } 40 | 41 | @Override 42 | public List getMixins() { 43 | return mixins; 44 | } 45 | 46 | @Override 47 | public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { 48 | 49 | } 50 | 51 | @Override 52 | public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/customscriptentrypoint/MixinFMLModContainer.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.customscriptentrypoint; 2 | 3 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; 4 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; 5 | import com.llamalad7.mixinextras.sugar.Local; 6 | import net.minecraftforge.fml.common.FMLModContainer; 7 | import net.minecraftforge.fml.common.event.FMLEvent; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import youyihj.zenutils.impl.zenscript.entrypoint.CustomScriptEntrypoint; 11 | 12 | import java.lang.reflect.Method; 13 | 14 | /** 15 | * @author youyihj 16 | */ 17 | @Mixin(value = FMLModContainer.class, remap = false) 18 | public class MixinFMLModContainer { 19 | @WrapOperation(method = "handleModStateEvent", at = @At(value = "INVOKE", target = "Ljava/lang/reflect/Method;invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;")) 20 | private Object zenutils$handleModStateEvent(Method instance, Object o, Object[] objects, Operation original, @Local(argsOnly = true) FMLEvent event) { 21 | CustomScriptEntrypoint.runScript(o, event, true); 22 | original.call(instance, o, objects); 23 | CustomScriptEntrypoint.runScript(o, event, false); 24 | // the original method always return null; 25 | return null; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/itf/IAnvilUpdateEventExtension.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.itf; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import youyihj.zenutils.api.util.ReflectionInvoked; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | public interface IAnvilUpdateEventExtension { 10 | @ReflectionInvoked 11 | EntityPlayer zu$getPlayer(); 12 | 13 | void zu$setPlayer(EntityPlayer player); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/itf/IEnvironmentClassExtension.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.itf; 2 | 3 | import youyihj.zenutils.impl.zenscript.nat.ZenTypeJavaNative; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public interface IEnvironmentClassExtension { 11 | List getMixinTargets(); 12 | 13 | void setMixinTargets(List targets); 14 | 15 | List getSuperClasses(); 16 | 17 | void setSubClasses(List superClasses); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/itf/IParsedClassConstructorExtension.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.itf; 2 | 3 | import youyihj.zenutils.impl.zenscript.nat.ZenTypeJavaNative; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public interface IParsedClassConstructorExtension { 9 | void setSuperClass(ZenTypeJavaNative superClass); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/itf/IParsedZenClassExtension.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.itf; 2 | 3 | import youyihj.zenutils.impl.zenscript.nat.ZenTypeJavaNative; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public interface IParsedZenClassExtension { 11 | ZenTypeJavaNative getSuperClass(); 12 | 13 | List getInterfaces(); 14 | 15 | void setSuperClass(ZenTypeJavaNative superClass); 16 | 17 | void setInterfaces(List interfaces); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/itf/IParsedZenClassFieldExtension.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.itf; 2 | 3 | import stanhebben.zenscript.util.ZenPosition; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public interface IParsedZenClassFieldExtension { 9 | void setPosition(ZenPosition position); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/simpledimensions/MixinWorldCustom.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.simpledimensions; 2 | 3 | import lumien.simpledimensions.server.WorldCustom; 4 | import net.minecraft.profiler.Profiler; 5 | import net.minecraft.world.World; 6 | import net.minecraft.world.WorldProvider; 7 | import net.minecraft.world.storage.ISaveHandler; 8 | import net.minecraft.world.storage.WorldInfo; 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.CallbackInfoReturnable; 13 | 14 | /** 15 | * @author youyihj 16 | */ 17 | @Mixin(WorldCustom.class) 18 | public abstract class MixinWorldCustom extends World { 19 | protected MixinWorldCustom(ISaveHandler saveHandlerIn, WorldInfo info, WorldProvider providerIn, Profiler profilerIn, boolean client) { 20 | super(saveHandlerIn, info, providerIn, profilerIn, client); 21 | } 22 | 23 | @Inject(method = "init", at = @At("RETURN")) 24 | private void zenutils$injectCapabilities(CallbackInfoReturnable cir) { 25 | initCapabilities(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/vanilla/ContainerRepairAccessor.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.vanilla; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.ContainerRepair; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.gen.Accessor; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | @Mixin(ContainerRepair.class) 12 | public interface ContainerRepairAccessor { 13 | @Accessor 14 | EntityPlayer getPlayer(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/vanilla/MixinAnvilUpdateEvent.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.vanilla; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraftforge.event.AnvilUpdateEvent; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Unique; 7 | import youyihj.zenutils.impl.mixin.itf.IAnvilUpdateEventExtension; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | @Mixin(value = AnvilUpdateEvent.class, remap = false) 13 | public abstract class MixinAnvilUpdateEvent implements IAnvilUpdateEventExtension { 14 | @Unique 15 | private EntityPlayer zu$player; 16 | 17 | @Override 18 | public EntityPlayer zu$getPlayer() { 19 | return zu$player; 20 | } 21 | 22 | @Override 23 | public void zu$setPlayer(EntityPlayer player) { 24 | this.zu$player = player; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/vanilla/MixinEntityItem.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.vanilla; 2 | 3 | import net.minecraft.entity.Entity; 4 | import net.minecraft.entity.item.EntityItem; 5 | import net.minecraft.util.DamageSource; 6 | import net.minecraft.world.World; 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 | import youyihj.zenutils.api.event.ExpandEventManager; 12 | 13 | /** 14 | * @author youyihj 15 | */ 16 | @Mixin(EntityItem.class) 17 | public abstract class MixinEntityItem extends Entity { 18 | public MixinEntityItem(World worldIn) { 19 | super(worldIn); 20 | } 21 | 22 | @Override 23 | public void fall(float distance, float damageMultiplier) { 24 | ExpandEventManager.handleEntityItemFallEvent((EntityItem) ((Object) this), distance); 25 | super.fall(distance, damageMultiplier); 26 | } 27 | 28 | @Inject(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/EntityItem;setDead()V")) 29 | private void fireAttackedEvent(DamageSource source, float amount, CallbackInfoReturnable cir) { 30 | ExpandEventManager.handleEntityItemDeathEvent((EntityItem) ((Object) this), source); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/vanilla/MixinForgeHooks.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.vanilla; 2 | 3 | import com.llamalad7.mixinextras.sugar.Local; 4 | import net.minecraft.inventory.ContainerRepair; 5 | import net.minecraft.inventory.IInventory; 6 | import net.minecraft.item.ItemStack; 7 | import net.minecraftforge.common.ForgeHooks; 8 | import net.minecraftforge.event.AnvilUpdateEvent; 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.CallbackInfoReturnable; 13 | import youyihj.zenutils.impl.mixin.itf.IAnvilUpdateEventExtension; 14 | 15 | /** 16 | * @author youyihj 17 | */ 18 | @Mixin(value = ForgeHooks.class, remap = false) 19 | public abstract class MixinForgeHooks { 20 | @Inject( 21 | method = "onAnvilChange", 22 | at = @At( 23 | value = "INVOKE", 24 | target = "Lnet/minecraftforge/event/AnvilUpdateEvent;(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;Ljava/lang/String;I)V", 25 | // shift to after two opcodes (INVOKESPECIAL, ASTORE) 26 | shift = At.Shift.BY, 27 | by = 2 28 | ) 29 | ) 30 | private static void passPlayer(ContainerRepair container, ItemStack left, ItemStack right, IInventory outputSlot, String name, int baseCost, CallbackInfoReturnable cir, @Local AnvilUpdateEvent event) { 31 | ((IAnvilUpdateEventExtension) event).zu$setPlayer(((ContainerRepairAccessor) container).getPlayer()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/vanilla/MixinWorldServer.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.vanilla; 2 | 3 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; 4 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; 5 | import com.llamalad7.mixinextras.sugar.Local; 6 | import net.minecraft.block.Block; 7 | import net.minecraft.block.state.IBlockState; 8 | import net.minecraft.util.math.BlockPos; 9 | import net.minecraft.world.World; 10 | import net.minecraft.world.WorldServer; 11 | import net.minecraft.world.chunk.storage.ExtendedBlockStorage; 12 | import net.minecraftforge.common.MinecraftForge; 13 | import org.spongepowered.asm.mixin.Mixin; 14 | import org.spongepowered.asm.mixin.injection.At; 15 | import youyihj.zenutils.api.event.RandomTickEvent; 16 | 17 | /** 18 | * @author youyihj 19 | */ 20 | @Mixin(WorldServer.class) 21 | public abstract class MixinWorldServer { 22 | @WrapOperation(method = "updateBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getTickRandomly()Z")) 23 | private boolean postRandomTickEvent( 24 | Block instance, Operation original, 25 | @Local IBlockState state, 26 | @Local(index = 14) int x, 27 | @Local(index = 16) int y, 28 | @Local(index = 15) int z, 29 | @Local(index = 6) int chunkX, 30 | @Local ExtendedBlockStorage extendedBlockStorage, 31 | @Local(index = 7) int chunkZ 32 | ) { 33 | if (MinecraftForge.EVENT_BUS.post(new RandomTickEvent((World) (Object) this, new BlockPos(x + chunkX, y + extendedBlockStorage.getYLocation(), z + chunkZ), state))) { 34 | return false; 35 | } else { 36 | return original.call(instance); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/zenbootstrap/MixinCleanroomLoadController.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.zenbootstrap; 2 | 3 | import net.minecraftforge.fml.common.LoadController; 4 | import net.minecraftforge.fml.common.LoaderState; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Inject; 8 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 9 | import youyihj.zenutils.impl.zenscript.mixin.ZenMixin; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @Mixin(value = LoadController.class, remap = false) 15 | public class MixinCleanroomLoadController { 16 | @Inject( 17 | method = "distributeStateMessage(Lnet/minecraftforge/fml/common/LoaderState;[Ljava/lang/Object;)V", 18 | at = @At(value = "INVOKE", target = "Lcom/google/common/eventbus/EventBus;post(Ljava/lang/Object;)V") 19 | ) 20 | private void beforeConstructing(LoaderState state, Object[] eventData, CallbackInfo ci) throws Throwable { 21 | if (state == LoaderState.CONSTRUCTING) { 22 | ZenMixin.load(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/zenbootstrap/MixinForgeLoadController.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.zenbootstrap; 2 | 3 | import net.minecraftforge.fml.common.LoadController; 4 | import net.minecraftforge.fml.common.LoaderState; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Inject; 8 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 9 | import youyihj.zenutils.impl.zenscript.mixin.ZenMixin; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | @Mixin(value = LoadController.class, remap = false, priority = Integer.MAX_VALUE) 15 | public class MixinForgeLoadController { 16 | @Inject(method = "distributeStateMessage(Lnet/minecraftforge/fml/common/LoaderState;[Ljava/lang/Object;)V", at = @At("HEAD")) 17 | private void beforeConstructing(LoaderState state, Object[] eventData, CallbackInfo ci) throws Throwable { 18 | if (state == LoaderState.CONSTRUCTING) { 19 | ZenMixin.load(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/mixin/zenbootstrap/ZenMixinBootstrapPlugin.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.mixin.zenbootstrap; 2 | 3 | import org.objectweb.asm.tree.ClassNode; 4 | import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; 5 | import org.spongepowered.asm.mixin.extensibility.IMixinInfo; 6 | import youyihj.zenutils.Reference; 7 | 8 | import java.util.Collections; 9 | import java.util.List; 10 | import java.util.Set; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | public class ZenMixinBootstrapPlugin implements IMixinConfigPlugin { 16 | @Override 17 | public void onLoad(String mixinPackage) { 18 | 19 | } 20 | 21 | @Override 22 | public String getRefMapperConfig() { 23 | return ""; 24 | } 25 | 26 | @Override 27 | public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { 28 | return Reference.IS_CLEANROOM 29 | ? "youyihj.zenutils.impl.mixin.zenbootstrap.MixinCleanroomLoadController".equals(mixinClassName) 30 | : "youyihj.zenutils.impl.mixin.zenbootstrap.MixinForgeLoadController".equals(mixinClassName); 31 | } 32 | 33 | @Override 34 | public void acceptTargets(Set myTargets, Set otherTargets) { 35 | 36 | } 37 | 38 | @Override 39 | public List getMixins() { 40 | return Collections.emptyList(); 41 | } 42 | 43 | @Override 44 | public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { 45 | 46 | } 47 | 48 | @Override 49 | public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/player/ActionResult.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.player; 2 | 3 | import crafttweaker.api.item.IItemStack; 4 | import crafttweaker.api.minecraft.CraftTweakerMC; 5 | import net.minecraft.item.ItemStack; 6 | import youyihj.zenutils.api.player.IActionResult; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class ActionResult implements IActionResult { 12 | private final ItemStack item; 13 | private final T result; 14 | 15 | public ActionResult(ItemStack item, T result) { 16 | this.item = item; 17 | this.result = result; 18 | } 19 | 20 | @Override 21 | public IItemStack getItem() { 22 | return CraftTweakerMC.getIItemStack(item); 23 | } 24 | 25 | @Override 26 | public T getResult() { 27 | return result; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/player/DummyNetHandler.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.player; 2 | 3 | import net.minecraft.entity.player.EntityPlayerMP; 4 | import net.minecraft.network.EnumPacketDirection; 5 | import net.minecraft.network.NetHandlerPlayServer; 6 | import net.minecraft.network.NetworkManager; 7 | import net.minecraft.network.Packet; 8 | import net.minecraft.network.play.client.CPacketVehicleMove; 9 | import net.minecraft.server.MinecraftServer; 10 | import net.minecraft.util.text.ITextComponent; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | public class DummyNetHandler extends NetHandlerPlayServer { 16 | public DummyNetHandler(MinecraftServer server, EntityPlayerMP playerIn) { 17 | super(server, new NetworkManager(EnumPacketDirection.SERVERBOUND), playerIn); 18 | } 19 | 20 | @Override 21 | public void disconnect(ITextComponent textComponent) { 22 | } 23 | 24 | @Override 25 | public void processVehicleMove(CPacketVehicleMove packetIn) { 26 | } 27 | 28 | @Override 29 | public void sendPacket(Packet packetIn) { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/player/FakePlayerHolder.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.player; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import net.minecraft.world.WorldServer; 5 | import net.minecraftforge.common.util.FakePlayer; 6 | import net.minecraftforge.common.util.FakePlayerFactory; 7 | 8 | import java.lang.ref.WeakReference; 9 | import java.util.UUID; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | public class FakePlayerHolder { 15 | private static WeakReference playerRef; 16 | private static final GameProfile PROFILE = new GameProfile(UUID.fromString("c813ca2f-1514-3c3e-bdfa-a70cd84240fa"), "[ZenUtils]"); 17 | 18 | public static FakePlayer get(WorldServer world) { 19 | FakePlayer ret = playerRef != null ? playerRef.get() : null; 20 | if (ret == null) { 21 | ret = FakePlayerFactory.get(world, PROFILE); 22 | // also set the handler to the player 23 | new DummyNetHandler(ret.getServer(), ret); 24 | playerRef = new WeakReference<>(ret); 25 | ret.setWorld(world); 26 | } 27 | return ret; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/player/IStatFormatterAdapter.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.player; 2 | 3 | import net.minecraft.stats.IStatType; 4 | import youyihj.zenutils.api.player.DefaultStatFormatters; 5 | import youyihj.zenutils.api.player.IStatFormatter; 6 | import youyihj.zenutils.api.util.ReflectionInvoked; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public interface IStatFormatterAdapter { 12 | IStatFormatter adapt(IStatType type); 13 | 14 | @ReflectionInvoked 15 | class Client implements IStatFormatterAdapter { 16 | 17 | @Override 18 | public IStatFormatter adapt(IStatType type) { 19 | return new PresentTypeFormatter(type::format, type); 20 | } 21 | } 22 | 23 | @ReflectionInvoked 24 | class Server implements IStatFormatterAdapter { 25 | 26 | @Override 27 | public IStatFormatter adapt(IStatType type) { 28 | return new PresentTypeFormatter(DefaultStatFormatters.simple(), type); 29 | } 30 | } 31 | 32 | class PresentTypeFormatter implements IStatFormatter { 33 | private final IStatFormatter parent; 34 | private final IStatType type; 35 | 36 | public PresentTypeFormatter(IStatFormatter parent, IStatType type) { 37 | this.parent = parent; 38 | this.type = type; 39 | } 40 | 41 | @Override 42 | public String format(int number) { 43 | return parent.format(number); 44 | } 45 | 46 | @Override 47 | public IStatType toType() { 48 | return type; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/runtime/HardFailLogger.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.runtime; 2 | 3 | import crafttweaker.api.player.IPlayer; 4 | import crafttweaker.runtime.ILogger; 5 | import youyihj.zenutils.impl.util.InternalUtils; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public class HardFailLogger implements ILogger { 11 | @Override 12 | public void logCommand(String message) { 13 | 14 | } 15 | 16 | @Override 17 | public void logInfo(String message) { 18 | 19 | } 20 | 21 | @Override 22 | public void logWarning(String message) { 23 | 24 | } 25 | 26 | @Override 27 | public void logError(String message) { 28 | if (InternalUtils.getScriptStatus().isDebug()) { 29 | return; 30 | } 31 | throw new ScriptRunException(message); 32 | } 33 | 34 | @Override 35 | public void logError(String message, Throwable exception) { 36 | if (InternalUtils.getScriptStatus().isDebug()) { 37 | return; 38 | } 39 | if (exception instanceof ScriptRunException) { 40 | if (exception.getCause() == null) { 41 | throw ((ScriptRunException) exception); 42 | } else { 43 | throw new ScriptRunException(message, exception.getCause()); 44 | } 45 | } else { 46 | throw new ScriptRunException(message, exception); 47 | } 48 | } 49 | 50 | @Override 51 | public void logPlayer(IPlayer player) { 52 | 53 | } 54 | 55 | @Override 56 | public void logDefault(String message) { 57 | 58 | } 59 | 60 | @Override 61 | public boolean isLogDisabled() { 62 | return false; 63 | } 64 | 65 | @Override 66 | public void setLogDisabled(boolean logDisabled) { 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/runtime/InvalidCraftTweakerVersionException.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.runtime; 2 | 3 | import crafttweaker.mc1120.CraftTweaker; 4 | import net.minecraftforge.fml.common.MissingModsException; 5 | import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion; 6 | import net.minecraftforge.fml.common.versioning.InvalidVersionSpecificationException; 7 | import net.minecraftforge.fml.common.versioning.VersionRange; 8 | import youyihj.zenutils.Reference; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | public class InvalidCraftTweakerVersionException extends MissingModsException { 14 | private final String requiredVersion; 15 | 16 | public InvalidCraftTweakerVersionException(String requiredVersion) { 17 | super(Reference.MODID, Reference.NAME); 18 | this.requiredVersion = requiredVersion; 19 | try { 20 | this.addMissingMod( 21 | new DefaultArtifactVersion(CraftTweaker.MODID, VersionRange.createFromVersionSpec("[" + requiredVersion + ",)")), 22 | null, 23 | true 24 | ); 25 | } catch (InvalidVersionSpecificationException e) { 26 | throw new AssertionError(); 27 | } 28 | } 29 | 30 | @Override 31 | public String getMessage() { 32 | return String.format("crafttweaker version must be %s or above!", requiredVersion); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/runtime/ScriptRunException.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.runtime; 2 | 3 | public class ScriptRunException extends RuntimeException { 4 | public ScriptRunException(String message, Throwable cause) { 5 | super(message, cause, false, false); 6 | } 7 | 8 | public ScriptRunException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/runtime/ScriptStatus.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.runtime; 2 | 3 | /** 4 | * @author youyihj 5 | */ 6 | public enum ScriptStatus { 7 | INIT(false), 8 | RELOAD(true), 9 | STARTED(false), 10 | SYNTAX(true); 11 | 12 | private final boolean debug; 13 | 14 | ScriptStatus(boolean debug) { 15 | this.debug = debug; 16 | } 17 | 18 | public boolean isDebug() { 19 | return debug; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/IVersionChecker.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util; 2 | 3 | /** 4 | * @author youyihj 5 | */ 6 | @FunctionalInterface 7 | public interface IVersionChecker { 8 | boolean check() throws Exception; 9 | 10 | default boolean getResult() { 11 | try { 12 | return check(); 13 | } catch (Exception e) { 14 | return false; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/JourneyMapPlugin.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util; 2 | 3 | import crafttweaker.CraftTweakerAPI; 4 | import crafttweaker.api.minecraft.CraftTweakerMC; 5 | import crafttweaker.api.world.IBlockPos; 6 | import crafttweaker.api.world.IWorld; 7 | import journeymap.client.api.ClientPlugin; 8 | import journeymap.client.api.IClientAPI; 9 | import journeymap.client.api.IClientPlugin; 10 | import journeymap.client.api.display.Waypoint; 11 | import journeymap.client.api.event.ClientEvent; 12 | import youyihj.zenutils.Reference; 13 | import youyihj.zenutils.ZenUtils; 14 | 15 | import java.util.Objects; 16 | 17 | /** 18 | * @author youyihj 19 | */ 20 | @ClientPlugin 21 | public class JourneyMapPlugin implements IClientPlugin { 22 | public static IClientAPI japi; 23 | 24 | public static void createWaypoint(String name, IBlockPos pos, IWorld world, int color) { 25 | if (japi == null) { 26 | CraftTweakerAPI.logError("JourneyMap API is not built yet!"); 27 | } 28 | String id = Reference.MODID + "-" + name + "-" + Objects.hash(pos.getInternal()); 29 | Waypoint waypoint = new Waypoint(Reference.MODID, id, name, world.getDimension(), CraftTweakerMC.getBlockPos(pos)); 30 | waypoint.setColor(color); 31 | waypoint.setDirty(); 32 | try { 33 | japi.show(waypoint); 34 | } catch (Exception e) { 35 | ZenUtils.forgeLogger.throwing(e); 36 | } 37 | } 38 | 39 | @Override 40 | public void initialize(IClientAPI jmClientApi) { 41 | japi = jmClientApi; 42 | } 43 | 44 | @Override 45 | public String getModId() { 46 | return Reference.MODID; 47 | } 48 | 49 | @Override 50 | public void onEvent(ClientEvent event) { 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/LogMTErrorRunnableWrapper.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util; 2 | 3 | import crafttweaker.CraftTweakerAPI; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public class LogMTErrorRunnableWrapper implements Runnable { 9 | private final Runnable internal; 10 | 11 | private LogMTErrorRunnableWrapper(Runnable internal) { 12 | this.internal = internal; 13 | } 14 | 15 | public static LogMTErrorRunnableWrapper create(Runnable internal) { 16 | return new LogMTErrorRunnableWrapper(internal); 17 | } 18 | 19 | @Override 20 | public void run() { 21 | try { 22 | internal.run(); 23 | } catch (Throwable throwable) { 24 | CraftTweakerAPI.logError(null, throwable); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/ReflectUtils.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Modifier; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class ReflectUtils { 12 | public static Field removePrivateFinal(Class clazz, String fieldName) throws NoSuchFieldException, IllegalAccessException { 13 | Field field = clazz.getDeclaredField(fieldName); 14 | Field modifiersField = Field.class.getDeclaredField("modifiers"); 15 | modifiersField.setAccessible(true); 16 | field.setAccessible(true); 17 | modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); 18 | return field; 19 | } 20 | 21 | public static Field removePrivate(Class clazz, String fieldName) throws NoSuchFieldException { 22 | Field field = clazz.getDeclaredField(fieldName); 23 | field.setAccessible(true); 24 | return field; 25 | } 26 | 27 | public static List getAllFieldsWithClass(Class target, Class fieldClass, Object targetInstance) throws IllegalAccessException, IllegalArgumentException, NullPointerException { 28 | List temp = new ArrayList<>(); 29 | for (Field field : target.getDeclaredFields()) { 30 | if (fieldClass.isAssignableFrom(field.getType())) { 31 | field.setAccessible(true); 32 | Object o = field.get(targetInstance); 33 | temp.add(fieldClass.cast(o)); 34 | } 35 | } 36 | return temp; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/SimpleCache.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Map; 6 | import java.util.Set; 7 | import java.util.function.Function; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public class SimpleCache { 13 | private final Map elements = new HashMap<>(); 14 | private final Set cachedKeys = new HashSet<>(); 15 | private final Function loader; 16 | 17 | public SimpleCache(Function loader) { 18 | this.loader = loader; 19 | } 20 | 21 | public V get(K key) { 22 | if (cachedKeys.contains(key)) { 23 | return elements.get(key); 24 | } else { 25 | cachedKeys.add(key); 26 | V result = loader.apply(key); 27 | if (result != null) { 28 | elements.put(key, result); 29 | } 30 | return result; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/TotallyImmutableItemStack.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util; 2 | 3 | import crafttweaker.api.item.IMutableItemStack; 4 | import crafttweaker.mc1120.item.MCItemStack; 5 | import net.minecraft.item.ItemStack; 6 | 7 | public class TotallyImmutableItemStack extends MCItemStack { 8 | public TotallyImmutableItemStack(ItemStack itemStack) { 9 | super(itemStack); 10 | } 11 | 12 | @Override 13 | public IMutableItemStack mutable() { 14 | throw new UnsupportedOperationException("The ItemStack is totally immutable. You can't make it mutable"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/CatenationBuilder.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation; 2 | 3 | import crafttweaker.CraftTweakerAPI; 4 | import crafttweaker.api.minecraft.CraftTweakerMC; 5 | import crafttweaker.api.world.IWorld; 6 | import youyihj.zenutils.api.util.catenation.Catenation; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class CatenationBuilder extends AbstractCatenationBuilder { 12 | private final IWorld world; 13 | 14 | public CatenationBuilder(IWorld world) { 15 | this.world = world; 16 | } 17 | 18 | @Override 19 | protected void register(Catenation catenation) { 20 | if (world.isRemote()) { 21 | CraftTweakerAPI.logWarning("This catenation is only run on server, but the world is on client side."); 22 | CraftTweakerAPI.logWarning("If it is expected, please call `client.catenation()` to build catenation that is run on client."); 23 | } else { 24 | CatenationManager.addCatenation(CraftTweakerMC.getWorld(world), catenation); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/CatenationTaskQueueBuilder.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation; 2 | 3 | import youyihj.zenutils.api.util.catenation.*; 4 | 5 | import java.util.ArrayDeque; 6 | import java.util.Queue; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class CatenationTaskQueueBuilder implements ICatenationTaskQueueBuilder { 12 | private final Queue tasks = new ArrayDeque<>(); 13 | 14 | @Override 15 | public ICatenationTaskQueueBuilder addTask(ICatenationTask task) { 16 | tasks.add(task); 17 | return this; 18 | } 19 | 20 | @Override 21 | public Queue build() { 22 | return tasks; 23 | } 24 | 25 | @Override 26 | public ICatenationTaskQueueBuilder run(IWorldFunction function) { 27 | return addTask(new InstantTask(function)); 28 | } 29 | 30 | @Override 31 | public ICatenationTaskQueueBuilder sleep(long ticks) { 32 | return addTask(new SleepTask(ticks)); 33 | } 34 | 35 | @Override 36 | public ICatenationTaskQueueBuilder sleepUntil(IWorldCondition condition) { 37 | return addTask(new SleepUntilTask(condition)); 38 | } 39 | 40 | @Override 41 | public ICatenationTaskQueueBuilder customTimer(long duration, ITimerHandler handler) { 42 | return addTask(new TimerTask(duration, handler)); 43 | } 44 | 45 | @Override 46 | public ICatenationTaskQueueBuilder repeat(int times, ICatenationTaskQueueBuilderConsumer taskQueueBuilderConsumer) { 47 | return addTask(new RepeatTask(taskQueueBuilderConsumer, times)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/ClientCatenationBuilder.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation; 2 | 3 | import com.google.common.base.Preconditions; 4 | import net.minecraftforge.fml.common.FMLCommonHandler; 5 | import youyihj.zenutils.api.util.catenation.Catenation; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public class ClientCatenationBuilder extends AbstractCatenationBuilder { 11 | @Override 12 | protected void register(Catenation catenation) { 13 | Preconditions.checkState(FMLCommonHandler.instance().getEffectiveSide().isClient(), "Trying to run a client catenation on server side."); 14 | CatenationManager.addClientCatenation(catenation); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/InstantTask.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation; 2 | 3 | import crafttweaker.api.data.DataBool; 4 | import crafttweaker.api.data.IData; 5 | import crafttweaker.api.world.IWorld; 6 | import youyihj.zenutils.api.util.catenation.CatenationContext; 7 | import youyihj.zenutils.api.util.catenation.ICatenationTask; 8 | import youyihj.zenutils.api.util.catenation.IWorldFunction; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | public class InstantTask implements ICatenationTask { 14 | private final IWorldFunction worldFunction; 15 | private boolean ran; 16 | 17 | public InstantTask(IWorldFunction worldFunction) { 18 | this.worldFunction = worldFunction; 19 | } 20 | 21 | @Override 22 | public void run(IWorld world, CatenationContext context) { 23 | worldFunction.apply(world, context); 24 | ran = true; 25 | } 26 | 27 | @Override 28 | public boolean isComplete() { 29 | return ran; 30 | } 31 | 32 | @Override 33 | public IData serializeToData() { 34 | return new DataBool(ran); 35 | } 36 | 37 | @Override 38 | public void deserializeFromData(IData data) { 39 | ran = data.asBool(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/SleepTask.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation; 2 | 3 | /** 4 | * @author youyihj 5 | */ 6 | public class SleepTask extends TimerTask { 7 | 8 | public SleepTask(long sleepTime) { 9 | super(sleepTime, ((timer, world, context) -> timer.update())); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/SleepUntilTask.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation; 2 | 3 | import crafttweaker.api.data.DataBool; 4 | import crafttweaker.api.data.IData; 5 | import crafttweaker.api.world.IWorld; 6 | import youyihj.zenutils.api.util.catenation.CatenationContext; 7 | import youyihj.zenutils.api.util.catenation.ICatenationTask; 8 | import youyihj.zenutils.api.util.catenation.IWorldCondition; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | public class SleepUntilTask implements ICatenationTask { 14 | private final IWorldCondition condition; 15 | private boolean sleep = true; 16 | 17 | public SleepUntilTask(IWorldCondition condition) { 18 | this.condition = condition; 19 | } 20 | 21 | @Override 22 | public void run(IWorld world, CatenationContext context) { 23 | if (sleep && condition.apply(world, context)) { 24 | sleep = false; 25 | } 26 | } 27 | 28 | @Override 29 | public boolean isComplete() { 30 | return !sleep; 31 | } 32 | 33 | @Override 34 | public IData serializeToData() { 35 | return new DataBool(sleep); 36 | } 37 | 38 | @Override 39 | public void deserializeFromData(IData data) { 40 | sleep = data.asBool(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/TimerTask.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation; 2 | 3 | import crafttweaker.api.data.DataLong; 4 | import crafttweaker.api.data.IData; 5 | import crafttweaker.api.world.IWorld; 6 | import youyihj.zenutils.api.util.catenation.CatenationContext; 7 | import youyihj.zenutils.api.util.catenation.ICatenationTask; 8 | import youyihj.zenutils.api.util.catenation.ITimerHandler; 9 | import youyihj.zenutils.api.util.catenation.Timer; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | public class TimerTask implements ICatenationTask { 15 | private final Timer timer; 16 | private final ITimerHandler handler; 17 | 18 | public TimerTask(long duration, ITimerHandler handler) { 19 | this.timer = new Timer(duration); 20 | this.handler = handler; 21 | } 22 | 23 | @Override 24 | public void run(IWorld world, CatenationContext context) { 25 | handler.apply(timer, world, context); 26 | } 27 | 28 | @Override 29 | public boolean isComplete() { 30 | return timer.isFinish(); 31 | } 32 | 33 | @Override 34 | public IData serializeToData() { 35 | return new DataLong(timer.getCurrent()); 36 | } 37 | 38 | @Override 39 | public void deserializeFromData(IData data) { 40 | timer.setCurrent(data.asLong()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/persistence/CatenationPersistedObjects.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation.persistence; 2 | 3 | import youyihj.zenutils.api.util.catenation.persistence.ICatenationObjectHolder; 4 | 5 | import java.util.HashMap; 6 | import java.util.HashSet; 7 | import java.util.Map; 8 | import java.util.Set; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | public class CatenationPersistedObjects { 14 | private final Map, Object> objects = new HashMap<>(); 15 | private final Set keys = new HashSet<>(); 16 | 17 | public void with(String key, ICatenationObjectHolder.Type type, T object) { 18 | if (!keys.add(key)) { 19 | throw new IllegalArgumentException("Key " + key + " already exists"); 20 | } 21 | objects.put(ICatenationObjectHolder.Key.of(key, type), object); 22 | } 23 | 24 | public Map, Object> getObjects() { 25 | return objects; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/persistence/DataObjectHolder.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation.persistence; 2 | 3 | import crafttweaker.api.data.IData; 4 | import youyihj.zenutils.api.util.catenation.persistence.BuiltinObjectHolderTypes; 5 | import youyihj.zenutils.api.util.catenation.persistence.ICatenationObjectHolder; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public class DataObjectHolder implements ICatenationObjectHolder { 11 | 12 | private IData data; 13 | 14 | @Override 15 | public Type getType() { 16 | return BuiltinObjectHolderTypes.DATA; 17 | } 18 | 19 | @Override 20 | public IData serializeToData() { 21 | return data; 22 | } 23 | 24 | @Override 25 | public void deserializeFromData(IData data) { 26 | this.data = data; 27 | } 28 | 29 | @Override 30 | public void receiveObject(IData object) { 31 | if (this.data != null) { 32 | this.data = object; 33 | } 34 | } 35 | 36 | @Override 37 | public IData getValue() { 38 | return data; 39 | } 40 | 41 | @Override 42 | public void setValue(IData value) { 43 | this.data = value; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/util/catenation/persistence/ObjectHolderTypeRegistry.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.util.catenation.persistence; 2 | 3 | import youyihj.zenutils.api.util.catenation.persistence.ICatenationObjectHolder.Type; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class ObjectHolderTypeRegistry { 12 | private static final Map> types = new HashMap<>(); 13 | 14 | public static void register(Type type) { 15 | types.put(type.getValueType().getName(), type); 16 | } 17 | 18 | public static Type get(String typeName) { 19 | return types.get(typeName); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/Defaults.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript; 2 | 3 | import youyihj.zenutils.api.event.CTEventPriority; 4 | import youyihj.zenutils.api.network.IByteBufWriter; 5 | import youyihj.zenutils.api.player.DefaultStatFormatters; 6 | import youyihj.zenutils.api.player.IStatFormatter; 7 | import youyihj.zenutils.api.util.ReflectionInvoked; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public class Defaults { 13 | @ReflectionInvoked 14 | public static CTEventPriority eventPriority(String unused) { 15 | return CTEventPriority.NORMAL; 16 | } 17 | 18 | @ReflectionInvoked 19 | public static IByteBufWriter byteBufWriter(String unused) { 20 | return (buf) -> {}; 21 | } 22 | 23 | @ReflectionInvoked 24 | public static IStatFormatter statFormatter(String unused) { 25 | return DefaultStatFormatters.simple(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/ExpressionDeepNull.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript; 2 | 3 | import org.objectweb.asm.Label; 4 | import stanhebben.zenscript.compiler.IEnvironmentGlobal; 5 | import stanhebben.zenscript.compiler.IEnvironmentMethod; 6 | import stanhebben.zenscript.expression.Expression; 7 | import stanhebben.zenscript.type.ZenType; 8 | import stanhebben.zenscript.util.ZenPosition; 9 | 10 | /** 11 | * @author youyihj 12 | */ 13 | public class ExpressionDeepNull extends Expression { 14 | public ExpressionDeepNull(ZenPosition position) { 15 | super(position); 16 | } 17 | 18 | @Override 19 | public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) { 20 | return type.defaultValue(position); 21 | } 22 | 23 | @Override 24 | public void compile(boolean result, IEnvironmentMethod environment) { 25 | if(result) { 26 | environment.getOutput().aConstNull(); 27 | } 28 | } 29 | 30 | @Override 31 | public ZenType getType() { 32 | return ZenTypeDeepNull.INSTANCE; 33 | } 34 | 35 | @Override 36 | public void compileIf(Label onElse, IEnvironmentMethod environment) { 37 | environment.getOutput().goTo(onElse); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/IOrderlyType.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript; 2 | 3 | /** 4 | * @author youyihj 5 | */ 6 | public interface IOrderlyType { 7 | boolean isOrderly(); 8 | 9 | void setOrderly(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/ParsedExpressionDeepNull.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript; 2 | 3 | import stanhebben.zenscript.compiler.IEnvironmentMethod; 4 | import stanhebben.zenscript.expression.partial.IPartialExpression; 5 | import stanhebben.zenscript.parser.expression.ParsedExpression; 6 | import stanhebben.zenscript.type.ZenType; 7 | import stanhebben.zenscript.util.ZenPosition; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public class ParsedExpressionDeepNull extends ParsedExpression { 13 | public ParsedExpressionDeepNull(ZenPosition position) { 14 | super(position); 15 | } 16 | 17 | @Override 18 | public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) { 19 | return new ExpressionDeepNull(getPosition()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/mixin/ExpressionMixinThis.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript.mixin; 2 | 3 | import stanhebben.zenscript.compiler.IEnvironmentGlobal; 4 | import stanhebben.zenscript.compiler.IEnvironmentMethod; 5 | import stanhebben.zenscript.expression.Expression; 6 | import stanhebben.zenscript.type.ZenType; 7 | import stanhebben.zenscript.util.MethodOutput; 8 | import stanhebben.zenscript.util.ZenPosition; 9 | import youyihj.zenutils.impl.member.LiteralType; 10 | 11 | /** 12 | * @author youyihj 13 | */ 14 | public class ExpressionMixinThis extends Expression { 15 | private final String mixinTarget; 16 | private final IEnvironmentGlobal environment; 17 | 18 | public ExpressionMixinThis(ZenPosition position, String mixinTarget, IEnvironmentGlobal environment) { 19 | super(position); 20 | this.mixinTarget = mixinTarget; 21 | this.environment = environment; 22 | } 23 | 24 | @Override 25 | public void compile(boolean result, IEnvironmentMethod environment) { 26 | if (result) { 27 | MethodOutput output = environment.getOutput(); 28 | output.loadObject(0); 29 | output.checkCast(mixinTarget); 30 | } 31 | } 32 | 33 | @Override 34 | public ZenType getType() { 35 | return environment.getType(new LiteralType("L" + mixinTarget + ";")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/nat/CastingRuleCoerced.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript.nat; 2 | 3 | import stanhebben.zenscript.compiler.IEnvironmentMethod; 4 | import stanhebben.zenscript.type.ZenType; 5 | import stanhebben.zenscript.type.casting.ICastingRule; 6 | 7 | /** 8 | * @author youyihj 9 | */ 10 | public class CastingRuleCoerced implements ICastingRule { 11 | private final ZenType from; 12 | private final ZenType to; 13 | 14 | public CastingRuleCoerced(ZenType from, ZenType to) { 15 | this.from = from; 16 | this.to = to; 17 | } 18 | 19 | @Override 20 | public void compile(IEnvironmentMethod method) { 21 | method.getOutput().checkCast(to.toASMType().getInternalName()); 22 | } 23 | 24 | @Override 25 | public ZenType getInputType() { 26 | return from; 27 | } 28 | 29 | @Override 30 | public ZenType getResultingType() { 31 | return to; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/nat/ExpressionClassConstant.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript.nat; 2 | 3 | import org.objectweb.asm.Type; 4 | import stanhebben.zenscript.compiler.IEnvironmentMethod; 5 | import stanhebben.zenscript.expression.Expression; 6 | import stanhebben.zenscript.type.ZenType; 7 | import stanhebben.zenscript.util.ZenPosition; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public class ExpressionClassConstant extends Expression { 13 | private final Type value; 14 | 15 | public ExpressionClassConstant(ZenPosition position, Type value) { 16 | super(position); 17 | this.value = value; 18 | } 19 | 20 | @Override 21 | public void compile(boolean result, IEnvironmentMethod environment) { 22 | environment.getOutput().constant(value); 23 | } 24 | 25 | @Override 26 | public ZenType getType() { 27 | return ZenTypeClass.INSTANCE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/nat/ExpressionSuper.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript.nat; 2 | 3 | import stanhebben.zenscript.compiler.IEnvironmentMethod; 4 | import stanhebben.zenscript.expression.Expression; 5 | import stanhebben.zenscript.type.ZenType; 6 | import stanhebben.zenscript.util.ZenPosition; 7 | 8 | /** 9 | * @author youyihj 10 | */ 11 | public class ExpressionSuper extends Expression { 12 | private final ZenTypeJavaNativeSuper superType; 13 | 14 | public ExpressionSuper(ZenPosition position, ZenTypeJavaNative type) { 15 | super(position); 16 | this.superType = type.toSuper(); 17 | } 18 | 19 | @Override 20 | public void compile(boolean result, IEnvironmentMethod environment) { 21 | if (result) { 22 | environment.getOutput().loadObject(0); 23 | } 24 | } 25 | 26 | @Override 27 | public ZenType getType() { 28 | return superType; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/nat/ParsedZenClassCompile.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript.nat; 2 | 3 | /** 4 | * @author youyihj 5 | */ 6 | public class ParsedZenClassCompile { 7 | public static Class compile(String name, byte[] bytecode) { 8 | return new ClassLoader(ParsedZenClassCompile.class.getClassLoader()) { 9 | private Class find(byte[] array) { 10 | return defineClass(name, array, 0, array.length); 11 | } 12 | }.find(bytecode); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/nat/SymbolCallSuperConstructor.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript.nat; 2 | 3 | import stanhebben.zenscript.compiler.ITypeRegistry; 4 | import stanhebben.zenscript.expression.partial.IPartialExpression; 5 | import stanhebben.zenscript.symbols.IZenSymbol; 6 | import stanhebben.zenscript.util.ZenPosition; 7 | import youyihj.zenutils.impl.member.LookupRequester; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public class SymbolCallSuperConstructor implements IZenSymbol { 13 | private final ZenTypeJavaNative superClass; 14 | private final ITypeRegistry types; 15 | 16 | public SymbolCallSuperConstructor(ZenTypeJavaNative superClass, ITypeRegistry types) { 17 | this.superClass = superClass; 18 | this.types = types; 19 | } 20 | 21 | @Override 22 | public IPartialExpression instance(ZenPosition position) { 23 | return new PartialCallSuperConstructor(position, superClass.getClassData().constructors(LookupRequester.SUBCLASS), types); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/youyihj/zenutils/impl/zenscript/nat/ZenTypeJavaNativeSuper.java: -------------------------------------------------------------------------------- 1 | package youyihj.zenutils.impl.zenscript.nat; 2 | 3 | import stanhebben.zenscript.compiler.IEnvironmentGlobal; 4 | import youyihj.zenutils.impl.member.ClassData; 5 | import youyihj.zenutils.impl.member.LookupRequester; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author youyihj 11 | */ 12 | public class ZenTypeJavaNativeSuper extends ZenTypeJavaNative { 13 | public ZenTypeJavaNativeSuper(ClassData clazz, List superClasses) { 14 | super(clazz, superClasses); 15 | } 16 | 17 | @Override 18 | protected JavaNativeMemberSymbol getSymbol(String name, IEnvironmentGlobal environment, boolean isStatic) { 19 | return super.getSymbol(name, environment, isStatic).special(); 20 | } 21 | 22 | @Override 23 | LookupRequester getLookupRequester(IEnvironmentGlobal environment) { 24 | return LookupRequester.SUBCLASS; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/zenutils_at.cfg: -------------------------------------------------------------------------------- 1 | public net.minecraft.command.CommandHandler field_71561_b # commandSet 2 | public net.minecraft.world.World func_191504_a(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/AxisAlignedBB;ZLjava/util/List;)Z # getCollisionBoxes 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/zenutils/lang/en_us.lang: -------------------------------------------------------------------------------- 1 | commands.undefined.usage=Command Usage is undefined. 2 | tooltip.zenutils.energy=Energy: %s / %s RF 3 | message.zenutils.validate=Your scripts are different from the server. Ask the server admin for more info. -------------------------------------------------------------------------------- /src/main/resources/assets/zenutils/lang/zh_cn.lang: -------------------------------------------------------------------------------- 1 | commands.undefined.usage=未定义命令用法 2 | tooltip.zenutils.energy=能量: %s / %s RF 3 | message.zenutils.validate=你的脚本与服务端的不同。询问服务器管理员以获取更多信息。 -------------------------------------------------------------------------------- /src/main/resources/assets/zenutils/templates/all_directional_block.json: -------------------------------------------------------------------------------- 1 | { 2 | "forge_marker": 1, 3 | "defaults": { 4 | "textures": { 5 | "texture": "##TEXTURE##", 6 | "particle": "##TEXTURE##" 7 | }, 8 | "model": "base:storage", 9 | "uvlock": true, 10 | "transform": "forge:default-block" 11 | }, 12 | "variants": { 13 | "normal": [ 14 | {} 15 | ], 16 | "inventory": [ 17 | {} 18 | ], 19 | "facing=up": [ 20 | { 21 | "x": 270 22 | } 23 | ], 24 | "facing=down": [ 25 | { 26 | "x": 90 27 | } 28 | ], 29 | "facing=north": [ 30 | {} 31 | ], 32 | "facing=south": [ 33 | { 34 | "y": 180 35 | } 36 | ], 37 | "facing=west": [ 38 | { 39 | "y": 270 40 | } 41 | ], 42 | "facing=east": [ 43 | { 44 | "y": 90 45 | } 46 | ] 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/resources/assets/zenutils/templates/horizontal_directional_block.json: -------------------------------------------------------------------------------- 1 | { 2 | "forge_marker": 1, 3 | "defaults": { 4 | "textures": { 5 | "texture": "##TEXTURE##", 6 | "particle": "##TEXTURE##" 7 | }, 8 | "model": "base:storage", 9 | "uvlock": true, 10 | "transform": "forge:default-block" 11 | }, 12 | "variants": { 13 | "normal": [ 14 | {} 15 | ], 16 | "inventory": [ 17 | {} 18 | ], 19 | "facing=north": [ 20 | {} 21 | ], 22 | "facing=south": [ 23 | { 24 | "y": 180 25 | } 26 | ], 27 | "facing=west": [ 28 | { 29 | "y": 270 30 | } 31 | ], 32 | "facing=east": [ 33 | { 34 | "y": 90 35 | } 36 | ] 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/resources/assets/zenutils/templates/item_tool.json: -------------------------------------------------------------------------------- 1 | { 2 | "parent": "item/handheld", 3 | "textures": { 4 | "layer0": "##TEXTURE##" 5 | } 6 | } -------------------------------------------------------------------------------- /src/main/resources/assets/zenutils/templates/plane_rotatable_vertical_directional_block.json: -------------------------------------------------------------------------------- 1 | { 2 | "forge_marker": 1, 3 | "defaults": { 4 | "textures": { 5 | "texture": "##TEXTURE##", 6 | "particle": "##TEXTURE##" 7 | }, 8 | "model": "base:storage", 9 | "uvlock": true, 10 | "transform": "forge:default-block" 11 | }, 12 | "variants": { 13 | "normal": [ 14 | {} 15 | ], 16 | "inventory": [ 17 | {} 18 | ], 19 | "facing=up,plane_rot=down": [{ 20 | "transform": { 21 | "rotation": [90, 0, 0] 22 | } 23 | }], 24 | "facing=up,plane_rot=up": [{ 25 | "transform": { 26 | "rotation": [90, 0, 180] 27 | } 28 | }], 29 | "facing=up,plane_rot=left": [{ 30 | "transform": { 31 | "rotation": [90, 0, 90] 32 | } 33 | }], 34 | "facing=up,plane_rot=right": [{ 35 | "transform": { 36 | "rotation": [90, 0, 270] 37 | } 38 | }], 39 | "facing=down,plane_rot=down": [{ 40 | "transform": { 41 | "rotation": [270, 0, 0] 42 | } 43 | }], 44 | "facing=down,plane_rot=up": [{ 45 | "transform": { 46 | "rotation": [270, 0, 180] 47 | } 48 | }], 49 | "facing=down,plane_rot=left": [{ 50 | "transform": { 51 | "rotation": [270, 0, 90] 52 | } 53 | }], 54 | "facing=down,plane_rot=right": [{ 55 | "transform": { 56 | "rotation": [270, 0, 270] 57 | } 58 | }] 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/resources/assets/zenutils/templates/vertical_directional_block.json: -------------------------------------------------------------------------------- 1 | { 2 | "forge_marker": 1, 3 | "defaults": { 4 | "textures": { 5 | "texture": "##TEXTURE##", 6 | "particle": "##TEXTURE##" 7 | }, 8 | "model": "base:storage", 9 | "uvlock": true, 10 | "transform": "forge:default-block" 11 | }, 12 | "variants": { 13 | "normal": [{}], 14 | "inventory": [{}], 15 | "facing=up": [ 16 | { 17 | "x": 270 18 | } 19 | ], 20 | "facing=down": [ 21 | { 22 | "x": 90 23 | } 24 | ] 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid": "zenutils", 4 | "name": "ZenUtils", 5 | "description": "A CraftTweaker addon", 6 | "version": "${version}", 7 | "mcversion": "${mcversion}", 8 | "url": "", 9 | "updateUrl": "", 10 | "authorList": ["youyihj"], 11 | "credits": "", 12 | "logoFile": "", 13 | "screenshots": [], 14 | "dependencies": [] 15 | } 16 | ] 17 | -------------------------------------------------------------------------------- /src/main/resources/mixins.zenutils.custom.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "compatibilityLevel": "JAVA_8", 4 | "package": "youyihj.zenutils.impl.mixin.custom", 5 | "plugin": "youyihj.zenutils.impl.mixin.custom.CustomMixinPlugin", 6 | "minVersion": "0.8", 7 | "priority": 1000, 8 | "refmap": "mixins.zenutils.refmap.json", 9 | "injectors": { 10 | "maxShiftBy": 3 11 | }, 12 | "mixins": [ 13 | ], 14 | "client": [ 15 | ] 16 | } -------------------------------------------------------------------------------- /src/main/resources/mixins.zenutils.customscriptentrypoint.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "compatibilityLevel": "JAVA_8", 4 | "package": "youyihj.zenutils.impl.mixin.customscriptentrypoint", 5 | "minVersion": "0.8", 6 | "priority": 1000, 7 | "refmap": "mixins.zenutils.refmap.json", 8 | "mixins": [ 9 | "MixinFMLModContainer" 10 | ], 11 | "client": [ 12 | ] 13 | } -------------------------------------------------------------------------------- /src/main/resources/mixins.zenutils.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "compatibilityLevel": "JAVA_8", 4 | "package": "youyihj.zenutils.impl.mixin.crafttweaker", 5 | "plugin": "youyihj.zenutils.impl.mixin.crafttweaker.CraftTweakerMixinPlugin", 6 | "minVersion": "0.7.11", 7 | "setSourceFile": true, 8 | "priority": 1000, 9 | "refmap": "mixins.zenutils.refmap.json", 10 | "injectors": { 11 | "maxShiftBy": 2 12 | }, 13 | "mixins": [ 14 | "MixinBlockContent", 15 | "MixinCoTItemBracketHandler", 16 | "MixinCraftTweaker", 17 | "MixinCraftTweakerAPI", 18 | "MixinCraftTweakerImplementationAPI", 19 | "MixinEnvironmentClass", 20 | "MixinExpression", 21 | "MixinExpressionMap", 22 | "MixinItemContent", 23 | "MixinMCEntity", 24 | "MixinMCPlayerAnvilUpdateEvent", 25 | "MixinParsedClassConstructor", 26 | "MixinParsedExpression", 27 | "MixinParsedExpressionFunction", 28 | "MixinParsedZenClass", 29 | "MixinParsedZenClassField", 30 | "MixinParsedZenClassMethod", 31 | "MixinPartialType", 32 | "MixinPlayerAnvilUpdateEvent", 33 | "MixinPreprocessorManager", 34 | "MixinTemplateStringTokener", 35 | "MixinTokenStream", 36 | "MixinTypeRegistry", 37 | "MixinZenTokener", 38 | "MixinZenType", 39 | "MixinZenTypeAssociate", 40 | "MixinZenTypeNative", 41 | "TokenStreamAccessor" 42 | ], 43 | "client": [ 44 | ] 45 | } -------------------------------------------------------------------------------- /src/main/resources/mixins.zenutils.randomtickevent.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "compatibilityLevel": "JAVA_8", 4 | "package": "youyihj.zenutils.impl.mixin.vanilla", 5 | "minVersion": "0.7.11", 6 | "setSourceFile": true, 7 | "priority": 1000, 8 | "refmap": "mixins.zenutils.refmap.json", 9 | "injectors": { 10 | "maxShiftBy": 2 11 | }, 12 | "mixins": [ 13 | "MixinWorldServer" 14 | ], 15 | "client": [ 16 | ] 17 | } -------------------------------------------------------------------------------- /src/main/resources/mixins.zenutils.simpledimensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "compatibilityLevel": "JAVA_8", 4 | "package": "youyihj.zenutils.impl.mixin.simpledimensions", 5 | "minVersion": "0.7.11", 6 | "setSourceFile": true, 7 | "priority": 1000, 8 | "refmap": "mixins.zenutils.refmap.json", 9 | "mixins": [ 10 | "MixinWorldCustom" 11 | ], 12 | "client": [ 13 | ] 14 | } -------------------------------------------------------------------------------- /src/main/resources/mixins.zenutils.vanilla.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "compatibilityLevel": "JAVA_8", 4 | "package": "youyihj.zenutils.impl.mixin.vanilla", 5 | "plugin": "youyihj.zenutils.impl.mixin.vanilla.VanillaMixinPlugin", 6 | "minVersion": "0.7.11", 7 | "setSourceFile": true, 8 | "priority": 1000, 9 | "refmap": "mixins.zenutils.refmap.json", 10 | "injectors": { 11 | "maxShiftBy": 2 12 | }, 13 | "mixins": [ 14 | "ContainerRepairAccessor", 15 | "MixinAnvilUpdateEvent", 16 | "MixinEntityItem", 17 | "MixinForgeHooks" 18 | ], 19 | "client": [ 20 | ] 21 | } -------------------------------------------------------------------------------- /src/main/resources/mixins.zenutils.zenbootstrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "compatibilityLevel": "JAVA_8", 4 | "package": "youyihj.zenutils.impl.mixin.zenbootstrap", 5 | "plugin": "youyihj.zenutils.impl.mixin.zenbootstrap.ZenMixinBootstrapPlugin", 6 | "minVersion": "0.7.11", 7 | "setSourceFile": true, 8 | "priority": 1000, 9 | "refmap": "mixins.zenutils.refmap.json", 10 | "injectors": { 11 | "maxShiftBy": 2 12 | }, 13 | "mixins": [ 14 | "MixinCleanroomLoadController", 15 | "MixinForgeLoadController" 16 | ], 17 | "client": [ 18 | ] 19 | } -------------------------------------------------------------------------------- /src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "zenutils resources", 4 | "pack_format": 3 5 | } 6 | } --------------------------------------------------------------------------------