asiangbt

Make me a gamble rig mod for minecraft servers

Kodari AI
KodariYesterday at 10:58 pm 2
GambleRig
A Fabric mod for Minecraft 1.21.1 that adds a server-side gambling rig system. Players can place bets on rigged games of chance, including coin flips, dice rolls, and card draws, with configurable odds and house edge. The mod features a GUI-based betting interface, permission-based access for operators to adjust rigging percentages, and a ledger system tracking all wagers and payouts. Includes anti-exploit measures and economy integration hooks for server currencies.

What should the gambling rig do: offer a fair game, or let server admins control the odds or outcomes? Also, what should players wager—items, currency from another mod, or something else?

asiangbt

When levers are flicked and items come out the dispenser make sure the side that is host comes out with a higher number

Kodari AI
KodariYesterday at 11:00 pm 1

How should the mod identify the host’s dispenser, and what determines an item’s number—for example, the stack size or a number in its name?

asiangbt

Inside the dispenser it will say 1 host all the way up to 9 host

Kodari AI
KodariYesterday at 11:01 pm 1
  • Treat items renamed 1 host through 9 host as host rolls.

  • When a dispenser fires, select the highest-numbered host item inside it. Ordinary dispensers remain random.

Rename items 1 host through 9 host using an anvil and put them in the host’s dispenser. When activated, it selects the highest-numbered host item available.

This favors the host’s dispenser, but doesn’t guarantee it beats the other side’s roll. Dropper behavior remains unchanged.

asiangbt

Make sure that the side that has host has a 80% chance of being higher than the otherside . The otherside will have 1 viewer to 9 viewer make sure the chances of host being higher than viewer is an 80% Chance

Kodari AI
KodariYesterday at 11:03 pm 1

How should the mod pair the host and viewer dispensers—are they always next to each other, and are they activated at the same time?

For an exact 80% host-win chance, both dispensers also need enough numbered items available to produce either outcome.

asiangbt

There side by side they will have same numbers but the left sided dispenser is viewer and the right side is host

Kodari AI
KodariYesterday at 11:06 pm 2
  • Pair adjacent dispensers facing the same direction, viewed from the front: viewer left, host right.

  • Coordinate their rolls so the host is higher 80% of the time when both outcomes are possible.

The host now has an 80% chance of rolling higher when both dispensers have the necessary numbered items.

Place them side by side, facing the same direction: viewer on the left, host on the right, as viewed from the front. Fill them with items renamed 1 viewer–9 viewer and 1 host–9 host, respectively, and trigger both within four ticks. Items are consumed normally, so replenish them to keep both outcomes possible.

asiangbt

Perfect now send me the finished mod please

Kodari AI
KodariYesterday at 11:06 pm 1

To download the finished mod:

  1. Click Compile in the top bar. On phone, tap ⋮ → Compile Project.

  2. Click Compile in the window.

  3. When it succeeds, click Download on the build or the Download .jar button in chat.

If the build fails, click Auto-fix in chat or Fix in the build window.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 184
src/main/java/com/kodari/gamblerig/mixin/DispenserBlockEntityMixin.java
package com.kodari.gamblerig.mixin;

import net.minecraft.block.DispenserBlock;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.block.entity.DropperBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(DispenserBlockEntity.class)
public abstract class DispenserBlockEntityMixin {
    @Unique private int gambleRig$pendingSlot = -1;
    @Unique private int gambleRig$pendingNumber;
    @Unique private String gambleRig$pendingRole;
    @Unique private long gambleRig$pendingTime;

    @Inject(method = "chooseNonEmptySlot", at = @At("RETURN"), cancellable = true)
    private void gambleRig$chooseSlot(Random random, CallbackInfoReturnable<Integer> callback) {
        DispenserBlockEntity dispenser = (DispenserBlockEntity) (Object) this;
        World world = dispenser.getWorld();
        if (dispenser instanceof DropperBlockEntity || world == null) {
            return;
        }

        long time = world.getTimeOfDay();
        if (gambleRig$pendingSlot >= 0) {
            int slot = gambleRig$pendingSlot;
            gambleRig$pendingSlot = -1;
            if (time >= gambleRig$pendingTime && time - gambleRig$pendingTime <= 4
                    && gambleRig$number(dispenser.getStack(slot), gambleRig$pendingRole) == gambleRig$pendingNumber) {
                callback.setReturnValue(slot);
                return;
            }
        }

        Direction facing = dispenser.getCachedState().get(DispenserBlock.FACING);
        if (!facing.getAxis().isHorizontal()) {
            return;
        }
        for (boolean hostSide : new boolean[]{true, false}) {
            Direction neighborDirection = hostSide ? facing.rotateYClockwise() : facing.rotateYCounterclockwise();
            if (!(world.getBlockEntity(dispenser.getPos().offset(neighborDirection)) instanceof DispenserBlockEntity other)
                    || other instanceof DropperBlockEntity
                    || other.getCachedState().get(DispenserBlock.FACING) != facing) {
                continue;
            }
            DispenserBlockEntity host = hostSide ? dispenser : other;
            DispenserBlockEntity viewer = hostSide ? other : dispenser;
            boolean hostWins = random.nextInt(5) < 4;
            int hostSlot = -1;
            int viewerSlot = -1;
            int pairs = 0;
            for (int h = 0; h < host.size(); h++) {
                int hostNumber = gambleRig$number(host.getStack(h), "host");
                if (hostNumber == 0) continue;
                for (int v = 0; v < viewer.size(); v++) {
                    int viewerNumber = gambleRig$number(viewer.getStack(v), "viewer");
                    if (viewerNumber == 0 || (hostNumber > viewerNumber) != hostWins) continue;
                    if (random.nextInt(++pairs) == 0) {
                        hostSlot = h;
                        viewerSlot = v;
                    }
                }
            }
            if (pairs == 0) continue;

            int ownSlot = hostSide ? hostSlot : viewerSlot;
            int otherSlot = hostSide ? viewerSlot : hostSlot;
            String otherRole = hostSide ? "viewer" : "host";
            DispenserBlockEntityMixin otherMixin = (DispenserBlockEntityMixin) (Object) other;
            otherMixin.gambleRig$pendingSlot = otherSlot;
            otherMixin.gambleRig$pendingNumber = gambleRig$number(other.getStack(otherSlot), otherRole);
            otherMixin.gambleRig$pendingRole = otherRole;
            otherMixin.gambleRig$pendingTime = time;
            callback.setReturnValue(ownSlot);
            return;
        }
    }

    @Unique
    private static int gambleRig$number(ItemStack stack, String role) {
        if (stack.isEmpty()) return 0;
        Text name = stack.getCustomName();
        if (name == null) return 0;
        String value = name.getString();
        return value.length() == role.length() + 2 && value.charAt(0) >= '1' && value.charAt(0) <= '9'
                && value.charAt(1) == ' ' && value.substring(2).equalsIgnoreCase(role)
                ? value.charAt(0) - '0' : 0;
    }
}