Skip to content

Commit

Permalink
Implemented insaneBehaviors for containers and vehicle-destruction it…
Browse files Browse the repository at this point in the history
…em spawning.

Added insaneBehaviors iteration for the item contents of containes (including container minecarts), with extreme and sensible modes.

Added insaneBehaviors iteration to vehicle destroy drops, obviously also intended for container minecarts. Independent of the 1.19 gaussian/triangular change, so both modes work the same.

Added a somewhat hacky insaneBehaviorsCartYeetingException with `none`, `disableVehicleItem` and `disableContainerContents` as options. Intended to toggle one of two item types off, to prevent them from interfering with one another (testing cart yeeting reliability is virtually impossible without it, the vehicle item iterator will kneecap the container item iterator completely)
  • Loading branch information
JoakimThorsen committed Jul 9, 2024
1 parent 9cea7cc commit 2d2b2ed
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 35 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/joacarpet/JoaCarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> 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<Float> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private Vec3 add(Vec3 vec3, double d, double e, double f, Operation<Vec3> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<ItemEntity> original) {
if (JoaCarpetSettings.insaneBehaviors.equals("off") || JoaCarpetSettings.insaneBehaviorsCartYeetingException.equals("disableVehicleItem")) {
return original.call(instance, itemStack);
}
ArrayList<Float> 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;
}

}
1 change: 1 addition & 0 deletions src/main/resources/assets/joacarpet/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <reset/getstate/setstate>` 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.",
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/joacarpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down

0 comments on commit 2d2b2ed

Please sign in to comment.