diff --git a/gradle.properties b/gradle.properties index 49085f0..9860961 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ # Mod Properties mod_id=joacarpet mod_name=JoaCarpet - mod_version=2.2.1 + mod_version=2.3 maven_group=me.fallenbreath archives_base_name=joacarpet diff --git a/src/main/java/com/joacarpet/JoaCarpetSettings.java b/src/main/java/com/joacarpet/JoaCarpetSettings.java index 160fdd6..29dc438 100644 --- a/src/main/java/com/joacarpet/JoaCarpetSettings.java +++ b/src/main/java/com/joacarpet/JoaCarpetSettings.java @@ -67,6 +67,17 @@ public class JoaCarpetSettings { ) public static String insaneBehaviorsSkipVisitedPoints = "false"; + @Rule( + //#if MC >= 11900 + categories = {CREATIVE, JOA}, + //#else +//$$ category = {CREATIVE, JOA}, +//$$ desc="Makes testing cart yeeting possible by disabling one of the two types of item drops (vehicle item and container items), to make the different iterators not interfere with each other.", + //#endif + options = {"none", "disableVehicleItem", "disableContainerContents"} + ) + public static String insaneBehaviorsCartYeetingException = "none"; + @Rule( //#if MC >= 11900 categories = {COMMAND, CREATIVE, JOA}, diff --git a/src/main/java/com/joacarpet/mixin/insaneBehaviors/ContainersMixin.java b/src/main/java/com/joacarpet/mixin/insaneBehaviors/ContainersMixin.java index b621c25..a534cff 100644 --- a/src/main/java/com/joacarpet/mixin/insaneBehaviors/ContainersMixin.java +++ b/src/main/java/com/joacarpet/mixin/insaneBehaviors/ContainersMixin.java @@ -20,41 +20,66 @@ package com.joacarpet.mixin.insaneBehaviors; +import com.joacarpet.JoaCarpetSettings; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.world.Containers; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import java.util.ArrayList; + +import static com.joacarpet.InsaneBehaviors.mapUnitVelocityToVec3; +import static com.joacarpet.InsaneBehaviors.nextEvenlyDistributedPoint; @Mixin(Containers.class) public class ContainersMixin { -// @Redirect(method = "dropItemStack", at = @At( -// value = "INVOKE", -// target = "Lnet/minecraft/world/entity/item/ItemEntity;setDeltaMovement(DDD)V" -// )) -// private static void setDeltaMovement(ItemEntity itemEntity, double d, double e, double f) { -// if (JoaCarpetSettings.insaneBehaviors.equals("off")) { -// itemEntity.setDeltaMovement(d+1, e, f); -// return; -// } -// // Vec3 unitVelocity = nextEvenlyDistributedPoint(); -// // Vec3 velocity = switch (JoaCarpetSettings.insaneBehaviors) { -// // // net.minecraft.core.dispenser.DefaultDispenseItemBehavior.spawnItem, Line 7 -// // case "sensible" -> mapUnitVelocityToVec3( -// // unitVelocity, -// // 1, -// // 0.3 * (double) direction.getStepX(), 0.0172275 * (double) i, -// // 0.2, 0.0172275 * (double) i, -// // 0.3 * (double) direction.getStepZ(), 0.0172275 * (double) i -// // ); -// // // spawnItem from pre-1.19 -// // case "extreme" -> mapUnitVelocityToVec3( -// // unitVelocity, -// // 8, -// // 0.3 * (double) direction.getStepX(), 0.0075 * (double) i, -// // 0.2, 0.0075 * (double) i, -// // 0.3 * (double) direction.getStepZ(), 0.0075 * (double) i -// // ); -// // default -> throw new IllegalStateException("Unexpected value: " + JoaCarpetSettings.insaneBehaviors); -// // }; -// // itemEntity.setDeltaMovement(velocity); -// } + @WrapOperation(method = "dropItemStack", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/item/ItemEntity;setDeltaMovement(DDD)V" + )) + private static void setDeltaMovement(ItemEntity itemEntity, double d, double e, double f, Operation original, Level level, double originX, double originY, double originZ, ItemStack itemStack) { + if (JoaCarpetSettings.insaneBehaviors.equals("off") || JoaCarpetSettings.insaneBehaviorsCartYeetingException.equals("disableContainerContents")) { + original.call(itemEntity, d, e, f); + return; + } + ArrayList unitVelocity = nextEvenlyDistributedPoint(6); + + double g = EntityType.ITEM.getWidth(); + double h = 1.0 - g; + double i = g / 2.0; + double j = Math.floor(originX) + unitVelocity.get(3) * h + i; + double k = Math.floor(originY) + unitVelocity.get(4) * h; + double l = Math.floor(originZ) + unitVelocity.get(5) * h + i; + + + itemEntity.setPos(j, k, l); + + Vec3 velocity = switch (JoaCarpetSettings.insaneBehaviors) { + // net.minecraft.world.Containers.dropItemStack, Line 11 + case "sensible" -> mapUnitVelocityToVec3( + new ArrayList<>(unitVelocity.subList(0, 2)), + 1, + 0.0, 0.11485000171139836, + 0.2, 0.11485000171139836, + 0.0, 0.11485000171139836 + ); // e.g. [-0.11485000171139836, 0.31485000171139836, 0.0] + // net.minecraft.world.Containers.dropItemStack from pre-1.19 + case "extreme" -> mapUnitVelocityToVec3( + new ArrayList<>(unitVelocity.subList(0, 3)), + 8, + 0.0, 0.05f, + 0.2, 0.05f, + 0.0, 0.05f + ); // e.g. [-0.4, 0.6, 0.0] + default -> throw new IllegalStateException("Unexpected insaneBehaviors value: " + JoaCarpetSettings.insaneBehaviors); + }; + original.call(itemEntity, velocity.x, velocity.y, velocity.z); + } } diff --git a/src/main/java/com/joacarpet/mixin/insaneBehaviors/DefaultDispenseItemBehaviorMixin.java b/src/main/java/com/joacarpet/mixin/insaneBehaviors/DefaultDispenseItemBehaviorMixin.java index 98079e4..3f99dd9 100644 --- a/src/main/java/com/joacarpet/mixin/insaneBehaviors/DefaultDispenseItemBehaviorMixin.java +++ b/src/main/java/com/joacarpet/mixin/insaneBehaviors/DefaultDispenseItemBehaviorMixin.java @@ -72,7 +72,7 @@ private static void setDeltaMovement( 0.2, 0.0075 * (double) i, 0.3 * (double) direction.getStepZ(), 0.0075 * (double) i ); - default -> throw new IllegalStateException("Unexpected value: " + JoaCarpetSettings.insaneBehaviors); + default -> throw new IllegalStateException("Unexpected insaneBehaviors value: " + JoaCarpetSettings.insaneBehaviors); }; original.call(itemEntity, velocity.x, velocity.y, velocity.z); } diff --git a/src/main/java/com/joacarpet/mixin/insaneBehaviors/ProjectileMixin.java b/src/main/java/com/joacarpet/mixin/insaneBehaviors/ProjectileMixin.java index ef38ed5..857c30d 100644 --- a/src/main/java/com/joacarpet/mixin/insaneBehaviors/ProjectileMixin.java +++ b/src/main/java/com/joacarpet/mixin/insaneBehaviors/ProjectileMixin.java @@ -70,7 +70,7 @@ private Vec3 add(Vec3 vec3, double d, double e, double f, Operation origin 0.0, (double)0.0075F * (double)divergence, 0.0, (double)0.0075F * (double)divergence ); - default -> throw new IllegalStateException("Unexpected value: " + JoaCarpetSettings.insaneBehaviors); + default -> throw new IllegalStateException("Unexpected insaneBehaviors value: " + JoaCarpetSettings.insaneBehaviors); }; return original.call(vec3, vec3.x + velocity.x, vec3.y + velocity.y, vec3.z + velocity.z); } diff --git a/src/main/java/com/joacarpet/mixin/insaneBehaviors/VehicleEntityOrAbstractMinecartMixin.java b/src/main/java/com/joacarpet/mixin/insaneBehaviors/VehicleEntityOrAbstractMinecartMixin.java new file mode 100644 index 0000000..d979ef1 --- /dev/null +++ b/src/main/java/com/joacarpet/mixin/insaneBehaviors/VehicleEntityOrAbstractMinecartMixin.java @@ -0,0 +1,91 @@ +/* + * This file is part of the JoaCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Joa and contributors + * + * JoaCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * JoaCarpet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JoaCarpet. If not, see . + */ + +package com.joacarpet.mixin.insaneBehaviors; + +import com.joacarpet.InsaneBehaviors; +import com.joacarpet.JoaCarpetSettings; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +//#if MC >= 12100 +import net.minecraft.world.entity.vehicle.VehicleEntity; +//#else +//$$ import net.minecraft.world.entity.vehicle.AbstractMinecart; +//#endif +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; +import org.spongepowered.asm.mixin.injection.At; + +import java.util.ArrayList; + +//#if MC >= 12100 + +@Mixin(VehicleEntity.class) +public class VehicleEntityOrAbstractMinecartMixin { + @WrapOperation( + method = "destroy(Lnet/minecraft/world/item/Item;)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/vehicle/VehicleEntity;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" + ) + ) + +//#else +//$$ @Mixin(AbstractMinecart.class) +//$$ public class VehicleEntityOrAbstractMinecartMixin { +//$$ @WrapOperation( +//$$ method = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", +//$$ at = @At( +//$$ value = "INVOKE", +//$$ target = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" +//$$ ) +//$$ ) +//#endif + private ItemEntity spawnAtLocation( + //#if MC >= 12100 + VehicleEntity + //#else +//$$ AbstractMinecart + //#endif + instance, ItemStack itemStack, Operation original) { + if (JoaCarpetSettings.insaneBehaviors.equals("off") || JoaCarpetSettings.insaneBehaviorsCartYeetingException.equals("disableVehicleItem")) { + return original.call(instance, itemStack); + } + ArrayList unitValueList = InsaneBehaviors.nextEvenlyDistributedPoint(2); + Vec3 velocity = new Vec3( + unitValueList.get(0) * 0.2 - 0.1, + 0.2, + unitValueList.get(1) * 0.2 - 0.1 + ); + //#if MC >= 11800 + Level level = instance.level(); + //#else +//$$ Level level = instance.getCommandSenderWorld(); + //#endif + ItemEntity itemEntity = new ItemEntity(level, instance.getX(), instance.getY(), instance.getZ(), itemStack, velocity.x, velocity.y, velocity.z); + itemEntity.setDefaultPickUpDelay(); + level.addFreshEntity(itemEntity); + return itemEntity; + } + +} diff --git a/src/main/resources/assets/joacarpet/lang/en_us.json b/src/main/resources/assets/joacarpet/lang/en_us.json index b0801c4..f069afb 100644 --- a/src/main/resources/assets/joacarpet/lang/en_us.json +++ b/src/main/resources/assets/joacarpet/lang/en_us.json @@ -2,6 +2,7 @@ "carpet.rule.insaneBehaviors.desc": "Makes the random velocities of droppers and projectiles (as well as both the position and velocity of blocks broken by pistons) systematically iterate through the most extreme values possible, and then repeatedly iterate through all the halfway points in between, in a sense attempting every point in a 3d/5d \"grid\" that slowly increases in resolution.\nFor droppers and projectiles, this setting determines whether the max value corresponds to the old gaussian randomness limits (\"extreme\"), or the limits of the triangular randomness introduced in 1.19 (\"sensible\"). Both settings function the same for blocks being broken by pistons.\nFor the `/insanebehaviors ` command, see `/carpet commandInsaneBehaviors`.\nDo note that insaneBehaviors works on a global iterator: any triggering event will step through an iteration from all other insaneBehaviors events, too.", "carpet.rule.insaneBehaviorsSkipVisitedPoints.desc": "Makes the `insaneBehaviors` rule skip points that coincide with previous resolutions, reducing the overall search space by a fraction that approaches 1/(2^resolution)", "carpet.rule.insaneBehaviorsIncrement.desc": "Determines the incrementing behavior of the `insaneBehaviors` rule. If set to `normal`, the counter increments normally until all points of the current resolution have been exhausted, then step to the next resolution.\n`loopCurrentResolution` will instead restart at the beginning of the current resolution.\n`Freeze` will stop both the counter and resolution from incrementing.", + "carpet.rule.insaneBehaviorsCartYeetingException.desc": "Makes testing cart yeeting possible by disabling one of the two types of item drops (vehicle item and container items), to make the different iterators not interfere with each other.", "carpet.rule.commandInsaneBehaviors.desc": "The command used for the `insaneBehaviors` rule.\n\"reset\" sets the `resolution` and `counter` back to the default values. \"getstate\" and \"setstate\" are used to manually read and write the current iteration state.", "carpet.rule.commandBlockTickling.desc": "Controls who can use the `/blocktickling` command, which lets you send manual block and/or shape updates to blocks using a feather item. Updates are sent from the block in front of the face you're clicking on. Useful if you're working with budded blocks, with /carpet interactionUpdates off, or with intricarpet's /interaction command.", "carpet.rule.disableEndermanGriefing.desc": "Disables enderman griefing.", diff --git a/src/main/resources/joacarpet.mixins.json b/src/main/resources/joacarpet.mixins.json index b60941a..9fae76d 100644 --- a/src/main/resources/joacarpet.mixins.json +++ b/src/main/resources/joacarpet.mixins.json @@ -6,13 +6,14 @@ "mixins": [ "blockTickling.ItemMixin", "blockTickling.PlayerMixin", + "insaneBehaviors.VehicleEntityOrAbstractMinecartMixin", "insaneBehaviors.BlockMixin", "insaneBehaviors.ContainersMixin", "insaneBehaviors.DefaultDispenseItemBehaviorMixin", "insaneBehaviors.PistonBaseBlockMixin", "insaneBehaviors.ProjectileMixin", - "miscSurvival.DisableEndermanGriefingMixin", "miscSurvival.DisableElytraRocketsMixin", + "miscSurvival.DisableEndermanGriefingMixin", "miscSurvival.VerticalRocketsFromStandstillMixin1", "miscSurvival.VerticalRocketsFromStandstillMixin2" ],