├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── carpet │ ├── CarpetExtension.java │ ├── CarpetServer.java │ ├── CarpetSettings.java │ ├── commands │ ├── CameraModeCommand.java │ ├── CounterCommand.java │ ├── DistanceCommand.java │ ├── DrawCommand.java │ ├── InfoCommand.java │ ├── LogCommand.java │ ├── MobAICommand.java │ ├── PerimeterInfoCommand.java │ ├── PlayerCommand.java │ ├── ScriptCommand.java │ ├── SpawnCommand.java │ ├── TestCommand.java │ └── TickCommand.java │ ├── fakes │ ├── BlockEntityRenderDispatcherInterface.java │ ├── ChunkTicketManagerInterface.java │ ├── CoralFeatureInterface.java │ ├── EntityInterface.java │ ├── ExperienceOrbInterface.java │ ├── ItemEntityInterface.java │ ├── MinecraftClientInferface.java │ ├── MinecraftServerInterface.java │ ├── MobEntityInterface.java │ ├── PistonBlockEntityInterface.java │ ├── PistonBlockInterface.java │ ├── PlayerListHudInterface.java │ ├── PortalForcerInterface.java │ ├── RedstoneWireBlockInterface.java │ ├── ServerPlayerEntityInterface.java │ ├── StatTypeInterface.java │ ├── StructureFeatureInterface.java │ ├── TicketInfoInterface.java │ ├── TntEntityInterface.java │ ├── WorldChunkInterface.java │ └── WorldInterface.java │ ├── helpers │ ├── BlockRotator.java │ ├── BlockSaplingHelper.java │ ├── EntityPlayerActionPack.java │ ├── FeatureGenerator.java │ ├── HopperCounter.java │ ├── InventoryHelper.java │ ├── OptimizedExplosion.java │ ├── ParticleDisplay.java │ ├── PortalHelper.java │ ├── RedstoneWireTurbo.java │ ├── TickSpeed.java │ ├── Tracer.java │ └── XPcombine.java │ ├── logging │ ├── HUDLogger.java │ ├── Logger.java │ ├── LoggerRegistry.java │ └── logHelpers │ │ ├── BlockEntityLogHelper.java │ │ ├── ChunkTicketLogHelper.java │ │ ├── DamageReporter.java │ │ ├── KillLogHelper.java │ │ ├── PacketCounter.java │ │ ├── PathfindingVisualizer.java │ │ ├── TNTLogHelper.java │ │ └── TrajectoryLogHelper.java │ ├── mixins │ ├── ArmorStandEntity_scarpetMarkerMixin.java │ ├── BlazeEntityShootFireballGoal_extremeMixin.java │ ├── BlazeEntity_extremeMixin.java │ ├── BlockEntityRenderDispatcher_movableTEMixin.java │ ├── BlockItem_scarpetEventMixin.java │ ├── BuriedTreasureGeneratorPieceMixin.java │ ├── CarpetBlockMixin.java │ ├── CauldronBlock_stackableSBoxesMixin.java │ ├── ChunkGeneratorMixin.java │ ├── ChunkMixin.java │ ├── ChunkTicketManager_scarpetMixin.java │ ├── ChunkTicketManager_ticketLogHelperMixin.java │ ├── ClientConnectionMixin.java │ ├── ClientPlayNetworkHandler_smoothClientAnimationsMixin.java │ ├── ClientPlayerInteractionManager_ghostBlocksMixin.java │ ├── CloneCommandMixin.java │ ├── CommandManagerMixin.java │ ├── ContainerMixin.java │ ├── CoralBlockMixin.java │ ├── CoralFeatureMixin.java │ ├── DamageTracker_scarpetEventMixin.java │ ├── DesertPyramidFeatureMixin.java │ ├── DirectionMixin.java │ ├── DispenserBlock_cactusMixin.java │ ├── DispenserBlock_qcMixin.java │ ├── EndCityFeatureMixin.java │ ├── EndGatewayFeature_BlockEntityLogMixin.java │ ├── EntityMixin.java │ ├── EntityNavigation_pathfindingMixin.java │ ├── EntityTrackerEntry_leashFixMixin.java │ ├── Entity_portalSuffocationMixin.java │ ├── Entity_scarpetEventsMixin.java │ ├── ExperienceOrbEntityMixin.java │ ├── ExplosionAccessor.java │ ├── ExplosionMixin.java │ ├── ExplosiveProjectileEntity_extremeMixin.java │ ├── FallingBlockEntityMixin.java │ ├── FallingBlockEntity_scarpetEventsMixin.java │ ├── FillCommandMixin.java │ ├── FireworkEntity_extremeMixin.java │ ├── FishingBobberEntity_extremeMixin.java │ ├── FlatChunkGeneratorMixin.java │ ├── FloatingIslandsChunkGeneratorMixin.java │ ├── ForceLoadCommand_forceLoadLimitMixin.java │ ├── FossilFeatureMixin.java │ ├── GameRenderer_pausedShakeMixin.java │ ├── GravityStructureProcessorMixin.java │ ├── GuardianEntityMixin.java │ ├── HopperBlockEntityMixin.java │ ├── HopperBlock_cactusMixin.java │ ├── HuskEntityMixin.java │ ├── IglooGeneratorPieceMixin.java │ ├── InGameHudMixin.java │ ├── InfestedBlockMixin.java │ ├── IntegratedServerMixin.java │ ├── ItemDispenserBehaviour_extremeBehavioursMixin.java │ ├── ItemEntityMixin.java │ ├── ItemScatterer_extremeMixin.java │ ├── ItemUsageContext_cactusMixin.java │ ├── KelpFeatureMixin.java │ ├── LivingEntity_maxCollisionsMixin.java │ ├── LivingEntity_scarpetEventsMixin.java │ ├── LlamaSpitEntity_extremeMixin.java │ ├── MinecraftClientMixin.java │ ├── MinecraftClient_pausedShakeMixin.java │ ├── MinecraftDedicatedServerMixin.java │ ├── MinecraftServer_coreMixin.java │ ├── MinecraftServer_scarpetMixin.java │ ├── MinecraftServer_tickspeedMixin.java │ ├── MobEntityMixin.java │ ├── MobEntity_extremeMixin.java │ ├── MobEntity_leashMixin.java │ ├── OceanRuinGeneratorPieceMixin.java │ ├── OverworldChunkGeneratorMixin.java │ ├── PickaxeItem_missingToolsMixin.java │ ├── PistonBlockEntityRenderer_movableTEMixin.java │ ├── PistonBlockEntity_movableTEMixin.java │ ├── PistonBlock_movableTEMixin.java │ ├── PistonBlock_qcMixin.java │ ├── PistonBlock_rotatorBlockMixin.java │ ├── PistonHandler_movableTEMixin.java │ ├── PistonHandler_pushLimitMixin.java │ ├── PlayerActionC2SPacketMixin.java │ ├── PlayerEntityMixin.java │ ├── PlayerEntity_horseFixMixin.java │ ├── PlayerEntity_parrotMixin.java │ ├── PlayerListHeaderS2CPacketMixin.java │ ├── PlayerListHudMixin.java │ ├── PlayerManagerMixin.java │ ├── PointOfInterest_scarpetMixin.java │ ├── PortalBlock_portalSuperCacheMixin.java │ ├── PortalForcer_portalSuffocationMixin.java │ ├── PortalForcer_portalSuperCacheMixin.java │ ├── PoweredRailBlock_powerLimitMixin.java │ ├── ProjectileEntityMixin.java │ ├── ProjectileEntity_extremeMixin.java │ ├── RedstoneWireBlockMixin.java │ ├── RenderTickCounter_tickSpeedMixin.java │ ├── SaplingBlockMixin.java │ ├── ServerChunkManagerMixin.java │ ├── ServerChunkManager_scarpetMixin.java │ ├── ServerChunkManager_tickMixin.java │ ├── ServerChunkManager_ticketLogHelperMixin.java │ ├── ServerLightProviderMixin.java │ ├── ServerMetadata_motdMixin.java │ ├── ServerPlayNetworkHandler_antiCheatDisabledMixin.java │ ├── ServerPlayNetworkHandler_coreMixin.java │ ├── ServerPlayNetworkHandler_interactionUpdatesMixin.java │ ├── ServerPlayNetworkHandler_scarpetEventsMixin.java │ ├── ServerPlayNetworkHandler_tickMixin.java │ ├── ServerPlayerEntityMixin.java │ ├── ServerPlayerEntity_scarpetEventMixin.java │ ├── ServerPlayerInteractionManager_cactusMixin.java │ ├── ServerPlayerInteractionManager_ghostBlocksMixin.java │ ├── ServerPlayerInteractionManager_scarpetEventsMixin.java │ ├── ServerWorld_fakePlayersMixin.java │ ├── ServerWorld_onePlayerSleepingMixin.java │ ├── ServerWorld_tickMixin.java │ ├── ServerWorld_unloadedEntityMixin.java │ ├── SetBlockCommandMixin.java │ ├── ShearsItem_missingToolsMixin.java │ ├── ShipwreckGeneratorPieceMixin.java │ ├── SkeletonHorseTrapTriggerGoal_extremeMixin.java │ ├── SpawnHelperMixin.java │ ├── StatType_scarpetMixin.java │ ├── StructureBlockBlockEntity_fillUpdatesMixin.java │ ├── StructureFeatureMixin.java │ ├── StructurePieceMixin.java │ ├── Structure_fillUpdatesMixin.java │ ├── SummonCommandMixin.java │ ├── ThreadedAnvilChunkStorage_tickMixin.java │ ├── ThrownEnderpearlEntity_fakePlayersMixin.java │ ├── ThrownEntityMixin.java │ ├── ThrownEntity_extremeMixin.java │ ├── TntBlockMixin.java │ ├── TntEntityMixin.java │ ├── VillagerEntity_aiMixin.java │ ├── WeightedPickerEntryMixin.java │ ├── WorldChunk_fillUpdatesMixin.java │ ├── WorldChunk_movableTEMixin.java │ ├── World_BlockEntityLogMixin.java │ ├── World_fillUpdatesMixin.java │ ├── World_movableTEMixin.java │ ├── World_tickMixin.java │ └── statsMixin.java │ ├── patches │ ├── EntityPlayerMPFake.java │ ├── NetHandlerPlayServerFake.java │ └── NetworkManagerFake.java │ ├── script │ ├── CarpetContext.java │ ├── CarpetEventServer.java │ ├── CarpetExpression.java │ ├── CarpetScriptHost.java │ ├── CarpetScriptServer.java │ ├── Context.java │ ├── EntityEventsGroup.java │ ├── Expression.java │ ├── ExpressionInspector.java │ ├── Fluff.java │ ├── LazyValue.java │ ├── ScriptHost.java │ ├── Tokenizer.java │ ├── bundled │ │ ├── BundledModule.java │ │ ├── FileModule.java │ │ └── Module.java │ ├── exception │ │ ├── BreakStatement.java │ │ ├── CarpetExpressionException.java │ │ ├── ContinueStatement.java │ │ ├── ExitStatement.java │ │ ├── ExpressionException.java │ │ ├── InternalExpressionException.java │ │ ├── InvalidCallbackException.java │ │ ├── ResolvedException.java │ │ ├── ReturnStatement.java │ │ └── ThrowStatement.java │ ├── utils │ │ ├── PerlinNoiseSampler.java │ │ └── SimplexNoiseSampler.java │ └── value │ │ ├── AbstractListValue.java │ │ ├── BlockValue.java │ │ ├── ContainerValueInterface.java │ │ ├── EntityValue.java │ │ ├── FrameworkValue.java │ │ ├── FunctionSignatureValue.java │ │ ├── FunctionValue.java │ │ ├── GlobalValue.java │ │ ├── LContainerValue.java │ │ ├── LazyListValue.java │ │ ├── ListValue.java │ │ ├── MapValue.java │ │ ├── NBTSerializableValue.java │ │ ├── NullValue.java │ │ ├── NumericValue.java │ │ ├── StringValue.java │ │ ├── ThreadValue.java │ │ └── Value.java │ ├── settings │ ├── ParsedRule.java │ ├── Rule.java │ ├── RuleCategory.java │ ├── SettingsManager.java │ └── Validator.java │ └── utils │ ├── BlockInfo.java │ ├── CarpetProfiler.java │ ├── DistanceCalculator.java │ ├── EntityInfo.java │ ├── EvictingQueue.java │ ├── HUDController.java │ ├── Messenger.java │ ├── MobAI.java │ ├── PerimeterDiagnostics.java │ ├── RandomTools.java │ ├── SpawnReporter.java │ ├── WoolTool.java │ └── portalsearcher │ ├── PortalSearchResult.java │ ├── PortalSearcherAbstract.java │ ├── PortalSearcherSuperCache.java │ └── SuperCacheHandler.java └── resources ├── assets └── carpet │ ├── icon.png │ └── scripts │ ├── camera.sc │ ├── event_test.sc │ ├── math.scl │ ├── overlay.sc │ └── stats_test.sc ├── carpet.mixins.json └── fabric.mod.json /.gitignore: -------------------------------------------------------------------------------- 1 | # gradle 2 | 3 | .gradle/ 4 | build/ 5 | out/ 6 | classes/ 7 | publish/ 8 | docs/ 9 | 10 | # idea 11 | 12 | .idea/ 13 | *.iml 14 | *.ipr 15 | *.iws 16 | 17 | # vscode 18 | 19 | .settings/ 20 | .vscode/ 21 | bin/ 22 | .classpath 23 | .project 24 | 25 | # fabric 26 | 27 | run/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HIT Carpet 2 | 3 | 一个经过魔改的 [1.14.4 carpet mod](https://github.com/gnembon/fabric-carpet) 4 | 5 | # carpet的命令设置 6 | 原版carpet指令请参考[wiki](https://github.com/gnembon/fabric-carpet/wiki/Current-Available-Settings)或[汉化版本](https://github.com/SFG-Minecraft-mods-Chinese-Translation/Translation-doc/blob/master/Fabric-Carpet/Commands.md) 7 | 8 | # 新增或调整功能 9 | ## 监视器(log) 10 | ### 方块实体(blockentity) 11 | `/log blockentity <监视场景>` 12 | 13 | 记录方块实体信息 14 | * 目前仅支持末地石农场设计所需的方块实体添加信息与末地折跃门相关信息 15 | * 默认值: `endislandfarm` 16 | * 可选参数: `endislandfarm` 17 | 18 | ### 加载票(ticket) 19 | `/log ticket <监视类型>` 20 | 21 | 记录加载票的添加与移除 22 | * 默认值: `portal` 23 | * 可选参数: `portal,player`, `portal,dragon`, `start`, `dragon`, `player`, `forced`, `light`, `portal`, `post_teleport`, `unknown` 24 | 25 | **警告:** 监视 `unknown` 加载票可能会导致刷屏 26 | 27 | ## 光照更新(lightUpdates) 28 | 关闭以关闭服务器光照更新 29 | * 默认值: `true` 30 | * 可选参数: `true`, `false` 31 | * 关闭方法: `/carpet lightUpdates false` 32 | 33 | **警告:** 请勿设置默认关闭,否则服务器将无法启动 34 | 35 | **警告:** 关闭光照抑制时无法加载新区块,请提前加载区块,请勿在未加载区块上线 36 | 37 | ## 地狱门缓存(portalSuperCache) 38 | 减少在1.14中实体经过地狱门而产生的卡顿 39 | * 默认值: `false` 40 | * 可选参数: `true`, `false` 41 | * 开启方法: `/carpet portalSuperCache true` 42 | 43 | **警告:** 非正常手段放置或破坏地狱门方块可能会导致无法建立缓存 44 | 45 | ## 合并TNT(mergeTNT) 46 | 合并大量TNT以减小实体及爆炸带来的卡顿 47 | * 默认值: `false` 48 | * 可选参数: `true`, `false` 49 | * 开启方法: `/carpet mergeTNT true` 50 | 51 | # Works Cited 52 | - Fallen_Breath [Carpet-TIS-Addition](https://github.com/TISUnion/Carpet-TIS-Addition) 53 | - LucunJi [fabric-carpet](https://github.com/LucunJi/fabric-carpet) 54 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'fabric-loom' version '0.2.6-SNAPSHOT' 3 | id 'maven-publish' 4 | } 5 | 6 | sourceCompatibility = JavaVersion.VERSION_1_8 7 | targetCompatibility = JavaVersion.VERSION_1_8 8 | 9 | archivesBaseName = project.archives_base_name 10 | version = project.minecraft_version+'-'+project.mod_version 11 | group = project.maven_group 12 | 13 | minecraft { 14 | } 15 | 16 | dependencies { 17 | //to change the versions see the gradle.properties file 18 | minecraft "com.mojang:minecraft:${project.minecraft_version}" 19 | mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" 20 | modCompile "net.fabricmc:fabric-loader:${project.loader_version}" 21 | 22 | // Fabric API. This is technically optional, but you probably want it anyway. 23 | // modCompile "net.fabricmc:fabric:${project.fabric_version}" 24 | 25 | // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. 26 | // You may need to force-disable transitiveness on them. 27 | } 28 | 29 | processResources { 30 | inputs.property "version", project.version 31 | 32 | from(sourceSets.main.resources.srcDirs) { 33 | include "fabric.mod.json" 34 | expand "version": project.version 35 | } 36 | 37 | from(sourceSets.main.resources.srcDirs) { 38 | exclude "fabric.mod.json" 39 | } 40 | } 41 | 42 | // ensure that the encoding is set to UTF-8, no matter what the system default is 43 | // this fixes some edge cases with special characters not displaying correctly 44 | // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html 45 | tasks.withType(JavaCompile) { 46 | options.encoding = "UTF-8" 47 | } 48 | 49 | // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task 50 | // if it is present. 51 | // If you remove this task, sources will not be generated. 52 | task sourcesJar(type: Jar, dependsOn: classes) { 53 | classifier = "sources" 54 | from sourceSets.main.allSource 55 | } 56 | 57 | jar { 58 | from "LICENSE" 59 | } 60 | 61 | // configure the maven publication 62 | publishing { 63 | publications { 64 | mavenJava(MavenPublication) { 65 | // add all the jars that should be included when publishing to maven 66 | artifact(remapJar) { 67 | builtBy remapJar 68 | } 69 | artifact(sourcesJar) { 70 | builtBy remapSourcesJar 71 | } 72 | } 73 | } 74 | 75 | // select the repositories you want to publish to 76 | repositories { 77 | // uncomment to publish to the local maven 78 | // mavenLocal() 79 | maven { 80 | url "$projectDir/publish" 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Done to increase the memory available to gradle. 2 | org.gradle.jvmargs=-Xmx1G 3 | 4 | # Fabric Properties 5 | # check these on https://fabricmc.net/use 6 | # or betterhttps://modmuss50.me/fabric.html: 7 | minecraft_version=1.14.4 8 | yarn_mappings=1.14.4+build.17 9 | loader_version=0.8.7+build.201 10 | 11 | # Mod Properties 12 | mod_version = 1.0.4+v200629 13 | maven_group = hit-carpet 14 | archives_base_name = hit-carpet 15 | 16 | # Dependencies 17 | # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api 18 | #fabric_version=0.8.2+build.252-1.14 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HIT-Craft/HIT-Carpet/ed93cfbcb247e0eb993ff2fc5848e899a8c4d8c6/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-5.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | jcenter() 4 | maven { 5 | name = 'Fabric' 6 | url = 'https://maven.fabricmc.net/' 7 | } 8 | gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/carpet/CarpetExtension.java: -------------------------------------------------------------------------------- 1 | package carpet; 2 | 3 | import carpet.settings.SettingsManager; 4 | import com.mojang.brigadier.CommandDispatcher; 5 | import net.minecraft.server.MinecraftServer; 6 | import net.minecraft.server.command.ServerCommandSource; 7 | import net.minecraft.server.network.ServerPlayerEntity; 8 | 9 | public interface CarpetExtension 10 | { 11 | /** 12 | * When game started before world is loaded 13 | */ 14 | default void onGameStarted() {} 15 | 16 | /** 17 | * Runs once per loaded world once the World files / gamerules etc are fully loaded 18 | * Can be loaded multiple times in SinglePlayer 19 | */ 20 | default void onServerLoaded(MinecraftServer server) {} 21 | 22 | /** 23 | * Runs once per game tick, as a first thing in the tick 24 | */ 25 | default void onTick(MinecraftServer server) {} 26 | 27 | /** 28 | * Register your own commands right after vanilla commands are added 29 | * If that matters for you 30 | */ 31 | default void registerCommands(CommandDispatcher dispatcher) {} 32 | 33 | /** 34 | * Provide your own custom settings manager managed in the same way as base /carpet 35 | * command, but separated to its own command as defined in SettingsManager. 36 | */ 37 | default SettingsManager customSettingsManager() {return null;} 38 | 39 | /** 40 | * todiddalidoo 41 | */ 42 | default void onPlayerLoggedIn(ServerPlayerEntity player) {} 43 | 44 | /** 45 | * todiddalidoo 46 | */ 47 | default void onPlayerLoggedOut(ServerPlayerEntity player) {} 48 | 49 | default void onServerClosed(MinecraftServer server) {} 50 | 51 | default String version() {return null;} 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/carpet/commands/DistanceCommand.java: -------------------------------------------------------------------------------- 1 | package carpet.commands; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.settings.SettingsManager; 5 | import carpet.utils.DistanceCalculator; 6 | import com.mojang.brigadier.CommandDispatcher; 7 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 8 | import net.minecraft.server.command.ServerCommandSource; 9 | import net.minecraft.command.arguments.Vec3ArgumentType; 10 | 11 | import static net.minecraft.server.command.CommandManager.argument; 12 | import static net.minecraft.server.command.CommandManager.literal; 13 | 14 | public class DistanceCommand 15 | { 16 | public static void register(CommandDispatcher dispatcher) 17 | { 18 | LiteralArgumentBuilder command = literal("distance"). 19 | requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDistance)). 20 | then(literal("from"). 21 | executes( (c) -> DistanceCalculator.setStart(c.getSource(), c.getSource().getPosition())). 22 | then(argument("from", Vec3ArgumentType.vec3()). 23 | executes( (c) -> DistanceCalculator.setStart( 24 | c.getSource(), 25 | Vec3ArgumentType.getVec3(c, "from"))). 26 | then(literal("to"). 27 | executes((c) -> DistanceCalculator.distance( 28 | c.getSource(), 29 | Vec3ArgumentType.getVec3(c, "from"), 30 | c.getSource().getPosition())). 31 | then(argument("to", Vec3ArgumentType.vec3()). 32 | executes( (c) -> DistanceCalculator.distance( 33 | c.getSource(), 34 | Vec3ArgumentType.getVec3(c, "from"), 35 | Vec3ArgumentType.getVec3(c, "to") 36 | )))))). 37 | then(literal("to"). 38 | executes( (c) -> DistanceCalculator.setEnd(c.getSource(), c.getSource().getPosition()) ). 39 | then(argument("to", Vec3ArgumentType.vec3()). 40 | executes( (c) -> DistanceCalculator.setEnd(c.getSource(), Vec3ArgumentType.getVec3(c, "to"))))); 41 | dispatcher.register(command); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/carpet/commands/MobAICommand.java: -------------------------------------------------------------------------------- 1 | package carpet.commands; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.settings.SettingsManager; 5 | import carpet.utils.MobAI; 6 | import com.mojang.brigadier.CommandDispatcher; 7 | import com.mojang.brigadier.arguments.StringArgumentType; 8 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 9 | import net.minecraft.command.arguments.EntitySummonArgumentType; 10 | import net.minecraft.server.command.ServerCommandSource; 11 | import net.minecraft.util.registry.Registry; 12 | 13 | import static net.minecraft.server.command.CommandManager.argument; 14 | import static net.minecraft.server.command.CommandManager.literal; 15 | import static net.minecraft.server.command.CommandSource.suggestMatching; 16 | 17 | public class MobAICommand 18 | { 19 | public static void register(CommandDispatcher dispatcher) 20 | { 21 | LiteralArgumentBuilder command = literal("track"). 22 | requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTrackAI)). 23 | then(argument("entity type", EntitySummonArgumentType.entitySummon()). 24 | 25 | suggests( (c, b) -> suggestMatching(MobAI.availbleTypes(), b)). 26 | then(literal("clear").executes( (c) -> 27 | { 28 | MobAI.clearTracking(Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type"))); 29 | return 1; 30 | } 31 | )). 32 | then(argument("aspect", StringArgumentType.word()). 33 | suggests( (c, b) -> suggestMatching(MobAI.availableFor(Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type"))),b)). 34 | executes( (c) -> { 35 | MobAI.startTracking( 36 | Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type")), 37 | MobAI.TrackingType.byName(StringArgumentType.getString(c, "aspect")) 38 | ); 39 | return 1; 40 | }))); 41 | dispatcher.register(command); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /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.server.command.ServerCommandSource; 8 | 9 | import static com.mojang.brigadier.arguments.StringArgumentType.getString; 10 | import static com.mojang.brigadier.arguments.StringArgumentType.word; 11 | import static net.minecraft.server.command.CommandManager.argument; 12 | import static net.minecraft.server.command.CommandManager.literal; 13 | 14 | public class TestCommand 15 | { 16 | public static void register(CommandDispatcher dispatcher) 17 | { 18 | dispatcher.register(literal("test"). 19 | then(literal("dump"). 20 | executes((c) -> CarpetServer.settingsManager.printAllRulesToLog(null)). 21 | then(argument("category", word()). 22 | executes( (c) -> CarpetServer.settingsManager.printAllRulesToLog(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/BlockEntityRenderDispatcherInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.block.entity.BlockEntity; 4 | 5 | public interface BlockEntityRenderDispatcherInterface 6 | { 7 | void renderBlockEntityOffset(BlockEntity blockEntity, float partialTicks, int destroyStage, double xOffset, double yOffset, double zOffset); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ChunkTicketManagerInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.server.world.ServerWorld; 4 | 5 | public interface ChunkTicketManagerInterface { 6 | public void setServerWorld(ServerWorld world); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/CoralFeatureInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.block.BlockState; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.world.World; 6 | 7 | import java.util.Random; 8 | 9 | public interface CoralFeatureInterface 10 | { 11 | boolean growSpecific(World worldIn, Random random, BlockPos pos, BlockState blockUnder); 12 | } 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ExperienceOrbInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface ExperienceOrbInterface 4 | { 5 | int getCombineDelay(); 6 | void setCombineDelay(int what); 7 | void setAmount(int what); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ItemEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface ItemEntityInterface 4 | { 5 | int getAge(); 6 | int getPickupDelay(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/MinecraftClientInferface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface MinecraftClientInferface 4 | { 5 | float getPausedTickDelta(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/MinecraftServerInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import java.util.function.BooleanSupplier; 4 | 5 | public interface MinecraftServerInterface 6 | { 7 | void forceTick(BooleanSupplier sup); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/MobEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.entity.ai.goal.Goal; 4 | import net.minecraft.entity.ai.goal.GoalSelector; 5 | 6 | import java.util.Map; 7 | 8 | public interface MobEntityInterface 9 | { 10 | GoalSelector getAI(boolean target); 11 | 12 | Map getTemporaryTasks(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/PistonBlockEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.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.util.math.BlockPos; 4 | import net.minecraft.util.math.Direction; 5 | import net.minecraft.world.World; 6 | 7 | public interface PistonBlockInterface 8 | { 9 | boolean publicShouldExtend(World 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/PortalForcerInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface PortalForcerInterface 4 | { 5 | void invalidateCache(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/RedstoneWireBlockInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.block.BlockState; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.world.World; 6 | 7 | public interface RedstoneWireBlockInterface { 8 | BlockState updateLogicPublic(World world_1, BlockPos blockPos_1, BlockState blockState_1); 9 | void setWiresGivePower(boolean wiresGivePower); 10 | boolean getWiresGivePower(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/ServerPlayerEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import carpet.helpers.EntityPlayerActionPack; 4 | 5 | public interface ServerPlayerEntityInterface 6 | { 7 | EntityPlayerActionPack getActionPack(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/StatTypeInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface StatTypeInterface 4 | { 5 | boolean hasStatCreated(T key); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/StructureFeatureInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | import net.minecraft.world.IWorld; 5 | import net.minecraft.world.gen.chunk.ChunkGenerator; 6 | import net.minecraft.world.gen.chunk.ChunkGeneratorConfig; 7 | 8 | public interface StructureFeatureInterface 9 | { 10 | boolean plopAnywhere(IWorld world, BlockPos pos); 11 | boolean gridAnywhere(IWorld world, BlockPos pos); 12 | boolean plopAnywhere(IWorld world, BlockPos pos, ChunkGenerator generator, boolean wireOnly); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/TicketInfoInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | 5 | public interface TicketInfoInterface 6 | { 7 | BlockPos getPos(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/TntEntityInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | public interface TntEntityInterface { 4 | 5 | int getMergedTNT(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/WorldChunkInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.block.BlockState; 4 | import net.minecraft.block.entity.BlockEntity; 5 | import net.minecraft.util.math.BlockPos; 6 | 7 | public interface WorldChunkInterface 8 | { 9 | BlockState setBlockStateWithBlockEntity(BlockPos blockPos, BlockState newBlockState, BlockEntity newBlockEntity, boolean boolean1); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/carpet/fakes/WorldInterface.java: -------------------------------------------------------------------------------- 1 | package carpet.fakes; 2 | 3 | import net.minecraft.block.BlockState; 4 | import net.minecraft.block.entity.BlockEntity; 5 | import net.minecraft.entity.Entity; 6 | import net.minecraft.entity.EntityType; 7 | import net.minecraft.util.math.BlockPos; 8 | 9 | import java.util.Map; 10 | 11 | public interface WorldInterface 12 | { 13 | Map getPrecookedMobs(); 14 | 15 | boolean setBlockStateWithBlockEntity(BlockPos blockPos, BlockState blockState, BlockEntity newBlockEntity, int int1); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/carpet/helpers/BlockSaplingHelper.java: -------------------------------------------------------------------------------- 1 | package carpet.helpers; 2 | 3 | import net.minecraft.block.Material; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.world.IWorld; 6 | 7 | public class BlockSaplingHelper 8 | { 9 | // Added code for checking water for dead shrub rule 10 | public static boolean hasWater(IWorld worldIn, BlockPos pos) 11 | { 12 | for (BlockPos blockpos$mutableblockpos : BlockPos.iterate(pos.add(-4, -4, -4), pos.add(4, 1, 4))) 13 | { 14 | if (worldIn.getBlockState(blockpos$mutableblockpos).getMaterial() == Material.WATER) 15 | { 16 | return true; 17 | } 18 | } 19 | 20 | return false; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/helpers/InventoryHelper.java: -------------------------------------------------------------------------------- 1 | package carpet.helpers; 2 | 3 | import net.minecraft.item.ItemStack; 4 | import net.minecraft.nbt.CompoundTag; 5 | 6 | public class InventoryHelper 7 | { 8 | // From nbt/Tag.java createTag() 9 | public static final int TAG_END = 0; 10 | public static final int TAG_BYTE = 1; 11 | public static final int TAG_SHORT = 2; 12 | public static final int TAG_INT = 3; 13 | public static final int TAG_LONG = 4; 14 | public static final int TAG_FLOAT = 5; 15 | public static final int TAG_DOUBLE = 6; 16 | public static final int TAG_BYTEARRAY = 7; 17 | public static final int TAG_STRING = 8; 18 | public static final int TAG_LIST = 9; 19 | public static final int TAG_COMPOUND = 10; 20 | public static final int TAG_INTARRAY = 11; 21 | public static final int TAG_LONGARRAY = 12; 22 | 23 | public static boolean cleanUpShulkerBoxTag(ItemStack stack) 24 | { 25 | boolean changed = false; 26 | CompoundTag tag = stack.getTag(); 27 | 28 | if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND)) 29 | return false; 30 | 31 | CompoundTag bet = tag.getCompound("BlockEntityTag"); 32 | if (bet.contains("Items", TAG_LIST) && bet.getList("Items", TAG_COMPOUND).isEmpty()) 33 | { 34 | bet.remove("Items"); 35 | changed = true; 36 | } 37 | 38 | if (bet.isEmpty()) 39 | { 40 | tag.remove("BlockEntityTag"); 41 | changed = true; 42 | } 43 | if (tag.isEmpty()) 44 | { 45 | stack.setTag(null); 46 | changed = true; 47 | } 48 | return changed; 49 | } 50 | 51 | public static boolean shulkerBoxHasItems(ItemStack stack) 52 | { 53 | CompoundTag tag = stack.getTag(); 54 | 55 | if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND)) 56 | return false; 57 | 58 | CompoundTag bet = tag.getCompound("BlockEntityTag"); 59 | return bet.contains("Items", TAG_LIST) && !bet.getList("Items", TAG_COMPOUND).isEmpty(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/carpet/helpers/PortalHelper.java: -------------------------------------------------------------------------------- 1 | package carpet.helpers; 2 | 3 | import net.minecraft.entity.player.PlayerEntity; 4 | import net.minecraft.block.Blocks; 5 | import net.minecraft.item.BlockItem; 6 | 7 | public class PortalHelper 8 | { 9 | public static boolean player_holds_obsidian(PlayerEntity playerIn) 10 | { 11 | return (!playerIn.getMainHandStack().isEmpty() 12 | && playerIn.getMainHandStack().getItem() instanceof BlockItem && 13 | ((BlockItem) (playerIn.getMainHandStack().getItem())).getBlock() == Blocks.OBSIDIAN); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/carpet/logging/HUDLogger.java: -------------------------------------------------------------------------------- 1 | package carpet.logging; 2 | 3 | import carpet.utils.HUDController; 4 | import net.minecraft.server.network.ServerPlayerEntity; 5 | import net.minecraft.text.BaseText; 6 | 7 | public class HUDLogger extends Logger 8 | { 9 | public HUDLogger(String logName, String def, String[] options) 10 | { 11 | super(logName, def, options); 12 | } 13 | 14 | @Override 15 | public void removePlayer(String playerName) 16 | { 17 | ServerPlayerEntity player = playerFromName(playerName); 18 | if (player != null) HUDController.clear_player(player); 19 | super.removePlayer(playerName); 20 | } 21 | 22 | @Override 23 | public void sendPlayerMessage(ServerPlayerEntity player, BaseText... messages) 24 | { 25 | for (BaseText m:messages) HUDController.addMessage(player, m); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/logging/logHelpers/KillLogHelper.java: -------------------------------------------------------------------------------- 1 | package carpet.logging.logHelpers; 2 | 3 | import carpet.logging.LoggerRegistry; 4 | import carpet.utils.Messenger; 5 | import net.minecraft.text.BaseText; 6 | 7 | public class KillLogHelper { 8 | 9 | public static void onSweep(String name, int count) 10 | { 11 | LoggerRegistry.getLogger("kills").log( () -> new BaseText[]{ 12 | Messenger.c("g "+name+" smacked ","r "+count,"g entities with sweeping")}); 13 | } 14 | 15 | public static void onNonSweepAttack(String name) 16 | { 17 | LoggerRegistry.getLogger("kills").log( () -> new BaseText[]{ 18 | Messenger.c("g "+name+" smacked ","r 1","g (no sweeping)")}); 19 | } 20 | 21 | public static void onDudHit(String name) 22 | { 23 | LoggerRegistry.getLogger("kills").log( () -> new BaseText[]{ 24 | Messenger.c("g "+name+" dud hot = no one affected")}); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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/logging/logHelpers/PathfindingVisualizer.java: -------------------------------------------------------------------------------- 1 | package carpet.logging.logHelpers; 2 | 3 | import carpet.helpers.ParticleDisplay; 4 | import carpet.logging.LoggerRegistry; 5 | import com.mojang.brigadier.StringReader; 6 | import com.mojang.brigadier.exceptions.CommandSyntaxException; 7 | import net.minecraft.command.arguments.ParticleArgumentType; 8 | import net.minecraft.entity.Entity; 9 | import net.minecraft.particle.ParticleEffect; 10 | import net.minecraft.server.network.ServerPlayerEntity; 11 | import net.minecraft.server.world.ServerWorld; 12 | import net.minecraft.util.math.Vec3d; 13 | 14 | public class PathfindingVisualizer 15 | { 16 | public static void slowPath(Entity entity, Vec3d target, float miliseconds, boolean successful) 17 | { 18 | if (!LoggerRegistry.__pathfinding) return; 19 | LoggerRegistry.getLogger("pathfinding").log( (option, player)-> 20 | { 21 | if (!(player instanceof ServerPlayerEntity)) 22 | return null; 23 | int minDuration = Integer.parseInt(option); 24 | if (miliseconds < minDuration) 25 | return null; 26 | if (player.squaredDistanceTo(entity) > 1000 && player.squaredDistanceTo(target) > 1000) 27 | return null; 28 | if (minDuration < 1) 29 | minDuration = 1; 30 | 31 | String accent = successful ? "happy_villager" : "angry_villager"; 32 | String color = (miliseconds/minDuration < 2)? "dust 1 1 0 1" : ((miliseconds/minDuration < 4)?"dust 1 0.5 0 1":"dust 1 0 0 1"); 33 | ParticleDisplay.drawParticleLine((ServerPlayerEntity) player, entity.getPos(), target, color, accent, 5, 0.5); 34 | return null; 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/carpet/logging/logHelpers/TNTLogHelper.java: -------------------------------------------------------------------------------- 1 | package carpet.logging.logHelpers; 2 | 3 | import carpet.logging.LoggerRegistry; 4 | import carpet.utils.Messenger; 5 | import net.minecraft.text.BaseText; 6 | import net.minecraft.util.math.Vec3d; 7 | 8 | public class TNTLogHelper 9 | { 10 | public boolean initialized; 11 | private double primedX, primedY, primedZ; 12 | private Vec3d primedAngle; 13 | /** 14 | * Runs when the TNT is primed. Expects the position and motion angle of the TNT. 15 | */ 16 | public void onPrimed(double x, double y, double z, Vec3d motion) 17 | { 18 | primedX = x; 19 | primedY = y; 20 | primedZ = z; 21 | primedAngle = motion; 22 | initialized = true; 23 | } 24 | /** 25 | * Runs when the TNT explodes. Expects the position of the TNT. 26 | */ 27 | public void onExploded(double x, double y, double z) 28 | { 29 | LoggerRegistry.getLogger("tnt").log( (option) -> { 30 | switch (option) 31 | { 32 | case "brief": 33 | return new BaseText[]{Messenger.c( 34 | "l P ",Messenger.dblt("l",primedX,primedY,primedZ), 35 | "w ",Messenger.dblt("l", primedAngle.x, primedAngle.y, primedAngle.z), 36 | "r E ",Messenger.dblt("r",x, y, z))}; 37 | case "full": 38 | return new BaseText[]{Messenger.c( 39 | "l P ",Messenger.dblf("l",primedX,primedY,primedZ), 40 | "w ",Messenger.dblf("l", primedAngle.x, primedAngle.y, primedAngle.z), 41 | "r E ",Messenger.dblf("r",x, y, z))}; 42 | } 43 | return null; 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ArmorStandEntity_scarpetMarkerMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import carpet.script.ExpressionInspector; 5 | import carpet.CarpetSettings; 6 | import net.minecraft.entity.EntityType; 7 | import net.minecraft.entity.LivingEntity; 8 | import net.minecraft.entity.decoration.ArmorStandEntity; 9 | import net.minecraft.world.World; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 15 | 16 | import java.util.Optional; 17 | 18 | @Mixin(ArmorStandEntity.class) 19 | public abstract class ArmorStandEntity_scarpetMarkerMixin extends LivingEntity 20 | { 21 | protected ArmorStandEntity_scarpetMarkerMixin(EntityType entityType_1, World world_1) 22 | { 23 | super(entityType_1, world_1); 24 | } 25 | 26 | /** 27 | * Remove all markers that do not belong to any script host and not part of the global one when loaded 28 | * @param ci 29 | */ 30 | @Inject(method = "readCustomDataFromTag", at = @At("HEAD")) 31 | private void checkScarpetMarkerUnloaded(CallbackInfo ci) 32 | { 33 | if ((CarpetSettings.scriptsAutoload || CarpetSettings.commandScript) && !world.isClient) 34 | { 35 | if (getScoreboardTags().contains(ExpressionInspector.MARKER_STRING)) 36 | { 37 | String prefix = ExpressionInspector.MARKER_STRING+"_"; 38 | Optional owner = getScoreboardTags().stream().filter(s -> s.startsWith(prefix)).findFirst(); 39 | if (owner.isPresent()) 40 | { 41 | String hostName = StringUtils.removeStart(owner.get(),prefix); 42 | if (!hostName.isEmpty() && CarpetServer.scriptServer.getHostByName(hostName) == null) 43 | { 44 | remove(); 45 | } 46 | 47 | } 48 | else 49 | { 50 | remove(); 51 | } 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlazeEntityShootFireballGoal_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.mob.BlazeEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(targets = "net.minecraft.entity.mob.BlazeEntity$ShootFireballGoal") 12 | public class BlazeEntityShootFireballGoal_extremeMixin 13 | { 14 | @Redirect(method = "tick()V", expect = 2, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlazeEntity_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.mob.BlazeEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(BlazeEntity.class) 12 | public class BlazeEntity_extremeMixin 13 | { 14 | // unused actually 15 | @Redirect(method = "mobTick", expect = 1, at = @At( 16 | value = "INVOKE", 17 | target = "Ljava/util/Random;nextGaussian()D" 18 | )) 19 | private double nextGauBian(Random random) 20 | { 21 | return RandomTools.nextGauBian(random); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlockEntityRenderDispatcher_movableTEMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.BlockEntityRenderDispatcherInterface; 4 | import com.mojang.blaze3d.platform.GLX; 5 | import com.mojang.blaze3d.platform.GlStateManager; 6 | import net.minecraft.block.entity.BlockEntity; 7 | import net.minecraft.client.render.Camera; 8 | import net.minecraft.client.render.DiffuseLighting; 9 | import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; 10 | import net.minecraft.util.math.BlockPos; 11 | import net.minecraft.world.World; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.Shadow; 14 | 15 | @Mixin(BlockEntityRenderDispatcher.class) 16 | public abstract class BlockEntityRenderDispatcher_movableTEMixin implements BlockEntityRenderDispatcherInterface 17 | { 18 | @Shadow 19 | public static double renderOffsetX; 20 | @Shadow 21 | public static double renderOffsetY; 22 | @Shadow 23 | public static double renderOffsetZ; 24 | @Shadow 25 | public Camera camera; 26 | @Shadow 27 | public World world; 28 | 29 | @Shadow 30 | public abstract void renderEntity(BlockEntity blockEntity_1, double double_1, double double_2, double double_3, 31 | float float_1, int int_1, boolean boolean_1); 32 | 33 | /** 34 | * @author 2No2Name 35 | */ 36 | //Renders the BlockEntity offset by the amount specified in the arguments xOffset yOffset zOffset (the moving block moved in the animation by this) 37 | public void renderBlockEntityOffset(BlockEntity blockEntity_1, float partialTicks, int destroyStage, double xOffset, 38 | double yOffset, double zOffset) 39 | { 40 | if (blockEntity_1.getSquaredDistance(this.camera.getPos().x - xOffset, this.camera.getPos().y - yOffset, 41 | camera.getPos().z - zOffset) < blockEntity_1.getSquaredRenderDistance()) 42 | { 43 | DiffuseLighting.enable(); 44 | int i = this.world.getLightmapIndex(blockEntity_1.getPos(), 0); 45 | int j = i % 65536; 46 | int k = i / 65536; 47 | GLX.glMultiTexCoord2f(GLX.GL_TEXTURE1, (float) j, (float) k); 48 | GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); 49 | BlockPos blockpos = blockEntity_1.getPos(); 50 | this.renderEntity(blockEntity_1, (double) blockpos.getX() - renderOffsetX + xOffset, (double) blockpos.getY() - renderOffsetY + yOffset, (double) blockpos.getZ() - renderOffsetZ + zOffset, partialTicks, destroyStage, false); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BlockItem_scarpetEventMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.item.BlockItem; 4 | import net.minecraft.item.ItemPlacementContext; 5 | import net.minecraft.server.network.ServerPlayerEntity; 6 | import net.minecraft.util.ActionResult; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 11 | 12 | import static carpet.script.CarpetEventServer.Event.PLAYER_PLACES_BLOCK; 13 | 14 | @Mixin(BlockItem.class) 15 | public class BlockItem_scarpetEventMixin 16 | { 17 | @Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", at = @At( 18 | value = "INVOKE", 19 | target = "Lnet/minecraft/block/Block;onPlaced(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;)V", 20 | shift = At.Shift.AFTER 21 | )) 22 | private void afterPlacement(ItemPlacementContext context, CallbackInfoReturnable cir) 23 | { 24 | if (context.getPlayer() instanceof ServerPlayerEntity && PLAYER_PLACES_BLOCK.isNeeded()) 25 | PLAYER_PLACES_BLOCK.onBlockPlaced((ServerPlayerEntity) context.getPlayer(), context.getBlockPos(), context.getHand(), context.getStack()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/BuriedTreasureGeneratorPieceMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.structure.BuriedTreasureGenerator; 5 | import net.minecraft.world.Heightmap; 6 | import net.minecraft.world.IWorld; 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(BuriedTreasureGenerator.Piece.class) 12 | public class BuriedTreasureGeneratorPieceMixin 13 | { 14 | @Redirect(method = "generate", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I" 17 | )) 18 | private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3) 19 | { 20 | return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CarpetBlockMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.WoolTool; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.block.BlockState; 6 | import net.minecraft.block.CarpetBlock; 7 | import net.minecraft.item.ItemPlacementContext; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | 10 | @Mixin(CarpetBlock.class) 11 | public abstract class CarpetBlockMixin extends Block 12 | { 13 | 14 | public CarpetBlockMixin(Settings block$Settings_1) 15 | { 16 | super(block$Settings_1); 17 | } 18 | 19 | public BlockState getPlacementState(ItemPlacementContext context) 20 | { 21 | BlockState state = super.getPlacementState(context); 22 | if (context.getPlayer() != null && !context.getWorld().isClient) 23 | { 24 | WoolTool.carpetPlacedAction(((CarpetBlock)(Object)this).getColor(), context.getPlayer(), context.getBlockPos(), context.getWorld()); 25 | } 26 | return state; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CauldronBlock_stackableSBoxesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.block.BlockState; 6 | import net.minecraft.block.CauldronBlock; 7 | import net.minecraft.entity.player.PlayerEntity; 8 | import net.minecraft.item.Item; 9 | import net.minecraft.item.ItemStack; 10 | import net.minecraft.util.Hand; 11 | import net.minecraft.util.hit.BlockHitResult; 12 | import net.minecraft.util.math.BlockPos; 13 | import net.minecraft.world.World; 14 | import org.spongepowered.asm.mixin.Mixin; 15 | import org.spongepowered.asm.mixin.injection.At; 16 | import org.spongepowered.asm.mixin.injection.Inject; 17 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 18 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 19 | 20 | @Mixin(CauldronBlock.class) 21 | public class CauldronBlock_stackableSBoxesMixin 22 | { 23 | @Inject(method = "activate", locals = LocalCapture.CAPTURE_FAILHARD, at = @At( 24 | value = "INVOKE", 25 | target = "Lnet/minecraft/item/ItemStack;hasTag()Z", 26 | shift = At.Shift.BEFORE 27 | )) 28 | private void setSboxCount(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult arg5, CallbackInfoReturnable cir, 29 | ItemStack itemStack, int i, Item item, Block block, ItemStack itemStack5) 30 | { 31 | if (CarpetSettings.stackableShulkerBoxes) 32 | itemStack5.setCount(itemStack.getCount()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ChunkGeneratorMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.biome.Biome; 5 | import net.minecraft.world.gen.chunk.ChunkGenerator; 6 | import net.minecraft.world.gen.feature.FeatureConfig; 7 | import net.minecraft.world.gen.feature.StructureFeature; 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(ChunkGenerator.class) 14 | public abstract class ChunkGeneratorMixin 15 | { 16 | 17 | ///used for plop - changed in 1.14 - feature needs reimplemnting 18 | 19 | @Inject(method = "hasStructure", at = @At("HEAD"), cancellable = true) 20 | private void skipGenerationBiomeChecks(Biome biome_1, StructureFeature structureFeature_1, CallbackInfoReturnable cir) 21 | { 22 | if (CarpetSettings.skipGenerationChecks) 23 | { 24 | cir.setReturnValue(true); 25 | cir.cancel(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ChunkMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.world.chunk.Chunk; 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(Chunk.class) 12 | public abstract class ChunkMixin 13 | { 14 | 15 | ///used for plop - changed in 1.14 - feature needs reimplemnting 16 | 17 | 18 | @Inject(method = "markBlockForPostProcessing(Lnet/minecraft/util/math/BlockPos;)V", 19 | at =@At("HEAD"), cancellable = true) 20 | private void squashWarnings(BlockPos blockPos_1, CallbackInfo ci) 21 | { 22 | if (CarpetSettings.skipGenerationChecks) ci.cancel(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ChunkTicketManager_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; 4 | import it.unimi.dsi.fastutil.objects.ObjectSortedSet; 5 | import net.minecraft.server.world.ChunkTicket; 6 | import net.minecraft.server.world.ChunkTicketManager; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.gen.Accessor; 9 | 10 | @Mixin(ChunkTicketManager.class) 11 | public interface ChunkTicketManager_scarpetMixin 12 | { 13 | @Accessor 14 | Long2ObjectOpenHashMap>> getTicketsByPosition(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ChunkTicketManager_ticketLogHelperMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.ChunkTicketManagerInterface; 4 | import carpet.logging.LoggerRegistry; 5 | import carpet.logging.logHelpers.ChunkTicketLogHelper; 6 | import net.minecraft.server.world.ChunkTicket; 7 | import net.minecraft.server.world.ChunkTicketManager; 8 | import net.minecraft.server.world.ServerWorld; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | import java.lang.reflect.Method; 15 | 16 | @Mixin(ChunkTicketManager.class) 17 | public class ChunkTicketManager_ticketLogHelperMixin implements ChunkTicketManagerInterface { 18 | private ServerWorld world; 19 | 20 | public void setServerWorld(ServerWorld world) 21 | { 22 | this.world = world; 23 | } 24 | 25 | @Inject( 26 | method = "Lnet/minecraft/server/world/ChunkTicketManager;addTicket(JLnet/minecraft/server/world/ChunkTicket;)V", 27 | at = @At(value = "HEAD") 28 | ) 29 | private void onAddTicket(long position, ChunkTicket ticket, CallbackInfo ci) { 30 | if (LoggerRegistry.__ticket) { 31 | ChunkTicketLogHelper.onAddTicket(this.world, position, ticket); 32 | } 33 | } 34 | 35 | @Inject( 36 | method = "Lnet/minecraft/server/world/ChunkTicketManager;removeTicket(JLnet/minecraft/server/world/ChunkTicket;)V", 37 | at = @At(value = "HEAD") 38 | ) 39 | private void onRemoveTicket(long position, ChunkTicket chunkTicket, CallbackInfo ci) 40 | { 41 | if (LoggerRegistry.__ticket) { 42 | ChunkTicketLogHelper.onRemoveTicket(this.world, position, chunkTicket); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ClientConnectionMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.logging.logHelpers.PacketCounter; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.util.concurrent.Future; 6 | import io.netty.util.concurrent.GenericFutureListener; 7 | import net.minecraft.network.ClientConnection; 8 | import net.minecraft.network.Packet; 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(ClientConnection.class) 15 | public abstract class ClientConnectionMixin 16 | { 17 | // Add to the packet counter whenever a packet is received. 18 | @Inject(method = "channelRead0", at = @At("HEAD")) 19 | private void packetInCount(ChannelHandlerContext channelHandlerContext_1, Packet packet_1, CallbackInfo ci) 20 | { 21 | PacketCounter.totalIn++; 22 | } 23 | 24 | // Add to the packet counter whenever a packet is sent. 25 | @Inject(method = "sendImmediately", at = @At("HEAD")) 26 | private void packetOutCount(Packet packet_1, 27 | GenericFutureListener> genericFutureListener_1, CallbackInfo ci) 28 | { 29 | PacketCounter.totalOut++; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ClientPlayNetworkHandler_smoothClientAnimationsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.BlockState; 5 | import net.minecraft.block.Blocks; 6 | import net.minecraft.block.entity.BlockEntity; 7 | import net.minecraft.block.entity.PistonBlockEntity; 8 | import net.minecraft.client.network.ClientPlayNetworkHandler; 9 | import net.minecraft.client.world.ClientWorld; 10 | import net.minecraft.nbt.CompoundTag; 11 | import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket; 12 | import net.minecraft.util.math.BlockPos; 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 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 19 | 20 | import java.util.Iterator; 21 | 22 | @Mixin(ClientPlayNetworkHandler.class) 23 | public class ClientPlayNetworkHandler_smoothClientAnimationsMixin 24 | { 25 | @Shadow private ClientWorld world; 26 | // fix as suggested by G4me4u 27 | @Inject( method = "onChunkData", locals = LocalCapture.CAPTURE_FAILHARD, require = 0, at = @At( 28 | value = "INVOKE", 29 | target = "Lnet/minecraft/client/world/ClientWorld;getBlockEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/entity/BlockEntity;", 30 | shift = At.Shift.AFTER 31 | )) 32 | private void recreateMovingPistons(ChunkDataS2CPacket packet, CallbackInfo ci, 33 | Iterator var5, CompoundTag tag, BlockPos blockPos) 34 | { 35 | if (CarpetSettings.smoothClientAnimations) 36 | { 37 | BlockEntity blockEntity = world.getBlockEntity(blockPos); 38 | if (blockEntity == null && "minecraft:piston".equals(tag.getString("id"))) 39 | { 40 | BlockState blockState = world.getBlockState(blockPos); 41 | if (blockState.getBlock() == Blocks.MOVING_PISTON) { 42 | tag.putFloat("progress", Math.min(tag.getFloat("progress") + 0.5F, 1.0F)); 43 | blockEntity = new PistonBlockEntity(); 44 | blockEntity.fromTag(tag); 45 | world.setBlockEntity(blockPos, blockEntity); 46 | blockEntity.resetBlock(); 47 | } 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CloneCommandMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.server.command.CloneCommand; 6 | import net.minecraft.server.world.ServerWorld; 7 | import net.minecraft.util.math.BlockPos; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Constant; 11 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 12 | import org.spongepowered.asm.mixin.injection.Redirect; 13 | 14 | 15 | @Mixin(CloneCommand.class) 16 | public abstract class CloneCommandMixin 17 | { 18 | @ModifyConstant(method = "execute", constant = @Constant(intValue = 32768)) 19 | private static int fillLimit(int original) { 20 | return CarpetSettings.fillLimit; 21 | } 22 | 23 | @Redirect(method = "execute", at = @At( 24 | value = "INVOKE", 25 | target = "Lnet/minecraft/server/world/ServerWorld;updateNeighbors(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;)V" 26 | )) 27 | private static void conditionalUpdating(ServerWorld serverWorld, BlockPos blockPos_1, Block block_1) 28 | { 29 | if (CarpetSettings.fillUpdates) serverWorld.updateNeighbors(blockPos_1, block_1); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CommandManagerMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import carpet.CarpetSettings; 5 | import com.mojang.brigadier.CommandDispatcher; 6 | import net.minecraft.server.command.CommandManager; 7 | import net.minecraft.server.command.ServerCommandSource; 8 | import org.apache.logging.log4j.Logger; 9 | import org.spongepowered.asm.mixin.Final; 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.Redirect; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 16 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 17 | 18 | 19 | @Mixin(CommandManager.class) 20 | public abstract class CommandManagerMixin 21 | { 22 | 23 | @Shadow 24 | @Final 25 | private CommandDispatcher dispatcher; 26 | 27 | @Inject(method = "", at = @At("RETURN")) 28 | private void onRegister(boolean boolean_1, CallbackInfo ci) { 29 | CarpetServer.registerCarpetCommands(this.dispatcher); 30 | } 31 | 32 | @Inject(method = "execute", at = @At("HEAD")) 33 | private void onExecuteBegin(ServerCommandSource serverCommandSource_1, String string_1, CallbackInfoReturnable cir) 34 | { 35 | if (!CarpetSettings.fillUpdates) 36 | CarpetSettings.impendingFillSkipUpdates = true; 37 | } 38 | 39 | @Inject(method = "execute", at = @At("RETURN")) 40 | private void onExecuteEnd(ServerCommandSource serverCommandSource_1, String string_1, CallbackInfoReturnable cir) 41 | { 42 | CarpetSettings.impendingFillSkipUpdates = false; 43 | } 44 | 45 | @Redirect(method = "execute", at = @At( 46 | value = "INVOKE", 47 | target = "Lorg/apache/logging/log4j/Logger;isDebugEnabled()Z" 48 | )) 49 | private boolean doesOutputCommandStackTrace(Logger logger) 50 | { 51 | if (CarpetSettings.superSecretSetting) 52 | return true; 53 | return logger.isDebugEnabled(); 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ContainerMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.container.Container; 5 | import net.minecraft.container.Slot; 6 | import net.minecraft.container.SlotActionType; 7 | import net.minecraft.entity.player.PlayerEntity; 8 | import net.minecraft.item.Item; 9 | import net.minecraft.item.ItemStack; 10 | import org.spongepowered.asm.mixin.Final; 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.CallbackInfoReturnable; 16 | 17 | import java.util.List; 18 | 19 | @Mixin(Container.class) 20 | public abstract class ContainerMixin 21 | { 22 | @Shadow @Final public List slots; 23 | 24 | @Shadow public abstract ItemStack onSlotClick(int int_1, int int_2, SlotActionType slotActionType_1, PlayerEntity playerEntity_1); 25 | 26 | @Shadow public abstract void sendContentUpdates(); 27 | 28 | @Inject( method = "onSlotClick", at = @At(value = "HEAD"), cancellable = true) 29 | private void onThrowClick( int slotId, int clickData, SlotActionType actionType, PlayerEntity playerEntity, CallbackInfoReturnable cir) 30 | { 31 | if (actionType == SlotActionType.THROW && CarpetSettings.ctrlQCraftingFix && playerEntity.inventory.getCursorStack().isEmpty() && slotId >= 0) 32 | { 33 | ItemStack itemStack_1 = ItemStack.EMPTY; 34 | Slot slot_4 = slots.get(slotId); 35 | if (slot_4 != null && slot_4.hasStack() && slot_4.canTakeItems(playerEntity)) 36 | { 37 | if(slotId == 0 && clickData == 1) 38 | { 39 | Item craftedItem = slot_4.getStack().getItem(); 40 | while(slot_4.hasStack() && slot_4.getStack().getItem() == craftedItem) 41 | { 42 | this.onSlotClick(slotId, 0, SlotActionType.THROW, playerEntity); 43 | } 44 | this.sendContentUpdates(); 45 | cir.setReturnValue(itemStack_1); 46 | cir.cancel(); 47 | } 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/CoralFeatureMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.CoralFeatureInterface; 4 | import net.minecraft.block.BlockState; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.IWorld; 7 | import net.minecraft.world.World; 8 | import net.minecraft.world.gen.feature.CoralFeature; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Shadow; 11 | 12 | import java.util.Random; 13 | 14 | @Mixin(CoralFeature.class) 15 | public abstract class CoralFeatureMixin implements CoralFeatureInterface 16 | { 17 | 18 | @Shadow protected abstract boolean spawnCoral(IWorld var1, Random var2, BlockPos var3, BlockState var4); 19 | 20 | @Override 21 | public boolean growSpecific(World worldIn, Random random, BlockPos pos, BlockState blockUnder) 22 | { 23 | return spawnCoral(worldIn, random, pos, blockUnder); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DamageTracker_scarpetEventMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.script.EntityEventsGroup; 5 | import net.minecraft.entity.LivingEntity; 6 | import net.minecraft.entity.damage.DamageSource; 7 | import net.minecraft.entity.damage.DamageTracker; 8 | import org.spongepowered.asm.mixin.Final; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Shadow; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 | 15 | @Mixin(DamageTracker.class) 16 | public class DamageTracker_scarpetEventMixin 17 | { 18 | @Shadow @Final private LivingEntity entity; 19 | 20 | @Inject(method = "onDamage", at = @At("HEAD")) 21 | private void onDamageTaken(DamageSource damageSource_1, float float_1, float float_2, CallbackInfo ci) 22 | { 23 | ((EntityInterface)entity).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DAMAGE, entity, float_2, damageSource_1); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DesertPyramidFeatureMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import com.google.common.collect.Lists; 5 | import com.mojang.datafixers.Dynamic; 6 | import net.minecraft.entity.EntityType; 7 | import net.minecraft.world.biome.Biome; 8 | import net.minecraft.world.gen.feature.AbstractTempleFeature; 9 | import net.minecraft.world.gen.feature.DefaultFeatureConfig; 10 | import net.minecraft.world.gen.feature.DesertPyramidFeature; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | import java.util.function.Function; 16 | 17 | @Mixin(DesertPyramidFeature.class) 18 | public abstract class DesertPyramidFeatureMixin extends AbstractTempleFeature 19 | { 20 | private static final List MONSTER_SPAWNS; 21 | 22 | static 23 | { 24 | MONSTER_SPAWNS = Lists.newArrayList(new Biome.SpawnEntry(EntityType.HUSK, 1, 1, 1)); 25 | } 26 | 27 | public DesertPyramidFeatureMixin(Function, ? extends DefaultFeatureConfig> function_1) 28 | { 29 | super(function_1); 30 | } 31 | 32 | @Override 33 | public List getMonsterSpawns() 34 | { 35 | if (CarpetSettings.huskSpawningInTemples) 36 | { 37 | return MONSTER_SPAWNS; 38 | } 39 | return Collections.emptyList(); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /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.entity.Entity; 7 | import net.minecraft.util.math.Direction; 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 = "getEntityFacingOrder", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw(F)F")) 16 | private static float getYaw(Entity entity, float float_1) 17 | { 18 | float yaw; 19 | if (!CarpetSettings.placementRotationFix) 20 | { 21 | yaw = entity.getYaw(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 = "getEntityFacingOrder", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch(F)F")) 34 | private static float getPitch(Entity entity, float float_1) 35 | { 36 | float pitch = entity.getPitch(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.block.DispenserBlock; 5 | import net.minecraft.block.dispenser.DispenserBehavior; 6 | import net.minecraft.item.Item; 7 | import net.minecraft.item.ItemStack; 8 | import net.minecraft.item.Items; 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(DispenserBlock.class) 15 | public abstract class DispenserBlock_cactusMixin 16 | { 17 | @Inject(method = "getBehaviorForItem", at = @At("HEAD"), cancellable = true) 18 | private void registerCarpetBehaviors(ItemStack stack, CallbackInfoReturnable cir) 19 | { 20 | Item item = stack.getItem(); 21 | if (item == Items.CACTUS) 22 | cir.setReturnValue(new BlockRotator.CactusDispenserBehaviour()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/DispenserBlock_qcMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.DispenserBlock; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.World; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Redirect; 10 | 11 | @Mixin(DispenserBlock.class) 12 | public class DispenserBlock_qcMixin 13 | { 14 | @Redirect(method = "neighborUpdate", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/World;isReceivingRedstonePower(Lnet/minecraft/util/math/BlockPos;)Z", 17 | ordinal = 1 18 | )) 19 | private boolean checkUpPower(World world, BlockPos blockPos_1) 20 | { 21 | if (!CarpetSettings.quasiConnectivity) 22 | return false; 23 | return world.isReceivingRedstonePower(blockPos_1); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/EndCityFeatureMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import com.google.common.collect.Lists; 5 | import com.mojang.datafixers.Dynamic; 6 | import net.minecraft.entity.EntityType; 7 | import net.minecraft.world.biome.Biome; 8 | import net.minecraft.world.gen.feature.DefaultFeatureConfig; 9 | import net.minecraft.world.gen.feature.EndCityFeature; 10 | import net.minecraft.world.gen.feature.StructureFeature; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | import java.util.function.Function; 16 | 17 | @Mixin(EndCityFeature.class) 18 | public abstract class EndCityFeatureMixin extends StructureFeature 19 | { 20 | private static final List spawnList = Lists.newArrayList(new Biome.SpawnEntry(EntityType.SHULKER, 10, 4, 4)); 21 | 22 | public EndCityFeatureMixin(Function, ? extends DefaultFeatureConfig> function_1) 23 | { 24 | super(function_1); 25 | } 26 | 27 | @Override 28 | public List getMonsterSpawns() 29 | { 30 | if (CarpetSettings.shulkerSpawningInEndCities) 31 | return spawnList; 32 | return Collections.emptyList(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/EndGatewayFeature_BlockEntityLogMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.logging.LoggerRegistry; 4 | import carpet.logging.logHelpers.BlockEntityLogHelper; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.IWorld; 7 | import net.minecraft.world.gen.chunk.ChunkGenerator; 8 | import net.minecraft.world.gen.chunk.ChunkGeneratorConfig; 9 | import net.minecraft.world.gen.feature.EndGatewayFeature; 10 | import net.minecraft.world.gen.feature.EndGatewayFeatureConfig; 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 | import java.util.Random; 17 | 18 | @Mixin(EndGatewayFeature.class) 19 | public abstract class EndGatewayFeature_BlockEntityLogMixin { 20 | 21 | @Inject(method = "generate", at=@At("HEAD")) 22 | private void log(IWorld iWorld, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, EndGatewayFeatureConfig endGatewayFeatureConfig, CallbackInfoReturnable cir){ 23 | if (LoggerRegistry.__blockentity) { 24 | BlockEntityLogHelper.onExitEndGatewayGenerate(iWorld.getBlockEntity(blockPos), blockPos); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/EntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import net.minecraft.entity.Entity; 5 | import net.minecraft.util.math.MathHelper; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.Shadow; 8 | 9 | @Mixin(Entity.class) 10 | public abstract class EntityMixin implements EntityInterface 11 | { 12 | @Shadow 13 | public float yaw; 14 | 15 | @Shadow 16 | public float prevYaw; 17 | 18 | public float getMainYaw(float partialTicks) 19 | { 20 | return partialTicks == 1.0F ? this.yaw : MathHelper.lerp(partialTicks, this.prevYaw, this.yaw); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/EntityTrackerEntry_leashFixMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.Entity; 5 | import net.minecraft.entity.mob.MobEntity; 6 | import net.minecraft.network.Packet; 7 | import net.minecraft.network.packet.s2c.play.EntityAttachS2CPacket; 8 | import net.minecraft.server.network.EntityTrackerEntry; 9 | import org.spongepowered.asm.mixin.Final; 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 | import java.util.function.Consumer; 17 | 18 | @Mixin(EntityTrackerEntry.class) 19 | public class EntityTrackerEntry_leashFixMixin 20 | { 21 | @Shadow @Final private Entity entity; 22 | 23 | @Inject(method = "sendPackets", at = @At("RETURN")) 24 | private void sendLeashPackets(Consumer> consumer_1, CallbackInfo ci) 25 | { 26 | if (CarpetSettings.leadFix) 27 | { 28 | if (entity instanceof MobEntity) 29 | { 30 | consumer_1.accept( new EntityAttachS2CPacket(entity, ((MobEntity) entity).getHoldingEntity())); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Entity_portalSuffocationMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.Entity; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.util.math.Box; 7 | import net.minecraft.world.dimension.DimensionType; 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.Redirect; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 14 | 15 | @Mixin(Entity.class) 16 | public abstract class Entity_portalSuffocationMixin 17 | { 18 | @Shadow public abstract Box getBoundingBox(); 19 | 20 | @Inject(method = "changeDimension", at = @At( 21 | value = "INVOKE", 22 | target = "Lnet/minecraft/entity/Entity;getLastNetherPortalDirection()Lnet/minecraft/util/math/Direction;" 23 | )) 24 | private void registerEntityDimensionChange(DimensionType dimensionType_1, CallbackInfoReturnable cir) 25 | { 26 | if (CarpetSettings.portalSuffocationFix) 27 | { 28 | CarpetSettings.currentTelepotingEntityBox = getBoundingBox(); 29 | CarpetSettings.fixedPosition = null; 30 | } 31 | } 32 | 33 | @Redirect(method = "changeDimension", at = @At( 34 | value = "INVOKE", 35 | target = "Lnet/minecraft/entity/Entity;refreshPositionAndAngles(Lnet/minecraft/util/math/BlockPos;FF)V" 36 | )) 37 | private void alternativeSetPositionAndAngles(Entity entity, BlockPos blockPos_1, float float_1, float float_2) 38 | { 39 | if (CarpetSettings.portalSuffocationFix && CarpetSettings.fixedPosition != null) 40 | entity.refreshPositionAndAngles(CarpetSettings.fixedPosition.x, CarpetSettings.fixedPosition.y, CarpetSettings.fixedPosition.z, float_1, float_2); 41 | else 42 | entity.refreshPositionAndAngles(blockPos_1, float_1, float_2); 43 | } 44 | 45 | @Inject(method = "changeDimension", at = @At("RETURN")) 46 | private void removeEntity(DimensionType dimensionType_1, CallbackInfoReturnable cir) 47 | { 48 | CarpetSettings.currentTelepotingEntityBox = null; 49 | CarpetSettings.fixedPosition = null; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Entity_scarpetEventsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.script.EntityEventsGroup; 5 | import net.minecraft.entity.Entity; 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(Entity.class) 13 | public abstract class Entity_scarpetEventsMixin implements EntityInterface 14 | { 15 | @Shadow public boolean removed; 16 | 17 | private final EntityEventsGroup events = new EntityEventsGroup(); 18 | 19 | @Override 20 | public EntityEventsGroup getEventContainer() 21 | { 22 | return events; 23 | } 24 | 25 | @Inject(method = "tick", at = @At("HEAD")) 26 | private void onTickCall(CallbackInfo ci) 27 | { 28 | events.onEvent(EntityEventsGroup.EntityEventType.ON_TICK, (Entity) (Object) this); 29 | } 30 | 31 | 32 | @Inject(method = "remove", at = @At("HEAD")) 33 | private void onRemove(CallbackInfo ci) 34 | { 35 | if (!removed) events.onEvent(EntityEventsGroup.EntityEventType.ON_REMOVED, (Entity) (Object) this); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ExperienceOrbEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.fakes.ExperienceOrbInterface; 5 | import carpet.helpers.XPcombine; 6 | import net.minecraft.entity.ExperienceOrbEntity; 7 | import net.minecraft.entity.player.PlayerEntity; 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.CallbackInfo; 13 | 14 | @Mixin(ExperienceOrbEntity.class) 15 | public abstract class ExperienceOrbEntityMixin implements ExperienceOrbInterface 16 | { 17 | @Shadow private int amount; 18 | 19 | public void setAmount(int amount) { this.amount = amount; } 20 | 21 | public int combineDelay = 50; 22 | 23 | public int getCombineDelay() { return combineDelay; } 24 | public void setCombineDelay(int what) { combineDelay = what; } 25 | 26 | @Inject(method = "tick", 27 | at = @At( 28 | value = "INVOKE", 29 | target = "Lnet/minecraft/entity/ExperienceOrbEntity;move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V", 30 | shift = At.Shift.AFTER 31 | )) 32 | void checkCombineAtTick(CallbackInfo ci) 33 | { 34 | if (CarpetSettings.combineXPOrbs) 35 | { 36 | if (getCombineDelay() > 0) 37 | { 38 | setCombineDelay(getCombineDelay()-1); 39 | } 40 | 41 | if (getCombineDelay() == 0) 42 | { 43 | XPcombine.searchForOtherXPNearby((ExperienceOrbEntity) (Object) this); 44 | } 45 | } 46 | } 47 | 48 | @Inject(method = "onPlayerCollision", at = @At("HEAD")) 49 | void removeDelay(PlayerEntity playerEntity_1, CallbackInfo ci) 50 | { 51 | if (CarpetSettings.xpNoCooldown) 52 | playerEntity_1.experiencePickUpDelay = 0; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ExplosionAccessor.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.entity.Entity; 4 | import net.minecraft.world.World; 5 | import net.minecraft.world.explosion.Explosion; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.gen.Accessor; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(Explosion.class) 12 | public interface ExplosionAccessor { 13 | 14 | @Accessor 15 | boolean isCreateFire(); 16 | 17 | @Accessor 18 | Explosion.DestructionType getBlockDestructionType(); 19 | 20 | @Accessor 21 | World getWorld(); 22 | 23 | @Accessor 24 | Random getRandom(); 25 | 26 | @Accessor 27 | double getX(); 28 | 29 | @Accessor 30 | double getY(); 31 | 32 | @Accessor 33 | double getZ(); 34 | 35 | @Accessor 36 | float getPower(); 37 | 38 | @Accessor 39 | Entity getEntity(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ExplosionMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.OptimizedExplosion; 4 | import carpet.CarpetSettings; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.explosion.Explosion; 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.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | import java.util.List; 15 | 16 | @Mixin(Explosion.class) 17 | public abstract class ExplosionMixin 18 | { 19 | @Shadow 20 | @Final 21 | private List affectedBlocks; 22 | 23 | @Inject(method = "collectBlocksAndDamageEntities", at = @At("HEAD"), 24 | cancellable = true) 25 | private void onExplosionA(CallbackInfo ci) 26 | { 27 | if (CarpetSettings.optimizedTNT) 28 | { 29 | OptimizedExplosion.doExplosionA((Explosion) (Object) this); 30 | ci.cancel(); 31 | } 32 | } 33 | 34 | @Inject(method = "affectWorld", at = @At("HEAD"), 35 | cancellable = true) 36 | private void onExplosionB(boolean spawnParticles, CallbackInfo ci) 37 | { 38 | if (CarpetSettings.optimizedTNT) 39 | { 40 | OptimizedExplosion.doExplosionB((Explosion) (Object) this, spawnParticles); 41 | ci.cancel(); 42 | } 43 | } 44 | 45 | @Inject(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", shift = At.Shift.AFTER, 46 | target = "Ljava/util/List;addAll(Ljava/util/Collection;)Z")) 47 | private void clearList(CallbackInfo ci) 48 | { 49 | if (CarpetSettings.explosionNoBlockDamage) 50 | { 51 | this.affectedBlocks.clear(); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ExplosiveProjectileEntity_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.projectile.ExplosiveProjectileEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(ExplosiveProjectileEntity.class) 12 | public class ExplosiveProjectileEntity_extremeMixin 13 | { 14 | @Redirect(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/entity/LivingEntity;DDDLnet/minecraft/world/World;)V", 15 | expect = 3, at = @At( 16 | value = "INVOKE", 17 | target = "Ljava/util/Random;nextGaussian()D" 18 | )) 19 | private double nextGauBian(Random random) 20 | { 21 | return RandomTools.nextGauBian(random); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FallingBlockEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.logging.LoggerRegistry; 4 | import carpet.logging.logHelpers.TrajectoryLogHelper; 5 | import net.minecraft.entity.Entity; 6 | import net.minecraft.entity.EntityType; 7 | import net.minecraft.entity.FallingBlockEntity; 8 | import net.minecraft.entity.projectile.ProjectileEntity; 9 | import net.minecraft.world.World; 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(FallingBlockEntity.class) 16 | public abstract class FallingBlockEntityMixin extends Entity 17 | { 18 | private TrajectoryLogHelper logHelper; 19 | public FallingBlockEntityMixin(EntityType entityType_1, World world_1) { super(entityType_1, world_1); } 20 | 21 | @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN")) 22 | private void addLogger(EntityType entityType_1, World world_1, CallbackInfo ci) 23 | { 24 | if (LoggerRegistry.__fallingBlocks && !world_1.isClient) 25 | logHelper = new TrajectoryLogHelper("fallingBlocks"); 26 | } 27 | 28 | @Inject(method = "tick", at = @At("HEAD")) 29 | private void tickCheck(CallbackInfo ci) 30 | { 31 | if (LoggerRegistry.__fallingBlocks && logHelper != null) 32 | logHelper.onTick(x, y, z, getVelocity()); 33 | } 34 | 35 | @Override 36 | public void remove() 37 | { 38 | super.remove(); 39 | if (LoggerRegistry.__fallingBlocks && logHelper != null) 40 | logHelper.onFinish(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /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.entity.Entity; 6 | import net.minecraft.entity.EntityType; 7 | import net.minecraft.entity.FallingBlockEntity; 8 | import net.minecraft.world.World; 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, World 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.EntityEventType.ON_TICK, this); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FillCommandMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.server.command.FillCommand; 6 | import net.minecraft.server.world.ServerWorld; 7 | import net.minecraft.util.math.BlockPos; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Constant; 11 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 12 | import org.spongepowered.asm.mixin.injection.Redirect; 13 | 14 | @Mixin(FillCommand.class) 15 | public abstract class FillCommandMixin 16 | { 17 | @ModifyConstant(method = "execute", constant = @Constant(intValue = 32768)) 18 | private static int fillLimit(int original) 19 | { 20 | return CarpetSettings.fillLimit; 21 | } 22 | 23 | @Redirect(method = "execute", at = @At( 24 | value = "INVOKE", 25 | target = "Lnet/minecraft/server/world/ServerWorld;updateNeighbors(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;)V" 26 | )) 27 | private static void conditionalUpdating(ServerWorld serverWorld, BlockPos blockPos_1, Block block_1) 28 | { 29 | if (CarpetSettings.fillUpdates) serverWorld.updateNeighbors(blockPos_1, block_1); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FireworkEntity_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.FireworkEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(FireworkEntity.class) 12 | public class FireworkEntity_extremeMixin 13 | { 14 | @Redirect(method = "(Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V", expect = 2, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | 23 | @Redirect(method = "setVelocity", expect = 3, at = @At( 24 | value = "INVOKE", 25 | target = "Ljava/util/Random;nextGaussian()D" 26 | )) 27 | private double nextGauBian2(Random random) 28 | { 29 | return RandomTools.nextGauBian(random); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FishingBobberEntity_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.projectile.FishingBobberEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(FishingBobberEntity.class) 12 | public class FishingBobberEntity_extremeMixin 13 | { 14 | @Redirect(method = "(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/World;II)V", expect =3, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FloatingIslandsChunkGeneratorMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.EntityCategory; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.IWorld; 7 | import net.minecraft.world.biome.Biome; 8 | import net.minecraft.world.biome.source.BiomeSource; 9 | import net.minecraft.world.gen.chunk.FloatingIslandsChunkGenerator; 10 | import net.minecraft.world.gen.chunk.FloatingIslandsChunkGeneratorConfig; 11 | import net.minecraft.world.gen.chunk.SurfaceChunkGenerator; 12 | import net.minecraft.world.gen.feature.Feature; 13 | import org.spongepowered.asm.mixin.Mixin; 14 | 15 | import java.util.List; 16 | 17 | @Mixin(FloatingIslandsChunkGenerator.class) 18 | public abstract class FloatingIslandsChunkGeneratorMixin extends SurfaceChunkGenerator 19 | { 20 | public FloatingIslandsChunkGeneratorMixin(IWorld iWorld_1, BiomeSource biomeSource_1, int int_1, int int_2, int int_3, FloatingIslandsChunkGeneratorConfig chunkGeneratorConfig_1, boolean boolean_1) 21 | { 22 | super(iWorld_1, biomeSource_1, int_1, int_2, int_3, chunkGeneratorConfig_1, boolean_1); 23 | } 24 | 25 | @Override 26 | public List getEntitySpawnList(EntityCategory entityCategory_1, BlockPos blockPos_1) 27 | { 28 | if (CarpetSettings.shulkerSpawningInEndCities && EntityCategory.MONSTER == entityCategory_1) 29 | { 30 | if (Feature.END_CITY.isInsideStructure(this.world, blockPos_1)) 31 | { 32 | return Feature.END_CITY.getMonsterSpawns(); 33 | } 34 | } 35 | return this.world.getBiome(blockPos_1).getEntitySpawnList(entityCategory_1); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ForceLoadCommand_forceLoadLimitMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.server.command.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 = "executeChange", constant = @Constant(longValue = 256L)) 13 | private static long forceloadLimit(long original) 14 | { 15 | return CarpetSettings.forceloadLimit; 16 | } 17 | 18 | @ModifyConstant(method = "executeChange", constant = @Constant(intValue = 256)) 19 | private static int forceloadLimitError(int original) 20 | { 21 | return CarpetSettings.forceloadLimit; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/FossilFeatureMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.Heightmap; 5 | import net.minecraft.world.IWorld; 6 | import net.minecraft.world.gen.feature.FossilFeature; 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(FossilFeature.class) 12 | public class FossilFeatureMixin 13 | { 14 | @Redirect(method = "generate", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I" 17 | )) 18 | private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3) 19 | { 20 | return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/GameRenderer_pausedShakeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.MinecraftClientInferface; 4 | import carpet.helpers.TickSpeed; 5 | import net.minecraft.client.MinecraftClient; 6 | import net.minecraft.client.render.Camera; 7 | import net.minecraft.client.render.GameRenderer; 8 | import net.minecraft.client.render.VisibleRegion; 9 | import net.minecraft.client.render.WorldRenderer; 10 | import org.spongepowered.asm.mixin.Final; 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.Redirect; 15 | 16 | @Mixin(GameRenderer.class) 17 | public class GameRenderer_pausedShakeMixin 18 | { 19 | @Shadow @Final private MinecraftClient client; 20 | 21 | @Redirect(method = "renderCenter", at = @At( 22 | value = "INVOKE", 23 | target = "Lnet/minecraft/client/render/WorldRenderer;renderEntities(Lnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/VisibleRegion;F)V" 24 | )) 25 | private void renderEntitiesNoShake(WorldRenderer worldRenderer, Camera camera_1, VisibleRegion visibleRegion_1, float float_1) 26 | { 27 | if (!TickSpeed.process_entities) 28 | { 29 | worldRenderer.renderEntities(camera_1, visibleRegion_1, ((MinecraftClientInferface)client).getPausedTickDelta()); 30 | } 31 | else 32 | { 33 | worldRenderer.renderEntities(camera_1, visibleRegion_1, float_1); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/GravityStructureProcessorMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.structure.processor.GravityStructureProcessor; 5 | import net.minecraft.world.CollisionView; 6 | import net.minecraft.world.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(GravityStructureProcessor.class) 12 | public class GravityStructureProcessorMixin 13 | { 14 | @Redirect(method = "process", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/CollisionView;getTop(Lnet/minecraft/world/Heightmap$Type;II)I" 17 | )) 18 | private int getTop(CollisionView world, Heightmap.Type type, int x, int z) 19 | { 20 | return world.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.WORLD_SURFACE:type, x, z); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/GuardianEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.EntityData; 5 | import net.minecraft.entity.EntityType; 6 | import net.minecraft.entity.LightningEntity; 7 | import net.minecraft.entity.SpawnType; 8 | import net.minecraft.entity.mob.ElderGuardianEntity; 9 | import net.minecraft.entity.mob.GuardianEntity; 10 | import net.minecraft.entity.mob.HostileEntity; 11 | import net.minecraft.nbt.CompoundTag; 12 | import net.minecraft.util.math.BlockPos; 13 | import net.minecraft.world.World; 14 | import org.spongepowered.asm.mixin.Mixin; 15 | 16 | @Mixin(GuardianEntity.class) 17 | public abstract class GuardianEntityMixin extends HostileEntity 18 | { 19 | protected GuardianEntityMixin(EntityType entityType_1, World world_1) 20 | { 21 | super(entityType_1, world_1); 22 | } 23 | 24 | @Override 25 | public void onStruckByLightning(LightningEntity lightning) 26 | { 27 | if (!this.world.isClient && !this.removed && CarpetSettings.renewableSponges) 28 | { 29 | ElderGuardianEntity elderGuardian = new ElderGuardianEntity(EntityType.ELDER_GUARDIAN ,this.world); 30 | elderGuardian.refreshPositionAndAngles(this.x, this.y, this.z, this.yaw, this.pitch); 31 | elderGuardian.initialize(this.world ,this.world.getLocalDifficulty(new BlockPos(elderGuardian)), SpawnType.CONVERSION, (EntityData)null, (CompoundTag)null); 32 | elderGuardian.setAiDisabled(this.isAiDisabled()); 33 | 34 | if (this.hasCustomName()) 35 | { 36 | elderGuardian.setCustomName(this.getCustomName()); 37 | elderGuardian.setCustomNameVisible(this.isCustomNameVisible()); 38 | } 39 | 40 | this.world.spawnEntity(elderGuardian); 41 | this.remove(); 42 | } 43 | else 44 | { 45 | super.onStruckByLightning(lightning); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/HopperBlockEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.HopperBlock; 5 | import net.minecraft.block.entity.BlockEntityType; 6 | import net.minecraft.block.entity.HopperBlockEntity; 7 | import net.minecraft.block.entity.LootableContainerBlockEntity; 8 | import net.minecraft.item.ItemStack; 9 | import net.minecraft.util.DyeColor; 10 | import net.minecraft.util.math.BlockPos; 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.CallbackInfoReturnable; 16 | import carpet.helpers.HopperCounter; 17 | import carpet.utils.WoolTool; 18 | 19 | @Mixin(HopperBlockEntity.class) 20 | public abstract class HopperBlockEntityMixin extends LootableContainerBlockEntity { 21 | 22 | protected HopperBlockEntityMixin(BlockEntityType blockEntityType_1) { 23 | super(blockEntityType_1); 24 | } 25 | 26 | @Shadow 27 | public abstract double getHopperX(); 28 | 29 | @Shadow 30 | public abstract double getHopperY(); 31 | 32 | @Shadow 33 | public abstract double getHopperZ(); 34 | 35 | @Shadow 36 | public abstract void setInvStack(int int_1, ItemStack itemStack_1); 37 | 38 | @Shadow 39 | public abstract int getInvSize(); 40 | 41 | @Inject(method = "insert", at = @At("HEAD"), cancellable = true) 42 | private void onInsert(CallbackInfoReturnable cir) 43 | { 44 | if (CarpetSettings.hopperCounters) { 45 | DyeColor wool_color = WoolTool.getWoolColorAtPosition( 46 | getWorld(), 47 | new BlockPos(getHopperX(), getHopperY(), getHopperZ()).offset(this.getCachedState().get(HopperBlock.FACING))); 48 | if (wool_color != null) 49 | { 50 | for (int i = 0; i < this.getInvSize(); ++i) 51 | { 52 | if (!this.getInvStack(i).isEmpty()) 53 | { 54 | ItemStack itemstack = this.getInvStack(i);//.copy(); 55 | HopperCounter.COUNTERS.get(wool_color).add(this.getWorld().getServer(), itemstack); 56 | this.setInvStack(i, ItemStack.EMPTY); 57 | } 58 | } 59 | cir.setReturnValue(true); 60 | } 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/HopperBlock_cactusMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.BlockRotator; 4 | import net.minecraft.block.HopperBlock; 5 | import net.minecraft.item.ItemPlacementContext; 6 | import net.minecraft.util.math.Direction; 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 = "getPlacementState", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/item/ItemPlacementContext;getSide()Lnet/minecraft/util/math/Direction;" 17 | )) 18 | private Direction getOppositeOpposite(ItemPlacementContext context) 19 | { 20 | if (BlockRotator.flippinEligibility(context.getPlayer())) 21 | { 22 | return context.getSide().getOpposite(); 23 | } 24 | return context.getSide(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/HuskEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.mob.HuskEntity; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.IWorld; 7 | import net.minecraft.world.gen.feature.Feature; 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(HuskEntity.class) 13 | public class HuskEntityMixin 14 | { 15 | @Redirect(method = "method_20677", at = @At(value = "INVOKE", target="Lnet/minecraft/world/IWorld;isSkyVisible(Lnet/minecraft/util/math/BlockPos;)Z")) 16 | private static boolean isSkylightOrTempleVisible(IWorld iWorld, BlockPos blockPos_1) 17 | { 18 | return iWorld.isSkyVisible(blockPos_1) || 19 | (CarpetSettings.huskSpawningInTemples && Feature.DESERT_PYRAMID.isApproximatelyInsideStructure(iWorld, blockPos_1)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/IglooGeneratorPieceMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.structure.IglooGenerator; 5 | import net.minecraft.world.Heightmap; 6 | import net.minecraft.world.IWorld; 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(IglooGenerator.Piece.class) 12 | public class IglooGeneratorPieceMixin 13 | { 14 | @Redirect(method = "generate", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I" 17 | )) 18 | private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3) 19 | { 20 | return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.WORLD_SURFACE:Heightmap.Type.WORLD_SURFACE_WG, var2, var3); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/InGameHudMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.PlayerListHudInterface; 4 | import net.minecraft.client.MinecraftClient; 5 | import net.minecraft.client.gui.hud.InGameHud; 6 | import net.minecraft.client.gui.hud.PlayerListHud; 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(InGameHud.class) 14 | public abstract class InGameHudMixin 15 | { 16 | @Shadow 17 | @Final 18 | private MinecraftClient client; 19 | 20 | @Shadow @Final private PlayerListHud playerListHud; 21 | 22 | @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;isInSingleplayer()Z")) 23 | private boolean onDraw(MinecraftClient minecraftClient) 24 | { 25 | return this.client.isInSingleplayer() && !((PlayerListHudInterface) playerListHud).hasFooterOrHeader(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/InfestedBlockMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.block.BlockState; 6 | import net.minecraft.block.Blocks; 7 | import net.minecraft.block.InfestedBlock; 8 | import net.minecraft.item.ItemStack; 9 | import net.minecraft.util.math.BlockPos; 10 | import net.minecraft.world.World; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 15 | 16 | @Mixin(InfestedBlock.class) 17 | public abstract class InfestedBlockMixin extends Block 18 | { 19 | public InfestedBlockMixin(Settings block$Settings_1) 20 | { 21 | super(block$Settings_1); 22 | } 23 | 24 | @Inject(method = "onStacksDropped", at = @At(value = "INVOKE", shift = At.Shift.AFTER, 25 | target = "Lnet/minecraft/entity/mob/SilverfishEntity;playSpawnEffects()V")) 26 | private void onOnStacksDropped(BlockState blockState_1, World world_1, BlockPos blockPos_1, 27 | ItemStack itemStack_1, CallbackInfo ci) 28 | { 29 | if (CarpetSettings.silverFishDropGravel) 30 | { 31 | dropStack(world_1, blockPos_1, new ItemStack(Blocks.GRAVEL)); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/IntegratedServerMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import com.google.gson.JsonElement; 5 | import net.minecraft.server.integrated.IntegratedServer; 6 | import net.minecraft.world.level.LevelGeneratorType; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 11 | 12 | @Mixin(IntegratedServer.class) 13 | public class IntegratedServerMixin 14 | { 15 | @Inject(method = "loadWorld", at = @At("HEAD")) 16 | private void onSetupServerIntegrated(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci) { 17 | CarpetServer.onServerLoaded((IntegratedServer) (Object) this); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ItemDispenserBehaviour_extremeBehavioursMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.block.dispenser.ItemDispenserBehavior; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(ItemDispenserBehavior.class) 12 | public class ItemDispenserBehaviour_extremeBehavioursMixin 13 | { 14 | @Redirect(method = "spawnItem", expect = 3, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private static double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ItemScatterer_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.util.ItemScatterer; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(ItemScatterer.class) 12 | public class ItemScatterer_extremeMixin 13 | { 14 | @Redirect(method = "spawn(Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V", expect = 3, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private static double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ItemUsageContext_cactusMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.BlockRotator; 4 | import net.minecraft.entity.player.PlayerEntity; 5 | import net.minecraft.item.ItemUsageContext; 6 | import net.minecraft.util.math.Direction; 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(ItemUsageContext.class) 12 | public class ItemUsageContext_cactusMixin 13 | { 14 | @Redirect(method = "getPlayerFacing", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/entity/player/PlayerEntity;getHorizontalFacing()Lnet/minecraft/util/math/Direction;" 17 | )) 18 | private Direction getPlayerFacing(PlayerEntity playerEntity) 19 | { 20 | Direction dir = playerEntity.getHorizontalFacing(); 21 | if (BlockRotator.flippinEligibility(playerEntity)) 22 | { 23 | dir = dir.getOpposite(); 24 | } 25 | return dir; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/KelpFeatureMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.world.gen.feature.KelpFeature; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(KelpFeature.class) 12 | public class KelpFeatureMixin 13 | { 14 | @Redirect(method = "generate", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I")) 15 | private int getRandom(Random random, int bound) 16 | { 17 | if (bound==10) 18 | return random.nextInt(bound); 19 | int limit = CarpetSettings.kelpGenerationGrowthLimit; 20 | if (limit == 0) 21 | return random.nextInt(bound); 22 | return 25-limit+random.nextInt(Math.min(23,limit+1)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LivingEntity_maxCollisionsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.Entity; 5 | import net.minecraft.entity.EntityType; 6 | import net.minecraft.entity.LivingEntity; 7 | import net.minecraft.entity.damage.DamageSource; 8 | import net.minecraft.predicate.entity.EntityPredicates; 9 | import net.minecraft.world.GameRules; 10 | import net.minecraft.world.World; 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 | import java.util.List; 18 | 19 | @Mixin(LivingEntity.class) 20 | public abstract class LivingEntity_maxCollisionsMixin extends Entity 21 | { 22 | 23 | public LivingEntity_maxCollisionsMixin(EntityType entityType_1, World world_1) 24 | { 25 | super(entityType_1, world_1); 26 | } 27 | 28 | @Shadow protected abstract void pushAway(Entity entity_1); 29 | 30 | @Inject(method = "tickCramming", cancellable = true, at = @At("HEAD")) 31 | private void tickPushingReplacement(CallbackInfo ci) 32 | { 33 | List list_1 = this.world.getEntities((Entity)this, this.getBoundingBox(), EntityPredicates.canBePushedBy(this)); 34 | if (!list_1.isEmpty()) { 35 | int int_1 = this.world.getGameRules().getInt(GameRules.MAX_ENTITY_CRAMMING); 36 | int int_2; 37 | if (int_1 > 0 && list_1.size() > int_1 - 1 && this.random.nextInt(4) == 0) { 38 | int_2 = 0; 39 | 40 | for(int int_3 = 0; int_3 < list_1.size(); ++int_3) { 41 | if (!((Entity)list_1.get(int_3)).hasVehicle()) { 42 | ++int_2; 43 | } 44 | } 45 | 46 | if (int_2 > int_1 - 1) { 47 | this.damage(DamageSource.CRAMMING, 6.0F); 48 | } 49 | } 50 | 51 | int limit = list_1.size(); 52 | if (CarpetSettings.maxEntityCollisions > 0) 53 | limit = Math.min(limit, CarpetSettings.maxEntityCollisions); 54 | 55 | for(int_2 = 0; int_2 < limit; ++int_2) { 56 | Entity entity_1 = (Entity)list_1.get(int_2); 57 | this.pushAway(entity_1); 58 | } 59 | } 60 | ci.cancel(); 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LivingEntity_scarpetEventsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.EntityInterface; 4 | import carpet.script.EntityEventsGroup; 5 | import net.minecraft.entity.Entity; 6 | import net.minecraft.entity.EntityType; 7 | import net.minecraft.entity.LivingEntity; 8 | import net.minecraft.entity.damage.DamageSource; 9 | import net.minecraft.world.World; 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(LivingEntity.class) 16 | public abstract class LivingEntity_scarpetEventsMixin extends Entity 17 | { 18 | 19 | public LivingEntity_scarpetEventsMixin(EntityType type, World world) 20 | { 21 | super(type, world); 22 | } 23 | 24 | @Inject(method = "onDeath", at = @At("HEAD")) 25 | private void onDeathCall(DamageSource damageSource_1, CallbackInfo ci) 26 | { 27 | ((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, this, damageSource_1.name); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/LlamaSpitEntity_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.projectile.LlamaSpitEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(LlamaSpitEntity.class) 12 | public class LlamaSpitEntity_extremeMixin 13 | { 14 | @Redirect(method = "setVelocity", expect = 3, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MinecraftClientMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import net.minecraft.client.MinecraftClient; 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(MinecraftClient.class) 11 | public class MinecraftClientMixin 12 | { 13 | //to inject right before 14 | // this.tickWorlds(booleanSupplier_1); 15 | @Inject(method = "init", at = @At(value = "RETURN") 16 | ) 17 | private void onInit(CallbackInfo ci) { 18 | //CM start game hook 19 | CarpetServer.onGameStarted(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MinecraftClient_pausedShakeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.MinecraftClientInferface; 4 | import net.minecraft.client.MinecraftClient; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | 8 | @Mixin(MinecraftClient.class) 9 | public class MinecraftClient_pausedShakeMixin implements MinecraftClientInferface 10 | { 11 | @Shadow private float pausedTickDelta; 12 | 13 | @Override 14 | public float getPausedTickDelta() 15 | { 16 | return pausedTickDelta; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MinecraftDedicatedServerMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import net.minecraft.server.dedicated.MinecraftDedicatedServer; 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(MinecraftDedicatedServer.class) 11 | public class MinecraftDedicatedServerMixin 12 | { 13 | //to inject right before 14 | // this.tickWorlds(booleanSupplier_1); 15 | @Inject(method = "setupServer", at = @At( 16 | value = "INVOKE", 17 | target = "Lnet/minecraft/server/dedicated/MinecraftDedicatedServer;loadWorld(Ljava/lang/String;Ljava/lang/String;JLnet/minecraft/world/level/LevelGeneratorType;Lcom/google/gson/JsonElement;)V", 18 | shift = At.Shift.BEFORE 19 | )) 20 | private void onSetupServer(CallbackInfoReturnable cir) { 21 | //CM start game hook 22 | CarpetServer.onGameStarted(); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MinecraftServer_coreMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import com.google.gson.JsonElement; 5 | import net.minecraft.server.MinecraftServer; 6 | import net.minecraft.world.level.LevelGeneratorType; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 11 | 12 | import java.util.function.BooleanSupplier; 13 | 14 | @Mixin(MinecraftServer.class) 15 | public abstract class MinecraftServer_coreMixin 16 | { 17 | //to inject right before 18 | // this.tickWorlds(booleanSupplier_1); 19 | @Inject( 20 | method = "tick", 21 | at = @At( 22 | value = "INVOKE", 23 | target = "Lnet/minecraft/server/MinecraftServer;tickWorlds(Ljava/util/function/BooleanSupplier;)V", 24 | shift = At.Shift.BEFORE, 25 | ordinal = 0 26 | ) 27 | ) 28 | private void onTick(BooleanSupplier booleanSupplier_1, CallbackInfo ci) { 29 | CarpetServer.tick((MinecraftServer) (Object) this); 30 | } 31 | 32 | // Dedicated server only 33 | @Inject(method = "loadWorld", at = @At("HEAD")) 34 | private void serverLoaded(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci) 35 | { 36 | CarpetServer.onServerLoaded((MinecraftServer) (Object) this); 37 | } 38 | 39 | @Inject(method = "shutdown", at = @At("HEAD")) 40 | private void serverClosed(CallbackInfo ci) 41 | { 42 | CarpetServer.onServerClosed((MinecraftServer) (Object) this); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MinecraftServer_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.MinecraftServerInterface; 4 | import net.minecraft.server.MinecraftServer; 5 | import net.minecraft.server.ServerTask; 6 | import net.minecraft.util.Util; 7 | import net.minecraft.util.thread.ReentrantThreadExecutor; 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.CallbackInfo; 13 | 14 | import java.util.function.BooleanSupplier; 15 | 16 | import static carpet.script.CarpetEventServer.Event.ENDER_TICK; 17 | import static carpet.script.CarpetEventServer.Event.NETHER_TICK; 18 | import static carpet.script.CarpetEventServer.Event.TICK; 19 | 20 | @Mixin(MinecraftServer.class) 21 | public abstract class MinecraftServer_scarpetMixin extends ReentrantThreadExecutor implements MinecraftServerInterface 22 | { 23 | public MinecraftServer_scarpetMixin(String string_1) 24 | { 25 | super(string_1); 26 | } 27 | 28 | @Shadow protected abstract void tick(BooleanSupplier booleanSupplier_1); 29 | 30 | @Shadow private long timeReference; 31 | 32 | @Shadow private long field_4557; 33 | 34 | @Override 35 | public void forceTick(BooleanSupplier isAhead) 36 | { 37 | timeReference = field_4557 = Util.getMeasuringTimeMs(); 38 | tick(isAhead); 39 | runTasks(); 40 | } 41 | 42 | @Inject(method = "tick", at = @At( 43 | value = "CONSTANT", 44 | args = "stringValue=tallying" 45 | )) 46 | public void tickTasks(BooleanSupplier booleanSupplier_1, CallbackInfo ci) 47 | { 48 | TICK.onTick(); 49 | NETHER_TICK.onTick(); 50 | ENDER_TICK.onTick(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MobEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.MobEntityInterface; 4 | import net.minecraft.entity.ai.goal.Goal; 5 | import net.minecraft.entity.ai.goal.GoalSelector; 6 | import net.minecraft.entity.mob.MobEntity; 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.HashMap; 12 | import java.util.Map; 13 | 14 | @Mixin(MobEntity.class) 15 | public abstract class MobEntityMixin implements MobEntityInterface 16 | { 17 | @Shadow @Final protected GoalSelector targetSelector; 18 | @Shadow @Final protected GoalSelector goalSelector; 19 | public final Map temporaryTasks = new HashMap<>(); 20 | 21 | @Override 22 | public GoalSelector getAI(boolean target) 23 | { 24 | return target?targetSelector:goalSelector; 25 | } 26 | 27 | @Override 28 | public Map getTemporaryTasks() 29 | { 30 | return temporaryTasks; 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MobEntity_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.mob.MobEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(MobEntity.class) 12 | public class MobEntity_extremeMixin 13 | { 14 | @Redirect(method = "initialize", expect = 1, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/MobEntity_leashMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.Entity; 5 | import net.minecraft.entity.mob.MobEntity; 6 | import net.minecraft.nbt.CompoundTag; 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(MobEntity.class) 14 | public abstract class MobEntity_leashMixin 15 | { 16 | @Shadow /*@Nullable*/ private Entity holdingEntity; 17 | 18 | @Shadow /*@Nullable*/ private CompoundTag leashTag; 19 | 20 | @Inject(method = "writeCustomDataToTag", at = @At("TAIL")) 21 | private void addLeashData(CompoundTag compoundTag_1, CallbackInfo ci) 22 | { 23 | if (holdingEntity == null && CarpetSettings.leadFix && leashTag != null) 24 | { 25 | compoundTag_1.put("Leash", leashTag); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/OceanRuinGeneratorPieceMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.structure.OceanRuinGenerator; 5 | import net.minecraft.world.Heightmap; 6 | import net.minecraft.world.IWorld; 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(OceanRuinGenerator.Piece.class) 12 | public class OceanRuinGeneratorPieceMixin 13 | { 14 | @Redirect(method = "generate", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I" 17 | )) 18 | private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3) 19 | { 20 | return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/OverworldChunkGeneratorMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.EntityCategory; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.IWorld; 7 | import net.minecraft.world.biome.Biome; 8 | import net.minecraft.world.biome.source.BiomeSource; 9 | import net.minecraft.world.gen.chunk.OverworldChunkGenerator; 10 | import net.minecraft.world.gen.chunk.OverworldChunkGeneratorConfig; 11 | import net.minecraft.world.gen.chunk.SurfaceChunkGenerator; 12 | import net.minecraft.world.gen.feature.Feature; 13 | import org.spongepowered.asm.mixin.Mixin; 14 | import org.spongepowered.asm.mixin.injection.At; 15 | import org.spongepowered.asm.mixin.injection.Inject; 16 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 17 | 18 | import java.util.List; 19 | 20 | @Mixin(OverworldChunkGenerator.class) 21 | public abstract class OverworldChunkGeneratorMixin extends SurfaceChunkGenerator 22 | { 23 | public OverworldChunkGeneratorMixin(IWorld iWorld_1, BiomeSource biomeSource_1, int int_1, int int_2, int int_3, OverworldChunkGeneratorConfig chunkGeneratorConfig_1, boolean boolean_1) 24 | { 25 | super(iWorld_1, biomeSource_1, int_1, int_2, int_3, chunkGeneratorConfig_1, boolean_1); 26 | } 27 | 28 | @Inject(method = "getEntitySpawnList", at = @At(value = "INVOKE", ordinal = 1, shift = At.Shift.BEFORE, 29 | target = "Lnet/minecraft/world/gen/feature/StructureFeature;isApproximatelyInsideStructure(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;)Z"), 30 | cancellable = true) 31 | private void onGetEntitySpawnList(EntityCategory entityCategory_1, BlockPos blockPos_1, 32 | CallbackInfoReturnable> cir) 33 | { 34 | if (CarpetSettings.huskSpawningInTemples) 35 | { 36 | if (Feature.DESERT_PYRAMID.isApproximatelyInsideStructure(this.world, blockPos_1)) 37 | { 38 | cir.setReturnValue(Feature.DESERT_PYRAMID.getMonsterSpawns()); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PickaxeItem_missingToolsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.BlockState; 5 | import net.minecraft.block.Material; 6 | import net.minecraft.item.PickaxeItem; 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(PickaxeItem.class) 12 | public class PickaxeItem_missingToolsMixin 13 | { 14 | @Redirect(method = "getMiningSpeed", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/block/BlockState;getMaterial()Lnet/minecraft/block/Material;" 17 | )) 18 | private Material getCustomMaterial(BlockState blockState) 19 | { 20 | Material material = blockState.getMaterial(); 21 | if (CarpetSettings.missingTools && (material == Material.PISTON || material == Material.GLASS)) 22 | material = Material.STONE; 23 | return material; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PistonBlockEntityRenderer_movableTEMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.fakes.BlockEntityRenderDispatcherInterface; 5 | import carpet.fakes.PistonBlockEntityInterface; 6 | import net.minecraft.block.entity.BlockEntity; 7 | import net.minecraft.block.entity.PistonBlockEntity; 8 | import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; 9 | import net.minecraft.client.render.block.entity.BlockEntityRenderer; 10 | import net.minecraft.client.render.block.entity.PistonBlockEntityRenderer; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 15 | 16 | @Mixin(PistonBlockEntityRenderer.class) 17 | public abstract class PistonBlockEntityRenderer_movableTEMixin extends BlockEntityRenderer 18 | { 19 | @Inject(method = "render", at = @At(value = "INVOKE", 20 | target = "Lnet/minecraft/client/render/block/entity/PistonBlockEntityRenderer;method_3575(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/client/render/BufferBuilder;Lnet/minecraft/world/World;Z)Z", ordinal = 3)) 21 | private void updateRenderBool(PistonBlockEntity pistonBlockEntity_1, double double_1, double double_2, 22 | double double_3, float float_1, int int_1, CallbackInfo ci) 23 | { 24 | if (!((PistonBlockEntityInterface) pistonBlockEntity_1).isRenderModeSet()) 25 | ((PistonBlockEntityInterface) pistonBlockEntity_1).setRenderCarriedBlockEntity(CarpetSettings.movableBlockEntities && ((PistonBlockEntityInterface) pistonBlockEntity_1).getCarriedBlockEntity() != null); 26 | } 27 | 28 | @Inject(method = "render", at = @At("RETURN")) 29 | private void endMethod3576(PistonBlockEntity pistonBlockEntity_1, double double_1, double double_2, double double_3, 30 | float float_1, int int_1, CallbackInfo ci) 31 | { 32 | if (((PistonBlockEntityInterface) pistonBlockEntity_1).getRenderCarriedBlockEntity()) 33 | { 34 | BlockEntity carriedBlockEntity = ((PistonBlockEntityInterface) pistonBlockEntity_1).getCarriedBlockEntity(); 35 | if (carriedBlockEntity != null) 36 | { 37 | carriedBlockEntity.setPos(pistonBlockEntity_1.getPos()); 38 | ((BlockEntityRenderDispatcherInterface) BlockEntityRenderDispatcher.INSTANCE).renderBlockEntityOffset(carriedBlockEntity, float_1, int_1, pistonBlockEntity_1.getRenderOffsetX(float_1), pistonBlockEntity_1.getRenderOffsetY(float_1), pistonBlockEntity_1.getRenderOffsetZ(float_1)); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PistonBlock_qcMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.PistonBlock; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.util.math.Direction; 7 | import net.minecraft.world.World; 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(PistonBlock.class) 14 | public class PistonBlock_qcMixin 15 | { 16 | @Inject(method = "shouldExtend", cancellable = true, at = @At( 17 | value = "INVOKE", 18 | target = "Lnet/minecraft/util/math/BlockPos;up()Lnet/minecraft/util/math/BlockPos;" 19 | )) 20 | private void cancelUpCheck(World world_1, BlockPos blockPos_1, Direction direction_1, CallbackInfoReturnable cir) 21 | { 22 | if (!CarpetSettings.quasiConnectivity) 23 | { 24 | cir.setReturnValue(false); 25 | cir.cancel(); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PistonBlock_rotatorBlockMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.PistonBlockInterface; 4 | import net.minecraft.block.PistonBlock; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.util.math.Direction; 7 | import net.minecraft.world.World; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.Shadow; 10 | 11 | @Mixin(PistonBlock.class) 12 | public abstract class PistonBlock_rotatorBlockMixin implements PistonBlockInterface 13 | { 14 | @Shadow protected abstract boolean shouldExtend(World world_1, BlockPos blockPos_1, Direction direction_1); 15 | 16 | @Override 17 | public boolean publicShouldExtend(World world_1, BlockPos blockPos_1, Direction direction_1) 18 | { 19 | return shouldExtend(world_1, blockPos_1,direction_1); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PistonHandler_pushLimitMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.piston.PistonHandler; 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 = PistonHandler.class, priority = 69420) // piston push limit is important for carpet 10 | public class PistonHandler_pushLimitMixin 11 | { 12 | @ModifyConstant(method = "tryMove", constant = @Constant(intValue = 12), expect = 3) 13 | private int pushLimit(int original) 14 | { 15 | return CarpetSettings.pushLimit; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PlayerActionC2SPacketMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.util.math.Direction; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.gen.Accessor; 8 | 9 | @Mixin(PlayerActionC2SPacket.class) 10 | public interface PlayerActionC2SPacketMixin 11 | { 12 | @Accessor("pos") 13 | void setPos(BlockPos pos); 14 | 15 | @Accessor("direction") 16 | void setDirection(Direction direction); 17 | 18 | @Accessor("action") 19 | void setAction(PlayerActionC2SPacket.Action action); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PlayerEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.helpers.PortalHelper; 5 | import net.minecraft.entity.player.PlayerEntity; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.Constant; 8 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 9 | 10 | @Mixin(PlayerEntity.class) 11 | public abstract class PlayerEntityMixin 12 | { 13 | @ModifyConstant(method = "getMaxNetherPortalTime", 14 | constant = @Constant(intValue = 1)) 15 | private int addFillUpdatesInt(int original) { 16 | if (CarpetSettings.portalCreativeDelay) 17 | if (PortalHelper.player_holds_obsidian((PlayerEntity) (Object)this)) 18 | return 72000; 19 | else 20 | return 80; 21 | return original; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PlayerEntity_horseFixMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.Entity; 5 | import net.minecraft.entity.EntityType; 6 | import net.minecraft.entity.mob.MobEntity; 7 | import net.minecraft.entity.player.PlayerEntity; 8 | import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket; 9 | import net.minecraft.network.packet.s2c.play.VehicleMoveS2CPacket; 10 | import net.minecraft.server.network.ServerPlayerEntity; 11 | import net.minecraft.server.world.ServerWorld; 12 | import net.minecraft.util.ActionResult; 13 | import net.minecraft.util.Hand; 14 | import net.minecraft.world.World; 15 | import org.spongepowered.asm.mixin.Mixin; 16 | import org.spongepowered.asm.mixin.Shadow; 17 | import org.spongepowered.asm.mixin.injection.At; 18 | import org.spongepowered.asm.mixin.injection.Inject; 19 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 20 | 21 | @Mixin(PlayerEntity.class) 22 | public abstract class PlayerEntity_horseFixMixin extends Entity 23 | { 24 | 25 | @Shadow public abstract ActionResult interact(Entity entity_1, Hand hand_1); 26 | 27 | public PlayerEntity_horseFixMixin(EntityType entityType_1, World world_1) 28 | { 29 | super(entityType_1, world_1); 30 | } 31 | 32 | @Inject(method = "stopRiding", at = @At("HEAD")) 33 | private void resetNavigation(CallbackInfo ci) 34 | { 35 | if (this.getVehicle() != null && CarpetSettings.horseWanderingFix) 36 | { 37 | if (getVehicle() instanceof MobEntity) 38 | ((MobEntity) getVehicle()).getNavigation().stop(); 39 | if (!getEntityWorld().isClient) 40 | { 41 | ((ServerWorld) getEntityWorld()).getChunkManager().sendToNearbyPlayers(this, new EntityPositionS2CPacket(getVehicle())); 42 | // not sure if player at this point is actually considered to be next to the exiting vehicle 43 | ((ServerPlayerEntity)(Object)this).networkHandler.sendPacket(new EntityPositionS2CPacket(getVehicle())); 44 | ((ServerPlayerEntity)(Object)this).networkHandler.sendPacket(new VehicleMoveS2CPacket(getVehicle())); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PlayerListHeaderS2CPacketMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.network.packet.s2c.play.PlayerListHeaderS2CPacket; 4 | import net.minecraft.text.Text; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.gen.Accessor; 7 | 8 | @Mixin(PlayerListHeaderS2CPacket.class) 9 | public interface PlayerListHeaderS2CPacketMixin 10 | { 11 | @Accessor("header") 12 | void setHeader(Text header); 13 | 14 | @Accessor("footer") 15 | void setFooter(Text footer); 16 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PlayerListHudMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | import carpet.fakes.PlayerListHudInterface; 3 | import net.minecraft.client.gui.hud.PlayerListHud; 4 | import net.minecraft.text.Text; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | 8 | @Mixin(PlayerListHud.class) 9 | public abstract class PlayerListHudMixin implements PlayerListHudInterface 10 | { 11 | @Shadow private Text footer; 12 | 13 | @Shadow private Text header; 14 | 15 | public boolean hasFooterOrHeader() 16 | { 17 | return footer != null || header != null; 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PointOfInterest_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.world.poi.PointOfInterest; 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(PointOfInterest.class) 9 | public interface PointOfInterest_scarpetMixin 10 | { 11 | @Accessor("freeTickets") 12 | int getFreeTickets(); 13 | 14 | @Invoker 15 | boolean callReserveTicket(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PortalBlock_portalSuperCacheMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.portalsearcher.SuperCacheHandler; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.block.BlockState; 6 | import net.minecraft.block.NetherPortalBlock; 7 | import net.minecraft.util.math.BlockPos; 8 | import net.minecraft.world.World; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | 11 | @Mixin(NetherPortalBlock.class) 12 | public abstract class PortalBlock_portalSuperCacheMixin extends Block { 13 | 14 | public PortalBlock_portalSuperCacheMixin(Settings block$Settings_1) { 15 | super(block$Settings_1); 16 | } 17 | 18 | @Override 19 | public void onBlockAdded(BlockState blockState_1, World world_1, BlockPos blockPos_1, BlockState blockState_2, boolean boolean_1) { 20 | if (!world_1.isClient() && blockPos_1.getY() < world_1.getEffectiveHeight()) { 21 | (world_1.getDimension().isNether() ? SuperCacheHandler.getHandlerNether() : SuperCacheHandler.getHandlerOverworld()).addPortal(blockPos_1); 22 | } 23 | } 24 | 25 | @Override 26 | public void onBlockRemoved(BlockState blockState_1, World world_1, BlockPos blockPos_1, BlockState blockState_2, boolean boolean_1) { 27 | if (!world_1.isClient() && blockPos_1.getY() < world_1.getEffectiveHeight()) { 28 | (world_1.getDimension().isNether() ? SuperCacheHandler.getHandlerNether() : SuperCacheHandler.getHandlerOverworld()).removePortal(blockPos_1); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/PoweredRailBlock_powerLimitMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.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 = "isPoweredByOtherRails(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/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/ProjectileEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.logging.LoggerRegistry; 4 | import carpet.logging.logHelpers.TrajectoryLogHelper; 5 | import net.minecraft.entity.Entity; 6 | import net.minecraft.entity.EntityType; 7 | import net.minecraft.entity.projectile.ProjectileEntity; 8 | import net.minecraft.util.hit.HitResult; 9 | import net.minecraft.world.World; 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(ProjectileEntity.class) 16 | public abstract class ProjectileEntityMixin extends Entity 17 | { 18 | private TrajectoryLogHelper logHelper; 19 | public ProjectileEntityMixin(EntityType entityType_1, World world_1) { super(entityType_1, world_1); } 20 | 21 | @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN")) 22 | private void addLogger(EntityType entityType_1, World world_1, CallbackInfo ci) 23 | { 24 | if (LoggerRegistry.__projectiles && !world_1.isClient) 25 | logHelper = new TrajectoryLogHelper("projectiles"); 26 | } 27 | 28 | @Inject(method = "tick", at = @At("HEAD")) 29 | private void tickCheck(CallbackInfo ci) 30 | { 31 | if (LoggerRegistry.__projectiles && logHelper != null) 32 | logHelper.onTick(x, y, z, getVelocity()); 33 | } 34 | 35 | @Inject(method = "onHit(Lnet/minecraft/util/hit/HitResult;)V", at = @At("RETURN")) 36 | private void remove(HitResult hitResult_1, CallbackInfo ci) 37 | { 38 | if (LoggerRegistry.__projectiles && 39 | (hitResult_1.getType() == HitResult.Type.ENTITY || hitResult_1.getType() == HitResult.Type.BLOCK) 40 | && logHelper != null) 41 | { 42 | logHelper.onFinish(); 43 | logHelper = null; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ProjectileEntity_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.projectile.ProjectileEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(ProjectileEntity.class) 12 | public class ProjectileEntity_extremeMixin 13 | { 14 | @Redirect(method = "setVelocity", expect = 3, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | 23 | // calculates damage 24 | @Redirect(method = "method_7435", expect = 1, at = @At( 25 | value = "INVOKE", 26 | target = "Ljava/util/Random;nextGaussian()D" 27 | )) 28 | private double nextGauBian2(Random random) 29 | { 30 | return RandomTools.nextGauBian(random); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/RenderTickCounter_tickSpeedMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.TickSpeed; 4 | import carpet.CarpetSettings; 5 | import net.minecraft.client.render.RenderTickCounter; 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(RenderTickCounter.class) 11 | public class RenderTickCounter_tickSpeedMixin { 12 | @Redirect(method = "beginRenderTick", at = @At( 13 | value = "FIELD", 14 | target = "Lnet/minecraft/client/render/RenderTickCounter;tickTime:F" 15 | )) 16 | private float adjustTickSpeed(RenderTickCounter counter) { 17 | if (CarpetSettings.smoothClientAnimations && TickSpeed.process_entities) 18 | { 19 | return Math.max(50.0f, TickSpeed.mspt); 20 | } 21 | return 50f; 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/SaplingBlockMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import carpet.helpers.BlockSaplingHelper; 5 | import net.minecraft.block.BlockState; 6 | import net.minecraft.block.Blocks; 7 | import net.minecraft.block.SaplingBlock; 8 | import net.minecraft.util.math.BlockPos; 9 | import net.minecraft.world.IWorld; 10 | import net.minecraft.world.biome.Biomes; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Inject; 14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 15 | 16 | import java.util.Random; 17 | 18 | @Mixin(SaplingBlock.class) 19 | public abstract class SaplingBlockMixin 20 | { 21 | @Inject(method = "generate", at = @At(value = "INVOKE", shift = At.Shift.BEFORE, 22 | target = "Lnet/minecraft/block/sapling/SaplingGenerator;generate(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Ljava/util/Random;)Z"), 23 | cancellable = true) 24 | private void onGenerate(IWorld iWorld_1, BlockPos blockPos_1, BlockState blockState_1, Random random_1, CallbackInfo ci) 25 | { 26 | if(CarpetSettings.desertShrubs && iWorld_1.getBiome(blockPos_1) == Biomes.DESERT && !BlockSaplingHelper.hasWater(iWorld_1, blockPos_1)) 27 | { 28 | iWorld_1.setBlockState(blockPos_1, Blocks.DEAD_BUSH.getDefaultState(), 3); 29 | ci.cancel(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerChunkManager_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.server.world.ChunkTicketManager; 4 | import net.minecraft.server.world.ServerChunkManager; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.gen.Accessor; 7 | 8 | @Mixin(ServerChunkManager.class) 9 | public interface ServerChunkManager_scarpetMixin 10 | { 11 | @Accessor 12 | ChunkTicketManager getTicketManager(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerChunkManager_ticketLogHelperMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.ChunkTicketManagerInterface; 4 | import com.mojang.datafixers.DataFixer; 5 | import net.minecraft.server.WorldGenerationProgressListener; 6 | import net.minecraft.server.world.ChunkTicketManager; 7 | import net.minecraft.server.world.ServerChunkManager; 8 | import net.minecraft.server.world.ServerWorld; 9 | import net.minecraft.structure.StructureManager; 10 | import net.minecraft.world.PersistentStateManager; 11 | import net.minecraft.world.gen.chunk.ChunkGenerator; 12 | import org.spongepowered.asm.mixin.Final; 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 | import java.io.File; 20 | import java.util.concurrent.Executor; 21 | import java.util.function.Supplier; 22 | 23 | @Mixin(ServerChunkManager.class) 24 | public class ServerChunkManager_ticketLogHelperMixin { 25 | @Shadow @Final private ChunkTicketManager ticketManager; 26 | 27 | @Inject( 28 | method = "", 29 | at = @At(value = "RETURN") 30 | ) 31 | private void onConstructed(ServerWorld serverWorld, File file, DataFixer dataFixer, StructureManager structureManager, Executor workerExecutor, ChunkGenerator chunkGenerator, int i, WorldGenerationProgressListener worldGenerationProgressListener, Supplier supplier, CallbackInfo ci) 32 | { 33 | ((ChunkTicketManagerInterface)this.ticketManager).setServerWorld(serverWorld); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerLightProviderMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.server.world.ServerLightingProvider; 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(ServerLightingProvider.class) 11 | public class ServerLightProviderMixin { 12 | @Inject(method = "tick", at = @At("HEAD"), cancellable = true) 13 | private void cancelcall1(CallbackInfo ci) { 14 | if (!CarpetSettings.lightUpdates){ 15 | ci.cancel(); 16 | } 17 | } 18 | 19 | @Inject(method = "enqueue(IILjava/util/function/IntSupplier;Lnet/minecraft/server/world/ServerLightingProvider$class_3901;Ljava/lang/Runnable;)V", at = @At("HEAD"), cancellable = true) 20 | private void cancelcall2(CallbackInfo ci) { 21 | if (!CarpetSettings.lightUpdates){ 22 | ci.cancel(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerMetadata_motdMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.server.ServerMetadata; 5 | import net.minecraft.text.LiteralText; 6 | import net.minecraft.text.Text; 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(ServerMetadata.class) 13 | public class ServerMetadata_motdMixin 14 | { 15 | @Inject(method = "getDescription", at = @At("HEAD"), cancellable = true) 16 | private void getDescriptionAlternative(CallbackInfoReturnable cir) 17 | { 18 | if (!CarpetSettings.customMOTD.equals("_")) 19 | { 20 | cir.setReturnValue(new LiteralText(CarpetSettings.customMOTD)); 21 | cir.cancel(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerPlayNetworkHandler_coreMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetServer; 4 | import net.minecraft.network.ClientConnection; 5 | import net.minecraft.server.MinecraftServer; 6 | import net.minecraft.server.network.ServerPlayNetworkHandler; 7 | import net.minecraft.server.network.ServerPlayerEntity; 8 | import net.minecraft.text.Text; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Shadow; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 | 15 | @Mixin(ServerPlayNetworkHandler.class) 16 | public class ServerPlayNetworkHandler_coreMixin { 17 | @Shadow 18 | public ServerPlayerEntity player; 19 | 20 | @Inject(method = "", at = @At("RETURN")) 21 | private void onPlayerConnect(MinecraftServer server, ClientConnection client, ServerPlayerEntity player, CallbackInfo ci) { 22 | CarpetServer.onPlayerLoggedIn(player); 23 | } 24 | 25 | @Inject(method = "onDisconnected", at = @At("HEAD")) 26 | private void onPlayerDisconnect(Text reason, CallbackInfo ci) { 27 | CarpetServer.onPlayerLoggedOut(this.player); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerPlayNetworkHandler_tickMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.TickSpeed; 4 | import net.minecraft.network.packet.c2s.play.PlayerInputC2SPacket; 5 | import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; 6 | import net.minecraft.server.network.ServerPlayNetworkHandler; 7 | import net.minecraft.server.network.ServerPlayerEntity; 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.CallbackInfo; 13 | 14 | @Mixin(ServerPlayNetworkHandler.class) 15 | public class ServerPlayNetworkHandler_tickMixin 16 | { 17 | @Shadow public ServerPlayerEntity player; 18 | 19 | @Shadow private double lastTickX; 20 | 21 | @Shadow private double lastTickY; 22 | 23 | @Inject(method = "onPlayerInput", at = @At(value = "RETURN")) 24 | private void checkMoves(PlayerInputC2SPacket p, CallbackInfo ci) 25 | { 26 | if (p.getSideways() != 0.0F || p.getForward() != 0.0F || p.isJumping() || p.isSneaking()) 27 | { 28 | TickSpeed.reset_player_active_timeout(); 29 | } 30 | } 31 | 32 | @Inject(method = "onPlayerMove", at = @At( 33 | value = "INVOKE", 34 | target = "Lnet/minecraft/server/network/ServerPlayerEntity;isSleeping()Z", 35 | shift = At.Shift.BEFORE 36 | )) 37 | private void checkMove(PlayerMoveC2SPacket p, CallbackInfo ci) 38 | { 39 | if (Math.abs(p.getX(player.x) - lastTickX) > 0.0001D 40 | || Math.abs(p.getY(player.y) - lastTickY) > 0.0001D 41 | || Math.abs(p.getY(player.y) - lastTickY) > 0.0001D) 42 | { 43 | TickSpeed.reset_player_active_timeout(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerPlayerEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.ServerPlayerEntityInterface; 4 | import carpet.helpers.EntityPlayerActionPack; 5 | import com.mojang.authlib.GameProfile; 6 | import net.minecraft.server.MinecraftServer; 7 | import net.minecraft.server.network.ServerPlayerEntity; 8 | import net.minecraft.server.network.ServerPlayerInteractionManager; 9 | import net.minecraft.server.world.ServerWorld; 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(ServerPlayerEntity.class) 16 | public abstract class ServerPlayerEntityMixin implements ServerPlayerEntityInterface 17 | { 18 | public EntityPlayerActionPack actionPack; 19 | public EntityPlayerActionPack getActionPack() 20 | { 21 | return actionPack; 22 | } 23 | 24 | @Inject(method = "", at = @At(value = "RETURN")) 25 | private void onServerPlayerEntityContructor( 26 | MinecraftServer minecraftServer_1, 27 | ServerWorld serverWorld_1, 28 | GameProfile gameProfile_1, 29 | ServerPlayerInteractionManager serverPlayerInteractionManager_1, 30 | CallbackInfo ci) 31 | { 32 | this.actionPack = new EntityPlayerActionPack((ServerPlayerEntity) (Object) this); 33 | } 34 | 35 | @Inject(method = "tick", at = @At(value = "HEAD")) 36 | private void onTick(CallbackInfo ci) 37 | { 38 | actionPack.onUpdate(); 39 | } 40 | 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerPlayerEntity_scarpetEventMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import net.minecraft.entity.player.PlayerEntity; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraft.server.network.ServerPlayerEntity; 7 | import net.minecraft.stat.Stat; 8 | import net.minecraft.util.Hand; 9 | import net.minecraft.world.World; 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.Redirect; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 16 | 17 | import static carpet.script.CarpetEventServer.Event.PLAYER_FINISHED_USING_ITEM; 18 | import static carpet.script.CarpetEventServer.Event.STATISTICS; 19 | 20 | @Mixin(ServerPlayerEntity.class) 21 | public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity 22 | { 23 | public ServerPlayerEntity_scarpetEventMixin(World world_1, GameProfile gameProfile_1) 24 | { 25 | super(world_1, gameProfile_1); 26 | } 27 | 28 | @Shadow protected abstract void method_6040(); 29 | 30 | @Redirect(method = "method_6040", at = @At( 31 | value = "INVOKE", 32 | target = "Lnet/minecraft/entity/player/PlayerEntity;method_6040()V" 33 | )) 34 | private void finishedUsingItem(PlayerEntity playerEntity) 35 | { 36 | if (PLAYER_FINISHED_USING_ITEM.isNeeded()) 37 | { 38 | Hand hand = getActiveHand(); 39 | ItemStack stack = getActiveItem().copy(); 40 | // do vanilla 41 | super.method_6040(); 42 | PLAYER_FINISHED_USING_ITEM.onItemAction((ServerPlayerEntity) (Object)this, hand, stack); 43 | } 44 | else 45 | { 46 | // do vanilla 47 | super.method_6040(); 48 | } 49 | } 50 | 51 | @Inject(method = "increaseStat", at = @At("HEAD")) 52 | private void grabStat(Stat stat, int amount, CallbackInfo ci) 53 | { 54 | STATISTICS.onPlayerStatistic((ServerPlayerEntity) (Object)this, stat, amount); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerPlayerInteractionManager_cactusMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.helpers.BlockRotator; 4 | import net.minecraft.block.BlockState; 5 | import net.minecraft.entity.player.PlayerEntity; 6 | import net.minecraft.server.network.ServerPlayerInteractionManager; 7 | import net.minecraft.util.Hand; 8 | import net.minecraft.util.hit.BlockHitResult; 9 | import net.minecraft.world.World; 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(ServerPlayerInteractionManager.class) 15 | public class ServerPlayerInteractionManager_cactusMixin 16 | { 17 | 18 | @Redirect(method = "interactBlock", at = @At( 19 | value = "INVOKE", 20 | target = "Lnet/minecraft/block/BlockState;activate(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Z" 21 | )) 22 | private boolean activateWithOptionalCactus(BlockState blockState, World world_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1) 23 | { 24 | boolean flipped = BlockRotator.flipBlockWithCactus(blockState, world_1, playerEntity_1, hand_1, blockHitResult_1); 25 | if (flipped) 26 | return true; 27 | 28 | return blockState.activate(world_1, playerEntity_1, hand_1, blockHitResult_1); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerPlayerInteractionManager_scarpetEventsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.block.BlockState; 5 | import net.minecraft.block.entity.BlockEntity; 6 | import net.minecraft.entity.player.PlayerEntity; 7 | import net.minecraft.item.ItemStack; 8 | import net.minecraft.server.network.ServerPlayerEntity; 9 | import net.minecraft.server.network.ServerPlayerInteractionManager; 10 | import net.minecraft.util.ActionResult; 11 | import net.minecraft.util.Hand; 12 | import net.minecraft.util.hit.BlockHitResult; 13 | import net.minecraft.util.math.BlockPos; 14 | import net.minecraft.world.World; 15 | import org.spongepowered.asm.mixin.Mixin; 16 | import org.spongepowered.asm.mixin.Shadow; 17 | import org.spongepowered.asm.mixin.injection.At; 18 | import org.spongepowered.asm.mixin.injection.Inject; 19 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 20 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 21 | 22 | import static carpet.script.CarpetEventServer.Event.PLAYER_BREAK_BLOCK; 23 | import static carpet.script.CarpetEventServer.Event.PLAYER_INTERACTS_WITH_BLOCK; 24 | 25 | 26 | @Mixin(ServerPlayerInteractionManager.class) 27 | public class ServerPlayerInteractionManager_scarpetEventsMixin 28 | { 29 | @Shadow public ServerPlayerEntity player; 30 | 31 | @Inject(method = "tryBreakBlock", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At( 32 | value = "INVOKE", 33 | target = "Lnet/minecraft/block/Block;onBroken(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V", 34 | shift = At.Shift.BEFORE 35 | )) 36 | private void onBlockBroken(BlockPos blockPos_1, CallbackInfoReturnable cir, BlockState blockState_1, BlockEntity be, Block b, boolean boolean_1) 37 | { 38 | PLAYER_BREAK_BLOCK.onBlockBroken(player, blockPos_1, blockState_1); 39 | } 40 | 41 | @Inject(method = "interactBlock", at = @At( 42 | value = "RETURN", 43 | ordinal = 2 44 | )) 45 | private void onBlockActivated(PlayerEntity playerArg, World world, ItemStack stack, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable cir) 46 | { 47 | PLAYER_INTERACTS_WITH_BLOCK.onBlockHit(player, hand, blockHitResult); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerWorld_fakePlayersMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.patches.EntityPlayerMPFake; 4 | import net.minecraft.entity.Entity; 5 | import net.minecraft.server.MinecraftServer; 6 | import net.minecraft.server.ServerTask; 7 | import net.minecraft.server.network.ServerPlayerEntity; 8 | import net.minecraft.server.world.ServerWorld; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.Shadow; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Redirect; 13 | 14 | @Mixin(ServerWorld.class) 15 | public abstract class ServerWorld_fakePlayersMixin 16 | { 17 | @Shadow 18 | boolean ticking; 19 | 20 | @Shadow /*@Nonnull*/ public abstract MinecraftServer getServer(); 21 | 22 | @Redirect( method = "removePlayer", at = @At( 23 | value = "INVOKE", 24 | target = "Lnet/minecraft/server/world/ServerWorld;removeEntity(Lnet/minecraft/entity/Entity;)V" 25 | )) 26 | private void crashRemovePlayer(ServerWorld serverWorld, Entity entity_1, ServerPlayerEntity serverPlayerEntity_1) 27 | { 28 | if ( !(ticking && serverPlayerEntity_1 instanceof EntityPlayerMPFake) ) 29 | serverWorld.removeEntity(entity_1); 30 | else 31 | getServer().send(new ServerTask(getServer().getTicks(), () -> 32 | { 33 | serverWorld.removeEntity(serverPlayerEntity_1); 34 | serverPlayerEntity_1.onTeleportationDone(); 35 | })); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerWorld_onePlayerSleepingMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.server.network.ServerPlayerEntity; 5 | import net.minecraft.server.world.ServerWorld; 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.Redirect; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | import java.util.List; 15 | import java.util.function.Predicate; 16 | import java.util.stream.Stream; 17 | 18 | @Mixin(ServerWorld.class) 19 | public class ServerWorld_onePlayerSleepingMixin 20 | { 21 | @Shadow @Final private List players; 22 | 23 | @Shadow private boolean allPlayersSleeping; 24 | 25 | @Inject(method = "updatePlayersSleeping", cancellable = true, at = @At("HEAD")) 26 | private void updateOnePlayerSleeping(CallbackInfo ci) 27 | { 28 | if(CarpetSettings.onePlayerSleeping) 29 | { 30 | allPlayersSleeping = false; 31 | for (ServerPlayerEntity p : players) 32 | if (!p.isSpectator() && p.isSleeping()) 33 | { 34 | allPlayersSleeping = true; 35 | ci.cancel(); 36 | return; 37 | } 38 | ci.cancel(); 39 | } 40 | } 41 | 42 | @Redirect(method = "tick", at = @At( 43 | value = "INVOKE", 44 | target = "Ljava/util/stream/Stream;noneMatch(Ljava/util/function/Predicate;)Z" 45 | )) 46 | private boolean noneMatchSleep(Stream stream, Predicate predicate) 47 | { 48 | if (CarpetSettings.onePlayerSleeping) 49 | return stream.anyMatch((p) -> !p.isSpectator() && p.isSleepingLongEnough()); 50 | return stream.noneMatch(predicate); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ServerWorld_unloadedEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.entity.Entity; 5 | import net.minecraft.server.world.ServerWorld; 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(ServerWorld.class) 11 | public class ServerWorld_unloadedEntityMixin 12 | { 13 | @Redirect(method = "checkChunk", at = @At( 14 | value = "INVOKE", 15 | target = "Lnet/minecraft/entity/Entity;teleportRequested()Z" 16 | )) 17 | private boolean addFastEntityCheck(Entity entity) 18 | { 19 | return CarpetSettings.unloadedEntityFix || entity.teleportRequested(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/SetBlockCommandMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.server.command.SetBlockCommand; 6 | import net.minecraft.server.world.ServerWorld; 7 | import net.minecraft.util.math.BlockPos; 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(SetBlockCommand.class) 13 | public class SetBlockCommandMixin 14 | { 15 | @Redirect(method = "execute", at = @At( 16 | value = "INVOKE", 17 | target = "Lnet/minecraft/server/world/ServerWorld;updateNeighbors(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;)V" 18 | )) 19 | private static void conditionalUpdating(ServerWorld serverWorld, BlockPos blockPos_1, Block block_1) 20 | { 21 | if (CarpetSettings.fillUpdates) serverWorld.updateNeighbors(blockPos_1, block_1); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ShearsItem_missingToolsMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.BlockState; 5 | import net.minecraft.block.Material; 6 | import net.minecraft.item.ItemStack; 7 | import net.minecraft.item.ShearsItem; 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(ShearsItem.class) 14 | public class ShearsItem_missingToolsMixin 15 | { 16 | @Inject(method = "getMiningSpeed", at = @At("HEAD"), cancellable = true) 17 | private void getCustomMaterial(ItemStack itemStack_1, BlockState blockState_1, CallbackInfoReturnable cir) 18 | { 19 | if (CarpetSettings.missingTools && (blockState_1.getMaterial() == Material.SPONGE)) 20 | { 21 | cir.setReturnValue(15.0F); 22 | cir.cancel(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ShipwreckGeneratorPieceMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.structure.ShipwreckGenerator; 5 | import net.minecraft.world.Heightmap; 6 | import net.minecraft.world.IWorld; 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(ShipwreckGenerator.Piece.class) 14 | public class ShipwreckGeneratorPieceMixin 15 | { 16 | @Shadow @Final private boolean grounded; 17 | 18 | @Redirect(method = "generate", at = @At( 19 | value = "INVOKE", 20 | target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I" 21 | )) 22 | private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3) 23 | { 24 | if (grounded) 25 | return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.WORLD_SURFACE:Heightmap.Type.WORLD_SURFACE_WG, var2, var3); 26 | else 27 | return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/SkeletonHorseTrapTriggerGoal_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.ai.goal.SkeletonHorseTrapTriggerGoal; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(SkeletonHorseTrapTriggerGoal.class) 12 | public class SkeletonHorseTrapTriggerGoal_extremeMixin 13 | { 14 | @Redirect(method = "tick", expect = 2, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/StatType_scarpetMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.fakes.StatTypeInterface; 4 | import net.minecraft.stat.Stat; 5 | import net.minecraft.stat.StatType; 6 | import org.spongepowered.asm.mixin.Final; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | 10 | import java.util.Map; 11 | 12 | @Mixin(StatType.class) 13 | public class StatType_scarpetMixin implements StatTypeInterface 14 | { 15 | @Shadow @Final private Map> stats; 16 | 17 | @Override 18 | public boolean hasStatCreated(T key) 19 | { 20 | return this.stats.containsKey(key); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/StructureBlockBlockEntity_fillUpdatesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.entity.StructureBlockBlockEntity; 5 | import net.minecraft.structure.Structure; 6 | import net.minecraft.structure.StructurePlacementData; 7 | import net.minecraft.util.math.BlockPos; 8 | import net.minecraft.world.IWorld; 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(StructureBlockBlockEntity.class) 14 | public abstract class StructureBlockBlockEntity_fillUpdatesMixin 15 | { 16 | @Redirect(method = "loadStructure(Z)Z", at = @At( 17 | value = "INVOKE", 18 | target = "Lnet/minecraft/structure/Structure;place(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/structure/StructurePlacementData;)V" 19 | )) 20 | private void onStructurePlacen(Structure structure, IWorld iWorld_1, BlockPos blockPos_1, StructurePlacementData structurePlacementData_1) 21 | { 22 | if(!CarpetSettings.fillUpdates) 23 | CarpetSettings.impendingFillSkipUpdates = true; 24 | try 25 | { 26 | structure.place(iWorld_1, blockPos_1, structurePlacementData_1); 27 | } 28 | finally 29 | { 30 | CarpetSettings.impendingFillSkipUpdates = false; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/StructurePieceMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.structure.StructurePiece; 5 | import net.minecraft.world.CollisionView; 6 | import net.minecraft.world.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(StructurePiece.class) 12 | public class StructurePieceMixin 13 | { 14 | @Redirect(method = "isUnderSeaLevel", at = @At( 15 | value = "INVOKE", 16 | target = "Lnet/minecraft/world/CollisionView;getTop(Lnet/minecraft/world/Heightmap$Type;II)I" 17 | )) 18 | private int getTop(CollisionView world, Heightmap.Type var1, int var2, int var3) 19 | { 20 | return world.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/Structure_fillUpdatesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.structure.Structure; 6 | import net.minecraft.structure.StructurePlacementData; 7 | import net.minecraft.util.math.BlockPos; 8 | import net.minecraft.world.IWorld; 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(Structure.class) 14 | public class Structure_fillUpdatesMixin 15 | { 16 | @Redirect( method = "method_15172", at = @At( 17 | value = "INVOKE", 18 | target = "Lnet/minecraft/world/IWorld;updateNeighbors(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;)V" 19 | )) 20 | private void skipUpdateNeighbours(IWorld iWorld, BlockPos var1, Block var2) 21 | { 22 | if (!CarpetSettings.impendingFillSkipUpdates) 23 | iWorld.updateNeighbors(var1, var2); 24 | } 25 | 26 | @Redirect(method = "method_15172", at = @At( 27 | value = "INVOKE", 28 | target = "Lnet/minecraft/structure/StructurePlacementData;method_16444()Z" 29 | )) 30 | private boolean skipPostprocess(StructurePlacementData structurePlacementData) 31 | { 32 | return structurePlacementData.method_16444() || CarpetSettings.impendingFillSkipUpdates; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ThreadedAnvilChunkStorage_tickMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.CarpetProfiler; 4 | import net.minecraft.server.world.ServerWorld; 5 | import net.minecraft.server.world.ThreadedAnvilChunkStorage; 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.CallbackInfo; 12 | 13 | import java.util.function.BooleanSupplier; 14 | 15 | @Mixin(ThreadedAnvilChunkStorage.class) 16 | public class ThreadedAnvilChunkStorage_tickMixin 17 | { 18 | @Shadow @Final private ServerWorld world; 19 | CarpetProfiler.ProfilerToken currentSection; 20 | 21 | @Inject(method = "tick", at = @At("HEAD")) 22 | private void startProfilerSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci) 23 | { 24 | currentSection = CarpetProfiler.start_section(world, "Unloading", CarpetProfiler.TYPE.GENERAL); 25 | } 26 | 27 | @Inject(method = "tick", 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 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ThrownEnderpearlEntity_fakePlayersMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.patches.EntityPlayerMPFake; 4 | import net.minecraft.entity.EntityType; 5 | import net.minecraft.entity.thrown.ThrownEnderpearlEntity; 6 | import net.minecraft.entity.thrown.ThrownItemEntity; 7 | import net.minecraft.network.ClientConnection; 8 | import net.minecraft.world.World; 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(ThrownEnderpearlEntity.class) 14 | public abstract class ThrownEnderpearlEntity_fakePlayersMixin extends ThrownItemEntity 15 | { 16 | public ThrownEnderpearlEntity_fakePlayersMixin(EntityType entityType_1, World world_1) 17 | { 18 | super(entityType_1, world_1); 19 | } 20 | 21 | @Redirect(method = "onCollision", at = @At( 22 | value = "INVOKE", 23 | target = "Lnet/minecraft/network/ClientConnection;isOpen()Z" 24 | )) 25 | private boolean isConnectionGood(ClientConnection clientConnection) 26 | { 27 | return clientConnection.isOpen() || getOwner() instanceof EntityPlayerMPFake; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ThrownEntityMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.logging.LoggerRegistry; 4 | import carpet.logging.logHelpers.TrajectoryLogHelper; 5 | import net.minecraft.entity.Entity; 6 | import net.minecraft.entity.EntityType; 7 | import net.minecraft.entity.projectile.ProjectileEntity; 8 | import net.minecraft.entity.thrown.ThrownEntity; 9 | import net.minecraft.world.World; 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(ThrownEntity.class) 16 | public abstract class ThrownEntityMixin extends Entity 17 | { 18 | private TrajectoryLogHelper logHelper; 19 | public ThrownEntityMixin(EntityType entityType_1, World world_1) { super(entityType_1, world_1); } 20 | 21 | @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN")) 22 | private void addLogger(EntityType entityType_1, World world_1, CallbackInfo ci) 23 | { 24 | if (LoggerRegistry.__projectiles && !world_1.isClient) 25 | logHelper = new TrajectoryLogHelper("projectiles"); 26 | } 27 | 28 | @Inject(method = "tick", at = @At("HEAD")) 29 | private void tickCheck(CallbackInfo ci) 30 | { 31 | if (LoggerRegistry.__projectiles && logHelper != null) 32 | logHelper.onTick(x, y, z, getVelocity()); 33 | } 34 | 35 | @Override 36 | public void remove() 37 | { 38 | super.remove(); 39 | if (LoggerRegistry.__projectiles && logHelper != null) 40 | logHelper.onFinish(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/ThrownEntity_extremeMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.utils.RandomTools; 4 | import net.minecraft.entity.thrown.ThrownEntity; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.At; 7 | import org.spongepowered.asm.mixin.injection.Redirect; 8 | 9 | import java.util.Random; 10 | 11 | @Mixin(ThrownEntity.class) 12 | public class ThrownEntity_extremeMixin 13 | { 14 | @Redirect(method = "setVelocity", expect = 3, at = @At( 15 | value = "INVOKE", 16 | target = "Ljava/util/Random;nextGaussian()D" 17 | )) 18 | private double nextGauBian(Random random) 19 | { 20 | return RandomTools.nextGauBian(random); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/TntBlockMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.TntBlock; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.World; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Redirect; 10 | 11 | @Mixin(TntBlock.class) 12 | public abstract class TntBlockMixin 13 | { 14 | // Add carpet rule check for tntDoNotUpdate to an if statement. 15 | @Redirect(method = "onBlockAdded", at = @At(value = "INVOKE", 16 | target = "Lnet/minecraft/world/World;isReceivingRedstonePower(Lnet/minecraft/util/math/BlockPos;)Z")) 17 | private boolean isTNTDoNotUpdate(World world, BlockPos blockPos) 18 | { 19 | return !CarpetSettings.tntDoNotUpdate && world.isReceivingRedstonePower(blockPos); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/WeightedPickerEntryMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import net.minecraft.util.WeightedPicker; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | @Mixin(WeightedPicker.Entry.class) 8 | public interface WeightedPickerEntryMixin 9 | { 10 | @Accessor("weight") 11 | int getWeight(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/WorldChunk_fillUpdatesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.BlockState; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.World; 7 | import net.minecraft.world.chunk.WorldChunk; 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(WorldChunk.class) 13 | public class WorldChunk_fillUpdatesMixin 14 | { 15 | @Redirect(method = "setBlockState", at = @At( 16 | value = "INVOKE", 17 | target = "Lnet/minecraft/block/BlockState;onBlockAdded(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)V" 18 | )) 19 | private void onAdded(BlockState blockState, World world_1, BlockPos blockPos_1, BlockState blockState_1, boolean boolean_1) 20 | { 21 | if (!CarpetSettings.impendingFillSkipUpdates) 22 | blockState.onBlockAdded(world_1, blockPos_1, blockState_1, boolean_1); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/World_BlockEntityLogMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.logging.LoggerRegistry; 4 | import carpet.logging.logHelpers.BlockEntityLogHelper; 5 | import jdk.internal.jline.internal.Nullable; 6 | import net.minecraft.block.entity.BlockEntity; 7 | import net.minecraft.util.math.BlockPos; 8 | import net.minecraft.world.World; 9 | import net.minecraft.world.chunk.WorldChunk; 10 | import org.spongepowered.asm.mixin.Final; 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 | import java.util.List; 18 | import java.util.Map; 19 | 20 | @Mixin(World.class) 21 | public abstract class World_BlockEntityLogMixin { 22 | 23 | @Shadow public abstract long getTime(); 24 | @Shadow @Final public List blockEntities; 25 | 26 | @Shadow @Nullable 27 | public abstract BlockEntity getBlockEntity(BlockPos pos); 28 | 29 | @Inject(method = "setBlockEntity", at = @At("HEAD")) 30 | 31 | private void log(BlockPos pos, BlockEntity blockEntity, CallbackInfo ci){ 32 | if (LoggerRegistry.__blockentity) { 33 | BlockEntityLogHelper.onSetBlockEntity(pos, blockEntity, getTime()); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/World_fillUpdatesMixin.java: -------------------------------------------------------------------------------- 1 | package carpet.mixins; 2 | 3 | import carpet.CarpetSettings; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.World; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Constant; 10 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 11 | import org.spongepowered.asm.mixin.injection.Redirect; 12 | 13 | @Mixin(World.class) 14 | public abstract class World_fillUpdatesMixin 15 | { 16 | @ModifyConstant(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", 17 | constant = @Constant(intValue = 16)) 18 | private int addFillUpdatesInt(int original) { 19 | if (CarpetSettings.impendingFillSkipUpdates) 20 | return -1; 21 | return original; 22 | } 23 | 24 | @Redirect(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", at = @At( 25 | value = "INVOKE", 26 | target = "Lnet/minecraft/world/World;updateNeighbors(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;)V" 27 | )) 28 | private void updateNeighborsMaybe(World world, BlockPos blockPos, Block block) 29 | { 30 | if (!CarpetSettings.impendingFillSkipUpdates) world.updateNeighbors(blockPos, block); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/carpet/mixins/statsMixin.java: -------------------------------------------------------------------------------- 1 | //package carpet.mixins; 2 | // 3 | //import carpet.fakes.MobEntityInterface; 4 | //import net.fabricmc.api.ModInitializer; 5 | //import net.minecraft.block.Block; 6 | //import net.minecraft.block.Material; 7 | //import net.minecraft.stat.StatFormatter; 8 | //import net.minecraft.util.Identifier; 9 | //import net.minecraft.util.registry.Registry; 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(ModInitializer.class) 16 | //public class statsMixin implements ModInitializer { 17 | // 18 | // @Override 19 | // public void onInitialize() { 20 | // Registry.register(Registry.CUSTOM_STAT,"break",new Identifier( "break")); 21 | // } 22 | //} 23 | -------------------------------------------------------------------------------- /src/main/java/carpet/patches/NetHandlerPlayServerFake.java: -------------------------------------------------------------------------------- 1 | package carpet.patches; 2 | 3 | import net.minecraft.network.ClientConnection; 4 | import net.minecraft.network.Packet; 5 | import net.minecraft.server.MinecraftServer; 6 | import net.minecraft.server.network.ServerPlayNetworkHandler; 7 | import net.minecraft.server.network.ServerPlayerEntity; 8 | import net.minecraft.text.Text; 9 | 10 | public class NetHandlerPlayServerFake extends ServerPlayNetworkHandler 11 | { 12 | public NetHandlerPlayServerFake(MinecraftServer server, ClientConnection cc, ServerPlayerEntity playerIn) 13 | { 14 | super(server, cc, playerIn); 15 | } 16 | 17 | @Override 18 | public void sendPacket(final Packet packetIn) 19 | { 20 | } 21 | 22 | @Override 23 | public void disconnect(Text message) 24 | { 25 | } 26 | } 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/carpet/patches/NetworkManagerFake.java: -------------------------------------------------------------------------------- 1 | package carpet.patches; 2 | 3 | import net.minecraft.network.ClientConnection; 4 | import net.minecraft.network.NetworkSide; 5 | 6 | public class NetworkManagerFake extends ClientConnection 7 | { 8 | public NetworkManagerFake(NetworkSide p) 9 | { 10 | super(p); 11 | } 12 | 13 | @Override 14 | public void disableAutoRead() 15 | { 16 | } 17 | 18 | @Override 19 | public void handleDisconnection() 20 | { 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/carpet/script/CarpetContext.java: -------------------------------------------------------------------------------- 1 | package carpet.script; 2 | 3 | import carpet.script.value.Value; 4 | import net.minecraft.server.command.ServerCommandSource; 5 | import net.minecraft.util.math.BlockPos; 6 | 7 | public class CarpetContext extends Context 8 | { 9 | public ServerCommandSource s; 10 | public final BlockPos origin; 11 | public CarpetContext(ScriptHost host, ServerCommandSource source, BlockPos origin) 12 | { 13 | super(host); 14 | s = source; 15 | this.origin = origin; 16 | } 17 | 18 | @Override 19 | public Context duplicate() 20 | { 21 | return new CarpetContext(this.host, this.s, this.origin); 22 | } 23 | 24 | @Override 25 | protected void initialize() 26 | { 27 | super.initialize(); 28 | variables.put("_x", (c, t) -> Value.ZERO); 29 | variables.put("_y", (c, t) -> Value.ZERO); 30 | variables.put("_z", (c, t) -> Value.ZERO); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/Context.java: -------------------------------------------------------------------------------- 1 | package carpet.script; 2 | 3 | import carpet.script.value.Value; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | import java.util.Set; 8 | 9 | public class Context 10 | { 11 | public static final int NONE = 0; 12 | public static final int VOID = 1; 13 | public static final int BOOLEAN = 2; 14 | public static final int NUMBER = 3; 15 | public static final int STRING = 4; 16 | public static final int LIST = 5; 17 | public static final int ITERATOR = 6; 18 | public static final int SIGNATURE = 7; 19 | public static final int LOCALIZATION = 8; 20 | public static final int LVALUE = 9; 21 | 22 | public final Map variables = new HashMap<>(); 23 | 24 | public final ScriptHost host; 25 | 26 | Context(ScriptHost host) 27 | { 28 | this.host = host; 29 | } 30 | 31 | LazyValue getVariable(String name) 32 | { 33 | return variables.get(name); 34 | } 35 | 36 | public void setVariable(String name, LazyValue lv) 37 | { 38 | variables.put(name, lv); 39 | } 40 | 41 | void delVariable(String variable) 42 | { 43 | variables.remove(variable); 44 | } 45 | 46 | public void removeVariablesMatching(String varname) 47 | { 48 | variables.entrySet().removeIf(e -> e.getKey().startsWith(varname)); 49 | } 50 | 51 | public Context with(String variable, LazyValue lv) 52 | { 53 | variables.put(variable, lv); 54 | return this; 55 | } 56 | 57 | public Set getAllVariableNames() 58 | { 59 | return variables.keySet(); 60 | } 61 | 62 | public Context recreate() 63 | { 64 | Context ctx = duplicate(); 65 | ctx.initialize(); 66 | return ctx; 67 | } 68 | 69 | protected void initialize() 70 | { 71 | //special variables for second order functions so we don't need to check them all the time 72 | variables.put("_", (c, t) -> Value.ZERO); 73 | variables.put("_i", (c, t) -> Value.ZERO); 74 | variables.put("_a", (c, t) -> Value.ZERO); 75 | } 76 | 77 | public Context duplicate() 78 | { 79 | return new Context(this.host); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/LazyValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script; 2 | 3 | import carpet.script.value.Value; 4 | 5 | /** LazyNumber interface created for lazily evaluated functions */ 6 | @FunctionalInterface 7 | public interface LazyValue 8 | { 9 | LazyValue FALSE = (c, t) -> Value.FALSE; 10 | LazyValue TRUE = (c, t) -> Value.TRUE; 11 | LazyValue NULL = (c, t) -> Value.NULL; 12 | LazyValue ZERO = (c, t) -> Value.ZERO; 13 | /** 14 | * The Value representation of the left parenthesis, used for parsing 15 | * varying numbers of function parameters. 16 | */ 17 | LazyValue PARAMS_START = (c, t) -> null; 18 | 19 | Value evalValue(Context c, Integer type); 20 | 21 | default Value evalValue(Context c){ 22 | return evalValue(c, Context.NONE); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/bundled/BundledModule.java: -------------------------------------------------------------------------------- 1 | package carpet.script.bundled; 2 | 3 | import org.apache.commons.io.IOUtils; 4 | 5 | import java.io.IOException; 6 | import java.nio.charset.StandardCharsets; 7 | import java.util.Locale; 8 | 9 | public class BundledModule extends Module 10 | { 11 | private String name; 12 | private String code; 13 | private boolean library; 14 | public BundledModule(String scriptName, boolean isLibrary) 15 | { 16 | library = isLibrary; 17 | try 18 | { 19 | name = scriptName.toLowerCase(Locale.ROOT); 20 | code = IOUtils.toString( 21 | getClass().getClassLoader().getResourceAsStream("assets/carpet/scripts/"+name+(isLibrary?".scl":".sc")), 22 | StandardCharsets.UTF_8 23 | ); 24 | } 25 | catch ( NullPointerException | IOException e) 26 | { 27 | name = null; 28 | code = null; 29 | } 30 | } 31 | 32 | @Override 33 | public boolean isLibrary() { return library; } 34 | 35 | @Override 36 | public String getName() { return name; } 37 | 38 | @Override 39 | public String getCode() { return code; } 40 | } -------------------------------------------------------------------------------- /src/main/java/carpet/script/bundled/Module.java: -------------------------------------------------------------------------------- 1 | package carpet.script.bundled; 2 | 3 | import carpet.CarpetServer; 4 | import net.minecraft.nbt.Tag; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.nio.file.Files; 9 | 10 | import static carpet.script.bundled.FileModule.read; 11 | import static carpet.script.bundled.FileModule.write; 12 | 13 | public abstract class Module 14 | { 15 | public abstract String getName(); 16 | public abstract String getCode(); 17 | public abstract boolean isLibrary(); 18 | 19 | public Tag getData(String file) 20 | { 21 | File dataFile = CarpetServer.minecraft_server.getLevelStorage().resolveFile( 22 | CarpetServer.minecraft_server.getLevelName(), "scripts/"+getName()+".data"+(file==null?"":"."+file)+".nbt"); 23 | if (!Files.exists(dataFile.toPath()) || !(dataFile.isFile())) return null; 24 | return read(dataFile); 25 | } 26 | 27 | public void saveData(String file, Tag globalState) 28 | { 29 | File dataFile =CarpetServer.minecraft_server.getLevelStorage().resolveFile( 30 | CarpetServer.minecraft_server.getLevelName(), "scripts/"+getName()+".data"+(file==null?"":"."+file)+".nbt"); 31 | if (!Files.exists(dataFile.toPath().getParent())) 32 | { 33 | try 34 | { 35 | Files.createDirectory(dataFile.toPath().getParent()); 36 | } 37 | catch (IOException ignored) 38 | { 39 | } 40 | } 41 | write(globalState, dataFile); 42 | 43 | } 44 | 45 | @Override 46 | public int hashCode() 47 | { 48 | return getName().hashCode(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/BreakStatement.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.Value; 4 | 5 | public class BreakStatement extends ExitStatement 6 | { 7 | public BreakStatement(Value value) 8 | { 9 | super(value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/CarpetExpressionException.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.FunctionValue; 4 | import carpet.utils.Messenger; 5 | import net.minecraft.server.command.ServerCommandSource; 6 | 7 | import java.util.List; 8 | 9 | public class CarpetExpressionException extends RuntimeException implements ResolvedException 10 | { 11 | public final List stack; 12 | 13 | public CarpetExpressionException(String message, List stack) 14 | { 15 | super(message); 16 | this.stack = stack; 17 | } 18 | public void printStack(ServerCommandSource source) 19 | { 20 | if (stack != null && !stack.isEmpty()) 21 | { 22 | for (FunctionValue fun : stack) 23 | { 24 | Messenger.m(source, "e ... in "+fun.fullName(), "e /"+(fun.getToken().lineno+1)+":"+(fun.getToken().linepos+1)); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/ContinueStatement.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.Value; 4 | 5 | public class ContinueStatement extends ExitStatement 6 | { 7 | public ContinueStatement(Value value) 8 | { 9 | super(value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/ExitStatement.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.Value; 4 | 5 | /* Exception thrown to terminate execution mid expression (aka return statement) */ 6 | public class ExitStatement extends RuntimeException 7 | { 8 | public final Value retval; 9 | public ExitStatement(Value value) 10 | { 11 | retval = value; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/InternalExpressionException.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.FunctionValue; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /* The internal expression evaluators exception class. */ 9 | public class InternalExpressionException extends RuntimeException 10 | { 11 | public List stack = new ArrayList<>(); 12 | public InternalExpressionException(String message) 13 | { 14 | super(message); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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/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 | 8 | public ReturnStatement(Value value) 9 | { 10 | super(value); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/exception/ThrowStatement.java: -------------------------------------------------------------------------------- 1 | package carpet.script.exception; 2 | 3 | import carpet.script.value.Value; 4 | 5 | public class ThrowStatement extends ExitStatement 6 | { 7 | public ThrowStatement(Value value) 8 | { 9 | super(value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/AbstractListValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | import carpet.script.exception.InternalExpressionException; 4 | 5 | import java.util.Iterator; 6 | 7 | public abstract class AbstractListValue extends Value 8 | { 9 | public abstract Iterator iterator(); 10 | public void fatality() { } 11 | public void append(Value v) 12 | { 13 | throw new InternalExpressionException("Cannot append a value to an abstract list"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /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 | default boolean put(Value where, Value value, Value conditions) 7 | { 8 | return put(where, value); 9 | } 10 | Value get(Value where); 11 | boolean has(Value where); 12 | boolean delete(Value where); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/FrameworkValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | public abstract class FrameworkValue extends Value 4 | { 5 | @Override 6 | public String getString() 7 | { 8 | throw new UnsupportedOperationException("Scarpet language component cannot be used"); 9 | } 10 | 11 | @Override 12 | public boolean getBoolean() 13 | { 14 | throw new UnsupportedOperationException("Scarpet language component cannot be used"); 15 | } 16 | 17 | @Override 18 | public Value clone() 19 | { 20 | throw new UnsupportedOperationException("Scarpet language component cannot be used"); 21 | } 22 | 23 | @Override 24 | public int hashCode() 25 | { 26 | throw new UnsupportedOperationException("Scarpet language component cannot be used as map key"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /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 String identifier; 8 | private List arguments; 9 | private List globals; 10 | 11 | public FunctionSignatureValue(String name, List args, List globals) 12 | { 13 | this.identifier = name; 14 | this.arguments = args; 15 | this.globals = globals; 16 | } 17 | public String getName() 18 | { 19 | return identifier; 20 | } 21 | public List getArgs() 22 | { 23 | return arguments; 24 | } 25 | public List getGlobals() {return globals;} 26 | 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/GlobalValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | import carpet.script.exception.InternalExpressionException; 4 | 5 | public class GlobalValue extends Value 6 | { 7 | public GlobalValue(Value variable) 8 | { 9 | if (variable.boundVariable == null) 10 | throw new InternalExpressionException("You can only borrow variables from the outer scope"); 11 | this.boundVariable = variable.boundVariable; 12 | } 13 | 14 | @Override 15 | public String getString() 16 | { 17 | return boundVariable; 18 | } 19 | 20 | @Override 21 | public boolean getBoolean() 22 | { 23 | return false; 24 | } 25 | 26 | @Override 27 | public int hashCode() 28 | { 29 | throw new UnsupportedOperationException("Global value cannot be used as a map key"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/LContainerValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | public class LContainerValue extends FrameworkValue 4 | { 5 | private ContainerValueInterface container; 6 | private Value address; 7 | 8 | public LContainerValue(ContainerValueInterface c, Value v) 9 | { 10 | container = c; 11 | address = v; 12 | } 13 | 14 | public ContainerValueInterface getContainer() {return container; } 15 | public Value getAddress() {return address; } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/NullValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | public class NullValue extends NumericValue // TODO check nonsingleton code 4 | { 5 | @Override 6 | public String getString() 7 | { 8 | return "null"; 9 | } 10 | 11 | @Override 12 | public String getPrettyString() 13 | { 14 | return "null"; 15 | } 16 | 17 | @Override 18 | public boolean getBoolean() 19 | { 20 | return false; 21 | } 22 | 23 | @Override 24 | public Value clone() 25 | { 26 | return new NullValue(); 27 | } 28 | public NullValue() {super(0.0D);} 29 | 30 | @Override 31 | public boolean equals(final Object o) 32 | { 33 | return o instanceof NullValue; 34 | } 35 | 36 | @Override 37 | public int compareTo(Value o) 38 | { 39 | return o instanceof NullValue ? 0 : -1; 40 | } 41 | 42 | @Override 43 | public String getTypeString() 44 | { 45 | return "null"; 46 | } 47 | 48 | @Override 49 | public int hashCode() 50 | { 51 | return 0; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/carpet/script/value/StringValue.java: -------------------------------------------------------------------------------- 1 | package carpet.script.value; 2 | 3 | public class StringValue extends Value 4 | { 5 | private String str; 6 | 7 | @Override 8 | public String getString() { 9 | return str; 10 | } 11 | 12 | @Override 13 | public boolean getBoolean() { 14 | return str != null && !str.isEmpty(); 15 | } 16 | 17 | @Override 18 | public Value clone() 19 | { 20 | return new StringValue(str); 21 | } 22 | 23 | public StringValue(String str) 24 | { 25 | this.str = str; 26 | } 27 | 28 | @Override 29 | public String getTypeString() 30 | { 31 | return "string"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/carpet/settings/Rule.java: -------------------------------------------------------------------------------- 1 | package carpet.settings; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Any field in this class annotated with this class is interpreted as a carpet rule. 10 | * The field must be static and have a type of one of: 11 | * - boolean 12 | * - int 13 | * - double 14 | * - String 15 | * - a subclass of Enum 16 | * The default value of the rule will be the initial value of the field. 17 | */ 18 | @Target(ElementType.FIELD) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | public @interface Rule 21 | { 22 | /** 23 | * The rule name, by default the same as the field name 24 | */ 25 | String name() default ""; // default same as field name 26 | 27 | /** 28 | * A description of the rule 29 | */ 30 | String desc(); 31 | 32 | /** 33 | * Extra information about the rule 34 | */ 35 | String[] extra() default {}; 36 | 37 | /** 38 | * A list of categories the rule is in 39 | */ 40 | String[] category(); 41 | 42 | /** 43 | * Options to select in menu. 44 | * Inferred for booleans and enums. Otherwise, must be present. 45 | */ 46 | String[] options() default {}; 47 | 48 | /** 49 | * if a rule is not strict - can take any value, otherwise it needs to match 50 | * any of the options 51 | * For enums, its always strict, same for booleans - no need to set that for them. 52 | */ 53 | boolean strict() default true; 54 | 55 | /** 56 | * The class of the validator checked when the rule is changed. 57 | */ 58 | Class[] validate() default {}; 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/carpet/settings/RuleCategory.java: -------------------------------------------------------------------------------- 1 | package carpet.settings; 2 | 3 | public class RuleCategory 4 | { 5 | public static final String BUGFIX = "bugfix"; 6 | public static final String SURVIVAL = "survival"; 7 | public static final String CREATIVE = "creative"; 8 | public static final String EXPERIMENTAL = "experimental"; 9 | public static final String OPTIMIZATION = "optimization"; 10 | public static final String FEATURE = "feature"; 11 | public static final String COMMAND = "command"; 12 | public static final String TNT = "tnt"; 13 | public static final String DISPENSER = "dispenser"; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/carpet/utils/DistanceCalculator.java: -------------------------------------------------------------------------------- 1 | package carpet.utils; 2 | 3 | import net.minecraft.server.command.ServerCommandSource; 4 | import net.minecraft.util.math.MathHelper; 5 | import net.minecraft.util.math.Vec3d; 6 | import net.minecraft.text.BaseText; 7 | 8 | import java.util.ArrayList; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | 12 | public class DistanceCalculator 13 | { 14 | public static final HashMap START_POINT_STORAGE = new HashMap<>(); 15 | 16 | public static boolean hasStartingPoint(ServerCommandSource source) 17 | { 18 | return START_POINT_STORAGE.containsKey(source.getName()); 19 | } 20 | 21 | public static List findDistanceBetweenTwoPoints(Vec3d pos1, Vec3d pos2) 22 | { 23 | double dx = MathHelper.abs((float)pos1.x-(float)pos2.x); 24 | double dy = MathHelper.abs((float)pos1.y-(float)pos2.y); 25 | double dz = MathHelper.abs((float)pos1.z-(float)pos2.z); 26 | double manhattan = dx+dy+dz; 27 | double spherical = MathHelper.sqrt(dx*dx + dy*dy + dz*dz); 28 | double cylindrical = MathHelper.sqrt(dx*dx + dz*dz); 29 | List res = new ArrayList<>(); 30 | res.add(Messenger.c("w Distance between ", 31 | Messenger.tp("c",pos1),"w and ", 32 | Messenger.tp("c",pos2),"w :")); 33 | res.add(Messenger.c("w - Spherical: ", String.format("wb %.2f", spherical))); 34 | res.add(Messenger.c("w - Cylindrical: ", String.format("wb %.2f", cylindrical))); 35 | res.add(Messenger.c("w - Manhattan: ", String.format("wb %.1f", manhattan))); 36 | return res; 37 | } 38 | 39 | public static int distance(ServerCommandSource source, Vec3d pos1, Vec3d pos2) 40 | { 41 | Messenger.send(source, findDistanceBetweenTwoPoints(pos1, pos2)); 42 | return 1; 43 | } 44 | 45 | public static int setStart(ServerCommandSource source, Vec3d pos) 46 | { 47 | START_POINT_STORAGE.put(source.getName(), pos); 48 | Messenger.m(source,"gi Initial point set to: ", Messenger.tp("g",pos)); 49 | return 1; 50 | } 51 | 52 | public static int setEnd(ServerCommandSource source, Vec3d pos) 53 | { 54 | if ( !hasStartingPoint(source) ) 55 | { 56 | START_POINT_STORAGE.put(source.getName(), pos); 57 | Messenger.m(source,"gi There was no initial point for "+source.getName()); 58 | Messenger.m(source,"gi Initial point set to: ", Messenger.tp("g",pos)); 59 | return 0; 60 | } 61 | Messenger.send(source, findDistanceBetweenTwoPoints( START_POINT_STORAGE.get(source.getName()), pos)); 62 | return 1; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /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/RandomTools.java: -------------------------------------------------------------------------------- 1 | package carpet.utils; 2 | 3 | import carpet.CarpetSettings; 4 | 5 | import java.util.Random; 6 | 7 | public class RandomTools 8 | { 9 | public static double nextGauBian(Random random) 10 | { 11 | if (CarpetSettings.extremeBehaviours) 12 | { 13 | random.nextDouble(); 14 | return 16.0D * random.nextDouble() - 8.0D; 15 | } 16 | return random.nextGaussian(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/carpet/utils/portalsearcher/PortalSearchResult.java: -------------------------------------------------------------------------------- 1 | package carpet.utils.portalsearcher; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | 5 | public class PortalSearchResult { 6 | private final BlockPos result; 7 | private final double distance; 8 | private final long nanoTimeCost; 9 | 10 | public PortalSearchResult(BlockPos result, double distance, long nanoTimeCost) { 11 | this.result = result; 12 | this.distance = distance; 13 | this.nanoTimeCost = nanoTimeCost; 14 | } 15 | 16 | public double getDistanceSq() { 17 | return distance; 18 | } 19 | 20 | public BlockPos getResult() { 21 | return result; 22 | } 23 | 24 | public long getNanoTimeCost() { 25 | return nanoTimeCost; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return String.format("Found %s, sqrt(%f) far away within %d nano seconds.", getResult().toString(), getDistanceSq(), getNanoTimeCost()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/carpet/utils/portalsearcher/PortalSearcherAbstract.java: -------------------------------------------------------------------------------- 1 | package carpet.utils.portalsearcher; 2 | 3 | import net.minecraft.block.Blocks; 4 | import net.minecraft.block.EndPortalBlock; 5 | import net.minecraft.block.NetherPortalBlock; 6 | import net.minecraft.util.math.BlockPos; 7 | import net.minecraft.world.World; 8 | 9 | import java.util.Comparator; 10 | 11 | public abstract class PortalSearcherAbstract { 12 | protected final World worldIn; 13 | public static NetherPortalBlock BLOCK_NETHER_PORTAL = (NetherPortalBlock) Blocks.NETHER_PORTAL; 14 | protected static final Comparator vallinaComparator = 15 | Comparator.comparing(BlockPos::getX).thenComparing(BlockPos::getZ).thenComparing(p -> -p.getY()); 16 | 17 | public PortalSearcherAbstract(World worldIn) { 18 | this.worldIn = worldIn; 19 | } 20 | 21 | public abstract PortalSearchResult search(BlockPos searchCenter); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/resources/assets/carpet/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HIT-Craft/HIT-Carpet/ed93cfbcb247e0eb993ff2fc5848e899a8c4d8c6/src/main/resources/assets/carpet/icon.png -------------------------------------------------------------------------------- /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 | _vec_length(vec) -> sqrt(reduce(vec, _a + _*_, 0)); -------------------------------------------------------------------------------- /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/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "carpet", 4 | "version": "1.0.4", 5 | 6 | "name": "HIT Carpet", 7 | "description": "Better carpet made out of fabric 1.14.4", 8 | "authors": [ 9 | "gnembon, ten_miles_away..." 10 | ], 11 | "contact": { 12 | "homepage": "https://github.com/ten-miles-away/HIT-Carpet", 13 | "sources": "https://github.com/ten-miles-away/HIT-Carpet" 14 | }, 15 | 16 | "license": "GNU LGPL V3", 17 | "icon": "assets/carpet/icon.png", 18 | 19 | "environment": "*", 20 | "entrypoints": { 21 | "main": [ 22 | ] 23 | }, 24 | "mixins": [ 25 | "carpet.mixins.json" 26 | ], 27 | 28 | "depends": { 29 | "minecraft": "1.14.x", 30 | "fabricloader": ">=0.7.1" 31 | }, 32 | "suggests": { 33 | "flamingo": "*" 34 | } 35 | } 36 | --------------------------------------------------------------------------------