├── .gitattributes ├── .github └── workflows │ ├── build-on-pr.yml │ ├── devbuild.yml │ └── publish-release.yml ├── .gitignore ├── LICENSE ├── README-ES.md ├── README.md ├── build.gradle ├── docs └── scarpet │ ├── Documentation.md │ ├── Full.md │ ├── api │ ├── Auxiliary.md │ ├── BlockIterations.md │ ├── BlocksAndWorldAccess.md │ ├── Entities.md │ ├── Events.md │ ├── Inventories.md │ ├── Overview.md │ ├── Scoreboard.md │ └── ScriptCommand.md │ ├── language │ ├── Containers.md │ ├── FunctionsAndControlFlow.md │ ├── LoopsAndHigherOrderFunctions.md │ ├── Math.md │ ├── Operators.md │ ├── Overview.md │ ├── SystemFunctions.md │ └── VariablesAndConstants.md │ └── resources │ ├── editors │ ├── idea │ │ ├── 1.txt │ │ ├── 2.txt │ │ ├── 3.txt │ │ ├── 4.txt │ │ └── Idea.md │ └── npp │ │ ├── scarpet.xml │ │ ├── scarpet_v1.0_notepad++.xml │ │ ├── scarpet_v1.4_notepad++.xml │ │ ├── scarpet_v1.5_notepad++.xml │ │ ├── scarpet_v1.6_notepad++.xml │ │ └── scarpet_v1.7_notepad++.xml │ └── media │ ├── idea_customize.png │ └── idea_settings.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack.yml ├── mergedoc.bat ├── mergedoc.sh ├── settings.gradle └── src └── main ├── java └── carpet │ ├── CarpetExtension.java │ ├── CarpetServer.java │ ├── CarpetSettings.java │ ├── api │ └── settings │ │ ├── CarpetRule.java │ │ ├── InvalidRuleValueException.java │ │ ├── Rule.java │ │ ├── RuleCategory.java │ │ ├── RuleHelper.java │ │ ├── SettingsManager.java │ │ ├── Validator.java │ │ └── Validators.java │ ├── commands │ ├── CounterCommand.java │ ├── DistanceCommand.java │ ├── DrawCommand.java │ ├── InfoCommand.java │ ├── LogCommand.java │ ├── MobAICommand.java │ ├── PerimeterInfoCommand.java │ ├── PlayerCommand.java │ ├── ProfileCommand.java │ ├── SpawnCommand.java │ └── TestCommand.java │ ├── fakes │ ├── AbstractContainerMenuInterface.java │ ├── BiomeInterface.java │ ├── BlockEntityInterface.java │ ├── BlockPistonBehaviourInterface.java │ ├── BlockPredicateInterface.java │ ├── BlockStateArgumentInterface.java │ ├── ChunkHolderInterface.java │ ├── ClientConnectionInterface.java │ ├── CommandDispatcherInterface.java │ ├── CommandNodeInterface.java │ ├── CoralFeatureInterface.java │ ├── DefaultRedstoneWireEvaluatorInferface.java │ ├── EntityInterface.java │ ├── FoodDataInterface.java │ ├── IngredientInterface.java │ ├── InventoryBearerInterface.java │ ├── ItemEntityInterface.java │ ├── LevelInterface.java │ ├── Lighting_scarpetChunkCreationInterface.java │ ├── LivingEntityInterface.java │ ├── MinecraftServerInterface.java │ ├── MobEntityInterface.java │ ├── PistonBlockEntityInterface.java │ ├── PistonBlockInterface.java │ ├── PlayerListHudInterface.java │ ├── PortalProcessorInterface.java │ ├── RandomStateVisitorAccessor.java │ ├── RedstoneWireBlockInterface.java │ ├── ServerGamePacketListenerImplInterface.java │ ├── ServerLightingProviderInterface.java │ ├── ServerPlayerInteractionManagerInterface.java │ ├── ServerPlayerInterface.java │ ├── ServerWorldInterface.java │ ├── SimpleEntityLookupInterface.java │ ├── SpawnGroupInterface.java │ ├── SpawnHelperInnerInterface.java │ ├── ThreadedAnvilChunkStorageInterface.java │ ├── TicketsFetcherInterface.java │ ├── TntEntityInterface.java │ └── WorldChunkInterface.java │ ├── helpers │ ├── BlockRotator.java │ ├── CarpetTaintedList.java │ ├── EntityPlayerActionPack.java │ ├── FertilizableCoral.java │ ├── HopperCounter.java │ ├── OptimizedExplosion.java │ ├── ParticleDisplay.java │ ├── QuasiConnectivity.java │ └── RedstoneWireTurbo.java │ ├── logging │ ├── HUDController.java │ ├── HUDLogger.java │ ├── Logger.java │ ├── LoggerRegistry.java │ └── logHelpers │ │ ├── ExplosionLogHelper.java │ │ ├── PacketCounter.java │ │ ├── PathfindingVisualizer.java │ │ ├── TNTLogHelper.java │ │ └── TrajectoryLogHelper.java │ ├── mixins │ ├── AbstractArrowMixin.java │ ├── AbstractContainerMenuSubclasses_scarpetMixin.java │ ├── AbstractContainerMenu_ctrlQCraftingMixin.java │ ├── AbstractContainerMenu_scarpetMixin.java │ ├── AbstractCraftingMenu_scarpetMixin.java │ ├── AbstractFurnaceMenu_scarpetMixin.java │ ├── AbstractMinecart_scarpetEventsMixin.java │ ├── ArmorStand_scarpetMarkerMixin.java │ ├── BarrierBlock_updateSuppressionBlockMixin.java │ ├── Biome_scarpetMixin.java │ ├── BlockBehaviourBlockStateBase_mixin.java │ ├── BlockEntity_movableBEMixin.java │ ├── BlockInput_fillUpdatesMixin.java │ ├── BlockInput_scarpetMixin.java │ ├── BlockItem_creativeNoClipMixin.java │ ├── BlockItem_scarpetEventMixin.java │ ├── BlockPredicate_scarpetMixin.java │ ├── BoundTickingBlockEntity_profilerMixin.java │ ├── BuddingAmethystBlock_movableAmethystMixin.java │ ├── ChainBlock_customStickyMixin.java │ ├── ChestBlock_customStickyMixin.java │ ├── ChunkAccess_warningsMixin.java │ ├── ChunkGenerator_customMobSpawnsMixin.java │ ├── ChunkHolder_scarpetChunkCreationMixin.java │ ├── ChunkMap_creativePlayersLoadChunksMixin.java │ ├── ChunkMap_profilerMixin.java │ ├── ChunkMap_scarpetChunkCreationMixin.java │ ├── ClientCommonPacketListenerImpl_customPacketMixin.java │ ├── ClientPacketListener_clientCommandMixin.java │ ├── ClientPacketListener_customPacketsMixin.java │ ├── ClientPacketListener_explosionMixin.java │ ├── CloneCommands_fillUpdatesMixin.java │ ├── CollectingNeighborUpdaterAccessor.java │ ├── CommandDispatcher_scarpetCommandsMixin.java │ ├── CommandNode_scarpetCommandsMixin.java │ ├── Commands_customCommandsMixin.java │ ├── Connection_packetCounterMixin.java │ ├── CoralFanBlock_renewableCoralMixin.java │ ├── CoralFeature_renewableCoralMixin.java │ ├── CoralPlantBlock_renewableCoralMixin.java │ ├── CustomPacketPayload_networkStuffMixin.java │ ├── DebugRenderer_scarpetRenderMixin.java │ ├── DefaultRedstoneWireEvaluator_redstoneMixin.java │ ├── DirectionMixin.java │ ├── DispenserBlock_cactusMixin.java │ ├── DispenserBlock_qcMixin.java │ ├── Display_scarpetEventMixin.java │ ├── DistanceManager_scarpetMixin.java │ ├── DynamicGraphMinFixedPoint_resetChunkInterface.java │ ├── EndCrystal_scarpetEventsMixin.java │ ├── EntityMixin.java │ ├── Entity_scarpetEventsMixin.java │ ├── ExperienceOrb_xpNoCooldownMixin.java │ ├── ExplosionAccessor.java │ ├── Explosion_optimizedTntMixin.java │ ├── Explosion_scarpetEventMixin.java │ ├── Explosion_xpFromBlocksMixin.java │ ├── FallingBlockEntityMixin.java │ ├── FallingBlockEntity_scarpetEventsMixin.java │ ├── FillCommandMixin.java │ ├── FlowingFluid_liquidDamageDisabledMixin.java │ ├── FoodData_scarpetMixin.java │ ├── ForceLoadCommand_forceLoadLimitMixin.java │ ├── Guardian_renewableSpongesMixin.java │ ├── Gui_tablistMixin.java │ ├── HangingEntity_scarpetEventsMixin.java │ ├── HopperBlockEntity_counterMixin.java │ ├── HopperBlock_cactusMixin.java │ ├── HorseBaseEntity_scarpetMixin.java │ ├── HugeFungusFeatureMixin.java │ ├── Husk_templesMixin.java │ ├── InfestedBlock_gravelMixin.java │ ├── Ingredient_scarpetMixin.java │ ├── Inventory_scarpetEventMixin.java │ ├── ItemEntityMixin.java │ ├── ItemStack_stackableShulkerBoxesMixin.java │ ├── Item_missingToolsMixin.java │ ├── LavaFluid_renewableDeepslateMixin.java │ ├── LayerLightEngine_scarpetChunkCreationMixin.java │ ├── LayerLightSectionStorage_scarpetChunkCreationMixin.java │ ├── LevelChunk_fillUpdatesMixin.java │ ├── LevelChunk_movableBEMixin.java │ ├── LevelEntityGetterAdapter_scarpetMixin.java │ ├── LevelLightEngine_scarpetChunkCreationMixin.java │ ├── LevelRenderer_creativeNoClipMixin.java │ ├── LevelRenderer_fogOffMixin.java │ ├── LevelRenderer_scarpetRenderMixin.java │ ├── Level_fillUpdatesMixin.java │ ├── Level_getOtherEntitiesLimited.java │ ├── Level_movableBEMixin.java │ ├── Level_scarpetPlopMixin.java │ ├── Level_tickMixin.java │ ├── LiquidBlock_renewableBlackstoneMixin.java │ ├── LiquidBlock_renewableDeepslateMixin.java │ ├── LivingEntity_cleanLogsMixin.java │ ├── LivingEntity_creativeFlyMixin.java │ ├── LivingEntity_maxCollisionsMixin.java │ ├── LivingEntity_scarpetEventsMixin.java │ ├── MerchantResultSlot_scarpetEventMixin.java │ ├── MinecraftMixin.java │ ├── MinecraftServer_coreMixin.java │ ├── MinecraftServer_pingPlayerSampleLimit.java │ ├── MinecraftServer_scarpetMixin.java │ ├── MinecraftServer_tickspeedMixin.java │ ├── Minecraft_tickMixin.java │ ├── MobCategory_spawnMixin.java │ ├── MobMixin.java │ ├── NaturalSpawnerMixin.java │ ├── Objective_scarpetMixin.java │ ├── PathNavigation_pathfindingMixin.java │ ├── PerfCommand_permissionMixin.java │ ├── PersistentEntitySectionManager_scarpetMixin.java │ ├── PieceGeneratorSupplier_plopMixin.java │ ├── PiglinBrute_getPlacementTypeMixin.java │ ├── PistonBaseBlock_movableBEMixin.java │ ├── PistonBaseBlock_qcMixin.java │ ├── PistonBaseBlock_rotatorBlockMixin.java │ ├── PistonHeadRenderer_movableBEMixin.java │ ├── PistonMovingBlockEntity_movableBEMixin.java │ ├── PistonMovingBlockEntity_playerHandlingMixin.java │ ├── PistonStructureResolver_customStickyMixin.java │ ├── PistonStructureResolver_pushLimitMixin.java │ ├── PlayerList_coreMixin.java │ ├── PlayerList_fakePlayersMixin.java │ ├── PlayerList_scarpetEventsMixin.java │ ├── PlayerTabOverlayMixin.java │ ├── Player_antiCheatDisabledMixin.java │ ├── Player_creativeNoClipMixin.java │ ├── Player_fakePlayersMixin.java │ ├── Player_parrotMixin.java │ ├── Player_scarpetEventsMixin.java │ ├── Player_xpNoCooldownMixin.java │ ├── PoiRecord_scarpetMixin.java │ ├── PortalProcessor_scarpetMixin.java │ ├── PoweredRailBlock_powerLimitMixin.java │ ├── PrimedTntMixin.java │ ├── PrimedTnt_scarpetEventsMixin.java │ ├── RandomState_ScarpetMixin.java │ ├── RedstoneWireBlock_fastMixin.java │ ├── ReloadCommand_reloadAppsMixin.java │ ├── SaplingBlock_desertShrubsMixin.java │ ├── Scoreboard_scarpetMixin.java │ ├── SculkSensorBlockEntityVibrationConfig_sculkSensorRangeMixin.java │ ├── ServerChunkCacheMixin.java │ ├── ServerChunkCache_profilerMixin.java │ ├── ServerFunctionManager_profilerMixin.java │ ├── ServerGamePacketListenerImplMixin.java │ ├── ServerGamePacketListenerImpl_antiCheatDisabledMixin.java │ ├── ServerGamePacketListenerImpl_coreMixin.java │ ├── ServerGamePacketListenerImpl_interactionUpdatesMixin.java │ ├── ServerGamePacketListenerImpl_scarpetEventsMixin.java │ ├── ServerGamePacketListenerimpl_connectionMixin.java │ ├── ServerLevel_scarpetMixin.java │ ├── ServerLevel_tickMixin.java │ ├── ServerPlayerGameMode_antiCheatMixin.java │ ├── ServerPlayerGameMode_cactusMixin.java │ ├── ServerPlayerGameMode_scarpetEventsMixin.java │ ├── ServerPlayer_actionPackMixin.java │ ├── ServerPlayer_scarpetEventMixin.java │ ├── ServerStatus_motdMixin.java │ ├── ServerboundSetStructureBlockPacketMixin.java │ ├── SetBlockCommand_fillUpdatesMixin.java │ ├── ShulkerBoxAccessMixin.java │ ├── ShulkerBoxBlockEntity_creativeNoClipMixin.java │ ├── SpawnState_scarpetMixin.java │ ├── StandingAndWallBlockItem_creativeNoClipMixin.java │ ├── StructureBlockEntity_fillUpdatesMixin.java │ ├── StructureBlockEntity_limitsMixin.java │ ├── StructureBlockRenderer_mixin.java │ ├── StructurePiece_scarpetPlopMixin.java │ ├── StructureTemplate_fillUpdatesMixin.java │ ├── SummonCommand_lightningMixin.java │ ├── SystemReport_addScarpetAppsMixin.java │ ├── TagPredicate_scarpetMixin.java │ ├── TheEndGatewayBlockEntity_creativeNoClipMixin.java │ ├── ThreadedLevelLightEngine_scarpetChunkCreationMixin.java │ ├── ThreadedLevelLightEngine_scarpetMixin.java │ ├── ThrowableProjectileMixin.java │ ├── TicketStorage_scarpetMixin.java │ ├── TntBlock_noUpdateMixin.java │ ├── UseOnContext_cactusMixin.java │ ├── Villager_aiMixin.java │ ├── WitherBoss_moreBlueMixin.java │ ├── WoolCarpetBlock_placeMixin.java │ ├── WorldBorder_syncedWorldBorderMixin.java │ └── WorldGenRegion_scarpetPlopMixin.java │ ├── network │ ├── CarpetClient.java │ ├── ClientNetworkHandler.java │ └── ServerNetworkHandler.java │ ├── patches │ ├── EntityPlayerMPFake.java │ ├── FakeClientConnection.java │ ├── NetHandlerPlayServerFake.java │ └── TickSyncedBorderExtent.java │ ├── script │ ├── CarpetContext.java │ ├── CarpetEventServer.java │ ├── CarpetExpression.java │ ├── CarpetScriptHost.java │ ├── CarpetScriptServer.java │ ├── Context.java │ ├── EntityEventsGroup.java │ ├── Expression.java │ ├── Fluff.java │ ├── LazyValue.java │ ├── Module.java │ ├── ScriptCommand.java │ ├── ScriptHost.java │ ├── ScriptServer.java │ ├── Token.java │ ├── Tokenizer.java │ ├── annotation │ │ ├── AnnotationParser.java │ │ ├── ListConverter.java │ │ ├── Locator.java │ │ ├── MapConverter.java │ │ ├── OptionalConverter.java │ │ ├── OutputConverter.java │ │ ├── Param.java │ │ ├── ScarpetFunction.java │ │ ├── SimpleTypeConverter.java │ │ ├── ValueCaster.java │ │ ├── ValueConverter.java │ │ └── package-info.java │ ├── api │ │ ├── Auxiliary.java │ │ ├── BlockIterators.java │ │ ├── Entities.java │ │ ├── Inventories.java │ │ ├── Monitoring.java │ │ ├── Scoreboards.java │ │ ├── Threading.java │ │ ├── WorldAccess.java │ │ └── package-info.java │ ├── argument │ │ ├── Argument.java │ │ ├── BlockArgument.java │ │ ├── FileArgument.java │ │ ├── FunctionArgument.java │ │ ├── Vector3Argument.java │ │ └── package-info.java │ ├── command │ │ ├── CommandArgument.java │ │ ├── CommandToken.java │ │ └── package-info.java │ ├── exception │ │ ├── BreakStatement.java │ │ ├── CarpetExpressionException.java │ │ ├── ContinueStatement.java │ │ ├── ExitStatement.java │ │ ├── ExpressionException.java │ │ ├── IntegrityException.java │ │ ├── InternalExpressionException.java │ │ ├── InvalidCallbackException.java │ │ ├── LoadException.java │ │ ├── ProcessedThrowStatement.java │ │ ├── ResolvedException.java │ │ ├── ReturnStatement.java │ │ ├── StacklessRuntimeException.java │ │ ├── ThrowStatement.java │ │ ├── Throwables.java │ │ └── package-info.java │ ├── external │ │ ├── Carpet.java │ │ ├── Vanilla.java │ │ ├── VanillaClient.java │ │ └── package-info.java │ ├── language │ │ ├── Arithmetic.java │ │ ├── ControlFlow.java │ │ ├── DataStructures.java │ │ ├── Functions.java │ │ ├── Loops.java │ │ ├── Operators.java │ │ ├── Sys.java │ │ ├── Threading.java │ │ └── package-info.java │ ├── package-info.java │ ├── utils │ │ ├── AppStoreManager.java │ │ ├── BiomeInfo.java │ │ ├── Colors.java │ │ ├── EntityTools.java │ │ ├── EquipmentInventory.java │ │ ├── Experimental.java │ │ ├── FeatureGenerator.java │ │ ├── GlocalFlag.java │ │ ├── InputValidator.java │ │ ├── ParticleParser.java │ │ ├── PerlinNoiseSampler.java │ │ ├── RecipeHelper.java │ │ ├── ScarpetJsonDeserializer.java │ │ ├── ShapeDispatcher.java │ │ ├── ShapesRenderer.java │ │ ├── SimplexNoiseSampler.java │ │ ├── SnoopyCommandSource.java │ │ ├── SystemInfo.java │ │ ├── Tracer.java │ │ ├── WorldTools.java │ │ ├── package-info.java │ │ └── shapes │ │ │ ├── ShapeDirection.java │ │ │ └── package-info.java │ └── value │ │ ├── AbstractListValue.java │ │ ├── BlockValue.java │ │ ├── BooleanValue.java │ │ ├── ContainerValueInterface.java │ │ ├── EntityValue.java │ │ ├── FormattedTextValue.java │ │ ├── FrameworkValue.java │ │ ├── FunctionAnnotationValue.java │ │ ├── FunctionSignatureValue.java │ │ ├── FunctionUnpackedArgumentsValue.java │ │ ├── FunctionValue.java │ │ ├── LContainerValue.java │ │ ├── LazyListValue.java │ │ ├── ListValue.java │ │ ├── MapValue.java │ │ ├── NBTSerializableValue.java │ │ ├── NullValue.java │ │ ├── NumericValue.java │ │ ├── ScreenValue.java │ │ ├── StringValue.java │ │ ├── ThreadValue.java │ │ ├── UndefValue.java │ │ ├── Value.java │ │ ├── ValueConversions.java │ │ └── package-info.java │ ├── settings │ ├── Condition.java │ ├── ParsedRule.java │ ├── Rule.java │ ├── RuleCategory.java │ ├── SettingsManager.java │ └── Validator.java │ └── utils │ ├── BlockInfo.java │ ├── CarpetProfiler.java │ ├── CarpetRulePrinter.java │ ├── CommandHelper.java │ ├── DistanceCalculator.java │ ├── EvictingQueue.java │ ├── FabricAPIHooks.java │ ├── Messenger.java │ ├── MobAI.java │ ├── PerimeterDiagnostics.java │ ├── SpawnOverrides.java │ ├── SpawnReporter.java │ ├── TranslationKeys.java │ ├── Translations.java │ └── WoolTool.java └── resources ├── assets └── carpet │ ├── icon.png │ ├── lang │ ├── en_us.json │ ├── es_ar.json │ ├── fr_fr.json │ ├── pt_br.json │ ├── zh_cn.json │ └── zh_tw.json │ └── scripts │ ├── ai_tracker.sc │ ├── camera.sc │ ├── chunk_display.sc │ ├── distance_beta.sc │ ├── draw_beta.sc │ ├── event_test.sc │ ├── math.scl │ ├── overlay.sc │ ├── shapes.scl │ └── stats_test.sc ├── carpet.accesswidener ├── carpet.mixins.json └── fabric.mod.json /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sc linguist-language=Python 2 | *.scl linguist-language=Python 3 | -------------------------------------------------------------------------------- /.github/workflows/build-on-pr.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Pull Request Builds 5 | 6 | on: [pull_request] 7 | 8 | jobs: 9 | Build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Set up JDK 21 15 | uses: actions/setup-java@v4 16 | with: 17 | distribution: 'temurin' 18 | java-version: 21 19 | cache: 'gradle' 20 | - name: Grant execute permission to gradlew 21 | run: chmod +x gradlew 22 | - name: Build with Gradle 23 | run: ./gradlew build 24 | - uses: actions/upload-artifact@v4 25 | with: 26 | name: "Compiled artifacts for Pull Request #${{github.event.number}}" 27 | path: build/libs 28 | -------------------------------------------------------------------------------- /.github/workflows/devbuild.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Development Builds 5 | 6 | on: [push] 7 | 8 | jobs: 9 | Build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v4 15 | - name: Set up JDK 21 16 | uses: actions/setup-java@v4 17 | with: 18 | distribution: 'temurin' 19 | java-version: 21 20 | cache: 'gradle' 21 | - name: Grant execute permission to gradlew 22 | run: chmod +x gradlew 23 | - name: Build with Gradle 24 | run: ./gradlew build 25 | - uses: actions/upload-artifact@v4 26 | with: 27 | name: Compiled artifacts for ${{ github.sha }} 28 | path: build/libs 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # gradle 2 | 3 | .gradle/ 4 | build/ 5 | out/ 6 | lout/ 7 | classes/ 8 | publish/ 9 | 10 | # git 11 | 12 | .shelf/ 13 | 14 | # idea 15 | 16 | .idea/ 17 | *.iml 18 | *.ipr 19 | *.iws 20 | 21 | # eclipse 22 | *.launch 23 | 24 | # vscode 25 | 26 | .settings/ 27 | .vscode/ 28 | bin/ 29 | .classpath 30 | .project 31 | *.code-workspace 32 | 33 | # fabric 34 | 35 | run/ 36 | logs/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 gnembon 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 | -------------------------------------------------------------------------------- /docs/scarpet/Documentation.md: -------------------------------------------------------------------------------- 1 | # Scarpet Language Documentation 2 | 3 | ## Language Specification 4 | 5 | [Overview](/docs/scarpet/language/Overview.md) 6 | 7 | [Variables and Constants](/docs/scarpet/language/VariablesAndConstants.md) 8 | 9 | [Operators](/docs/scarpet/language/Operators.md) 10 | 11 | [Mathematical Functions](/docs/scarpet/language/Math.md) 12 | 13 | [System Functions](/docs/scarpet/language/SystemFunctions.md) 14 | 15 | [Loops and Higher Order Functions](/docs/scarpet/language/LoopsAndHigherOrderFunctions.md) 16 | 17 | [User Defined Functions and Control Flow](/docs/scarpet/language/FunctionsAndControlFlow.md) 18 | 19 | [Container Types](/docs/scarpet/language/Containers.md) 20 | 21 | ## Minecraft API 22 | 23 | [Overview](/docs/scarpet/api/Overview.md) 24 | 25 | [Blocks and World Access](/docs/scarpet/api/BlocksAndWorldAccess.md) 26 | 27 | [Block Iterations](/docs/scarpet/api/BlockIterations.md) 28 | 29 | [Entities](/docs/scarpet/api/Entities.md) 30 | 31 | [Inventories](/docs/scarpet/api/Inventories.md) 32 | 33 | [Events](/docs/scarpet/api/Events.md) 34 | 35 | [Scoreboard manipulation](/docs/scarpet/api/Scoreboard.md) 36 | 37 | [Auxiliary Functions](/docs/scarpet/api/Auxiliary.md) 38 | 39 | [`/script` Command](/docs/scarpet/api/ScriptCommand.md) 40 | 41 | ## [One Page](/docs/scarpet/Full.md) 42 | 43 | -------------------------------------------------------------------------------- /docs/scarpet/resources/editors/idea/1.txt: -------------------------------------------------------------------------------- 1 | abs 2 | acos 3 | acosh 4 | acot 5 | all 6 | and 7 | asin 8 | asinh 9 | atan 10 | atan2 11 | atanh 12 | bitwise_and 13 | bitwise_or 14 | bitwise_xor 15 | bitwise_shift_left 16 | bitwise_shift_right 17 | bitwise_roll_left 18 | bitwise_roll_right 19 | bitwise_not 20 | bitwise_popcount 21 | bool 22 | break 23 | call 24 | ceil 25 | c_for 26 | continue 27 | copy 28 | cos 29 | cosh 30 | cot 31 | coth 32 | csc 33 | csch 34 | decreasing 35 | deg 36 | delete 37 | difference 38 | double_to_long_bits 39 | equal 40 | exit 41 | fact 42 | filter 43 | first 44 | floor 45 | for 46 | get 47 | has 48 | hash_code 49 | if 50 | import 51 | increasing 52 | join 53 | keys 54 | l 55 | length 56 | log 57 | log10 58 | log1p 59 | long_bits_to_double 60 | loop 61 | lower 62 | m 63 | mandelbrot 64 | map 65 | max 66 | min 67 | nondecreasing 68 | nonincreasing 69 | not 70 | number 71 | or 72 | outer 73 | pairs 74 | perlin 75 | print 76 | product 77 | profile_expr 78 | put 79 | quotient 80 | rad 81 | rand 82 | range 83 | reduce 84 | relu 85 | replace 86 | replace_first 87 | reset_seed 88 | return 89 | round 90 | sec 91 | sech 92 | simplex 93 | sin 94 | sinh 95 | sleep 96 | slice 97 | sort 98 | sort_key 99 | sum 100 | synchronize 101 | system_variable_get 102 | system_variable_set 103 | split 104 | sqrt 105 | str 106 | tan 107 | tanh 108 | task 109 | task_completed 110 | task_count 111 | task_dock 112 | task_join 113 | task_thread 114 | task_value 115 | then 116 | throw 117 | time 118 | title 119 | try 120 | type 121 | undef 122 | unique 123 | upper 124 | values 125 | var 126 | vars 127 | while 128 | -------------------------------------------------------------------------------- /docs/scarpet/resources/editors/idea/3.txt: -------------------------------------------------------------------------------- 1 | _ 2 | _a 3 | _i 4 | _x 5 | _y 6 | _z 7 | _trace 8 | euler 9 | false 10 | null 11 | pi 12 | true -------------------------------------------------------------------------------- /docs/scarpet/resources/editors/idea/Idea.md: -------------------------------------------------------------------------------- 1 | # Custom Language Support for Intellij 2 | 3 | ### Add scarpet to registered file types (`.sc` and `.scl`) 4 | 5 | ![Settings -> File Types](/docs/scarpet/resources/media/idea_settings.png) 6 | 7 | ### When adding use the following settings 8 | 9 | ![Customize your settings](/docs/scarpet/resources/media/idea_customize.png) 10 | 11 | ### Grab lists of keywords (1,2,3 and 4) from the following files: 12 | 13 | [1](/docs/scarpet/resources/editors/idea/1.txt) 14 | [2](/docs/scarpet/resources/editors/idea/2.txt) 15 | [3](/docs/scarpet/resources/editors/idea/3.txt) 16 | [4](/docs/scarpet/resources/editors/idea/4.txt) 17 | -------------------------------------------------------------------------------- /docs/scarpet/resources/media/idea_customize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnembon/fabric-carpet/5f9744e065242643b3307c720c4961480f3b4c20/docs/scarpet/resources/media/idea_customize.png -------------------------------------------------------------------------------- /docs/scarpet/resources/media/idea_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnembon/fabric-carpet/5f9744e065242643b3307c720c4961480f3b4c20/docs/scarpet/resources/media/idea_settings.png -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Done to increase the memory available to gradle. 2 | org.gradle.jvmargs=-Xmx1G 3 | 4 | # Fabric Properties 5 | # check https://fabricmc.net/develop/ 6 | minecraft_version=1.21.6-pre1 7 | loader_version=0.16.10 8 | jsr305_version=3.0.2 9 | fabric_version=0.119.5+1.21.5 10 | 11 | # Mod Properties 12 | mod_version = 1.4.175 13 | maven_group = carpet 14 | archives_base_name = fabric-carpet 15 | 16 | # Release Action properties for Curseforge and Snapshots 17 | # The Curseforge versions "names" or ids for the main branch (comma separated: 1.16.4,1.16.5) 18 | # This is needed because CF uses too vague names for prereleases and release candidates 19 | # Can also be the version ID directly coming from https://minecraft.curseforge.com/api/game/versions?token=[API_TOKEN] 20 | release-curse-versions = Minecraft 1.21:1.21.6-Snapshot 21 | # Whether or not to build another branch on release 22 | release-extra-branch = false 23 | # The name of the second branch to release 24 | release-extra-branch-name = 1.20.4 25 | # The "name" or id of the Curseforge version for the secondary branch 26 | # This is needed because CF uses too vague names for snapshots 27 | # Can also be the version ID directly coming from https://minecraft.curseforge.com/api/game/versions?token=[API_TOKEN] 28 | release-extra-curse-version = Minecraft 1.20:1.20.4-Snapshot 29 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnembon/fabric-carpet/5f9744e065242643b3307c720c4961480f3b4c20/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-8.11-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | before_install: 2 | - sdk install java 21.0.2-open 3 | - sdk use java 21.0.2-open 4 | -------------------------------------------------------------------------------- /mergedoc.bat: -------------------------------------------------------------------------------- 1 | cat docs/scarpet/language/Overview.md docs/scarpet/language/VariablesAndConstants.md docs/scarpet/language/Operators.md docs/scarpet/language/Math.md docs/scarpet/language/SystemFunctions.md docs/scarpet/language/LoopsAndHigherOrderFunctions.md docs/scarpet/language/FunctionsAndControlFlow.md docs/scarpet/language/Containers.md docs/scarpet/api/Overview.md docs/scarpet/api/BlocksAndWorldAccess.md docs/scarpet/api/BlockIterations.md docs/scarpet/api/Entities.md docs/scarpet/api/Inventories.md docs/scarpet/api/Events.md docs/scarpet/api/Scoreboard.md docs/scarpet/api/Auxiliary.md docs/scarpet/api/ScriptCommand.md > docs/scarpet/Full.md 2 | 3 | -------------------------------------------------------------------------------- /mergedoc.sh: -------------------------------------------------------------------------------- 1 | cat docs/scarpet/language/Overview.md docs/scarpet/language/VariablesAndConstants.md docs/scarpet/language/Operators.md docs/scarpet/language/Math.md docs/scarpet/language/SystemFunctions.md docs/scarpet/language/LoopsAndHigherOrderFunctions.md docs/scarpet/language/FunctionsAndControlFlow.md docs/scarpet/language/Containers.md docs/scarpet/api/Overview.md docs/scarpet/api/BlocksAndWorldAccess.md docs/scarpet/api/BlockIterations.md docs/scarpet/api/Entities.md docs/scarpet/api/Inventories.md docs/scarpet/api/Events.md docs/scarpet/api/Scoreboard.md docs/scarpet/api/Auxiliary.md docs/scarpet/api/ScriptCommand.md > docs/scarpet/Full.md 2 | 3 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { // for all the fabric stuffs 4 | name = 'Fabric' 5 | url = 'https://maven.fabricmc.net/' 6 | } 7 | gradlePluginPortal() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/carpet/api/settings/InvalidRuleValueException.java: -------------------------------------------------------------------------------- 1 | package carpet.api.settings; 2 | 3 | import carpet.utils.Messenger; 4 | import net.minecraft.commands.CommandSourceStack; 5 | 6 | /** 7 | *

An {@link Exception} thrown when the value given for a {@link CarpetRule} is invalid.

8 | * 9 | *

It can hold a message to be sent to the executing source.

10 | */ 11 | public class InvalidRuleValueException extends Exception { 12 | 13 | /** 14 | *

Constructs a new {@link InvalidRuleValueException} with a message that will be passed to the executing source

15 | * @param cause The cause of the exception 16 | */ 17 | public InvalidRuleValueException(String cause) { 18 | super(cause); 19 | } 20 | 21 | /** 22 | *

Constructs a new {@link InvalidRuleValueException} with no detail message, that therefore should not notify the source

23 | */ 24 | public InvalidRuleValueException() { 25 | super(); 26 | } 27 | 28 | /** 29 | *

Notifies the given source with the exception's message if it exists, does nothing if it doesn't exist or it is {@code null}

30 | * @param source The source to notify 31 | */ 32 | public void notifySource(String ruleName, CommandSourceStack source) { 33 | if (getMessage() != null) 34 | Messenger.m(source, "r Couldn't set value for rule " + ruleName + ": "+ getMessage()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/carpet/api/settings/RuleCategory.java: -------------------------------------------------------------------------------- 1 | package carpet.api.settings; 2 | 3 | /** 4 | *

Multiple categories for rules that Carpet uses and can be used to group other rules under the same 5 | * categories.

6 | * 7 | *

These are not the only categories that can be used, you can create your own ones for your rules 8 | * and they will be added to the SettingsManager.

9 | * 10 | */ 11 | public class RuleCategory { 12 | public static final String BUGFIX = "bugfix"; 13 | public static final String SURVIVAL = "survival"; 14 | public static final String CREATIVE = "creative"; 15 | public static final String EXPERIMENTAL = "experimental"; 16 | public static final String OPTIMIZATION = "optimization"; 17 | public static final String FEATURE = "feature"; 18 | public static final String COMMAND = "command"; 19 | public static final String TNT = "tnt"; 20 | public static final String DISPENSER = "dispenser"; 21 | public static final String SCARPET = "scarpet"; 22 | /** 23 | * Rules with this {@link RuleCategory} will have a client-side 24 | * counterpart, so they can be set independently without the server 25 | * running Carpet 26 | */ 27 | public static final String CLIENT = "client"; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/commands/TestCommand.java: -------------------------------------------------------------------------------- 1 | package carpet.commands; 2 | 3 | import carpet.CarpetServer; 4 | import carpet.utils.Messenger; 5 | import com.mojang.brigadier.CommandDispatcher; 6 | import com.mojang.brigadier.context.CommandContext; 7 | import net.minecraft.commands.CommandSourceStack; 8 | 9 | import static com.mojang.brigadier.arguments.StringArgumentType.getString; 10 | import static com.mojang.brigadier.arguments.StringArgumentType.word; 11 | import static net.minecraft.commands.Commands.argument; 12 | import static net.minecraft.commands.Commands.literal; 13 | 14 | public class TestCommand 15 | { 16 | public static void register(CommandDispatcher dispatcher) 17 | { 18 | dispatcher.register(literal("testcarpet"). 19 | then(literal("dump"). 20 | executes((c) -> CarpetServer.settingsManager.dumpAllRulesToStream(System.out, null)). 21 | then(argument("category", word()). 22 | executes( (c) -> CarpetServer.settingsManager.dumpAllRulesToStream(System.out, getString(c, "category"))))). 23 | then(argument("first",word()). 24 | executes( (c)-> test(c, getString(c, "first")+" 1"))). 25 | then(argument("second", word()). 26 | executes( (c)-> test(c, getString(c, "second")+" 2")))); 27 | } 28 | 29 | private static int test(CommandContext c, String term) 30 | { 31 | Messenger.m(c.getSource(),term.substring(0,1)+" "+term+": how did you get here?"); 32 | return 1; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/AbstractContainerMenuInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.server.level.ServerPlayer; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.DataSlot; 6 | import net.minecraft.world.item.crafting.RecipeHolder; 7 | 8 | public interface AbstractContainerMenuInterface 9 | { 10 | DataSlot getDataSlot(int index); 11 | boolean callButtonClickListener(int button, Player player); 12 | boolean callSelectRecipeListener(ServerPlayer player, RecipeHolder recipe, boolean craftAll); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/BiomeInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.world.level.biome.Biome; 4 | 5 | public interface BiomeInterface { 6 | Biome.ClimateSettings getClimateSettings(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/BlockEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.core.BlockPos; 4 | 5 | public interface BlockEntityInterface 6 | { 7 | void setCMPos(BlockPos pos); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/BlockPistonBehaviourInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import carpet.mixins.PistonStructureResolver_customStickyMixin; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.core.Direction; 6 | import net.minecraft.world.level.Level; 7 | import net.minecraft.world.level.block.piston.PistonStructureResolver; 8 | import net.minecraft.world.level.block.state.BlockState; 9 | 10 | /** 11 | * Opt-in Interface that allows for more control on a blocks interaction within the {@link PistonStructureResolver} via {@link PistonStructureResolver_customStickyMixin} 12 | */ 13 | public interface BlockPistonBehaviourInterface { 14 | 15 | /** 16 | * @return whether this block is sticky in any way when moved by pistons 17 | */ 18 | boolean isSticky(BlockState state); 19 | 20 | /** 21 | * @return whether the neighboring block is pulled along if this block is moved by pistons 22 | */ 23 | boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/BlockPredicateInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import carpet.script.value.Value; 4 | import java.util.Map; 5 | import net.minecraft.nbt.CompoundTag; 6 | import net.minecraft.tags.TagKey; 7 | import net.minecraft.world.level.block.Block; 8 | import net.minecraft.world.level.block.state.BlockState; 9 | 10 | public interface BlockPredicateInterface 11 | { 12 | BlockState getCMBlockState(); 13 | TagKey getCMBlockTagKey(); 14 | Map getCMProperties(); 15 | CompoundTag getCMDataTag(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/BlockStateArgumentInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.nbt.CompoundTag; 4 | 5 | public interface BlockStateArgumentInterface 6 | { 7 | CompoundTag getCMTag(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ChunkHolderInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import net.minecraft.server.level.ChunkResult; 5 | import net.minecraft.server.level.ServerLevel; 6 | import net.minecraft.util.thread.BlockableEventLoop; 7 | import net.minecraft.world.level.ChunkPos; 8 | import net.minecraft.world.level.chunk.ChunkAccess; 9 | 10 | public interface ChunkHolderInterface 11 | { 12 | //CompletableFuture> setDefaultProtoChunk(ChunkPos chpos, BlockableEventLoop executor, ServerLevel world); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ClientConnectionInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import io.netty.channel.Channel; 4 | 5 | public interface ClientConnectionInterface { 6 | void setChannel(Channel channel); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/CommandDispatcherInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface CommandDispatcherInterface { 4 | void carpet$unregister(String node); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/CommandNodeInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface CommandNodeInterface { 4 | void carpet$removeChild(String name); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/CoralFeatureInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import java.util.Random; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.util.RandomSource; 6 | import net.minecraft.world.level.Level; 7 | import net.minecraft.world.level.block.state.BlockState; 8 | 9 | public interface CoralFeatureInterface 10 | { 11 | boolean growSpecific(Level worldIn, RandomSource random, BlockPos pos, BlockState blockUnder); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/DefaultRedstoneWireEvaluatorInferface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.core.BlockPos; 4 | import net.minecraft.world.level.Level; 5 | 6 | 7 | public interface DefaultRedstoneWireEvaluatorInferface 8 | { 9 | int calculateTargetStrengthCM(final Level level, final BlockPos pos); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/EntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import carpet.script.EntityEventsGroup; 4 | 5 | public interface EntityInterface 6 | { 7 | float getMainYaw(float partialTicks); 8 | 9 | EntityEventsGroup getEventContainer(); 10 | 11 | boolean isPermanentVehicle(); 12 | 13 | void setPermanentVehicle(boolean permanent); 14 | 15 | int getPortalTimer(); 16 | 17 | void setPortalTimer(int amount); 18 | 19 | int getPublicNetherPortalCooldown(); 20 | void setPublicNetherPortalCooldown(int what); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/FoodDataInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface FoodDataInterface 4 | { 5 | float getCMExhaustionLevel(); 6 | 7 | void setExhaustion(float aFloat); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/IngredientInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import java.util.Collection; 4 | import java.util.List; 5 | import net.minecraft.world.item.ItemStack; 6 | 7 | public interface IngredientInterface 8 | { 9 | /** 10 | * Gets all the stacks of the ingredients for a given item recipe. Also used for {@link carpet.helpers.HopperCounter#guessColor} 11 | * to guess the colour of an item to display it prettily 12 | */ 13 | //List> getRecipeStacks(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/InventoryBearerInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.world.Container; 4 | 5 | public interface InventoryBearerInterface 6 | { 7 | Container getCMInventory(); // can be removed in 1.17 due to class_6067 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ItemEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface ItemEntityInterface 4 | { 5 | int getPickupDelayCM(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/LevelInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.world.level.redstone.NeighborUpdater; 4 | import org.jetbrains.annotations.Nullable; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.function.Predicate; 9 | import net.minecraft.core.BlockPos; 10 | import net.minecraft.world.entity.Entity; 11 | import net.minecraft.world.entity.EntityType; 12 | import net.minecraft.world.level.block.entity.BlockEntity; 13 | import net.minecraft.world.level.block.state.BlockState; 14 | import net.minecraft.world.phys.AABB; 15 | 16 | public interface LevelInterface 17 | { 18 | Map, Entity> getPrecookedMobs(); 19 | 20 | boolean setBlockStateWithBlockEntity(BlockPos blockPos, BlockState blockState, BlockEntity newBlockEntity, int int1); 21 | 22 | List getOtherEntitiesLimited(@Nullable Entity except, AABB box, Predicate predicate, int limit); 23 | 24 | NeighborUpdater getNeighborUpdater(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/Lighting_scarpetChunkCreationInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface Lighting_scarpetChunkCreationInterface 4 | { 5 | void removeLightData(long pos); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/LivingEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface LivingEntityInterface 4 | { 5 | void doJumpCM(); // added CM suffix to remove potential collisions with other mods 6 | boolean isJumpingCM(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/MinecraftServerInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import java.util.Map; 4 | import java.util.function.BooleanSupplier; 5 | import carpet.script.CarpetScriptServer; 6 | import net.minecraft.core.RegistryAccess; 7 | import net.minecraft.resources.ResourceKey; 8 | import net.minecraft.server.MinecraftServer; 9 | import net.minecraft.server.level.ServerLevel; 10 | import net.minecraft.world.level.Level; 11 | import net.minecraft.world.level.storage.LevelStorageSource; 12 | 13 | public interface MinecraftServerInterface 14 | { 15 | void forceTick(BooleanSupplier sup); 16 | LevelStorageSource.LevelStorageAccess getCMSession(); 17 | Map, ServerLevel> getCMWorlds(); 18 | void reloadAfterReload(RegistryAccess newRegs); 19 | 20 | MinecraftServer.ReloadableResources getResourceManager(); 21 | 22 | void addScriptServer(CarpetScriptServer scriptServer); 23 | CarpetScriptServer getScriptServer(); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/MobEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import java.util.Map; 4 | import net.minecraft.world.entity.ai.goal.Goal; 5 | import net.minecraft.world.entity.ai.goal.GoalSelector; 6 | 7 | public interface MobEntityInterface 8 | { 9 | GoalSelector getAI(boolean target); 10 | 11 | Map getTemporaryTasks(); 12 | 13 | void setPersistence(boolean what); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/PistonBlockEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.world.level.block.entity.BlockEntity; 4 | 5 | public interface PistonBlockEntityInterface 6 | { 7 | void setCarriedBlockEntity(BlockEntity blockEntity); 8 | BlockEntity getCarriedBlockEntity(); 9 | void setRenderCarriedBlockEntity(boolean b); 10 | boolean getRenderCarriedBlockEntity(); 11 | boolean isRenderModeSet(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/PistonBlockInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.core.BlockPos; 4 | import net.minecraft.core.Direction; 5 | import net.minecraft.world.level.Level; 6 | 7 | public interface PistonBlockInterface 8 | { 9 | boolean publicShouldExtend(Level world_1, BlockPos blockPos_1, Direction direction_1); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/PlayerListHudInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface PlayerListHudInterface 4 | { 5 | boolean hasFooterOrHeader(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/PortalProcessorInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface PortalProcessorInterface 4 | { 5 | void setPortalTime(int time); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/RandomStateVisitorAccessor.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.world.level.levelgen.DensityFunction; 4 | 5 | public interface RandomStateVisitorAccessor { 6 | DensityFunction.Visitor getVisitor(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/RedstoneWireBlockInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.core.BlockPos; 4 | import net.minecraft.world.level.Level; 5 | import net.minecraft.world.level.block.state.BlockState; 6 | 7 | public interface RedstoneWireBlockInterface { 8 | BlockState updateLogicPublic(Level world_1, BlockPos blockPos_1, BlockState blockState_1); 9 | void setWiresGivePower(boolean wiresGivePower); 10 | boolean getWiresGivePower(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ServerGamePacketListenerImplInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.network.Connection; 4 | 5 | public interface ServerGamePacketListenerImplInterface { 6 | Connection getConnection(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ServerLightingProviderInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import net.minecraft.world.level.ChunkPos; 5 | import net.minecraft.world.level.chunk.ChunkAccess; 6 | 7 | public interface ServerLightingProviderInterface 8 | { 9 | void invokeUpdateChunkStatus(ChunkPos pos); 10 | 11 | void removeLightData(ChunkAccess chunk); 12 | 13 | CompletableFuture relight(ChunkAccess chunk); 14 | 15 | void resetLight(ChunkAccess chunk, ChunkPos pos); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ServerPlayerInteractionManagerInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.core.BlockPos; 4 | 5 | public interface ServerPlayerInteractionManagerInterface 6 | { 7 | BlockPos getCurrentBreakingBlock(); 8 | 9 | int getCurrentBlockBreakingProgress(); 10 | 11 | void setBlockBreakingProgress(int progress); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ServerPlayerInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import carpet.helpers.EntityPlayerActionPack; 4 | 5 | public interface ServerPlayerInterface 6 | { 7 | EntityPlayerActionPack getActionPack(); 8 | void invalidateEntityObjectReference(); 9 | boolean isInvalidEntityObject(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ServerWorldInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.world.entity.Entity; 4 | import net.minecraft.world.level.entity.LevelEntityGetter; 5 | import net.minecraft.world.level.storage.ServerLevelData; 6 | 7 | public interface ServerWorldInterface { 8 | ServerLevelData getWorldPropertiesCM(); 9 | LevelEntityGetter getEntityLookupCMPublic(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/SimpleEntityLookupInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import java.util.List; 4 | import net.minecraft.world.level.ChunkPos; 5 | import net.minecraft.world.level.entity.EntityAccess; 6 | 7 | public interface SimpleEntityLookupInterface 8 | { 9 | List getChunkEntities(ChunkPos chpos); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/SpawnGroupInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface SpawnGroupInterface 4 | { 5 | int getInitialSpawnCap(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/SpawnHelperInnerInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.world.level.PotentialCalculator; 4 | 5 | public interface SpawnHelperInnerInterface 6 | { 7 | PotentialCalculator getPotentialCalculator(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ThreadedAnvilChunkStorageInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import net.minecraft.server.level.ChunkHolder; 6 | import net.minecraft.world.level.ChunkPos; 7 | 8 | public interface ThreadedAnvilChunkStorageInterface 9 | { 10 | //Map regenerateChunkRegion(List requestedChunks); 11 | 12 | //void relightChunk(ChunkPos pos); 13 | 14 | //void releaseRelightTicket(ChunkPos pos); 15 | 16 | //Iterable getChunksCM(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/TicketsFetcherInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; 4 | import net.minecraft.server.level.Ticket; 5 | 6 | import java.util.List; 7 | 8 | public interface TicketsFetcherInterface 9 | { 10 | Long2ObjectOpenHashMap> getTicketsByPosition(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/TntEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface TntEntityInterface 4 | { 5 | int getMergedTNT(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/WorldChunkInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.core.BlockPos; 4 | import net.minecraft.world.level.block.entity.BlockEntity; 5 | import net.minecraft.world.level.block.state.BlockState; 6 | 7 | public interface WorldChunkInterface 8 | { 9 | BlockState setBlockStateWithBlockEntity(BlockPos blockPos, BlockState newBlockState, BlockEntity newBlockEntity, int flags); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/carpet/helpers/CarpetTaintedList.java: -------------------------------------------------------------------------------- 1 | package carpet.helpers; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class CarpetTaintedList extends ArrayList 7 | { 8 | public CarpetTaintedList(final List list) 9 | { 10 | super(list); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/carpet/helpers/ParticleDisplay.java: -------------------------------------------------------------------------------- 1 | package carpet.helpers; 2 | 3 | import net.minecraft.core.particles.ParticleOptions; 4 | import net.minecraft.server.level.ServerPlayer; 5 | import net.minecraft.world.phys.Vec3; 6 | 7 | public class ParticleDisplay 8 | { 9 | public static void drawParticleLine(ServerPlayer player, Vec3 from, Vec3 to, ParticleOptions mainParticle, ParticleOptions accentParticle, int count, double spread) 10 | { 11 | 12 | if (accentParticle != null) player.level().sendParticles( 13 | player, 14 | accentParticle, 15 | true, true, 16 | to.x, to.y, to.z, count, 17 | spread, spread, spread, 0.0); 18 | 19 | double lineLengthSq = from.distanceToSqr(to); 20 | if (lineLengthSq == 0) return; 21 | 22 | Vec3 incvec = to.subtract(from).normalize();// multiply(50/sqrt(lineLengthSq)); 23 | for (Vec3 delta = new Vec3(0.0,0.0,0.0); 24 | delta.lengthSqr() < lineLengthSq; 25 | delta = delta.add(incvec.scale(player.level().random.nextFloat()))) 26 | { 27 | player.level().sendParticles( 28 | player, 29 | mainParticle, 30 | true, true, 31 | delta.x+from.x, delta.y+from.y, delta.z+from.z, 1, 32 | 0.0, 0.0, 0.0, 0.0); 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/carpet/helpers/QuasiConnectivity.java: -------------------------------------------------------------------------------- 1 | package carpet.helpers; 2 | 3 | import carpet.CarpetSettings; 4 | 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.world.level.SignalGetter; 7 | 8 | public class QuasiConnectivity { 9 | 10 | public static boolean hasQuasiSignal(SignalGetter level, BlockPos pos) { 11 | for (int i = 1; i <= CarpetSettings.quasiConnectivity; i++) { 12 | BlockPos above = pos.above(i); 13 | 14 | if (level.isOutsideBuildHeight(above)) { 15 | break; 16 | } 17 | if (level.hasNeighborSignal(above)) { 18 | return true; 19 | } 20 | } 21 | 22 | return false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/logging/HUDLogger.java: -------------------------------------------------------------------------------- 1 | package carpet.logging; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | import net.minecraft.network.chat.Component; 6 | import net.minecraft.server.level.ServerPlayer; 7 | 8 | public class HUDLogger extends Logger 9 | { 10 | static Logger stardardHUDLogger(String logName, String def, String [] options) 11 | { 12 | return stardardHUDLogger(logName, def, options, false); 13 | } 14 | 15 | static Logger stardardHUDLogger(String logName, String def, String [] options, boolean strictOptions) 16 | { 17 | // should convert to factory method if more than 2 classes are here 18 | try 19 | { 20 | return new HUDLogger(LoggerRegistry.class.getField("__"+logName), logName, def, options, strictOptions); 21 | } 22 | catch (NoSuchFieldException e) 23 | { 24 | throw new RuntimeException("Failed to create logger "+logName); 25 | } 26 | } 27 | 28 | public HUDLogger(Field field, String logName, String def, String[] options, boolean strictOptions) 29 | { 30 | super(field, logName, def, options, strictOptions); 31 | } 32 | 33 | @Deprecated 34 | public HUDLogger(Field field, String logName, String def, String[] options) { 35 | super(field, logName, def, options, false); 36 | } 37 | 38 | @Override 39 | public void removePlayer(String playerName) 40 | { 41 | ServerPlayer player = playerFromName(playerName); 42 | if (player != null) HUDController.clearPlayer(player); 43 | super.removePlayer(playerName); 44 | } 45 | 46 | @Override 47 | public void sendPlayerMessage(ServerPlayer player, Component... messages) 48 | { 49 | for (Component m:messages) HUDController.addMessage(player, m); 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/carpet/logging/logHelpers/PacketCounter.java: -------------------------------------------------------------------------------- 1 | package carpet.logging.logHelpers; 2 | 3 | public class PacketCounter 4 | { 5 | public static long totalOut=0; 6 | public static long totalIn=0; 7 | public static void reset() {totalIn = 0L; totalOut = 0L; } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/AbstractContainerMenuSubclasses_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.AbstractContainerMenuInterface; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.AbstractContainerMenu; 6 | import net.minecraft.world.inventory.EnchantmentMenu; 7 | import net.minecraft.world.inventory.LecternMenu; 8 | import net.minecraft.world.inventory.LoomMenu; 9 | import net.minecraft.world.inventory.MenuType; 10 | import net.minecraft.world.inventory.StonecutterMenu; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 15 | 16 | 17 | //classes that override onButtonClick 18 | @Mixin({EnchantmentMenu.class, LecternMenu.class, LoomMenu.class, StonecutterMenu.class}) 19 | public abstract class AbstractContainerMenuSubclasses_scarpetMixin extends AbstractContainerMenu { 20 | protected AbstractContainerMenuSubclasses_scarpetMixin(MenuType type, int syncId) { 21 | super(type, syncId); 22 | } 23 | 24 | @Inject(method = "clickMenuButton", at = @At("HEAD"), cancellable = true) 25 | private void buttonClickCallback(Player player, int id, CallbackInfoReturnable cir) { 26 | if(((AbstractContainerMenuInterface) this).callButtonClickListener(id,player)) 27 | cir.cancel(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/AbstractCraftingMenu_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.AbstractContainerMenuInterface; 4 | import net.minecraft.server.level.ServerLevel; 5 | import net.minecraft.server.level.ServerPlayer; 6 | import net.minecraft.world.entity.player.Inventory; 7 | import net.minecraft.world.inventory.AbstractCraftingMenu; 8 | import net.minecraft.world.inventory.RecipeBookMenu; 9 | import net.minecraft.world.item.crafting.RecipeHolder; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 14 | 15 | @Mixin(AbstractCraftingMenu.class) 16 | public class AbstractCraftingMenu_scarpetMixin 17 | { 18 | @Inject(method = "handlePlacement",at = @At("HEAD"), cancellable = true) 19 | private void selectRecipeCallback(boolean craftAll, boolean b, RecipeHolder recipe, ServerLevel serverLevel, Inventory player, CallbackInfoReturnable cir) { 20 | if(((AbstractContainerMenuInterface) this).callSelectRecipeListener((ServerPlayer) player.player ,recipe,craftAll)) 21 | cir.setReturnValue(RecipeBookMenu.PostPlaceAction.NOTHING); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/AbstractFurnaceMenu_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.AbstractContainerMenuInterface; 4 | import net.minecraft.server.level.ServerLevel; 5 | import net.minecraft.server.level.ServerPlayer; 6 | import net.minecraft.world.entity.player.Inventory; 7 | import net.minecraft.world.inventory.AbstractFurnaceMenu; 8 | import net.minecraft.world.inventory.RecipeBookMenu; 9 | import net.minecraft.world.item.crafting.RecipeHolder; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 14 | 15 | @Mixin(AbstractFurnaceMenu.class) 16 | public class AbstractFurnaceMenu_scarpetMixin 17 | { 18 | @Inject(method = "handlePlacement",at = @At("HEAD"), cancellable = true) 19 | private void selectRecipeCallback(boolean craftAll, boolean b, RecipeHolder recipe, ServerLevel level, Inventory player, CallbackInfoReturnable cir) { 20 | if(((AbstractContainerMenuInterface) this).callSelectRecipeListener((ServerPlayer) player.player ,recipe,craftAll)) 21 | cir.setReturnValue(RecipeBookMenu.PostPlaceAction.NOTHING); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/AbstractMinecart_scarpetEventsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.script.EntityEventsGroup; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.entity.EntityType; 7 | import net.minecraft.world.entity.vehicle.AbstractMinecart; 8 | import net.minecraft.world.level.Level; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | @Mixin(AbstractMinecart.class) 15 | public abstract class AbstractMinecart_scarpetEventsMixin extends Entity 16 | { 17 | public AbstractMinecart_scarpetEventsMixin(EntityType type, Level world) 18 | { 19 | super(type, world); 20 | } 21 | 22 | @Inject(method = "tick", at = @At("HEAD")) 23 | private void onTickCall(CallbackInfo ci) 24 | { 25 | // calling extra on_tick because falling blocks do not fall back to super tick call 26 | ((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.Event.ON_TICK); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Biome_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.BiomeInterface; 4 | import net.minecraft.world.level.biome.Biome; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | 8 | @Mixin(Biome.class) 9 | public class Biome_scarpetMixin implements BiomeInterface { 10 | @Shadow 11 | private Biome.ClimateSettings climateSettings; 12 | 13 | @Override 14 | public Biome.ClimateSettings getClimateSettings() { 15 | return climateSettings; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlockBehaviourBlockStateBase_mixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.level.block.Block; 5 | import net.minecraft.world.level.block.BuddingAmethystBlock; 6 | import net.minecraft.world.level.block.state.BlockBehaviour; 7 | import net.minecraft.world.level.material.PushReaction; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.Shadow; 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 | @Mixin(BlockBehaviour.BlockStateBase.class) 15 | public abstract class BlockBehaviourBlockStateBase_mixin 16 | { 17 | @Shadow public abstract Block getBlock(); 18 | 19 | @Inject(method = "getPistonPushReaction", at = @At("HEAD"), cancellable = true) 20 | private void onGetPistonPushReaction(CallbackInfoReturnable cir) 21 | { 22 | if (CarpetSettings.movableAmethyst && getBlock() instanceof BuddingAmethystBlock) 23 | { 24 | cir.setReturnValue(PushReaction.NORMAL); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlockEntity_movableBEMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.BlockEntityInterface; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.level.block.entity.BlockEntity; 6 | import org.spongepowered.asm.mixin.Final; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Mutable; 9 | import org.spongepowered.asm.mixin.Shadow; 10 | 11 | @Mixin(BlockEntity.class) 12 | public abstract class BlockEntity_movableBEMixin implements BlockEntityInterface 13 | { 14 | @Mutable 15 | @Shadow @Final protected BlockPos worldPosition; 16 | 17 | public void setCMPos(BlockPos newPos) 18 | { 19 | worldPosition = newPos; 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlockInput_fillUpdatesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import org.spongepowered.asm.mixin.injection.At; 5 | import org.spongepowered.asm.mixin.injection.Redirect; 6 | 7 | import carpet.CarpetSettings; 8 | import net.minecraft.commands.arguments.blocks.BlockInput; 9 | import net.minecraft.core.BlockPos; 10 | import net.minecraft.world.level.LevelAccessor; 11 | import net.minecraft.world.level.block.Block; 12 | import net.minecraft.world.level.block.state.BlockState; 13 | 14 | @Mixin(BlockInput.class) 15 | public class BlockInput_fillUpdatesMixin 16 | { 17 | @Redirect(method = "place", at = @At( 18 | value = "INVOKE", 19 | target = "Lnet/minecraft/world/level/block/Block;updateFromNeighbourShapes(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState;" 20 | )) 21 | private BlockState postProcessStateProxy(BlockState state, LevelAccessor serverWorld, BlockPos blockPos) 22 | { 23 | if (CarpetSettings.impendingFillSkipUpdates.get()) 24 | { 25 | return state; 26 | } 27 | 28 | return Block.updateFromNeighbourShapes(state, serverWorld, blockPos); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlockInput_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.BlockStateArgumentInterface; 4 | import net.minecraft.commands.arguments.blocks.BlockInput; 5 | import net.minecraft.nbt.CompoundTag; 6 | import org.jetbrains.annotations.Nullable; 7 | import org.spongepowered.asm.mixin.Final; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.Shadow; 10 | 11 | @Mixin(BlockInput.class) 12 | public class BlockInput_scarpetMixin implements BlockStateArgumentInterface 13 | { 14 | @Shadow @Final private @Nullable CompoundTag tag; 15 | 16 | @Override 17 | public CompoundTag getCMTag() 18 | { 19 | return tag; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlockItem_creativeNoClipMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.entity.player.Player; 6 | import net.minecraft.world.item.BlockItem; 7 | import net.minecraft.world.item.context.BlockPlaceContext; 8 | import net.minecraft.world.level.Level; 9 | import net.minecraft.world.level.block.state.BlockState; 10 | import net.minecraft.world.phys.shapes.CollisionContext; 11 | import net.minecraft.world.phys.shapes.VoxelShape; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Redirect; 15 | 16 | @Mixin(BlockItem.class) 17 | public class BlockItem_creativeNoClipMixin 18 | { 19 | @Redirect(method = "canPlace", at = @At( 20 | value = "INVOKE", 21 | target = "Lnet/minecraft/world/level/Level;isUnobstructed(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/shapes/CollisionContext;)Z" 22 | )) 23 | private boolean canSpectatingPlace(Level world, BlockState state, BlockPos pos, CollisionContext context, 24 | BlockPlaceContext contextOuter, BlockState stateOuter) 25 | { 26 | Player player = contextOuter.getPlayer(); 27 | if (CarpetSettings.creativeNoClip && player != null && player.isCreative() && player.getAbilities().flying) 28 | { 29 | // copy from canPlace 30 | VoxelShape voxelShape = state.getCollisionShape(world, pos, context); 31 | return voxelShape.isEmpty() || world.isUnobstructed(player, voxelShape.move(pos.getX(), pos.getY(), pos.getZ())); 32 | 33 | } 34 | return world.isUnobstructed(state, pos, context); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlockPredicate_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.BlockPredicateInterface; 4 | import carpet.script.value.StringValue; 5 | import carpet.script.value.Value; 6 | import carpet.script.value.ValueConversions; 7 | import net.minecraft.tags.TagKey; 8 | import org.spongepowered.asm.mixin.Final; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Shadow; 11 | 12 | import java.util.Map; 13 | import java.util.Set; 14 | import java.util.stream.Collectors; 15 | import net.minecraft.nbt.CompoundTag; 16 | import net.minecraft.world.level.block.Block; 17 | import net.minecraft.world.level.block.state.BlockState; 18 | import net.minecraft.world.level.block.state.properties.Property; 19 | 20 | @Mixin(targets = "net.minecraft.commands.arguments.blocks.BlockPredicateArgument$BlockPredicate") 21 | public class BlockPredicate_scarpetMixin implements BlockPredicateInterface 22 | { 23 | 24 | @Shadow @Final private BlockState state; 25 | 26 | @Shadow @Final /*@Nullable*/ private CompoundTag nbt; 27 | 28 | @Shadow @Final private Set> properties; 29 | 30 | @Override 31 | public BlockState getCMBlockState() 32 | { 33 | return state; 34 | } 35 | 36 | @Override 37 | public TagKey getCMBlockTagKey() 38 | { 39 | return null; 40 | } 41 | 42 | @Override 43 | public Map getCMProperties() 44 | { 45 | return properties.stream().collect(Collectors.toMap( 46 | p -> StringValue.of(p.getName()), 47 | p -> ValueConversions.fromProperty(state, p), 48 | (a, b) -> b 49 | )); 50 | } 51 | 52 | @Override 53 | public CompoundTag getCMDataTag() 54 | { 55 | return nbt; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BoundTickingBlockEntity_profilerMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.CarpetProfiler; 4 | import net.minecraft.world.level.block.entity.BlockEntity; 5 | import org.spongepowered.asm.mixin.Final; 6 | import org.spongepowered.asm.mixin.Mixin; 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 | 12 | @Mixin(targets = "net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity") 13 | public class BoundTickingBlockEntity_profilerMixin 14 | { 15 | @Shadow @Final private T blockEntity; 16 | CarpetProfiler.ProfilerToken entitySection; 17 | 18 | @Inject(method = "tick()V", at = @At("HEAD")) 19 | private void startTileEntitySection(CallbackInfo ci) 20 | { 21 | entitySection = CarpetProfiler.start_block_entity_section(blockEntity.getLevel(), blockEntity, CarpetProfiler.TYPE.TILEENTITY); 22 | } 23 | 24 | @Inject(method = "tick()V", at = @At("RETURN")) 25 | private void endTileEntitySection(CallbackInfo ci) 26 | { 27 | CarpetProfiler.end_current_entity_section(entitySection); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ChainBlock_customStickyMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.BlockPistonBehaviourInterface; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | 6 | import carpet.CarpetSettings; 7 | import carpet.CarpetSettings.ChainStoneMode; 8 | 9 | import net.minecraft.core.BlockPos; 10 | import net.minecraft.core.Direction; 11 | import net.minecraft.core.Direction.Axis; 12 | import net.minecraft.world.level.Level; 13 | import net.minecraft.world.level.block.Block; 14 | import net.minecraft.world.level.block.Blocks; 15 | import net.minecraft.world.level.block.ChainBlock; 16 | import net.minecraft.world.level.block.EndRodBlock; 17 | import net.minecraft.world.level.block.state.BlockState; 18 | 19 | @Mixin(ChainBlock.class) 20 | public class ChainBlock_customStickyMixin implements BlockPistonBehaviourInterface { 21 | 22 | @Override 23 | public boolean isSticky(BlockState state) { 24 | return CarpetSettings.chainStone.enabled(); 25 | } 26 | 27 | @Override 28 | public boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir) { 29 | Axis axis = state.getValue(ChainBlock.AXIS); 30 | 31 | if (axis != dir.getAxis()) { 32 | return false; 33 | } 34 | 35 | if (CarpetSettings.chainStone == ChainStoneMode.STICK_TO_ALL) { 36 | return true; 37 | } 38 | if (neighborState.is((Block)(Object)this)) { 39 | return axis == neighborState.getValue(ChainBlock.AXIS); 40 | } 41 | if (neighborState.is(Blocks.END_ROD)) { 42 | return axis == neighborState.getValue(EndRodBlock.FACING).getAxis(); 43 | } 44 | 45 | return Block.canSupportCenter(level, neighborPos, dir.getOpposite()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ChestBlock_customStickyMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | 5 | import carpet.CarpetSettings; 6 | import carpet.fakes.BlockPistonBehaviourInterface; 7 | 8 | import net.minecraft.core.BlockPos; 9 | import net.minecraft.core.Direction; 10 | import net.minecraft.world.level.Level; 11 | import net.minecraft.world.level.block.Block; 12 | import net.minecraft.world.level.block.ChestBlock; 13 | import net.minecraft.world.level.block.state.BlockState; 14 | import net.minecraft.world.level.block.state.properties.ChestType; 15 | 16 | import static net.minecraft.world.level.block.ChestBlock.getConnectedDirection; 17 | 18 | @Mixin(ChestBlock.class) 19 | public class ChestBlock_customStickyMixin implements BlockPistonBehaviourInterface { 20 | 21 | @Override 22 | public boolean isSticky(BlockState state) { 23 | return CarpetSettings.movableBlockEntities; 24 | } 25 | 26 | @Override 27 | public boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir) { 28 | if (!neighborState.is((Block)(Object)this)) { 29 | return false; 30 | } 31 | 32 | ChestType type = state.getValue(ChestBlock.TYPE); 33 | ChestType neighborType = neighborState.getValue(ChestBlock.TYPE); 34 | 35 | if (type == ChestType.SINGLE || neighborType == ChestType.SINGLE) { 36 | return false; 37 | } 38 | 39 | return getConnectedDirection(state) == dir; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ChunkAccess_warningsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.level.chunk.ChunkAccess; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 10 | 11 | @Mixin(ChunkAccess.class) 12 | public abstract class ChunkAccess_warningsMixin 13 | { 14 | // failed to mixin into interface. need to mixin in two places that uses it 15 | @Inject(method = "markPosForPostprocessing(Lnet/minecraft/core/BlockPos;)V", 16 | at =@At("HEAD"), cancellable = true) 17 | private void squashWarnings(BlockPos blockPos_1, CallbackInfo ci) 18 | { 19 | if (CarpetSettings.skipGenerationChecks.get()) ci.cancel(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ChunkMap_creativePlayersLoadChunksMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.server.level.ChunkMap; 5 | import net.minecraft.server.level.ServerPlayer; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 10 | 11 | @Mixin(ChunkMap.class) 12 | public class ChunkMap_creativePlayersLoadChunksMixin { 13 | 14 | @Inject(method = "skipPlayer(Lnet/minecraft/server/level/ServerPlayer;)Z", at = @At("HEAD"), cancellable = true) 15 | private void startProfilerSection(ServerPlayer serverPlayer, CallbackInfoReturnable cir) 16 | { 17 | if (!CarpetSettings.creativePlayersLoadChunks && serverPlayer.isCreative()) { 18 | cir.setReturnValue(true); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ChunkMap_profilerMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.CarpetProfiler; 4 | import org.spongepowered.asm.mixin.Final; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 10 | 11 | import java.util.function.BooleanSupplier; 12 | import net.minecraft.server.level.ChunkMap; 13 | import net.minecraft.server.level.ServerLevel; 14 | 15 | @Mixin(ChunkMap.class) 16 | public class ChunkMap_profilerMixin 17 | { 18 | @Shadow @Final ServerLevel level; 19 | CarpetProfiler.ProfilerToken currentSection; 20 | 21 | @Inject(method = "tick(Ljava/util/function/BooleanSupplier;)V", at = @At("HEAD")) 22 | private void startProfilerSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci) 23 | { 24 | currentSection = CarpetProfiler.start_section(level, "Unloading", CarpetProfiler.TYPE.GENERAL); 25 | } 26 | 27 | @Inject(method = "tick(Ljava/util/function/BooleanSupplier;)V", at = @At("RETURN")) 28 | private void stopProfilerSecion(BooleanSupplier booleanSupplier_1, CallbackInfo ci) 29 | { 30 | if (currentSection != null) 31 | { 32 | CarpetProfiler.end_current_section(currentSection); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ClientCommonPacketListenerImpl_customPacketMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.network.CarpetClient; 4 | import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; 5 | import net.minecraft.network.DisconnectionDetails; 6 | import net.minecraft.network.chat.Component; 7 | import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 12 | 13 | @Mixin(ClientCommonPacketListenerImpl.class) 14 | public class ClientCommonPacketListenerImpl_customPacketMixin 15 | { 16 | @Inject(method = "onDisconnect", at = @At("HEAD")) 17 | private void onCMDisconnected(DisconnectionDetails reason, CallbackInfo ci) 18 | { 19 | CarpetClient.disconnect(); 20 | } 21 | 22 | @Inject(method = "handleCustomPayload(Lnet/minecraft/network/protocol/common/ClientboundCustomPayloadPacket;)V", 23 | at = @At("HEAD")) 24 | private void onOnCustomPayload(ClientboundCustomPayloadPacket packet, CallbackInfo ci) 25 | { 26 | //System.out.println("CustomPayload of : " + packet.payload()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CloneCommands_fillUpdatesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.server.commands.CloneCommands; 6 | import net.minecraft.server.level.ServerLevel; 7 | import net.minecraft.world.level.block.Block; 8 | import net.minecraft.world.level.block.state.BlockState; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Redirect; 12 | 13 | @Mixin(CloneCommands.class) 14 | public abstract class CloneCommands_fillUpdatesMixin 15 | { 16 | @Redirect(method = "clone", at = @At( 17 | value = "INVOKE", 18 | target = "Lnet/minecraft/server/level/ServerLevel;updateNeighboursOnBlockSet(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V" 19 | )) 20 | private static void conditionalUpdating(ServerLevel serverWorld, BlockPos blockPos_1, BlockState block_1) 21 | { 22 | if (CarpetSettings.fillUpdates) serverWorld.updateNeighboursOnBlockSet(blockPos_1, block_1); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CollectingNeighborUpdaterAccessor.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.world.level.redstone.CollectingNeighborUpdater; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | @Mixin(CollectingNeighborUpdater.class) 8 | public interface CollectingNeighborUpdaterAccessor { 9 | @Accessor("count") 10 | void setCount(int count); 11 | @Accessor("maxChainedNeighborUpdates") 12 | int getMaxChainedNeighborUpdates(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CommandDispatcher_scarpetCommandsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import org.spongepowered.asm.mixin.Final; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.Shadow; 6 | 7 | import com.mojang.brigadier.CommandDispatcher; 8 | import com.mojang.brigadier.tree.RootCommandNode; 9 | 10 | import carpet.fakes.CommandDispatcherInterface; 11 | import carpet.fakes.CommandNodeInterface; 12 | 13 | @Mixin(value = CommandDispatcher.class, remap = false) 14 | public class CommandDispatcher_scarpetCommandsMixin implements CommandDispatcherInterface { 15 | @Shadow @Final 16 | private RootCommandNode root; 17 | 18 | @Override 19 | public void carpet$unregister(String node) { 20 | ((CommandNodeInterface)this.root).carpet$removeChild(node); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CommandNode_scarpetCommandsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import java.util.Map; 4 | 5 | import org.spongepowered.asm.mixin.Final; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.Shadow; 8 | 9 | import com.mojang.brigadier.tree.ArgumentCommandNode; 10 | import com.mojang.brigadier.tree.CommandNode; 11 | import com.mojang.brigadier.tree.LiteralCommandNode; 12 | 13 | import carpet.fakes.CommandNodeInterface; 14 | 15 | @Mixin(value = CommandNode.class, remap = false) 16 | public class CommandNode_scarpetCommandsMixin implements CommandNodeInterface { 17 | @Shadow @Final 18 | private Map> children; 19 | @Shadow @Final 20 | private Map> literals; 21 | @Shadow @Final 22 | private Map> arguments; 23 | 24 | @Override 25 | public void carpet$removeChild(String name) { 26 | this.children.remove(name); 27 | this.literals.remove(name); 28 | this.arguments.remove(name); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Connection_packetCounterMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.ClientConnectionInterface; 4 | import carpet.logging.logHelpers.PacketCounter; 5 | import io.netty.channel.Channel; 6 | import io.netty.channel.ChannelFutureListener; 7 | import io.netty.channel.ChannelHandlerContext; 8 | import io.netty.util.concurrent.Future; 9 | import io.netty.util.concurrent.GenericFutureListener; 10 | import net.minecraft.network.Connection; 11 | import net.minecraft.network.PacketSendListener; 12 | import net.minecraft.network.protocol.Packet; 13 | import org.jetbrains.annotations.Nullable; 14 | import org.spongepowered.asm.mixin.Mixin; 15 | import org.spongepowered.asm.mixin.gen.Accessor; 16 | import org.spongepowered.asm.mixin.injection.At; 17 | import org.spongepowered.asm.mixin.injection.Inject; 18 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 19 | 20 | @Mixin(Connection.class) 21 | public abstract class Connection_packetCounterMixin implements ClientConnectionInterface 22 | { 23 | // Add to the packet counter whenever a packet is received. 24 | @Inject(method = "channelRead0", at = @At("HEAD")) 25 | private void packetInCount(ChannelHandlerContext channelHandlerContext_1, Packet packet_1, CallbackInfo ci) 26 | { 27 | PacketCounter.totalIn++; 28 | } 29 | 30 | // Add to the packet counter whenever a packet is sent. 31 | @Inject(method = "sendPacket", at = @At("HEAD")) 32 | private void packetOutCount(Packet packet, ChannelFutureListener channelFutureListener, boolean bl, CallbackInfo ci) 33 | { 34 | PacketCounter.totalOut++; 35 | } 36 | 37 | @Override 38 | @Accessor //Compat with adventure-platform-fabric 39 | public abstract void setChannel(Channel channel); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CoralFanBlock_renewableCoralMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.helpers.FertilizableCoral; 5 | import net.minecraft.world.level.block.CoralFanBlock; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | 8 | @Mixin(CoralFanBlock.class) 9 | public class CoralFanBlock_renewableCoralMixin implements FertilizableCoral 10 | { 11 | @Override 12 | public boolean isEnabled() { 13 | return CarpetSettings.renewableCoral == CarpetSettings.RenewableCoralMode.EXPANDED; 14 | } 15 | // Logic in FertilizableCoral 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CoralFeature_renewableCoralMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.CoralFeatureInterface; 4 | import net.minecraft.util.RandomSource; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | 8 | import java.util.Random; 9 | import net.minecraft.core.BlockPos; 10 | import net.minecraft.world.level.Level; 11 | import net.minecraft.world.level.LevelAccessor; 12 | import net.minecraft.world.level.block.state.BlockState; 13 | import net.minecraft.world.level.levelgen.feature.CoralFeature; 14 | 15 | @Mixin(CoralFeature.class) 16 | public abstract class CoralFeature_renewableCoralMixin implements CoralFeatureInterface 17 | { 18 | 19 | @Shadow protected abstract boolean placeFeature(LevelAccessor var1, RandomSource var2, BlockPos var3, BlockState var4); 20 | 21 | @Override 22 | public boolean growSpecific(Level worldIn, RandomSource random, BlockPos pos, BlockState blockUnder) 23 | { 24 | return placeFeature(worldIn, random, pos, blockUnder); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CoralPlantBlock_renewableCoralMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.helpers.FertilizableCoral; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | 7 | import net.minecraft.world.level.block.CoralPlantBlock; 8 | 9 | @Mixin(CoralPlantBlock.class) 10 | public class CoralPlantBlock_renewableCoralMixin implements FertilizableCoral 11 | { 12 | @Override 13 | public boolean isEnabled() { 14 | return CarpetSettings.renewableCoral == CarpetSettings.RenewableCoralMode.EXPANDED 15 | || CarpetSettings.renewableCoral == CarpetSettings.RenewableCoralMode.TRUE; 16 | } 17 | // Logic in FertilizableCoral 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DebugRenderer_scarpetRenderMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.network.CarpetClient; 4 | import net.minecraft.client.renderer.debug.DebugRenderer; 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 | 10 | @Mixin(DebugRenderer.class) 11 | public class DebugRenderer_scarpetRenderMixin 12 | { 13 | @Inject(method = "clear", at = @At("HEAD")) 14 | private void resetScarpetRenderes(CallbackInfo ci) 15 | { 16 | if (CarpetClient.shapes != null) 17 | CarpetClient.shapes.reset(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DefaultRedstoneWireEvaluator_redstoneMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.DefaultRedstoneWireEvaluatorInferface; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.level.Level; 6 | import net.minecraft.world.level.redstone.DefaultRedstoneWireEvaluator; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | 10 | @Mixin(DefaultRedstoneWireEvaluator.class) 11 | public abstract class DefaultRedstoneWireEvaluator_redstoneMixin implements DefaultRedstoneWireEvaluatorInferface 12 | { 13 | @Shadow protected abstract int calculateTargetStrength(final Level level, final BlockPos blockPos); 14 | 15 | @Override 16 | public int calculateTargetStrengthCM(final Level level, final BlockPos pos) 17 | { 18 | return calculateTargetStrength(level, pos); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DirectionMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.fakes.EntityInterface; 5 | import carpet.helpers.BlockRotator; 6 | import net.minecraft.core.Direction; 7 | import net.minecraft.world.entity.Entity; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Redirect; 11 | 12 | @Mixin(Direction.class) 13 | public abstract class DirectionMixin 14 | { 15 | @Redirect(method = "orderedByNearest", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getViewYRot(F)F")) 16 | private static float getYaw(Entity entity, float float_1) 17 | { 18 | float yaw; 19 | if (!CarpetSettings.placementRotationFix) 20 | { 21 | yaw = entity.getViewYRot(float_1); 22 | } 23 | else 24 | { 25 | yaw = ((EntityInterface) entity).getMainYaw(float_1); 26 | } 27 | if (BlockRotator.flippinEligibility(entity)) 28 | { 29 | yaw += 180f; 30 | } 31 | return yaw; 32 | } 33 | @Redirect(method = "orderedByNearest", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getViewXRot(F)F")) 34 | private static float getPitch(Entity entity, float float_1) 35 | { 36 | float pitch = entity.getViewXRot(float_1); 37 | if (BlockRotator.flippinEligibility(entity)) 38 | { 39 | pitch = -pitch; 40 | } 41 | return pitch; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DispenserBlock_cactusMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.BlockRotator; 4 | import net.minecraft.core.dispenser.DispenseItemBehavior; 5 | import net.minecraft.world.item.Item; 6 | import net.minecraft.world.item.ItemStack; 7 | import net.minecraft.world.item.Items; 8 | import net.minecraft.world.level.Level; 9 | import net.minecraft.world.level.block.DispenserBlock; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 14 | 15 | @Mixin(DispenserBlock.class) 16 | public abstract class DispenserBlock_cactusMixin 17 | { 18 | @Inject(method = "getDispenseMethod", at = @At("HEAD"), cancellable = true) 19 | private void registerCarpetBehaviors(Level level, ItemStack stack, CallbackInfoReturnable cir) 20 | { 21 | Item item = stack.getItem(); 22 | if (item == Items.CACTUS) 23 | cir.setReturnValue(new BlockRotator.CactusDispenserBehaviour()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DispenserBlock_qcMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.world.level.redstone.Orientation; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.injection.At; 6 | import org.spongepowered.asm.mixin.injection.Redirect; 7 | 8 | import carpet.helpers.QuasiConnectivity; 9 | 10 | import net.minecraft.core.BlockPos; 11 | import net.minecraft.world.level.Level; 12 | import net.minecraft.world.level.block.Block; 13 | import net.minecraft.world.level.block.DispenserBlock; 14 | import net.minecraft.world.level.block.state.BlockState; 15 | 16 | @Mixin(DispenserBlock.class) 17 | public class DispenserBlock_qcMixin { 18 | 19 | @Redirect( 20 | method = "neighborChanged", 21 | at = @At( 22 | value = "INVOKE", 23 | ordinal = 1, 24 | target = "Lnet/minecraft/world/level/Level;hasNeighborSignal(Lnet/minecraft/core/BlockPos;)Z" 25 | ) 26 | ) 27 | private boolean carpet_hasQuasiSignal(Level _level, BlockPos above, BlockState state, Level level, BlockPos pos, Block neighborBlock, Orientation neighborPos, boolean movedByPiston) { 28 | return QuasiConnectivity.hasQuasiSignal(level, pos); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Display_scarpetEventMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.script.EntityEventsGroup; 5 | import net.minecraft.world.entity.Display; 6 | import net.minecraft.world.entity.Entity; 7 | import net.minecraft.world.entity.EntityType; 8 | import net.minecraft.world.level.Level; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | @Mixin(Display.class) 15 | public abstract class Display_scarpetEventMixin extends Entity 16 | { 17 | public Display_scarpetEventMixin(final EntityType entityType, final Level level) 18 | { 19 | super(entityType, level); 20 | } 21 | 22 | @Inject(method = "tick", at = @At("HEAD")) 23 | private void onTickCall(CallbackInfo ci) 24 | { 25 | // calling extra on_tick because displays don't tick 26 | ((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.Event.ON_TICK); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DistanceManager_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.TicketsFetcherInterface; 4 | import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; 5 | import net.minecraft.server.level.DistanceManager; 6 | import net.minecraft.server.level.Ticket; 7 | import net.minecraft.world.level.TicketStorage; 8 | import org.spongepowered.asm.mixin.Final; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Shadow; 11 | 12 | import java.util.List; 13 | 14 | @Mixin(DistanceManager.class) 15 | public abstract class DistanceManager_scarpetMixin implements TicketsFetcherInterface 16 | { 17 | @Shadow @Final private TicketStorage ticketStorage; 18 | 19 | @Override 20 | public Long2ObjectOpenHashMap> getTicketsByPosition() 21 | { 22 | return ((TicketsFetcherInterface)ticketStorage).getTicketsByPosition(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DynamicGraphMinFixedPoint_resetChunkInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.world.level.lighting.DynamicGraphMinFixedPoint; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Invoker; 6 | 7 | @Mixin(DynamicGraphMinFixedPoint.class) 8 | public interface DynamicGraphMinFixedPoint_resetChunkInterface 9 | { 10 | @Invoker("checkEdge") 11 | void cmInvokeUpdateLevel(long sourceId, long id, int level, boolean decrease); 12 | 13 | @Invoker("computeLevelFromNeighbor") 14 | int cmCallGetPropagatedLevel(long sourceId, long targetId, int level); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/EndCrystal_scarpetEventsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.script.EntityEventsGroup; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.entity.EntityType; 7 | import net.minecraft.world.entity.boss.enderdragon.EndCrystal; 8 | import net.minecraft.world.level.Level; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | @Mixin(EndCrystal.class) 15 | public abstract class EndCrystal_scarpetEventsMixin extends Entity 16 | { 17 | public EndCrystal_scarpetEventsMixin(EntityType type, Level world) 18 | { 19 | super(type, world); 20 | } 21 | 22 | @Inject(method = "tick", at = @At("HEAD")) 23 | private void onTickCall(CallbackInfo ci) 24 | { 25 | // calling extra on_tick because falling blocks do not fall back to super tick call 26 | ((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.Event.ON_TICK); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/EntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.patches.EntityPlayerMPFake; 5 | import net.minecraft.util.Mth; 6 | import net.minecraft.world.entity.Entity; 7 | import net.minecraft.world.entity.LivingEntity; 8 | import net.minecraft.world.level.Level; 9 | import org.jetbrains.annotations.Nullable; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Shadow; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 15 | 16 | @Mixin(Entity.class) 17 | public abstract class EntityMixin implements EntityInterface 18 | { 19 | @Shadow 20 | public float yRot; 21 | 22 | @Shadow 23 | public float yRotO; 24 | 25 | @Shadow public @Nullable abstract LivingEntity getControllingPassenger(); 26 | 27 | @Shadow public Level level; 28 | 29 | @Override 30 | public float getMainYaw(float partialTicks) 31 | { 32 | return partialTicks == 1.0F ? this.yRot : Mth.lerp(partialTicks, this.yRotO, this.yRot); 33 | } 34 | 35 | @Inject(method = "isLocalInstanceAuthoritative", at = @At("HEAD"), cancellable = true) 36 | private void isFakePlayer(CallbackInfoReturnable cir) 37 | { 38 | if (getControllingPassenger() instanceof EntityPlayerMPFake) cir.setReturnValue(!level.isClientSide); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ExperienceOrb_xpNoCooldownMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.server.level.ServerPlayer; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.entity.EntityType; 7 | import net.minecraft.world.entity.ExperienceOrb; 8 | import net.minecraft.world.entity.player.Player; 9 | import net.minecraft.world.level.Level; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Shadow; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 15 | 16 | @Mixin(ExperienceOrb.class) 17 | public abstract class ExperienceOrb_xpNoCooldownMixin extends Entity 18 | { 19 | @Shadow 20 | private int count; 21 | 22 | public ExperienceOrb_xpNoCooldownMixin(EntityType type, Level world) 23 | { 24 | super(type, world); 25 | } 26 | 27 | @Shadow 28 | protected abstract int repairPlayerItems(ServerPlayer player, int amount); 29 | 30 | @Shadow public abstract int getValue(); 31 | 32 | @Inject(method = "playerTouch", at = @At("HEAD")) 33 | private void addXP(Player player, CallbackInfo ci) { 34 | if (CarpetSettings.xpNoCooldown && !level().isClientSide) { 35 | player.takeXpDelay = 0; 36 | // reducing the count to 1 and leaving vanilla to deal with it 37 | while (this.count > 1) { 38 | int remainder = this.repairPlayerItems((ServerPlayer) player, this.getValue()); 39 | if (remainder > 0) { 40 | player.giveExperiencePoints(remainder); 41 | } 42 | this.count--; 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ExplosionAccessor.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.server.level.ServerLevel; 4 | import net.minecraft.world.damagesource.DamageSource; 5 | import net.minecraft.world.level.ServerExplosion; 6 | import net.minecraft.world.phys.Vec3; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.gen.Accessor; 9 | 10 | import net.minecraft.world.entity.Entity; 11 | 12 | @Mixin(ServerExplosion.class) 13 | public interface ExplosionAccessor { 14 | 15 | @Accessor 16 | ServerLevel getLevel(); 17 | 18 | @Accessor 19 | Vec3 getCenter(); 20 | 21 | @Accessor 22 | float getRadius(); 23 | 24 | @Accessor 25 | Entity getSource(); 26 | 27 | @Accessor 28 | DamageSource getDamageSource(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Explosion_xpFromBlocksMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.server.level.ServerLevel; 6 | import net.minecraft.world.item.ItemStack; 7 | import net.minecraft.world.level.block.state.BlockBehaviour; 8 | import net.minecraft.world.level.block.state.BlockState; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Redirect; 12 | 13 | @Mixin(BlockBehaviour.class) 14 | public class Explosion_xpFromBlocksMixin { 15 | 16 | @Redirect(method = "onExplosionHit", at = @At( 17 | value = "INVOKE", 18 | target = "Lnet/minecraft/world/level/block/state/BlockState;spawnAfterBreak(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;Z)V" 19 | )) 20 | private void spawnXPAfterBreak(BlockState instance, ServerLevel serverLevel, BlockPos blockPos, ItemStack itemStack, boolean b) 21 | { 22 | instance.spawnAfterBreak(serverLevel, blockPos, itemStack, b || CarpetSettings.xpFromExplosions); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FallingBlockEntity_scarpetEventsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.script.EntityEventsGroup; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.entity.EntityType; 7 | import net.minecraft.world.entity.item.FallingBlockEntity; 8 | import net.minecraft.world.level.Level; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | @Mixin(FallingBlockEntity.class) 15 | public abstract class FallingBlockEntity_scarpetEventsMixin extends Entity 16 | { 17 | public FallingBlockEntity_scarpetEventsMixin(EntityType type, Level world) 18 | { 19 | super(type, world); 20 | } 21 | 22 | @Inject(method = "tick", at = @At("HEAD")) 23 | private void onTickCall(CallbackInfo ci) 24 | { 25 | // calling extra on_tick because falling blocks do not fall back to super tick call 26 | ((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.Event.ON_TICK); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FillCommandMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.server.commands.FillCommand; 6 | import net.minecraft.server.level.ServerLevel; 7 | import net.minecraft.world.level.block.Block; 8 | import net.minecraft.world.level.block.state.BlockState; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Redirect; 12 | 13 | @Mixin(FillCommand.class) 14 | public abstract class FillCommandMixin 15 | { 16 | @Redirect(method = "fillBlocks", at = @At( 17 | value = "INVOKE", 18 | target = "Lnet/minecraft/server/level/ServerLevel;updateNeighboursOnBlockSet(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V" 19 | )) 20 | private static void conditionalUpdating(ServerLevel serverWorld, BlockPos blockPos_1, BlockState block_1) 21 | { 22 | if (CarpetSettings.fillUpdates) serverWorld.updateNeighboursOnBlockSet(blockPos_1, block_1); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FlowingFluid_liquidDamageDisabledMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.level.BlockGetter; 6 | import net.minecraft.world.level.block.Blocks; 7 | import net.minecraft.world.level.block.state.BlockState; 8 | import net.minecraft.world.level.material.FlowingFluid; 9 | import net.minecraft.world.level.material.Fluid; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 14 | 15 | @Mixin(FlowingFluid.class) 16 | public class FlowingFluid_liquidDamageDisabledMixin 17 | { 18 | @Inject( 19 | method = "canHoldAnyFluid", 20 | at = @At( 21 | value = "INVOKE", 22 | target = "Lnet/minecraft/world/level/block/state/BlockState;blocksMotion()Z" 23 | ), 24 | cancellable = true 25 | ) 26 | private static void stopBreakingBlock(final BlockState state, final CallbackInfoReturnable cir) 27 | { 28 | if (CarpetSettings.liquidDamageDisabled) 29 | { 30 | cir.setReturnValue(state.isAir() || state.is(Blocks.WATER) || state.is(Blocks.LAVA)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FoodData_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.FoodDataInterface; 4 | import net.minecraft.world.food.FoodData; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | 8 | @Mixin(FoodData.class) 9 | public class FoodData_scarpetMixin implements FoodDataInterface 10 | { 11 | @Shadow private float exhaustionLevel; 12 | 13 | @Override 14 | public float getCMExhaustionLevel() 15 | { 16 | return exhaustionLevel; 17 | } 18 | 19 | @Override 20 | public void setExhaustion(float aFloat) 21 | { 22 | exhaustionLevel = aFloat; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ForceLoadCommand_forceLoadLimitMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.server.commands.ForceLoadCommand; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.Constant; 7 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 8 | 9 | @Mixin(ForceLoadCommand.class) 10 | public class ForceLoadCommand_forceLoadLimitMixin 11 | { 12 | @ModifyConstant(method = "changeForceLoad", constant = @Constant(longValue = 256L)) 13 | private static long forceloadLimit(long original) 14 | { 15 | return CarpetSettings.forceloadLimit; 16 | } 17 | 18 | @ModifyConstant(method = "changeForceLoad", constant = @Constant(intValue = 256)) 19 | private static int forceloadLimitError(int original) 20 | { 21 | return CarpetSettings.forceloadLimit; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Gui_tablistMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.PlayerListHudInterface; 4 | import net.minecraft.client.Minecraft; 5 | import net.minecraft.client.gui.Gui; 6 | import net.minecraft.client.gui.components.PlayerTabOverlay; 7 | import org.spongepowered.asm.mixin.Final; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.Shadow; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Redirect; 12 | 13 | @Mixin(Gui.class) 14 | public abstract class Gui_tablistMixin 15 | { 16 | @Shadow 17 | @Final 18 | private Minecraft minecraft; 19 | 20 | @Shadow @Final private PlayerTabOverlay tabList; 21 | 22 | @Redirect(method = "renderTabList", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;isLocalServer()Z")) 23 | private boolean onDraw(Minecraft minecraftClient) 24 | { 25 | return this.minecraft.isLocalServer() && !((PlayerListHudInterface) tabList).hasFooterOrHeader(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/HangingEntity_scarpetEventsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.script.EntityEventsGroup; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.entity.EntityType; 7 | import net.minecraft.world.entity.decoration.BlockAttachedEntity; 8 | import net.minecraft.world.entity.decoration.HangingEntity; 9 | import net.minecraft.world.level.Level; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 | 15 | @Mixin(BlockAttachedEntity.class) 16 | public abstract class HangingEntity_scarpetEventsMixin extends Entity 17 | { 18 | public HangingEntity_scarpetEventsMixin(EntityType type, Level world) 19 | { 20 | super(type, world); 21 | } 22 | 23 | @Inject(method = "tick", at = @At("HEAD")) 24 | private void onTickCall(CallbackInfo ci) 25 | { 26 | // calling extra on_tick because falling blocks do not fall back to super tick call 27 | ((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.Event.ON_TICK); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/HopperBlock_cactusMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.BlockRotator; 4 | import net.minecraft.core.Direction; 5 | import net.minecraft.world.item.context.BlockPlaceContext; 6 | import net.minecraft.world.level.block.HopperBlock; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Redirect; 10 | 11 | @Mixin(HopperBlock.class) 12 | public class HopperBlock_cactusMixin 13 | { 14 | @Redirect(method = "getStateForPlacement", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/item/context/BlockPlaceContext;getClickedFace()Lnet/minecraft/core/Direction;" 17 | )) 18 | private Direction getOppositeOpposite(BlockPlaceContext context) 19 | { 20 | if (BlockRotator.flippinEligibility(context.getPlayer())) 21 | { 22 | return context.getClickedFace().getOpposite(); 23 | } 24 | return context.getClickedFace(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/HorseBaseEntity_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.InventoryBearerInterface; 4 | import net.minecraft.world.Container; 5 | import net.minecraft.world.SimpleContainer; 6 | import net.minecraft.world.entity.animal.horse.AbstractHorse; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | 10 | @Mixin(AbstractHorse.class) 11 | public class HorseBaseEntity_scarpetMixin implements InventoryBearerInterface 12 | { 13 | 14 | @Shadow protected SimpleContainer inventory; 15 | 16 | @Override 17 | public Container getCMInventory() 18 | { 19 | return inventory; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/HugeFungusFeatureMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.util.RandomSource; 5 | import net.minecraft.world.level.levelgen.feature.HugeFungusConfiguration; 6 | import net.minecraft.world.level.levelgen.feature.HugeFungusFeature; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.ModifyArgs; 10 | import org.spongepowered.asm.mixin.injection.invoke.arg.Args; 11 | 12 | import static carpet.CarpetSettings.FungusGrowthMode.*; 13 | 14 | @Mixin(HugeFungusFeature.class) 15 | public class HugeFungusFeatureMixin { 16 | @ModifyArgs(method = "place", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/feature/HugeFungusFeature;placeStem(Lnet/minecraft/world/level/WorldGenLevel;Lnet/minecraft/util/RandomSource;Lnet/minecraft/world/level/levelgen/feature/HugeFungusConfiguration;Lnet/minecraft/core/BlockPos;IZ)V")) 17 | private void mixin(Args args) { 18 | boolean natural = !((HugeFungusConfiguration) args.get(2)).planted; 19 | args.set(5, natural && ((boolean) args.get(5)) || 20 | !natural && (CarpetSettings.thickFungusGrowth == ALL || 21 | CarpetSettings.thickFungusGrowth == RANDOM && ((RandomSource) args.get(1)).nextFloat() < 0.06F) 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Husk_templesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.utils.SpawnOverrides; 5 | import net.minecraft.core.BlockPos; 6 | import net.minecraft.server.level.ServerLevel; 7 | import net.minecraft.world.entity.monster.Husk; 8 | import net.minecraft.world.level.ServerLevelAccessor; 9 | import net.minecraft.world.level.levelgen.structure.BuiltinStructures; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Redirect; 13 | 14 | @Mixin(Husk.class) 15 | public class Husk_templesMixin 16 | { 17 | @Redirect(method = "checkHuskSpawnRules", at = @At(value = "INVOKE", target="Lnet/minecraft/world/level/ServerLevelAccessor;canSeeSky(Lnet/minecraft/core/BlockPos;)Z")) 18 | private static boolean isSkylightOrTempleVisible(ServerLevelAccessor serverWorldAccess, BlockPos pos) 19 | { 20 | return serverWorldAccess.canSeeSky(pos) || 21 | (CarpetSettings.huskSpawningInTemples && SpawnOverrides.isStructureAtPosition((ServerLevel)serverWorldAccess, BuiltinStructures.DESERT_PYRAMID, pos)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/InfestedBlock_gravelMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.server.level.ServerLevel; 6 | import net.minecraft.world.item.ItemStack; 7 | import net.minecraft.world.level.block.Block; 8 | import net.minecraft.world.level.block.Blocks; 9 | import net.minecraft.world.level.block.InfestedBlock; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 | 15 | @Mixin(InfestedBlock.class) 16 | public abstract class InfestedBlock_gravelMixin extends Block 17 | { 18 | public InfestedBlock_gravelMixin(Properties block$Settings_1) 19 | { 20 | super(block$Settings_1); 21 | } 22 | 23 | @Inject(method = "spawnInfestation", at = @At(value = "INVOKE", shift = At.Shift.AFTER, 24 | target = "Lnet/minecraft/world/entity/monster/Silverfish;spawnAnim()V")) 25 | private void onOnStacksDropped(ServerLevel serverWorld, BlockPos pos, CallbackInfo ci) 26 | { 27 | if (CarpetSettings.silverFishDropGravel) 28 | { 29 | popResource(serverWorld, pos, new ItemStack(Blocks.GRAVEL)); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Ingredient_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | 5 | import net.minecraft.world.item.crafting.Ingredient; 6 | 7 | @Mixin(Ingredient.class) 8 | public class Ingredient_scarpetMixin// implements IngredientInterface 9 | { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Inventory_scarpetEventMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 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.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import static carpet.script.CarpetEventServer.Event.PLAYER_PICKS_UP_ITEM; 10 | 11 | import net.minecraft.server.level.ServerPlayer; 12 | import net.minecraft.world.entity.player.Inventory; 13 | import net.minecraft.world.entity.player.Player; 14 | import net.minecraft.world.item.ItemStack; 15 | 16 | @Mixin(Inventory.class) 17 | public abstract class Inventory_scarpetEventMixin 18 | { 19 | @Shadow @Final public Player player; 20 | 21 | @Redirect(method = "add(Lnet/minecraft/world/item/ItemStack;)Z", at = @At( 22 | value = "INVOKE", 23 | target = "Lnet/minecraft/world/entity/player/Inventory;add(ILnet/minecraft/world/item/ItemStack;)Z" 24 | )) 25 | private boolean onItemAcquired(Inventory playerInventory, int slot, ItemStack stack) 26 | { 27 | if (!PLAYER_PICKS_UP_ITEM.isNeeded() || !(player instanceof ServerPlayer)) 28 | return playerInventory.add(-1, stack); 29 | int count = stack.getCount(); 30 | ItemStack previous = stack.copy(); 31 | boolean res = playerInventory.add(-1, stack); 32 | if (count != stack.getCount()) // res returns false for larger item adding to a almost full ineventory 33 | { 34 | ItemStack diffStack = previous.copyWithCount(count - stack.getCount()); 35 | PLAYER_PICKS_UP_ITEM.onItemAction((ServerPlayer) player, null, diffStack); 36 | } 37 | return res; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ItemEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.server.level.ServerLevel; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.entity.EntityType; 7 | import net.minecraft.world.entity.LightningBolt; 8 | import net.minecraft.world.entity.item.ItemEntity; 9 | import net.minecraft.world.level.Level; 10 | import carpet.fakes.ItemEntityInterface; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.Shadow; 13 | 14 | @Mixin(ItemEntity.class) 15 | public abstract class ItemEntityMixin extends Entity implements ItemEntityInterface 16 | { 17 | @Shadow private int age; 18 | @Shadow private int pickupDelay; 19 | 20 | public ItemEntityMixin(EntityType entityType_1, Level world_1) { 21 | super(entityType_1, world_1); 22 | } 23 | 24 | @Override 25 | public void thunderHit(ServerLevel world, LightningBolt lightning) { 26 | if (CarpetSettings.lightningKillsDropsFix) { 27 | if (this.age > 8) { //Only kill item if it's older than 8 ticks 28 | super.thunderHit(world, lightning); 29 | } 30 | } else { 31 | super.thunderHit(world, lightning); 32 | } 33 | } 34 | 35 | @Override 36 | public int getPickupDelayCM() { 37 | return this.pickupDelay; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ItemStack_stackableShulkerBoxesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.component.DataComponents; 5 | import net.minecraft.world.item.BlockItem; 6 | import net.minecraft.world.item.ItemStack; 7 | import net.minecraft.world.item.component.ItemContainerContents; 8 | import net.minecraft.world.level.block.ShulkerBoxBlock; 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 | @Mixin(ItemStack.class) 15 | public class ItemStack_stackableShulkerBoxesMixin 16 | { 17 | @Inject(method = "getMaxStackSize", at = @At("HEAD"), cancellable = true) 18 | private void getCMMAxStackSize(CallbackInfoReturnable cir) 19 | { 20 | if (CarpetSettings.shulkerBoxStackSize > 1 21 | && ((ItemStack)((Object)this)).getItem() instanceof BlockItem blockItem 22 | && blockItem.getBlock() instanceof ShulkerBoxBlock 23 | && ((ItemStack) ((Object) this)).getOrDefault(DataComponents.CONTAINER, ItemContainerContents.EMPTY).stream().findAny().isEmpty() 24 | ) { 25 | cir.setReturnValue(CarpetSettings.shulkerBoxStackSize); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Item_missingToolsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.component.DataComponents; 5 | import net.minecraft.tags.ItemTags; 6 | import net.minecraft.world.item.Item; 7 | import net.minecraft.world.item.ItemStack; 8 | import net.minecraft.world.item.component.Tool; 9 | import net.minecraft.world.level.block.Blocks; 10 | import net.minecraft.world.level.block.SoundType; 11 | import net.minecraft.world.level.block.state.BlockState; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Inject; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 16 | 17 | @Mixin(Item.class) 18 | public class Item_missingToolsMixin 19 | { 20 | @Inject(method = "getDestroySpeed", at = @At("HEAD"), cancellable = true) 21 | public void getDestroySpeed(ItemStack itemStack, BlockState blockState, CallbackInfoReturnable cir) { 22 | if (CarpetSettings.missingTools && blockState.getSoundType() == SoundType.GLASS && itemStack.is(ItemTags.PICKAXES)) 23 | { 24 | Tool tool = itemStack.get(DataComponents.TOOL); 25 | if (tool != null) { 26 | cir.setReturnValue(tool.getMiningSpeed(Blocks.STONE.defaultBlockState())); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LavaFluid_renewableDeepslateMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.core.Direction; 6 | import net.minecraft.world.level.Level; 7 | import net.minecraft.world.level.LevelAccessor; 8 | import net.minecraft.world.level.block.Blocks; 9 | import net.minecraft.world.level.block.state.BlockState; 10 | import net.minecraft.world.level.material.FluidState; 11 | import net.minecraft.world.level.material.LavaFluid; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.Shadow; 14 | import org.spongepowered.asm.mixin.injection.At; 15 | import org.spongepowered.asm.mixin.injection.Inject; 16 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 17 | 18 | @Mixin(LavaFluid.class) 19 | public abstract class LavaFluid_renewableDeepslateMixin { 20 | @Shadow protected abstract void fizz(LevelAccessor world, BlockPos pos); 21 | 22 | @Inject(method = "spreadTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;defaultBlockState()Lnet/minecraft/world/level/block/state/BlockState;"), cancellable = true) 23 | private void generateDeepslate(LevelAccessor world, BlockPos pos, BlockState state, Direction direction, FluidState fluidState, CallbackInfo ci) 24 | { 25 | if(CarpetSettings.renewableDeepslate && ((Level)world).dimension() == Level.OVERWORLD && pos.getY() < 0) 26 | { 27 | world.setBlock(pos, Blocks.DEEPSLATE.defaultBlockState(), 3); 28 | this.fizz(world, pos); 29 | ci.cancel(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LayerLightEngine_scarpetChunkCreationMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import org.spongepowered.asm.mixin.Final; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.Shadow; 6 | 7 | import carpet.fakes.Lighting_scarpetChunkCreationInterface; 8 | import net.minecraft.world.level.lighting.LightEngine; 9 | import net.minecraft.world.level.lighting.LayerLightSectionStorage; 10 | 11 | @Mixin(LightEngine.class) 12 | public abstract class LayerLightEngine_scarpetChunkCreationMixin implements Lighting_scarpetChunkCreationInterface 13 | { 14 | @Shadow 15 | @Final 16 | protected LayerLightSectionStorage storage; 17 | 18 | @Override 19 | public void removeLightData(final long pos) 20 | { 21 | ((Lighting_scarpetChunkCreationInterface) this.storage).removeLightData(pos); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LevelEntityGetterAdapter_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.SimpleEntityLookupInterface; 4 | import org.spongepowered.asm.mixin.Final; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | 8 | import java.util.List; 9 | import java.util.stream.Collectors; 10 | import net.minecraft.world.level.ChunkPos; 11 | import net.minecraft.world.level.entity.EntityAccess; 12 | import net.minecraft.world.level.entity.EntitySection; 13 | import net.minecraft.world.level.entity.EntitySectionStorage; 14 | import net.minecraft.world.level.entity.LevelEntityGetterAdapter; 15 | 16 | @Mixin(LevelEntityGetterAdapter.class) 17 | public class LevelEntityGetterAdapter_scarpetMixin implements SimpleEntityLookupInterface 18 | { 19 | 20 | @Shadow @Final private EntitySectionStorage sectionStorage; 21 | 22 | @Override 23 | public List getChunkEntities(ChunkPos chpos) { 24 | return this.sectionStorage.getExistingSectionsInChunk(chpos.toLong()).flatMap(EntitySection::getEntities).collect(Collectors.toList()); 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LevelLightEngine_scarpetChunkCreationMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import org.spongepowered.asm.mixin.Final; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.Shadow; 6 | 7 | import carpet.fakes.Lighting_scarpetChunkCreationInterface; 8 | import net.minecraft.world.level.lighting.LightEngine; 9 | import net.minecraft.world.level.lighting.LevelLightEngine; 10 | 11 | @Mixin(LevelLightEngine.class) 12 | public abstract class LevelLightEngine_scarpetChunkCreationMixin implements Lighting_scarpetChunkCreationInterface 13 | { 14 | @Shadow 15 | @Final 16 | private LightEngine blockEngine; 17 | 18 | @Shadow 19 | @Final 20 | private LightEngine skyEngine; 21 | 22 | @Override 23 | public void removeLightData(final long pos) 24 | { 25 | if (this.blockEngine != null) 26 | ((Lighting_scarpetChunkCreationInterface) this.blockEngine).removeLightData(pos); 27 | 28 | if (this.skyEngine != null) 29 | ((Lighting_scarpetChunkCreationInterface) this.skyEngine).removeLightData(pos); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LevelRenderer_creativeNoClipMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.client.player.LocalPlayer; 5 | import net.minecraft.client.renderer.LevelRenderer; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Redirect; 9 | 10 | @Mixin(LevelRenderer.class) 11 | public class LevelRenderer_creativeNoClipMixin 12 | { 13 | @Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isSpectator()Z")) 14 | private boolean canSeeWorld(LocalPlayer clientPlayerEntity) 15 | { 16 | return clientPlayerEntity.isSpectator() || (CarpetSettings.creativeNoClip && clientPlayerEntity.isCreative()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LevelRenderer_fogOffMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.client.renderer.DimensionSpecialEffects; 5 | import net.minecraft.client.renderer.LevelRenderer; 6 | //import net.minecraft.world.dimension.Dimension; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Redirect; 10 | 11 | @Mixin(value = LevelRenderer.class, priority = 69420) 12 | public class LevelRenderer_fogOffMixin 13 | { 14 | @Redirect(method = "renderLevel", require = 0, expect = 0, at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/client/renderer/DimensionSpecialEffects;isFoggyAt(II)Z" 17 | )) 18 | private boolean isReallyThick(DimensionSpecialEffects skyProperties, int x, int z) 19 | { 20 | if (CarpetSettings.fogOff) return false; 21 | return skyProperties.isFoggyAt(x, z); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Level_fillUpdatesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.level.Level; 6 | import net.minecraft.world.level.block.Block; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Constant; 10 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 11 | import org.spongepowered.asm.mixin.injection.Redirect; 12 | 13 | @Mixin(Level.class) 14 | public abstract class Level_fillUpdatesMixin 15 | { 16 | @ModifyConstant(method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z", //setBlockState main 17 | constant = @Constant(intValue = 16)) 18 | private int addFillUpdatesInt(int original) { 19 | if (CarpetSettings.impendingFillSkipUpdates.get()) 20 | return -1; 21 | return original; 22 | } 23 | 24 | @Redirect(method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z", at = @At( //setBlockState main 25 | value = "INVOKE", 26 | target = "Lnet/minecraft/world/level/Level;updateNeighborsAt(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;)V" 27 | )) 28 | private void updateNeighborsMaybe(Level world, BlockPos blockPos, Block block) 29 | { 30 | if (!CarpetSettings.impendingFillSkipUpdates.get()) world.updateNeighborsAt(blockPos, block); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Level_scarpetPlopMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.level.Level; 5 | import net.minecraft.world.level.chunk.LevelChunk; 6 | import net.minecraft.world.level.levelgen.Heightmap; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Redirect; 10 | 11 | @Mixin(Level.class) 12 | public class Level_scarpetPlopMixin 13 | { 14 | 15 | @Redirect(method = "getHeight", at = @At( 16 | value = "INVOKE", 17 | target = "net/minecraft/world/level/chunk/LevelChunk.getHeight(Lnet/minecraft/world/level/levelgen/Heightmap$Types;II)I" 18 | )) 19 | private int fixSampleHeightmap(LevelChunk chunk, Heightmap.Types type, int x, int z) 20 | { 21 | if (CarpetSettings.skipGenerationChecks.get()) 22 | { 23 | Heightmap.Types newType = type; 24 | if (type == Heightmap.Types.OCEAN_FLOOR_WG) newType = Heightmap.Types.OCEAN_FLOOR; 25 | else if (type == Heightmap.Types.WORLD_SURFACE_WG) newType = Heightmap.Types.WORLD_SURFACE; 26 | return chunk.getHeight(newType, x, z); 27 | } 28 | return chunk.getHeight(type, x, z); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LiquidBlock_renewableDeepslateMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.level.Level; 6 | import net.minecraft.world.level.LevelAccessor; 7 | import net.minecraft.world.level.block.Blocks; 8 | import net.minecraft.world.level.block.LiquidBlock; 9 | import net.minecraft.world.level.block.state.BlockState; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Shadow; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 15 | 16 | @Mixin(LiquidBlock.class) 17 | public abstract class LiquidBlock_renewableDeepslateMixin { 18 | 19 | @Shadow protected abstract void fizz(LevelAccessor world, BlockPos pos); 20 | 21 | @Inject(method = "shouldSpreadLiquid", at = @At(value = "INVOKE",target = "Lnet/minecraft/world/level/material/FluidState;isSource()Z"), cancellable = true) 22 | private void receiveFluidToDeepslate(Level world, BlockPos pos, BlockState state, CallbackInfoReturnable cir) 23 | { 24 | if(CarpetSettings.renewableDeepslate && !world.getFluidState(pos).isSource() && world.dimension() == Level.OVERWORLD && pos.getY() < 0) 25 | { 26 | world.setBlockAndUpdate(pos, Blocks.COBBLED_DEEPSLATE.defaultBlockState()); 27 | this.fizz(world, pos); 28 | cir.setReturnValue(false); 29 | cir.cancel(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LivingEntity_cleanLogsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.server.level.ServerLevel; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.entity.EntityType; 7 | import net.minecraft.world.entity.LivingEntity; 8 | import net.minecraft.world.level.GameRules; 9 | import net.minecraft.world.level.Level; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Redirect; 13 | 14 | @Mixin(LivingEntity.class) 15 | public abstract class LivingEntity_cleanLogsMixin extends Entity 16 | { 17 | 18 | public LivingEntity_cleanLogsMixin(EntityType type, Level world) 19 | { 20 | super(type, world); 21 | } 22 | 23 | @Redirect(method = "die", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hasCustomName()Z")) 24 | private boolean shouldLogDeaths(LivingEntity livingEntity) 25 | { 26 | return livingEntity.hasCustomName() && CarpetSettings.cleanLogs && livingEntity.getServer().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MerchantResultSlot_scarpetEventMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 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.At; 7 | import org.spongepowered.asm.mixin.injection.Inject; 8 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 9 | 10 | import static carpet.script.CarpetEventServer.Event.PLAYER_TRADES; 11 | 12 | import net.minecraft.server.level.ServerPlayer; 13 | import net.minecraft.world.entity.player.Player; 14 | import net.minecraft.world.inventory.MerchantContainer; 15 | import net.minecraft.world.inventory.MerchantResultSlot; 16 | import net.minecraft.world.item.ItemStack; 17 | import net.minecraft.world.item.trading.Merchant; 18 | 19 | @Mixin(MerchantResultSlot.class) 20 | public abstract class MerchantResultSlot_scarpetEventMixin { 21 | @Shadow @Final private Merchant merchant; 22 | 23 | @Shadow @Final private MerchantContainer slots; 24 | 25 | @Inject(method = "onTake", at = @At(value = "INVOKE", 26 | target = "Lnet/minecraft/world/item/trading/Merchant;notifyTrade(Lnet/minecraft/world/item/trading/MerchantOffer;)V") 27 | ) 28 | private void onTrade(Player player, ItemStack stack, CallbackInfo ci) { 29 | if(PLAYER_TRADES.isNeeded() && !player.level().isClientSide()) 30 | { 31 | PLAYER_TRADES.onTrade((ServerPlayer) player, merchant, slots.getActiveOffer()); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MinecraftMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.network.CarpetClient; 4 | import net.minecraft.client.Minecraft; 5 | import net.minecraft.client.gui.screens.Screen; 6 | import net.minecraft.client.multiplayer.ClientLevel; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 12 | 13 | @Mixin(Minecraft.class) 14 | public class MinecraftMixin 15 | { 16 | @Shadow public ClientLevel level; 17 | 18 | @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;Z)V", at = @At("HEAD")) 19 | private void onCloseGame(Screen screen, boolean b, CallbackInfo ci) 20 | { 21 | CarpetClient.disconnect(); 22 | } 23 | 24 | @Inject(at = @At("HEAD"), method = "tick") 25 | private void onClientTick(CallbackInfo info) { 26 | if (this.level != null) { 27 | boolean runsNormally = level.tickRateManager().runsNormally(); 28 | // hope server doesn't need to tick - should be handled by the server on its own 29 | if (!runsNormally) 30 | CarpetClient.shapes.renewShapes(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MinecraftServer_pingPlayerSampleLimit.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 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 | 7 | import carpet.CarpetSettings; 8 | import net.minecraft.server.MinecraftServer; 9 | 10 | @Mixin(MinecraftServer.class) 11 | public abstract class MinecraftServer_pingPlayerSampleLimit 12 | { 13 | 14 | @ModifyConstant(method = "buildPlayerStatus", constant = @Constant(intValue = 12), require = 1) 15 | private int modifyPlayerSampleLimit(int value) 16 | { 17 | return CarpetSettings.pingPlayerListLimit; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Minecraft_tickMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.client.Minecraft; 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.CallbackInfoReturnable; 9 | 10 | @Mixin(Minecraft.class) 11 | public class Minecraft_tickMixin 12 | { 13 | @Inject(method = "getTickTargetMillis", at = @At("HEAD"), cancellable = true) 14 | private void onGetTickTargetMillis(final float f, final CallbackInfoReturnable cir) 15 | { 16 | if (!CarpetSettings.smoothClientAnimations) { 17 | cir.setReturnValue(f); 18 | } 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MobCategory_spawnMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.SpawnGroupInterface; 4 | import carpet.utils.SpawnReporter; 5 | import net.minecraft.world.entity.MobCategory; 6 | import org.spongepowered.asm.mixin.Final; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 12 | 13 | @Mixin(MobCategory.class) 14 | public class MobCategory_spawnMixin implements SpawnGroupInterface 15 | { 16 | @Shadow @Final private int max; 17 | 18 | @Inject(method = "getMaxInstancesPerChunk", at = @At("HEAD"), cancellable = true) 19 | private void getModifiedCapacity(CallbackInfoReturnable cir) 20 | { 21 | cir.setReturnValue ((int) ((double)max*(Math.pow(2.0,(SpawnReporter.mobcap_exponent/4))))); 22 | } 23 | 24 | @Override 25 | public int getInitialSpawnCap() 26 | { 27 | return max; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MobMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.MobEntityInterface; 4 | import org.spongepowered.asm.mixin.Final; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | import net.minecraft.world.entity.Mob; 11 | import net.minecraft.world.entity.ai.goal.Goal; 12 | import net.minecraft.world.entity.ai.goal.GoalSelector; 13 | 14 | @Mixin(Mob.class) 15 | public abstract class MobMixin implements MobEntityInterface 16 | { 17 | @Shadow @Final protected GoalSelector targetSelector; 18 | @Shadow @Final protected GoalSelector goalSelector; 19 | @Shadow private boolean persistenceRequired; 20 | public final Map temporaryTasks = new HashMap<>(); 21 | 22 | @Override 23 | public GoalSelector getAI(boolean target) 24 | { 25 | return target?targetSelector:goalSelector; 26 | } 27 | 28 | @Override 29 | public Map getTemporaryTasks() 30 | { 31 | return temporaryTasks; 32 | } 33 | 34 | @Override 35 | public void setPersistence(boolean what) 36 | { 37 | persistenceRequired = what; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Objective_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.world.scores.Objective; 4 | import net.minecraft.world.scores.criteria.ObjectiveCriteria; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Mutable; 7 | import org.spongepowered.asm.mixin.gen.Accessor; 8 | 9 | @Mixin(Objective.class) 10 | public interface Objective_scarpetMixin { 11 | @Mutable @Accessor("criteria") 12 | void setCriterion(ObjectiveCriteria criterion); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PerfCommand_permissionMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.commands.Commands; 5 | import net.minecraft.commands.PermissionSource; 6 | import net.minecraft.server.commands.PerfCommand; 7 | import net.minecraft.server.commands.PermissionCheck; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Redirect; 11 | 12 | @Mixin(PerfCommand.class) 13 | public class PerfCommand_permissionMixin 14 | { 15 | @Redirect(method = "register", at = @At( 16 | value = "INVOKE", 17 | target = "Lnet/minecraft/commands/Commands;hasPermission(I)Lnet/minecraft/server/commands/PermissionCheck;" 18 | )) 19 | private static PermissionCheck canRun(int i) 20 | { 21 | return Commands.hasPermission(CarpetSettings.perfPermissionLevel); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PieceGeneratorSupplier_plopMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.injection.At; 6 | import org.spongepowered.asm.mixin.injection.Redirect; 7 | 8 | import java.util.function.Predicate; 9 | import net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier; 10 | 11 | @Mixin(PieceGeneratorSupplier.class) 12 | public interface PieceGeneratorSupplier_plopMixin 13 | { 14 | @Redirect(method = "method_39845", at = @At( 15 | value = "INVOKE", 16 | target = "java/util/function/Predicate.test(Ljava/lang/Object;)Z" 17 | ), remap = false) 18 | private static boolean checkMate(Predicate predicate, Object o) 19 | { 20 | return CarpetSettings.skipGenerationChecks.get() || predicate.test(o); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PiglinBrute_getPlacementTypeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.entity.EntityType; 5 | import net.minecraft.world.entity.SpawnPlacementType; 6 | import net.minecraft.world.entity.SpawnPlacementTypes; 7 | import net.minecraft.world.entity.SpawnPlacements; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 12 | 13 | @Mixin(SpawnPlacements.class) 14 | public class PiglinBrute_getPlacementTypeMixin { 15 | @Inject(method = "getPlacementType", at = @At("HEAD"), cancellable = true) 16 | private static void getPlacementType(final EntityType entityType, final CallbackInfoReturnable cir) { 17 | if (CarpetSettings.piglinsSpawningInBastions && entityType == EntityType.PIGLIN_BRUTE) { 18 | cir.setReturnValue(SpawnPlacementTypes.ON_GROUND); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PistonBaseBlock_qcMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.world.level.SignalGetter; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.injection.At; 6 | import org.spongepowered.asm.mixin.injection.Inject; 7 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 8 | 9 | import carpet.helpers.QuasiConnectivity; 10 | 11 | import net.minecraft.core.BlockPos; 12 | import net.minecraft.core.Direction; 13 | import net.minecraft.world.level.block.piston.PistonBaseBlock; 14 | 15 | @Mixin(PistonBaseBlock.class) 16 | public class PistonBaseBlock_qcMixin { 17 | 18 | @Inject( 19 | method = "getNeighborSignal", 20 | cancellable = true, 21 | at = @At( 22 | value = "INVOKE", 23 | target = "Lnet/minecraft/core/BlockPos;above()Lnet/minecraft/core/BlockPos;" 24 | ) 25 | ) 26 | private void carpet_checkQuasiSignal(SignalGetter level, BlockPos pos, Direction facing, CallbackInfoReturnable cir) { 27 | cir.setReturnValue(QuasiConnectivity.hasQuasiSignal(level, pos)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PistonBaseBlock_rotatorBlockMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.PistonBlockInterface; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.core.Direction; 6 | import net.minecraft.world.level.Level; 7 | import net.minecraft.world.level.SignalGetter; 8 | import net.minecraft.world.level.block.piston.PistonBaseBlock; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Shadow; 11 | 12 | @Mixin(PistonBaseBlock.class) 13 | public abstract class PistonBaseBlock_rotatorBlockMixin implements PistonBlockInterface 14 | { 15 | @Shadow protected abstract boolean getNeighborSignal(SignalGetter world_1, BlockPos blockPos_1, Direction direction_1); 16 | 17 | @Override 18 | public boolean publicShouldExtend(Level world_1, BlockPos blockPos_1, Direction direction_1) 19 | { 20 | return getNeighborSignal(world_1, blockPos_1,direction_1); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PistonStructureResolver_pushLimitMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.level.block.piston.PistonStructureResolver; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.Constant; 7 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 8 | 9 | @Mixin(value = PistonStructureResolver.class, priority = 420) // piston push limit is important for carpet 10 | public class PistonStructureResolver_pushLimitMixin 11 | { 12 | @ModifyConstant(method = "addBlockLine", constant = @Constant(intValue = PistonStructureResolver.MAX_PUSH_DEPTH), expect = 3) 13 | private int pushLimit(int original) 14 | { 15 | return CarpetSettings.pushLimit; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PlayerList_coreMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import carpet.network.ServerNetworkHandler; 5 | import net.minecraft.network.Connection; 6 | import net.minecraft.server.level.ServerLevel; 7 | import net.minecraft.server.level.ServerPlayer; 8 | import net.minecraft.server.network.CommonListenerCookie; 9 | import net.minecraft.server.players.PlayerList; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 | 15 | @Mixin(PlayerList.class) 16 | public class PlayerList_coreMixin 17 | { 18 | 19 | @Inject(method = "placeNewPlayer", at = @At("RETURN")) 20 | private void onPlayerConnected(Connection connection, ServerPlayer player, CommonListenerCookie i, CallbackInfo ci) 21 | { 22 | CarpetServer.onPlayerLoggedIn(player); 23 | } 24 | 25 | @Inject(method = "sendLevelInfo", at = @At("RETURN")) 26 | private void onLevelChanged(final ServerPlayer serverPlayer, final ServerLevel serverLevel, final CallbackInfo ci) 27 | { 28 | ServerNetworkHandler.sendPlayerLevelData(serverPlayer, serverLevel); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PlayerTabOverlayMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | import carpet.fakes.PlayerListHudInterface; 3 | import net.minecraft.client.gui.components.PlayerTabOverlay; 4 | import net.minecraft.network.chat.Component; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | 8 | @Mixin(PlayerTabOverlay.class) 9 | public abstract class PlayerTabOverlayMixin implements PlayerListHudInterface 10 | { 11 | @Shadow private Component footer; 12 | 13 | @Shadow private Component header; 14 | 15 | @Override 16 | public boolean hasFooterOrHeader() 17 | { 18 | return footer != null || header != null; 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Player_fakePlayersMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.patches.EntityPlayerMPFake; 4 | import net.minecraft.world.entity.Entity; 5 | import net.minecraft.world.entity.player.Player; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Redirect; 9 | 10 | @Mixin(Player.class) 11 | public abstract class Player_fakePlayersMixin 12 | { 13 | /** 14 | * To make sure player attacks are able to knockback fake players 15 | */ 16 | @Redirect( 17 | method = "attack", 18 | at = @At( 19 | value = "FIELD", 20 | target = "Lnet/minecraft/world/entity/Entity;hurtMarked:Z", 21 | ordinal = 0 22 | ) 23 | ) 24 | private boolean velocityModifiedAndNotCarpetFakePlayer(Entity target) 25 | { 26 | return target.hurtMarked && !(target instanceof EntityPlayerMPFake); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Player_xpNoCooldownMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.Shadow; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.List; 10 | import net.minecraft.world.entity.Entity; 11 | import net.minecraft.world.entity.player.Player; 12 | 13 | @Mixin(Player.class) 14 | public abstract class Player_xpNoCooldownMixin { 15 | 16 | @Shadow 17 | protected abstract void touch(Entity entity); 18 | 19 | @Redirect(method = "aiStep",at = @At(value = "INVOKE", target = "java/util/List.add(Ljava/lang/Object;)Z")) 20 | public boolean processXpOrbCollisions(List instance, Object e) { 21 | Entity entity = (Entity) e; 22 | if (CarpetSettings.xpNoCooldown) { 23 | this.touch(entity); 24 | return true; 25 | } 26 | return instance.add(entity); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PoiRecord_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.world.entity.ai.village.poi.PoiRecord; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | import org.spongepowered.asm.mixin.gen.Invoker; 7 | 8 | @Mixin(PoiRecord.class) 9 | public interface PoiRecord_scarpetMixin 10 | { 11 | @Accessor("freeTickets") 12 | int getFreeTickets(); 13 | 14 | @Invoker 15 | boolean callAcquireTicket(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PortalProcessor_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.PortalProcessorInterface; 4 | import net.minecraft.world.entity.PortalProcessor; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | 8 | @Mixin(PortalProcessor.class) 9 | public class PortalProcessor_scarpetMixin implements PortalProcessorInterface 10 | { 11 | 12 | @Shadow private int portalTime; 13 | 14 | @Override 15 | public void setPortalTime(int time) 16 | { 17 | portalTime = time; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PoweredRailBlock_powerLimitMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.level.block.PoweredRailBlock; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.Constant; 7 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 8 | 9 | @Mixin(PoweredRailBlock.class) 10 | public class PoweredRailBlock_powerLimitMixin 11 | { 12 | @ModifyConstant(method = "findPoweredRailSignal(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;ZI)Z", 13 | constant = @Constant(intValue = 8)) 14 | private int powerLimit(int original) 15 | { 16 | return CarpetSettings.railPowerLimit-1; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PrimedTnt_scarpetEventsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.script.EntityEventsGroup; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.entity.EntityType; 7 | import net.minecraft.world.entity.item.PrimedTnt; 8 | import net.minecraft.world.level.Level; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | @Mixin(PrimedTnt.class) 15 | public abstract class PrimedTnt_scarpetEventsMixin extends Entity 16 | { 17 | public PrimedTnt_scarpetEventsMixin(EntityType type, Level world) 18 | { 19 | super(type, world); 20 | } 21 | 22 | @Inject(method = "tick", at = @At("HEAD")) 23 | private void onTickCall(CallbackInfo ci) 24 | { 25 | // calling extra on_tick because falling blocks do not fall back to super tick call 26 | ((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.Event.ON_TICK); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/RandomState_ScarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.RandomStateVisitorAccessor; 4 | import net.minecraft.world.level.levelgen.DensityFunction; 5 | import net.minecraft.world.level.levelgen.RandomState; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.Unique; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.ModifyArg; 10 | 11 | @Mixin(RandomState.class) 12 | public class RandomState_ScarpetMixin implements RandomStateVisitorAccessor { 13 | @Unique 14 | private DensityFunction.Visitor visitor; 15 | 16 | @ModifyArg( 17 | method = "", 18 | at = @At( 19 | value = "INVOKE", 20 | target = "Lnet/minecraft/world/level/levelgen/NoiseRouter;mapAll(Lnet/minecraft/world/level/levelgen/DensityFunction$Visitor;)Lnet/minecraft/world/level/levelgen/NoiseRouter;" 21 | ), 22 | index = 0 23 | ) 24 | private DensityFunction.Visitor captureVisitor(DensityFunction.Visitor visitor) { 25 | this.visitor = visitor; 26 | return visitor; 27 | } 28 | 29 | @Override 30 | public DensityFunction.Visitor getVisitor() { 31 | return this.visitor; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ReloadCommand_reloadAppsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import com.mojang.brigadier.context.CommandContext; 5 | import net.minecraft.commands.CommandSourceStack; 6 | import net.minecraft.server.commands.ReloadCommand; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 11 | 12 | @Mixin(ReloadCommand.class) 13 | public class ReloadCommand_reloadAppsMixin { 14 | //method_13530(Lcom/mojang/brigadier/context/CommandContext;)I 15 | // internal of register. 16 | @Inject(method = "method_13530", at = @At("TAIL"), remap = false) 17 | private static void onReload(CommandContext context, CallbackInfoReturnable cir) 18 | { 19 | // can't fetch here the reference to the server 20 | CarpetServer.onReload(context.getSource().getServer()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Scoreboard_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | import java.util.List; 8 | import net.minecraft.world.scores.Objective; 9 | import net.minecraft.world.scores.Scoreboard; 10 | import net.minecraft.world.scores.criteria.ObjectiveCriteria; 11 | 12 | @Mixin(Scoreboard.class) 13 | public interface Scoreboard_scarpetMixin { 14 | @Accessor("objectivesByCriteria") 15 | Reference2ObjectMap> getObjectivesByCriterion(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/SculkSensorBlockEntityVibrationConfig_sculkSensorRangeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | 4 | import carpet.CarpetSettings; 5 | import net.minecraft.world.level.block.entity.SculkSensorBlockEntity; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 10 | 11 | @Mixin(SculkSensorBlockEntity.VibrationUser.class) 12 | public class SculkSensorBlockEntityVibrationConfig_sculkSensorRangeMixin 13 | { 14 | @Inject(method = "getListenerRadius", at = @At("HEAD"), cancellable = true) 15 | private void sculkSensorRange(CallbackInfoReturnable cir) 16 | { 17 | if (CarpetSettings.sculkSensorRange != SculkSensorBlockEntity.VibrationUser.LISTENER_RANGE) { 18 | cir.setReturnValue(CarpetSettings.sculkSensorRange); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerChunkCache_profilerMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.CarpetProfiler; 4 | import org.spongepowered.asm.mixin.Final; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 10 | 11 | import net.minecraft.server.level.ServerChunkCache; 12 | import net.minecraft.server.level.ServerLevel; 13 | 14 | @Mixin(ServerChunkCache.class) 15 | public abstract class ServerChunkCache_profilerMixin 16 | { 17 | 18 | @Shadow @Final ServerLevel level; 19 | 20 | CarpetProfiler.ProfilerToken currentSection; 21 | 22 | @Inject(method = "tickChunks(Lnet/minecraft/util/profiling/ProfilerFiller;J)V", at = @At("HEAD")) 23 | private void startSpawningSection(CallbackInfo ci) 24 | { 25 | currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL); 26 | } 27 | 28 | @Inject(method = "tickChunks(Lnet/minecraft/util/profiling/ProfilerFiller;J)V", at = @At("RETURN")) 29 | private void stopSpawningSection(CallbackInfo ci) 30 | { 31 | if (currentSection != null) 32 | { 33 | CarpetProfiler.end_current_section(currentSection); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerFunctionManager_profilerMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.CarpetProfiler; 4 | import net.minecraft.server.ServerFunctionManager; 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 | 10 | @Mixin(ServerFunctionManager.class) 11 | public class ServerFunctionManager_profilerMixin 12 | { 13 | CarpetProfiler.ProfilerToken currentSection; 14 | 15 | @Inject(method = "tick", at = @At("HEAD"), cancellable = true) 16 | private void beforeDatapacks(CallbackInfo ci) 17 | { 18 | currentSection = CarpetProfiler.start_section(null, "Datapacks", CarpetProfiler.TYPE.GENERAL); 19 | } 20 | 21 | @Inject(method = "tick", at = @At("RETURN")) 22 | private void afterDatapacks(CallbackInfo ci) 23 | { 24 | CarpetProfiler.end_current_section(currentSection); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerGamePacketListenerImplMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.network.CarpetClient; 4 | import carpet.network.ServerNetworkHandler; 5 | import net.minecraft.network.protocol.PacketUtils; 6 | import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; 7 | import net.minecraft.network.protocol.game.ServerGamePacketListener; 8 | import net.minecraft.resources.ResourceLocation; 9 | import net.minecraft.server.level.ServerPlayer; 10 | import net.minecraft.server.network.ServerGamePacketListenerImpl; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.Shadow; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Inject; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 16 | 17 | @Mixin(ServerGamePacketListenerImpl.class) 18 | public class ServerGamePacketListenerImplMixin 19 | { 20 | @Shadow public ServerPlayer player; 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerGamePacketListenerImpl_coreMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import carpet.fakes.ServerGamePacketListenerImplInterface; 5 | import net.minecraft.network.Connection; 6 | import net.minecraft.network.DisconnectionDetails; 7 | import net.minecraft.network.chat.Component; 8 | import net.minecraft.server.MinecraftServer; 9 | import net.minecraft.server.level.ServerPlayer; 10 | import net.minecraft.server.network.CommonListenerCookie; 11 | import net.minecraft.server.network.ServerCommonPacketListenerImpl; 12 | import net.minecraft.server.network.ServerGamePacketListenerImpl; 13 | import org.spongepowered.asm.mixin.Mixin; 14 | import org.spongepowered.asm.mixin.Shadow; 15 | import org.spongepowered.asm.mixin.injection.At; 16 | import org.spongepowered.asm.mixin.injection.Inject; 17 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 18 | 19 | @Mixin(ServerGamePacketListenerImpl.class) 20 | public abstract class ServerGamePacketListenerImpl_coreMixin extends ServerCommonPacketListenerImpl implements ServerGamePacketListenerImplInterface { 21 | @Shadow 22 | public ServerPlayer player; 23 | 24 | public ServerGamePacketListenerImpl_coreMixin(final MinecraftServer minecraftServer, final Connection connection, final CommonListenerCookie i) 25 | { 26 | super(minecraftServer, connection, i); 27 | } 28 | 29 | @Inject(method = "onDisconnect", at = @At("HEAD")) 30 | private void onPlayerDisconnect(DisconnectionDetails reason, CallbackInfo ci) { 31 | CarpetServer.onPlayerLoggedOut(this.player, reason.reason()); 32 | } 33 | 34 | @Override 35 | public Connection getConnection() { 36 | return connection; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerGamePacketListenerimpl_connectionMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.network.CarpetClient; 4 | import carpet.network.ServerNetworkHandler; 5 | import net.minecraft.network.protocol.PacketUtils; 6 | import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; 7 | import net.minecraft.network.protocol.game.ServerGamePacketListener; 8 | import net.minecraft.server.level.ServerPlayer; 9 | import net.minecraft.server.network.ServerGamePacketListenerImpl; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Shadow; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 15 | 16 | @Mixin(ServerGamePacketListenerImpl.class) 17 | public class ServerGamePacketListenerimpl_connectionMixin 18 | { 19 | @Shadow 20 | public ServerPlayer player; 21 | 22 | @Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true) 23 | private void onCustomCarpetPayload(ServerboundCustomPayloadPacket serverboundCustomPayloadPacket, CallbackInfo ci) 24 | { 25 | if (serverboundCustomPayloadPacket.payload() instanceof CarpetClient.CarpetPayload cpp) { 26 | // We should force onto the main thread here 27 | // ServerNetworkHandler.handleData can possibly mutate data that isn't 28 | // thread safe, and also allows for client commands to be executed 29 | PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, player.level()); 30 | ServerNetworkHandler.onClientData(player, cpp.data()); 31 | ci.cancel(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerPlayerGameMode_cactusMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.BlockRotator; 4 | import net.minecraft.server.level.ServerPlayerGameMode; 5 | import net.minecraft.world.InteractionHand; 6 | import net.minecraft.world.InteractionResult; 7 | import net.minecraft.world.entity.player.Player; 8 | import net.minecraft.world.item.ItemStack; 9 | import net.minecraft.world.level.Level; 10 | import net.minecraft.world.level.block.state.BlockState; 11 | import net.minecraft.world.phys.BlockHitResult; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Redirect; 15 | 16 | @Mixin(ServerPlayerGameMode.class) 17 | public class ServerPlayerGameMode_cactusMixin 18 | { 19 | 20 | @Redirect(method = "useItemOn", at = @At( 21 | value = "INVOKE", 22 | target = "Lnet/minecraft/world/level/block/state/BlockState;useItemOn(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;" 23 | )) 24 | private InteractionResult activateWithOptionalCactus(final BlockState blockState, final ItemStack itemStack, final Level world_1, final Player playerEntity_1, final InteractionHand hand_1, final BlockHitResult blockHitResult_1) 25 | { 26 | boolean flipped = BlockRotator.flipBlockWithCactus(blockState, world_1, playerEntity_1, hand_1, blockHitResult_1); 27 | if (flipped) 28 | return InteractionResult.SUCCESS; 29 | 30 | return blockState.useItemOn(itemStack, world_1, playerEntity_1, hand_1, blockHitResult_1); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.ServerPlayerInterface; 4 | import carpet.helpers.EntityPlayerActionPack; 5 | import com.mojang.authlib.GameProfile; 6 | import net.minecraft.server.MinecraftServer; 7 | import net.minecraft.server.level.ClientInformation; 8 | import net.minecraft.server.level.ServerLevel; 9 | import net.minecraft.server.level.ServerPlayer; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Unique; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 15 | 16 | @Mixin(ServerPlayer.class) 17 | public abstract class ServerPlayer_actionPackMixin implements ServerPlayerInterface 18 | { 19 | @Unique 20 | public EntityPlayerActionPack actionPack; 21 | @Override 22 | public EntityPlayerActionPack getActionPack() 23 | { 24 | return actionPack; 25 | } 26 | 27 | @Inject(method = "", at = @At(value = "RETURN")) 28 | private void onServerPlayerEntityContructor(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ClientInformation cli, CallbackInfo ci) 29 | { 30 | this.actionPack = new EntityPlayerActionPack((ServerPlayer) (Object) this); 31 | } 32 | 33 | @Inject(method = "tick", at = @At(value = "HEAD")) 34 | private void onTick(CallbackInfo ci) 35 | { 36 | actionPack.onUpdate(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerStatus_motdMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.network.chat.Component; 5 | import net.minecraft.network.protocol.status.ServerStatus; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 10 | 11 | @Mixin(ServerStatus.class) 12 | public class ServerStatus_motdMixin 13 | { 14 | @Inject(method = "description", at = @At("HEAD"), cancellable = true) 15 | private void getDescriptionAlternative(CallbackInfoReturnable cir) 16 | { 17 | if (!CarpetSettings.customMOTD.equals("_")) 18 | { 19 | cir.setReturnValue(Component.literal(CarpetSettings.customMOTD)); 20 | cir.cancel(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/SetBlockCommand_fillUpdatesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.server.commands.SetBlockCommand; 6 | import net.minecraft.server.level.ServerLevel; 7 | import net.minecraft.world.level.block.Block; 8 | import net.minecraft.world.level.block.state.BlockState; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Redirect; 12 | 13 | @Mixin(SetBlockCommand.class) 14 | public class SetBlockCommand_fillUpdatesMixin 15 | { 16 | @Redirect(method = "setBlock", at = @At( 17 | value = "INVOKE", 18 | target = "Lnet/minecraft/server/level/ServerLevel;updateNeighboursOnBlockSet(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V" 19 | )) 20 | private static void conditionalUpdating(ServerLevel serverWorld, BlockPos blockPos_1, BlockState block_1) 21 | { 22 | if (CarpetSettings.fillUpdates) serverWorld.updateNeighboursOnBlockSet(blockPos_1, block_1); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ShulkerBoxAccessMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | import org.spongepowered.asm.mixin.Mixin; 3 | 4 | @Mixin(net.minecraft.client.renderer.blockentity.ShulkerBoxRenderer.class) 5 | public interface ShulkerBoxAccessMixin { 6 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ShulkerBoxBlockEntity_creativeNoClipMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.entity.Entity; 5 | import net.minecraft.world.entity.player.Player; 6 | import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; 7 | import net.minecraft.world.level.material.PushReaction; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Redirect; 11 | 12 | @Mixin(ShulkerBoxBlockEntity.class) 13 | public class ShulkerBoxBlockEntity_creativeNoClipMixin 14 | { 15 | @Redirect(method = "moveCollidedEntities", at = @At( 16 | value = "INVOKE", 17 | target = "Lnet/minecraft/world/entity/Entity;getPistonPushReaction()Lnet/minecraft/world/level/material/PushReaction;" 18 | )) 19 | private PushReaction getPistonBehaviourOfNoClipPlayers(Entity entity) 20 | { 21 | if (CarpetSettings.creativeNoClip && entity instanceof Player && (((Player) entity).isCreative()) && ((Player) entity).getAbilities().flying) 22 | return PushReaction.IGNORE; 23 | return entity.getPistonPushReaction(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/SpawnState_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.SpawnHelperInnerInterface; 4 | import net.minecraft.world.level.NaturalSpawner; 5 | import net.minecraft.world.level.PotentialCalculator; 6 | import org.spongepowered.asm.mixin.Final; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | 10 | @Mixin(NaturalSpawner.SpawnState.class) 11 | public class SpawnState_scarpetMixin implements SpawnHelperInnerInterface 12 | { 13 | @Shadow @Final private PotentialCalculator spawnPotential; 14 | 15 | @Override 16 | public PotentialCalculator getPotentialCalculator() 17 | { 18 | return spawnPotential; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/StructureBlockRenderer_mixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; 5 | import net.minecraft.client.renderer.blockentity.BlockEntityWithBoundingBoxRenderer; 6 | import net.minecraft.world.level.block.entity.StructureBlockEntity; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 11 | 12 | @Mixin(BlockEntityWithBoundingBoxRenderer.class) 13 | public abstract class StructureBlockRenderer_mixin implements BlockEntityRenderer 14 | { 15 | @Inject(method = "getViewDistance", at = @At("HEAD"), cancellable = true) 16 | void newLimit(CallbackInfoReturnable cir) 17 | { 18 | if (CarpetSettings.structureBlockOutlineDistance != 96) 19 | cir.setReturnValue(CarpetSettings.structureBlockOutlineDistance); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/StructurePiece_scarpetPlopMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.level.chunk.ChunkAccess; 6 | import net.minecraft.world.level.levelgen.structure.StructurePiece; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Redirect; 10 | 11 | @Mixin(StructurePiece.class) 12 | public class StructurePiece_scarpetPlopMixin 13 | { 14 | @Redirect(method = "placeBlock", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/level/chunk/ChunkAccess;markPosForPostprocessing(Lnet/minecraft/core/BlockPos;)V" 17 | )) 18 | private void markOrNot(ChunkAccess chunk, BlockPos pos) 19 | { 20 | if (!CarpetSettings.skipGenerationChecks.get()) chunk.markPosForPostprocessing(pos); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/StructureTemplate_fillUpdatesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.level.ServerLevelAccessor; 6 | import net.minecraft.world.level.block.Block; 7 | import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; 8 | import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Redirect; 12 | 13 | @Mixin(StructureTemplate.class) 14 | public class StructureTemplate_fillUpdatesMixin 15 | { 16 | @Redirect( method = "placeInWorld", at = @At( 17 | value = "INVOKE", 18 | target = "Lnet/minecraft/world/level/ServerLevelAccessor;updateNeighborsAt(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;)V" 19 | )) 20 | private void skipUpdateNeighbours(ServerLevelAccessor serverWorldAccess, BlockPos pos, Block block) 21 | { 22 | if (!CarpetSettings.impendingFillSkipUpdates.get()) 23 | serverWorldAccess.updateNeighborsAt(pos, block); 24 | } 25 | 26 | @Redirect(method = "placeInWorld", at = @At( 27 | value = "INVOKE", 28 | target = "Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings;getKnownShape()Z" 29 | )) 30 | private boolean skipPostprocess(StructurePlaceSettings structurePlacementData) 31 | { 32 | return structurePlacementData.getKnownShape() || CarpetSettings.impendingFillSkipUpdates.get(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/SystemReport_addScarpetAppsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import java.util.function.Supplier; 4 | import java.util.stream.Collectors; 5 | import net.minecraft.SystemReport; 6 | import org.spongepowered.asm.mixin.Mixin; 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 | 12 | import carpet.CarpetServer; 13 | 14 | @Mixin(SystemReport.class) 15 | public abstract class SystemReport_addScarpetAppsMixin 16 | { 17 | @Shadow public abstract void setDetail(String name, Supplier valueSupplier); 18 | 19 | @Inject(method = "", at = @At("RETURN")) 20 | private void fillSystemDetails(CallbackInfo info) { 21 | if (CarpetServer.scriptServer == null || CarpetServer.scriptServer.modules.isEmpty()) return; 22 | setDetail("Loaded Scarpet Apps", () -> { 23 | return CarpetServer.scriptServer.modules.keySet().stream().collect(Collectors.joining("\n\t\t", "\n\t\t", "")); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/TagPredicate_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.BlockPredicateInterface; 4 | import carpet.script.value.StringValue; 5 | import carpet.script.value.Value; 6 | import net.minecraft.core.HolderSet; 7 | import net.minecraft.tags.TagKey; 8 | import org.spongepowered.asm.mixin.Final; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Shadow; 11 | 12 | import java.util.Map; 13 | import java.util.stream.Collectors; 14 | import net.minecraft.nbt.CompoundTag; 15 | import net.minecraft.world.level.block.Block; 16 | import net.minecraft.world.level.block.state.BlockState; 17 | 18 | @Mixin(targets = "net.minecraft.commands.arguments.blocks.BlockPredicateArgument$TagPredicate") 19 | public class TagPredicate_scarpetMixin implements BlockPredicateInterface 20 | { 21 | @Shadow @Final private HolderSet tag; 22 | 23 | @Shadow @Final private Map vagueProperties; 24 | 25 | @Shadow @Final /*@Nullable*/ private CompoundTag nbt; 26 | 27 | @Override 28 | public BlockState getCMBlockState() 29 | { 30 | return null; 31 | } 32 | 33 | @Override 34 | public TagKey getCMBlockTagKey() 35 | { 36 | // might be good to explose the holder set nature of it. 37 | return tag.unwrap().left().orElse(null); 38 | } 39 | 40 | @Override 41 | public Map getCMProperties() 42 | { 43 | return vagueProperties.entrySet().stream().collect(Collectors.toMap( 44 | e -> new StringValue(e.getKey()), 45 | e -> new StringValue(e.getValue()) 46 | )); 47 | } 48 | 49 | @Override 50 | public CompoundTag getCMDataTag() 51 | { 52 | return nbt; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/TheEndGatewayBlockEntity_creativeNoClipMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.entity.Entity; 5 | import net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 10 | 11 | @Mixin(TheEndGatewayBlockEntity.class) 12 | public class TheEndGatewayBlockEntity_creativeNoClipMixin 13 | { 14 | // removeme 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/TicketStorage_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.TicketsFetcherInterface; 4 | import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; 5 | import net.minecraft.server.level.Ticket; 6 | import net.minecraft.world.level.TicketStorage; 7 | import org.spongepowered.asm.mixin.Final; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.Shadow; 10 | 11 | import java.util.List; 12 | 13 | @Mixin(TicketStorage.class) 14 | public class TicketStorage_scarpetMixin implements TicketsFetcherInterface 15 | { 16 | @Shadow @Final private Long2ObjectOpenHashMap> tickets; 17 | 18 | @Override 19 | public Long2ObjectOpenHashMap> getTicketsByPosition() 20 | { 21 | return tickets; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/TntBlock_noUpdateMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.world.level.Level; 6 | import net.minecraft.world.level.block.TntBlock; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Redirect; 10 | 11 | @Mixin(TntBlock.class) 12 | public abstract class TntBlock_noUpdateMixin 13 | { 14 | // Add carpet rule check for tntDoNotUpdate to an if statement. 15 | @Redirect(method = "onPlace", at = @At(value = "INVOKE", 16 | target = "Lnet/minecraft/world/level/Level;hasNeighborSignal(Lnet/minecraft/core/BlockPos;)Z")) 17 | private boolean isTNTDoNotUpdate(Level world, BlockPos blockPos) 18 | { 19 | return !CarpetSettings.tntDoNotUpdate && world.hasNeighborSignal(blockPos); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/UseOnContext_cactusMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.BlockRotator; 4 | import net.minecraft.core.Direction; 5 | import net.minecraft.world.entity.player.Player; 6 | import net.minecraft.world.item.context.UseOnContext; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Redirect; 10 | 11 | @Mixin(UseOnContext.class) 12 | public class UseOnContext_cactusMixin 13 | { 14 | @Redirect(method = "getHorizontalDirection", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/entity/player/Player;getDirection()Lnet/minecraft/core/Direction;" 17 | )) 18 | private Direction getPlayerFacing(Player playerEntity) 19 | { 20 | Direction dir = playerEntity.getDirection(); 21 | if (BlockRotator.flippinEligibility(playerEntity)) 22 | { 23 | dir = dir.getOpposite(); 24 | } 25 | return dir; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/WitherBoss_moreBlueMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | 4 | import carpet.CarpetSettings; 5 | import net.minecraft.util.RandomSource; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Redirect; 9 | 10 | import net.minecraft.world.entity.boss.wither.WitherBoss; 11 | 12 | @Mixin(WitherBoss.class) 13 | public class WitherBoss_moreBlueMixin 14 | { 15 | @Redirect(method = "performRangedAttack(ILnet/minecraft/world/entity/LivingEntity;)V", at = @At( 16 | value = "INVOKE", 17 | target = "Lnet/minecraft/util/RandomSource;nextFloat()F") 18 | ) 19 | private float nextFloatAmplfied(RandomSource random) 20 | { 21 | if (CarpetSettings.moreBlueSkulls) return random.nextFloat()/100; 22 | return random.nextFloat(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/WoolCarpetBlock_placeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.WoolTool; 4 | import net.minecraft.server.level.ServerLevel; 5 | import net.minecraft.server.level.ServerPlayer; 6 | import net.minecraft.world.item.context.BlockPlaceContext; 7 | import net.minecraft.world.level.block.Block; 8 | import net.minecraft.world.level.block.WoolCarpetBlock; 9 | import net.minecraft.world.level.block.state.BlockState; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | 12 | @Mixin(WoolCarpetBlock.class) // WoolCarpetBlock 13 | public abstract class WoolCarpetBlock_placeMixin extends Block 14 | { 15 | 16 | public WoolCarpetBlock_placeMixin(Properties block$Settings_1) 17 | { 18 | super(block$Settings_1); 19 | } 20 | 21 | @Override 22 | public BlockState getStateForPlacement(BlockPlaceContext context) 23 | { 24 | BlockState state = super.getStateForPlacement(context); 25 | if (context.getPlayer() != null && !context.getLevel().isClientSide) 26 | { // getColor() 27 | WoolTool.carpetPlacedAction(((WoolCarpetBlock)(Object)this).getColor(), (ServerPlayer) context.getPlayer(), context.getClickedPos(), (ServerLevel) context.getLevel()); 28 | } 29 | return state; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/WorldBorder_syncedWorldBorderMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.patches.TickSyncedBorderExtent; 5 | import net.minecraft.world.level.border.WorldBorder; 6 | import org.spongepowered.asm.mixin.Mixin; 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 | 12 | @Mixin(WorldBorder.class) 13 | public class WorldBorder_syncedWorldBorderMixin 14 | { 15 | @Shadow private WorldBorder.BorderExtent extent; 16 | 17 | @Inject(method = "lerpSizeBetween", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/border/WorldBorder;getListeners()Ljava/util/List;")) 18 | private void getExtent(double d, double e, long l, CallbackInfo ci) 19 | { 20 | if (d != e && CarpetSettings.tickSyncedWorldBorders) 21 | { 22 | this.extent = new TickSyncedBorderExtent((WorldBorder) (Object) this, l, d, e); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/WorldGenRegion_scarpetPlopMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.server.level.WorldGenRegion; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 10 | 11 | @Mixin(WorldGenRegion.class) 12 | public class WorldGenRegion_scarpetPlopMixin 13 | { 14 | @Inject(method = "markPosForPostprocessing", at = @At("HEAD"), cancellable = true) 15 | private void markOrNot(BlockPos blockPos, CallbackInfo ci) 16 | { 17 | if (CarpetSettings.skipGenerationChecks.get()) ci.cancel(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/carpet/patches/FakeClientConnection.java: -------------------------------------------------------------------------------- 1 | package carpet.patches; 2 | 3 | import carpet.fakes.ClientConnectionInterface; 4 | import io.netty.channel.embedded.EmbeddedChannel; 5 | import net.minecraft.network.Connection; 6 | import net.minecraft.network.PacketListener; 7 | import net.minecraft.network.ProtocolInfo; 8 | import net.minecraft.network.protocol.PacketFlow; 9 | 10 | public class FakeClientConnection extends Connection 11 | { 12 | public FakeClientConnection(PacketFlow p) 13 | { 14 | super(p); 15 | // compat with adventure-platform-fabric. This does NOT trigger other vanilla handlers for establishing a channel 16 | // also makes #isOpen return true, allowing enderpearls to teleport fake players 17 | ((ClientConnectionInterface)this).setChannel(new EmbeddedChannel()); 18 | } 19 | 20 | @Override 21 | public void setReadOnly() 22 | { 23 | } 24 | 25 | @Override 26 | public void handleDisconnection() 27 | { 28 | } 29 | 30 | @Override 31 | public void setListenerForServerboundHandshake(PacketListener packetListener) 32 | { 33 | } 34 | 35 | @Override 36 | public void setupInboundProtocol(ProtocolInfo protocolInfo, T packetListener) 37 | { 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/carpet/script/LazyValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script; 2 | 3 | import carpet.script.value.Value; 4 | 5 | /** 6 | * LazyNumber interface created for lazily evaluated functions 7 | */ 8 | @FunctionalInterface 9 | public interface LazyValue 10 | { 11 | LazyValue FALSE = (c, t) -> Value.FALSE; 12 | LazyValue TRUE = (c, t) -> Value.TRUE; 13 | LazyValue NULL = (c, t) -> Value.NULL; 14 | LazyValue ZERO = (c, t) -> Value.ZERO; 15 | 16 | static LazyValue ofConstant(Value val) 17 | { 18 | return new Constant(val); 19 | } 20 | 21 | Value evalValue(Context c, Context.Type type); 22 | 23 | default Value evalValue(Context c) 24 | { 25 | return evalValue(c, Context.Type.NONE); 26 | } 27 | 28 | @FunctionalInterface 29 | interface ContextFreeLazyValue extends LazyValue 30 | { 31 | 32 | Value evalType(Context.Type type); 33 | 34 | @Override 35 | default Value evalValue(Context c, Context.Type type) 36 | { 37 | return evalType(type); 38 | } 39 | } 40 | 41 | 42 | class Constant implements ContextFreeLazyValue 43 | { 44 | Value result; 45 | 46 | public Constant(Value value) 47 | { 48 | result = value; 49 | } 50 | 51 | public Value get() 52 | { 53 | return result; 54 | } 55 | 56 | @Override 57 | public Value evalType(Context.Type type) 58 | { 59 | 60 | return result.fromConstant(); 61 | } 62 | 63 | @Override 64 | public Value evalValue(Context c, Context.Type type) 65 | { 66 | return result.fromConstant(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/ScriptServer.java: -------------------------------------------------------------------------------- 1 | package carpet.script; 2 | 3 | import java.nio.file.Path; 4 | import java.util.Map; 5 | import java.util.concurrent.ConcurrentHashMap; 6 | 7 | import carpet.script.value.Value; 8 | 9 | // WIP 10 | public abstract class ScriptServer 11 | { 12 | public final Map systemGlobals = new ConcurrentHashMap<>(); 13 | 14 | public abstract Path resolveResource(String suffix); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.annotation; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/api/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.api; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/argument/Argument.java: -------------------------------------------------------------------------------- 1 | package carpet.script.argument; 2 | 3 | public abstract class Argument 4 | { 5 | public final int offset; 6 | 7 | protected Argument(int offset) 8 | { 9 | this.offset = offset; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/argument/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.argument; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/command/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.command; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/BreakStatement.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.Value; 4 | 5 | import javax.annotation.Nullable; 6 | 7 | public class BreakStatement extends ExitStatement 8 | { 9 | public BreakStatement(@Nullable Value value) 10 | { 11 | super(value); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/CarpetExpressionException.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.external.Carpet; 4 | import carpet.script.value.FunctionValue; 5 | 6 | import java.util.List; 7 | 8 | import net.minecraft.commands.CommandSourceStack; 9 | 10 | public class CarpetExpressionException extends StacklessRuntimeException implements ResolvedException 11 | { 12 | public final List stack; 13 | 14 | public CarpetExpressionException(String message, List stack) 15 | { 16 | super(message); 17 | this.stack = stack; 18 | } 19 | 20 | public void printStack(CommandSourceStack source) 21 | { 22 | if (stack != null && !stack.isEmpty()) 23 | { 24 | for (FunctionValue fun : stack) 25 | { 26 | Carpet.Messenger_message(source, "e ... in " + fun.fullName(), "e /" + (fun.getToken().lineno + 1) + ":" + (fun.getToken().linepos + 1)); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/ContinueStatement.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.Value; 4 | 5 | import javax.annotation.Nullable; 6 | 7 | public class ContinueStatement extends ExitStatement 8 | { 9 | public ContinueStatement(@Nullable Value value) 10 | { 11 | super(value); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/ExitStatement.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.Value; 4 | 5 | import javax.annotation.Nullable; 6 | 7 | /* Exception thrown to terminate execution mid expression (aka return statement) */ 8 | public class ExitStatement extends StacklessRuntimeException 9 | { 10 | @Nullable 11 | public final Value retval; 12 | 13 | public ExitStatement(@Nullable Value value) 14 | { 15 | retval = value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/IntegrityException.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | public class IntegrityException extends RuntimeException 4 | { 5 | public IntegrityException(String message) 6 | { 7 | super(message); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/InternalExpressionException.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.Context; 4 | import carpet.script.Expression; 5 | import carpet.script.Token; 6 | import carpet.script.value.FunctionValue; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /* The internal expression evaluators exception class. */ 12 | public class InternalExpressionException extends StacklessRuntimeException 13 | { 14 | public List stack = new ArrayList<>(); 15 | 16 | public InternalExpressionException(String message) 17 | { 18 | super(message); 19 | } 20 | 21 | /** 22 | *

Promotes this simple exception into one with context and extra information. 23 | * 24 | *

Provides a cleaner way of handling similar exceptions, in this case 25 | * {@link InternalExpressionException} and {@link ThrowStatement} 26 | * 27 | * @param c Context 28 | * @param e Expression 29 | * @param token Token 30 | * @return The new {@link ExpressionException} (or {@link ProcessedThrowStatement}), 31 | * depending on the implementation. 32 | */ 33 | public ExpressionException promote(Context c, Expression e, Token token) 34 | { 35 | return new ExpressionException(c, e, token, getMessage(), stack); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/InvalidCallbackException.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | public class InvalidCallbackException extends Exception 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/LoadException.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | /** 4 | * A Scarpet exception that indicates that load of the app has failed. 5 | *

6 | * Goes up the stack to the point of app load and gets caught there, preventing the app from loading with 7 | * the given message. 8 | */ 9 | public class LoadException extends RuntimeException implements ResolvedException 10 | { 11 | public LoadException() 12 | { 13 | super(); 14 | } 15 | public LoadException(String message) 16 | { 17 | super(message); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/ProcessedThrowStatement.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import java.util.List; 4 | 5 | import carpet.script.Context; 6 | import carpet.script.Expression; 7 | import carpet.script.Token; 8 | import carpet.script.value.FunctionValue; 9 | import carpet.script.value.Value; 10 | 11 | public class ProcessedThrowStatement extends ExpressionException 12 | { 13 | public final Throwables thrownExceptionType; 14 | public final Value data; 15 | 16 | public ProcessedThrowStatement(Context c, Expression e, Token token, List stack, Throwables thrownExceptionType, Value data) 17 | { 18 | super(c, e, token, () -> "Unhandled " + thrownExceptionType.getId() + " exception: " + data.getString(), stack); 19 | this.thrownExceptionType = thrownExceptionType; 20 | this.data = data; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/ResolvedException.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | public interface ResolvedException 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/ReturnStatement.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.Value; 4 | 5 | public class ReturnStatement extends ExitStatement 6 | { 7 | public ReturnStatement(Value value) 8 | { 9 | super(value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/StacklessRuntimeException.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | /** 4 | * A type of {@link RuntimeException} that doesn't spend time producing and filling a stacktrace 5 | */ 6 | public abstract class StacklessRuntimeException extends RuntimeException 7 | { 8 | public StacklessRuntimeException() 9 | { 10 | super(); 11 | } 12 | 13 | public StacklessRuntimeException(String message) 14 | { 15 | super(message); 16 | } 17 | 18 | @Override 19 | public Throwable fillInStackTrace() 20 | { 21 | return this; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.exception; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/external/VanillaClient.java: -------------------------------------------------------------------------------- 1 | package carpet.script.external; 2 | 3 | public class VanillaClient 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/external/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.external; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /src/main/java/carpet/script/language/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.language; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/utils/EntityTools.java: -------------------------------------------------------------------------------- 1 | package carpet.script.utils; 2 | 3 | import net.minecraft.core.BlockPos; 4 | import net.minecraft.util.Mth; 5 | import net.minecraft.world.entity.Entity; 6 | import net.minecraft.world.phys.Vec3; 7 | 8 | public class EntityTools 9 | { 10 | /** 11 | * Not a replacement for living entity jump() - this barely is to allow other entities that can't jump in vanilla to 'jump' 12 | */ 13 | public static void genericJump(Entity e) 14 | { 15 | if (!e.onGround() && !e.isInLiquid()) 16 | { 17 | return; 18 | } 19 | float m = e.level().getBlockState(e.blockPosition()).getBlock().getJumpFactor(); 20 | float g = e.level().getBlockState(BlockPos.containing(e.getX(), e.getBoundingBox().minY - 0.5000001D, e.getZ())).getBlock().getJumpFactor(); 21 | float jumpVelocityMultiplier = m == 1.0D ? g : m; 22 | float jumpStrength = (0.42F * jumpVelocityMultiplier); 23 | Vec3 vec3d = e.getDeltaMovement(); 24 | e.setDeltaMovement(vec3d.x, jumpStrength, vec3d.z); 25 | if (e.isSprinting()) 26 | { 27 | float u = e.getYRot() * 0.017453292F; // yaw 28 | e.setDeltaMovement(e.getDeltaMovement().add((-Mth.sin(g) * 0.2F), 0.0D, (Mth.cos(u) * 0.2F))); 29 | } 30 | e.hasImpulse = true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/utils/InputValidator.java: -------------------------------------------------------------------------------- 1 | package carpet.script.utils; 2 | 3 | import carpet.script.exception.InternalExpressionException; 4 | 5 | import java.util.Locale; 6 | 7 | import net.minecraft.ResourceLocationException; 8 | import net.minecraft.resources.ResourceLocation; 9 | 10 | public class InputValidator 11 | { 12 | public static String validateSimpleString(String input, boolean strict) 13 | { 14 | String simplified = input.toLowerCase(Locale.ROOT).replaceAll("[^A-Za-z0-9+_]", ""); 15 | if (simplified.isEmpty() || (strict && !simplified.equals(input))) 16 | { 17 | throw new InternalExpressionException("simple name can only contain numbers, letter and _"); 18 | } 19 | return simplified; 20 | } 21 | 22 | public static ResourceLocation identifierOf(String string) 23 | { 24 | try 25 | { 26 | return ResourceLocation.parse(string); 27 | } 28 | catch (ResourceLocationException iie) 29 | { 30 | throw new InternalExpressionException("Incorrect identifier format '" + string + "': " + iie.getMessage()); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/utils/ParticleParser.java: -------------------------------------------------------------------------------- 1 | package carpet.script.utils; 2 | 3 | import com.mojang.brigadier.StringReader; 4 | import com.mojang.brigadier.exceptions.CommandSyntaxException; 5 | import net.minecraft.commands.arguments.ParticleArgument; 6 | import net.minecraft.core.RegistryAccess; 7 | import net.minecraft.core.particles.ParticleOptions; 8 | 9 | import javax.annotation.Nullable; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | public class ParticleParser 14 | { 15 | private static final Map particleCache = new HashMap<>(); // we reset this on reloads, but probably need something better 16 | 17 | private static ParticleOptions parseParticle(String name, RegistryAccess lookup) 18 | { 19 | try 20 | { 21 | return ParticleArgument.readParticle(new StringReader(name), lookup); 22 | } 23 | catch (CommandSyntaxException e) 24 | { 25 | throw new IllegalArgumentException("No such particle: " + name); 26 | } 27 | } 28 | 29 | @Nullable 30 | public static ParticleOptions getEffect(@Nullable String name, RegistryAccess lookup) 31 | { 32 | if (name == null) 33 | { 34 | return null; 35 | } 36 | return particleCache.computeIfAbsent(name, particle -> parseParticle(particle, lookup)); 37 | } 38 | 39 | public static void resetCache() 40 | { 41 | particleCache.clear(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/utils/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.utils; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/utils/shapes/ShapeDirection.java: -------------------------------------------------------------------------------- 1 | package carpet.script.utils.shapes; 2 | 3 | import javax.annotation.Nullable; 4 | import java.util.Locale; 5 | 6 | public enum ShapeDirection 7 | { 8 | NORTH, 9 | SOUTH, 10 | EAST, 11 | WEST, 12 | UP, 13 | DOWN, 14 | CAMERA, 15 | PLAYER; 16 | 17 | @Nullable 18 | public static ShapeDirection fromString(String direction) 19 | { 20 | return switch (direction.toLowerCase(Locale.ROOT)) 21 | { 22 | case "north" -> NORTH; 23 | case "south" -> SOUTH; 24 | case "east" -> EAST; 25 | case "west" -> WEST; 26 | case "up" -> UP; 27 | case "down" -> DOWN; 28 | case "camera" -> CAMERA; 29 | case "player" -> PLAYER; 30 | default -> null; 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/utils/shapes/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.utils.shapes; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/AbstractListValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | import carpet.script.exception.InternalExpressionException; 4 | import com.google.common.collect.Lists; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public abstract class AbstractListValue extends Value implements Iterable 10 | { 11 | public List unpack() 12 | { 13 | ArrayList retVal = Lists.newArrayList(); 14 | for (Value value : this) 15 | { 16 | if (value != Value.EOL) 17 | { 18 | retVal.add(value); 19 | } 20 | } 21 | fatality(); 22 | return retVal; 23 | } 24 | 25 | public void fatality() 26 | { 27 | } 28 | 29 | public void append(Value v) 30 | { 31 | throw new InternalExpressionException("Cannot append a value to an abstract list"); 32 | } 33 | 34 | @Override 35 | public Value fromConstant() 36 | { 37 | return this.deepcopy(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/BooleanValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.JsonPrimitive; 5 | import net.minecraft.core.RegistryAccess; 6 | import net.minecraft.nbt.ByteTag; 7 | import net.minecraft.nbt.Tag; 8 | 9 | public class BooleanValue extends NumericValue 10 | { 11 | public static final BooleanValue FALSE = new BooleanValue(false); 12 | public static final BooleanValue TRUE = new BooleanValue(true); 13 | 14 | boolean boolValue; 15 | 16 | private BooleanValue(boolean boolval) 17 | { 18 | super(boolval ? 1L : 0L); 19 | boolValue = boolval; 20 | } 21 | 22 | public static BooleanValue of(boolean value) 23 | { 24 | return value ? TRUE : FALSE; 25 | } 26 | 27 | @Override 28 | public String getString() 29 | { 30 | return boolValue ? "true" : "false"; 31 | } 32 | 33 | @Override 34 | public String getPrettyString() 35 | { 36 | return getString(); 37 | } 38 | 39 | @Override 40 | public String getTypeString() 41 | { 42 | return "bool"; 43 | } 44 | 45 | @Override 46 | public Value clone() 47 | { 48 | return new BooleanValue(boolValue); 49 | } 50 | 51 | @Override 52 | public int hashCode() 53 | { 54 | return Boolean.hashCode(boolValue); 55 | } 56 | 57 | @Override 58 | public Tag toTag(boolean force, RegistryAccess regs) 59 | { 60 | return ByteTag.valueOf(boolValue); 61 | } 62 | 63 | @Override 64 | public JsonElement toJson() 65 | { 66 | return new JsonPrimitive(boolValue); 67 | } 68 | 69 | @Override 70 | public boolean isInteger() 71 | { 72 | return true; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/ContainerValueInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | public interface ContainerValueInterface 4 | { 5 | boolean put(Value where, Value value); 6 | 7 | default boolean put(Value where, Value value, Value conditions) 8 | { 9 | return put(where, value); 10 | } 11 | 12 | Value get(Value where); 13 | 14 | boolean has(Value where); 15 | 16 | boolean delete(Value where); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/FrameworkValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | import net.minecraft.core.RegistryAccess; 4 | import net.minecraft.nbt.Tag; 5 | 6 | public abstract class FrameworkValue extends Value 7 | { 8 | @Override 9 | public String getString() 10 | { 11 | throw new UnsupportedOperationException("Scarpet language component cannot be used"); 12 | } 13 | 14 | @Override 15 | public boolean getBoolean() 16 | { 17 | throw new UnsupportedOperationException("Scarpet language component cannot be used"); 18 | } 19 | 20 | @Override 21 | public Value clone() 22 | { 23 | throw new UnsupportedOperationException("Scarpet language component cannot be used"); 24 | } 25 | 26 | @Override 27 | public int hashCode() 28 | { 29 | throw new UnsupportedOperationException("Scarpet language component cannot be used as map key"); 30 | } 31 | 32 | @Override 33 | public Tag toTag(boolean force, RegistryAccess regs) 34 | { 35 | throw new UnsupportedOperationException("Scarpet language component cannot be serialized to the tag"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/FunctionAnnotationValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | import carpet.script.exception.InternalExpressionException; 4 | import net.minecraft.core.RegistryAccess; 5 | import net.minecraft.nbt.Tag; 6 | 7 | public class FunctionAnnotationValue extends Value 8 | { 9 | public enum Type 10 | { 11 | GLOBAL, VARARG 12 | } 13 | 14 | public Type type; 15 | 16 | public FunctionAnnotationValue(Value variable, Type type) 17 | { 18 | if (variable.boundVariable == null) 19 | { 20 | throw new InternalExpressionException("You can only borrow variables from the outer scope"); 21 | } 22 | this.boundVariable = variable.boundVariable; 23 | this.type = type; 24 | } 25 | 26 | @Override 27 | public String getString() 28 | { 29 | return boundVariable; 30 | } 31 | 32 | @Override 33 | public boolean getBoolean() 34 | { 35 | return false; 36 | } 37 | 38 | @Override 39 | public int hashCode() 40 | { 41 | throw new UnsupportedOperationException("Global value cannot be used as a map key"); 42 | } 43 | 44 | @Override 45 | public Tag toTag(boolean force, RegistryAccess regs) 46 | { 47 | throw new UnsupportedOperationException("Global value cannot be serialized to the tag"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/FunctionSignatureValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | import java.util.List; 4 | 5 | public class FunctionSignatureValue extends FrameworkValue 6 | { 7 | private final String identifier; 8 | private final List arguments; 9 | private final List globals; 10 | private final String varArgs; 11 | 12 | public FunctionSignatureValue(String name, List args, String varArgs, List globals) 13 | { 14 | this.identifier = name; 15 | this.arguments = args; 16 | this.varArgs = varArgs; 17 | this.globals = globals; 18 | } 19 | public String identifier() 20 | { 21 | return identifier; 22 | } 23 | public List arguments() 24 | { 25 | return arguments; 26 | } 27 | public List globals() {return globals;} 28 | public String varArgs() { return varArgs;} 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/FunctionUnpackedArgumentsValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | import java.util.List; 4 | 5 | public class FunctionUnpackedArgumentsValue extends ListValue 6 | { 7 | public FunctionUnpackedArgumentsValue(List list) 8 | { 9 | super(list); 10 | } 11 | 12 | @Override 13 | public Value clone() 14 | { 15 | return new FunctionUnpackedArgumentsValue(items); 16 | } 17 | 18 | @Override 19 | public Value deepcopy() 20 | { 21 | return new FunctionUnpackedArgumentsValue(((ListValue) super.deepcopy()).items); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/LContainerValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | public class LContainerValue extends FrameworkValue 4 | { 5 | private final ContainerValueInterface container; 6 | private final Value address; 7 | public static final LContainerValue NULL_CONTAINER = new LContainerValue(null, null); 8 | 9 | public LContainerValue(ContainerValueInterface c, Value v) 10 | { 11 | container = c; 12 | address = v; 13 | } 14 | 15 | public ContainerValueInterface container() 16 | { 17 | return container; 18 | } 19 | 20 | public Value address() 21 | { 22 | return address; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/StringValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | import net.minecraft.core.RegistryAccess; 4 | import net.minecraft.nbt.StringTag; 5 | import net.minecraft.nbt.Tag; 6 | 7 | import javax.annotation.Nullable; 8 | 9 | public class StringValue extends Value 10 | { 11 | public static Value EMPTY = StringValue.of(""); 12 | 13 | private final String str; 14 | 15 | @Override 16 | public String getString() 17 | { 18 | return str; 19 | } 20 | 21 | @Override 22 | public boolean getBoolean() 23 | { 24 | return str != null && !str.isEmpty(); 25 | } 26 | 27 | @Override 28 | public Value clone() 29 | { 30 | return new StringValue(str); 31 | } 32 | 33 | public StringValue(String str) 34 | { 35 | this.str = str; 36 | } 37 | 38 | public static Value of(@Nullable String value) 39 | { 40 | return value == null ? Value.NULL : new StringValue(value); 41 | } 42 | 43 | @Override 44 | public String getTypeString() 45 | { 46 | return "string"; 47 | } 48 | 49 | @Override 50 | public Tag toTag(boolean force, RegistryAccess regs) 51 | { 52 | return StringTag.valueOf(str); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | @FieldsAreNonnullByDefault 3 | @MethodsReturnNonnullByDefault 4 | package carpet.script.value; 5 | 6 | import net.minecraft.FieldsAreNonnullByDefault; 7 | import net.minecraft.MethodsReturnNonnullByDefault; 8 | import javax.annotation.ParametersAreNonnullByDefault; 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/settings/Condition.java: -------------------------------------------------------------------------------- 1 | package carpet.settings; 2 | 3 | import carpet.CarpetSettings; 4 | 5 | /** 6 | * @deprecated Use {@link carpet.api.settings.Rule.Condition} instead 7 | * 8 | */ 9 | @Deprecated(forRemoval = true) 10 | public interface Condition extends carpet.api.settings.Rule.Condition { 11 | boolean isTrue(); 12 | 13 | @Override 14 | default boolean shouldRegister() { 15 | CarpetSettings.LOG.warn(""" 16 | Extension is referencing outdated Condition class! Class that caused this was: %s 17 | This won't be supported in later Carpet versions and will crash the game!""".formatted(getClass().getName())); 18 | return isTrue(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/carpet/utils/EvictingQueue.java: -------------------------------------------------------------------------------- 1 | package carpet.utils; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | public class EvictingQueue extends LinkedHashMap 7 | { 8 | public void put(K key) 9 | { 10 | super.put(key, 1); 11 | } 12 | 13 | @Override 14 | protected boolean removeEldestEntry(Map.Entry eldest) 15 | { 16 | return this.size() > 10; 17 | } 18 | 19 | 20 | } -------------------------------------------------------------------------------- /src/main/java/carpet/utils/FabricAPIHooks.java: -------------------------------------------------------------------------------- 1 | package carpet.utils; 2 | /* 3 | import carpet.network.CarpetClient; 4 | import com.mojang.blaze3d.systems.RenderSystem; 5 | import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; 6 | import net.fabricmc.loader.api.FabricLoader; 7 | import net.fabricmc.loader.api.SemanticVersion; 8 | import net.fabricmc.loader.api.Version; 9 | import net.fabricmc.loader.api.VersionParsingException; 10 | */ 11 | public class FabricAPIHooks { 12 | /* 13 | public static final boolean WORLD_RENDER_EVENTS = hasMod("fabric-rendering-v1", "1.5.0"); 14 | 15 | private FabricAPIHooks() { 16 | } 17 | 18 | public static void initialize() { 19 | if (WORLD_RENDER_EVENTS) { 20 | //WorldRenderEvents.BEFORE_DEBUG_RENDER.register(context -> { 21 | if (false) {//(CarpetClient.shapes != null) { // likely won't need it. 22 | CarpetClient.shapes.render(context.matrixStack(), context.camera(), context.tickDelta()); 23 | } 24 | }); 25 | } 26 | } 27 | 28 | private static boolean hasMod(String id, String minimumVersion) { 29 | return FabricLoader.getInstance().getModContainer(id).map(m -> { 30 | Version version = m.getMetadata().getVersion(); 31 | 32 | if (version instanceof SemanticVersion) { 33 | try { 34 | return ((SemanticVersion) version).compareTo(SemanticVersion.parse(minimumVersion)) >= 0; 35 | } catch (VersionParsingException ignored) { 36 | } 37 | } 38 | 39 | return false; 40 | }).orElse(false); 41 | } 42 | 43 | */ 44 | } 45 | -------------------------------------------------------------------------------- /src/main/resources/assets/carpet/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnembon/fabric-carpet/5f9744e065242643b3307c720c4961480f3b4c20/src/main/resources/assets/carpet/icon.png -------------------------------------------------------------------------------- /src/main/resources/assets/carpet/lang/en_us.json: -------------------------------------------------------------------------------- 1 | { 2 | // TODO Rules 3 | 4 | // Categories: 5 | 6 | "carpet.category.bugfix": "bugfix", 7 | "carpet.category.survival": "survival", 8 | "carpet.category.creative": "creative", 9 | "carpet.category.experimental": "experimental", 10 | "carpet.category.optimization": "optimization", 11 | "carpet.category.feature": "feature", 12 | "carpet.category.command": "command", 13 | "carpet.category.tnt": "TNT", 14 | "carpet.category.dispenser": "dispenser", 15 | "carpet.category.scarpet": "scarpet", 16 | "carpet.category.client": "client", 17 | 18 | // Settings command UI elements 19 | 20 | "carpet.settings.command.browse_categories": "Browse categories", 21 | "carpet.settings.command.version": "version", 22 | "carpet.settings.command.list_all_category": "list all %s settings", 23 | "carpet.settings.command.current_settings_header": "Current %s settings", 24 | "carpet.settings.command.switch_to": "Switch to %s", 25 | "carpet.settings.command.unknown_rule": "Unknown rule", 26 | "carpet.settings.command.current_from_file_header": "Current %s Startup Settings from %s", 27 | "carpet.settings.command.mod_settings_matching": "%s settings matching \"%s\" ", 28 | "carpet.settings.command.all_mod_settings": "All %s settings", 29 | "carpet.settings.command.tags": "Tags", 30 | "carpet.settings.command.change_permanently": "Change permanently", 31 | "carpet.settings.command.change_permanently_tooltip": "click to keep the settings in %s to save across restarts", 32 | "carpet.settings.command.default_set": "Rule %s will now default to %s", 33 | "carpet.settings.command.default_removed": "Rule %s will no longer be set on restart", 34 | "carpet.settings.command.current_value": "current value" 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/assets/carpet/scripts/math.scl: -------------------------------------------------------------------------------- 1 | _euclidean_sq(vec1, vec2) -> reduce(vec1 - vec2, _a + _*_, 0); 2 | _euclidean(vec1, vec2) -> sqrt(reduce(vec1 - vec2, _a + _*_, 0)); 3 | _manhattan(vec1, vec2) -> reduce(vec1-vec2,_a+abs(_),0); 4 | _vec_length(vec) -> sqrt(reduce(vec, _a + _*_, 0)); 5 | _round(num,precision) -> round(num/precision)*precision; 6 | -------------------------------------------------------------------------------- /src/main/resources/assets/carpet/scripts/stats_test.sc: -------------------------------------------------------------------------------- 1 | __on_statistic(player, category, event, value) -> 2 | ( 3 | print('__on_statistic(player, category, event, value) -> '); 4 | print(' ['+join(', ',l(player, category, event, value))+']'); 5 | ); -------------------------------------------------------------------------------- /src/main/resources/carpet.accesswidener: -------------------------------------------------------------------------------- 1 | accessWidener v1 named 2 | 3 | accessible class net/minecraft/server/level/ChunkMap$DistanceManager 4 | accessible class net/minecraft/server/level/ThreadedLevelLightEngine$TaskType 5 | accessible class net/minecraft/world/level/lighting/BlockLightSectionStorage$BlockDataLayerStorageMap 6 | accessible class net/minecraft/world/level/border/WorldBorder$BorderExtent 7 | accessible class net/minecraft/world/level/border/WorldBorder$StaticBorderExtent 8 | accessible class net/minecraft/server/MinecraftServer$ReloadableResources 9 | accessible class net/minecraft/world/level/biome/Biome$ClimateSettings 10 | accessible class net/minecraft/world/level/block/entity/SculkSensorBlockEntity$VibrationUser 11 | 12 | #TODO fields and methods should be fetched via interfaces unless there is a good reason not to 13 | accessible method net/minecraft/world/level/border/WorldBorder getListeners ()Ljava/util/List; 14 | accessible method net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator calculateTargetStrength (Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)I 15 | 16 | #cause I don't want to deal with the interfaces until stuff is stable 17 | accessible method net/minecraft/world/level/block/entity/SkullBlockEntity fetchGameProfile (Ljava/lang/String;)Ljava/util/concurrent/CompletableFuture; 18 | 19 | accessible field net/minecraft/world/level/block/state/BlockBehaviour UPDATE_SHAPE_ORDER [Lnet/minecraft/core/Direction; 20 | -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "carpet", 4 | "version": "${version}", 5 | 6 | "name": "Carpet Mod", 7 | "description": "Carpet made out of fabric", 8 | "authors": [ 9 | "gnembon, ..." 10 | ], 11 | "contact": { 12 | "homepage": "https://github.com/gnembon/fabric-carpet", 13 | "issues": "https://github.com/gnembon/fabric-carpet/issues", 14 | "sources": "https://github.com/gnembon/fabric-carpet" 15 | }, 16 | 17 | "license": "MIT", 18 | "icon": "assets/carpet/icon.png", 19 | 20 | "environment": "*", 21 | "entrypoints": { 22 | "client": [ 23 | "carpet.CarpetServer::onGameStarted" 24 | ], 25 | "server": [ 26 | "carpet.CarpetServer::onGameStarted", 27 | "carpet.utils.CarpetRulePrinter" 28 | ] 29 | }, 30 | "mixins": [ 31 | "carpet.mixins.json" 32 | ], 33 | "accessWidener" : "carpet.accesswidener", 34 | 35 | "depends": { 36 | "minecraft": ">=1.21.4", 37 | "fabricloader": ">=0.16.10", 38 | "java": ">=21" 39 | } 40 | } 41 | --------------------------------------------------------------------------------