Skip to content

Commit f9b51ef

Browse files
committed
extremeBehaviours
1 parent 55065a3 commit f9b51ef

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/main/java/carpet/CarpetServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
public class CarpetServer // static for now - easier to handle all around the code, its one anyways
3232
{
33-
public static final Random rand = new Random((int)((2>>16)*Math.random()));
33+
public static final Random rand = new Random();
3434
public static MinecraftServer minecraft_server;
3535
private static CommandDispatcher<ServerCommandSource> currentCommandDispatcher;
3636
public static CarpetScriptServer scriptServer;

src/main/java/carpet/CarpetSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,11 @@ private static class KelpLimit extends Validator<Integer>
508508
category = {EXPERIMENTAL, CREATIVE}
509509
)
510510
public static boolean flatWorldStructureSpawning = false;
511+
512+
@Rule(
513+
desc = "Edge cases are as frequent as common cases, for testing only!!",
514+
extra = "Dispensers and Droppers will use extreme random velocity values",
515+
category = CREATIVE
516+
)
517+
public static boolean extremeBehaviours = false;
511518
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package carpet.mixins;
2+
3+
import carpet.CarpetServer;
4+
import carpet.CarpetSettings;
5+
import net.minecraft.block.dispenser.ItemDispenserBehavior;
6+
import net.minecraft.entity.ItemEntity;
7+
import net.minecraft.item.ItemStack;
8+
import net.minecraft.util.math.Direction;
9+
import net.minecraft.util.math.Position;
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.Redirect;
14+
15+
@Mixin(ItemDispenserBehavior.class)
16+
public class ItemDispenserBehaviour_extremeBehavioursMixin
17+
{
18+
@Redirect(method = "spawnItem", at = @At(
19+
value = "INVOKE",
20+
target = "Lnet/minecraft/entity/ItemEntity;setVelocity(DDD)V"
21+
))
22+
private static void setExtremeVelocity(ItemEntity itemEntity, double x, double y, double z,
23+
World world, ItemStack stack, int offset, Direction side, Position pos)
24+
{
25+
if (CarpetSettings.extremeBehaviours)
26+
{
27+
double g = CarpetServer.rand.nextDouble() * 0.1D + 0.2D;
28+
itemEntity.setVelocity(
29+
(16*world.random.nextDouble()-8) * 0.007499999832361937D * (double) offset + (double) side.getOffsetX() * g,
30+
(16*world.random.nextDouble()-8) * 0.007499999832361937D * (double) offset + 0.20000000298023224D,
31+
(16*world.random.nextDouble()-8) * 0.007499999832361937D * (double) offset + (double) side.getOffsetZ() * g
32+
);
33+
}
34+
else
35+
{
36+
itemEntity.setVelocity(x, y, z);
37+
}
38+
}
39+
40+
}

src/main/resources/carpet.mixins.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
"PickaxeItem_missingToolsMixin",
124124
"ShearsItem_missingToolsMixin",
125125

126+
"ItemDispenserBehaviour_extremeBehavioursMixin",
127+
126128
"ArmorStandEntity_scarpetMarkerMixin",
127129
"Entity_scarpetEventsMixin",
128130
"LivingEntity_scarpetEventsMixin",

0 commit comments

Comments
 (0)