ahh
This commit is contained in:
@@ -6,7 +6,7 @@ minecraft_version=1.20.1
|
||||
yarn_mappings=1.20.1+build.10
|
||||
loader_version=0.18.3
|
||||
# Mod Properties
|
||||
mod_version=26.3.2.1
|
||||
mod_version=26.3.3
|
||||
maven_group=dev.tggamesyt
|
||||
archives_base_name=szar
|
||||
# Dependencies
|
||||
|
||||
@@ -58,7 +58,6 @@ public class Joint extends SpyglassItem {
|
||||
int value = Szar.PLAYER_JOINT_LEVEL.getOrDefault(user.getUuid(), 0) + 1;
|
||||
boolean addicted = Szar.PLAYER_ADDICTION_LEVEL.getOrDefault(user.getUuid(), false);
|
||||
Szar.PLAYER_JOINT_LEVEL.put(user.getUuid(), value);
|
||||
Szar.LOGGER.info(user.getEntityName() + "'s joint level is now " + value);
|
||||
if (value > 80) {
|
||||
RegistryEntry<DamageType> drogAttackType =
|
||||
user.getWorld()
|
||||
@@ -70,11 +69,9 @@ public class Joint extends SpyglassItem {
|
||||
user.damage(source, Float.MAX_VALUE);
|
||||
Szar.PLAYER_JOINT_LEVEL.put(user.getUuid(), 0);
|
||||
Szar.PLAYER_ADDICTION_LEVEL.put(user.getUuid(), false);
|
||||
Szar.LOGGER.info(user.getEntityName() + "'s joint level is now " + 0);
|
||||
}
|
||||
if (value > 40 && !addicted) {
|
||||
Szar.PLAYER_ADDICTION_LEVEL.put(user.getUuid(), true);
|
||||
Szar.LOGGER.info(user.getEntityName() + "'s addiction is now true");
|
||||
}
|
||||
// Consume 1 durability
|
||||
stack.damage(1, user, p -> p.sendToolBreakStatus(user.getActiveHand()));
|
||||
|
||||
@@ -45,7 +45,6 @@ public class PlayerValueTimer {
|
||||
|
||||
int current = Szar.PLAYER_JOINT_LEVEL.getOrDefault(uuid, 0);
|
||||
int newValue = Math.max(0, current - 2);
|
||||
Szar.LOGGER.info(player.getEntityName() + "'s joint level is now " + newValue);
|
||||
Szar.PLAYER_JOINT_LEVEL.put(uuid, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,14 @@ import java.util.Random;
|
||||
public class SlotMachineBlockEntity extends BlockEntity {
|
||||
|
||||
public final int[] currentSymbol = new int[3];
|
||||
public final int[] finalSymbol = new int[3];
|
||||
public static final int TOTAL_SYMBOLS = 7;
|
||||
private boolean spinning = false;
|
||||
private int spinTimer = 0;
|
||||
private int currentBetAmount = 0;
|
||||
private ItemStack currentBetStack = ItemStack.EMPTY;
|
||||
private boolean forceWin = false;
|
||||
private int winTier = 0; // 0 = fruit, 1 = golden apple small, 2 = golden apple jackpot
|
||||
|
||||
public SlotMachineBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(Szar.SLOT_MACHINE_BLOCKENTITY, pos, state);
|
||||
@@ -33,11 +40,24 @@ public class SlotMachineBlockEntity extends BlockEntity {
|
||||
world.updateListeners(pos, getCachedState(), getCachedState(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
public int getSymbol(int i) {
|
||||
return currentSymbol[i];
|
||||
}
|
||||
|
||||
public int getFinalSymbol(int i) {
|
||||
return finalSymbol[i];
|
||||
}
|
||||
|
||||
public void setFinalSymbols(int s0, int s1, int s2) {
|
||||
finalSymbol[0] = s0;
|
||||
finalSymbol[1] = s1;
|
||||
finalSymbol[2] = s2;
|
||||
markDirty();
|
||||
if (world != null && !world.isClient) {
|
||||
world.updateListeners(pos, getCachedState(), getCachedState(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNbt(NbtCompound nbt) {
|
||||
super.writeNbt(nbt);
|
||||
@@ -65,4 +85,48 @@ public class SlotMachineBlockEntity extends BlockEntity {
|
||||
writeNbt(nbt);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void setSpinning(boolean spinning) {
|
||||
this.spinning = spinning;
|
||||
}
|
||||
|
||||
public boolean getSpinning() {
|
||||
return spinning;
|
||||
}
|
||||
public void setspinTimer(int spinTimer) {
|
||||
this.spinTimer = spinTimer;
|
||||
}
|
||||
public int getspinTimer() {return spinTimer;}
|
||||
public void setcurrentBetAmount(int currentBetAmount) {this.currentBetAmount = currentBetAmount;}
|
||||
public int getcurrentBetAmount() {return currentBetAmount;}
|
||||
public void setcurrentBetStack(ItemStack currentBetStack) {this.currentBetStack = currentBetStack;}
|
||||
public ItemStack getcurrentBetStack() {return currentBetStack;}
|
||||
public void setForceWin(boolean forceWin) {this.forceWin = forceWin;}
|
||||
public boolean getForceWin() {return forceWin;}
|
||||
public void setwinTier(int winTier) {this.winTier = winTier;}
|
||||
public int getwinTier() {return winTier;}
|
||||
|
||||
void finishSpin() {
|
||||
if (getForceWin()) {
|
||||
int payout = switch (getwinTier()) {
|
||||
case 0 -> getcurrentBetAmount() * 2; // fruit 2x
|
||||
case 1 -> getcurrentBetAmount() * 10; // golden apple small
|
||||
case 2 -> getcurrentBetAmount() * 30; // jackpot
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
Direction facing = getCachedState().get(SlotMachineBlock.FACING);
|
||||
BlockPos drop = getPos().offset(facing);
|
||||
assert getWorld() != null;
|
||||
ItemScatterer.spawn(
|
||||
getWorld(),
|
||||
drop.getX(),
|
||||
drop.getY(),
|
||||
drop.getZ(),
|
||||
new ItemStack(getcurrentBetStack().getItem(), payout)
|
||||
);
|
||||
}
|
||||
setcurrentBetAmount(0);
|
||||
setcurrentBetStack(ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
@@ -32,18 +32,6 @@ public class SlotMachineScreenHandler extends ScreenHandler {
|
||||
private final PropertyDelegate propertyDelegate;
|
||||
private final Random random = new Random();
|
||||
|
||||
private int spinTimer = 0;
|
||||
private boolean spinning = false;
|
||||
private boolean lastSpinWon = false;
|
||||
|
||||
private int currentBetAmount = 0;
|
||||
private ItemStack currentBetStack = ItemStack.EMPTY;
|
||||
|
||||
private SlotSymbol final0, final1, final2;
|
||||
|
||||
private boolean forceWin = false;
|
||||
private int winTier = 0; // 0 = fruit, 1 = golden apple small, 2 = golden apple jackpot
|
||||
|
||||
public SlotMachineScreenHandler(int syncId, PlayerInventory playerInv, SlotMachineBlockEntity blockEntity) {
|
||||
super(Szar.SLOT_MACHINE_SCREEN_HANDLER_TYPE, syncId);
|
||||
this.playerInventory = playerInv;
|
||||
@@ -53,17 +41,7 @@ public class SlotMachineScreenHandler extends ScreenHandler {
|
||||
this.addProperties(propertyDelegate);
|
||||
|
||||
// Bet slot
|
||||
this.addSlot(new Slot(betInventory, 0, 44, 35) {
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return !spinning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeItems(PlayerEntity playerEntity) {
|
||||
return !spinning;
|
||||
}
|
||||
});
|
||||
this.addSlot(new Slot(betInventory, 0, 44, 35));
|
||||
|
||||
// Player inventory slots
|
||||
for (int y = 0; y < 3; y++)
|
||||
@@ -75,57 +53,53 @@ public class SlotMachineScreenHandler extends ScreenHandler {
|
||||
|
||||
@Override
|
||||
public boolean onButtonClick(PlayerEntity player, int id) {
|
||||
if (id != 0 || spinning) return false;
|
||||
if (id != 0 || blockEntity.getSpinning()) return false;
|
||||
|
||||
ItemStack bet = betInventory.getStack(0);
|
||||
if (bet.isEmpty()) return false;
|
||||
|
||||
currentBetAmount = bet.getCount();
|
||||
currentBetStack = bet.copy();
|
||||
blockEntity.setcurrentBetAmount(bet.getCount());
|
||||
blockEntity.setcurrentBetStack(bet.copy());
|
||||
betInventory.setStack(0, ItemStack.EMPTY);
|
||||
|
||||
// === Determine if this spin will definitely win (40%) ===
|
||||
forceWin = random.nextFloat() < 0.4f;
|
||||
if (forceWin) {
|
||||
blockEntity.setForceWin(random.nextFloat() < 0.4f);
|
||||
if (blockEntity.getForceWin()) {
|
||||
float tierRoll = random.nextFloat();
|
||||
if (tierRoll < 0.80f) winTier = 0; // Fruit win (2x items)
|
||||
else if (tierRoll < 0.96f) winTier = 1; // Golden Apple small (25x)
|
||||
else winTier = 2; // Jackpot (100x)
|
||||
if (tierRoll < 0.88f) blockEntity.setwinTier(0); // 88%
|
||||
else if (tierRoll < 0.98f) blockEntity.setwinTier(1); // 10%
|
||||
else blockEntity.setwinTier(2); // 2%
|
||||
} else {
|
||||
winTier = -1; // no win
|
||||
blockEntity.setwinTier(-1);
|
||||
}
|
||||
|
||||
// === Preselect final symbols based on forced win type ===
|
||||
if (forceWin) {
|
||||
switch (winTier) {
|
||||
if (blockEntity.getForceWin()) {
|
||||
switch (blockEntity.getwinTier()) {
|
||||
case 0 -> { // fruit
|
||||
final0 = SlotSymbol.rollFruit(random);
|
||||
final1 = final0;
|
||||
final2 = final0;
|
||||
int symbol = SlotSymbol.symbolToInt(SlotSymbol.rollFruit(random));
|
||||
blockEntity.setFinalSymbols(symbol, symbol, symbol);
|
||||
}
|
||||
case 1 -> { // golden apple small
|
||||
final0 = SlotSymbol.BELL;
|
||||
final1 = final0;
|
||||
final2 = final0;
|
||||
int symbol = SlotSymbol.symbolToInt(SlotSymbol.BELL);
|
||||
blockEntity.setFinalSymbols(symbol, symbol, symbol);
|
||||
}
|
||||
case 2 -> { // jackpot
|
||||
final0 = SlotSymbol.SEVEN;
|
||||
final1 = final0;
|
||||
final2 = final0;
|
||||
int symbol = SlotSymbol.symbolToInt(SlotSymbol.SEVEN);
|
||||
blockEntity.setFinalSymbols(symbol, symbol, symbol);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final0 = SlotSymbol.roll(random);
|
||||
final1 = SlotSymbol.roll(random);
|
||||
final2 = SlotSymbol.roll(random);
|
||||
if (final0 == final1 && final1 == final2) {
|
||||
forceWin = true;
|
||||
winTier = final0 == SlotSymbol.BELL ? 1 : final0 == SlotSymbol.SEVEN ? 2 : 0;
|
||||
blockEntity.setFinalSymbols(SlotSymbol.symbolToInt(SlotSymbol.roll(random)), SlotSymbol.symbolToInt(SlotSymbol.roll(random)), SlotSymbol.symbolToInt(SlotSymbol.roll(random)));
|
||||
|
||||
if (blockEntity.getFinalSymbol(0) == blockEntity.getFinalSymbol(1) && blockEntity.getFinalSymbol(1) == blockEntity.getFinalSymbol(2)) {
|
||||
blockEntity.setForceWin(true);
|
||||
blockEntity.setwinTier(SlotSymbol.intToSymbol(blockEntity.getFinalSymbol(0)) == SlotSymbol.BELL ? 1 : SlotSymbol.intToSymbol(blockEntity.getFinalSymbol(0)) == SlotSymbol.SEVEN ? 2 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
spinTimer = 0;
|
||||
spinning = true;
|
||||
blockEntity.setspinTimer(0);
|
||||
blockEntity.setSpinning(true);
|
||||
propertyDelegate.set(0, 1);
|
||||
|
||||
return true;
|
||||
@@ -135,7 +109,7 @@ public class SlotMachineScreenHandler extends ScreenHandler {
|
||||
public void sendContentUpdates() {
|
||||
super.sendContentUpdates();
|
||||
|
||||
if (!spinning) {
|
||||
if (!blockEntity.getSpinning()) {
|
||||
if (blockEntity.getWorld().getTime() % IDLE_SPEED == 0) {
|
||||
blockEntity.setSymbols(
|
||||
random.nextInt(7),
|
||||
@@ -146,7 +120,7 @@ public class SlotMachineScreenHandler extends ScreenHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
spinTimer++;
|
||||
blockEntity.setspinTimer(blockEntity.getspinTimer() + 1);
|
||||
|
||||
int totalSpinDuration =
|
||||
PREPARE_TIME +
|
||||
@@ -154,59 +128,33 @@ public class SlotMachineScreenHandler extends ScreenHandler {
|
||||
LOCK_INTERVAL * 3 +
|
||||
RESULT_VIEW_TIME;
|
||||
|
||||
int speed = switch (spinTimer < PREPARE_TIME ? 0 : spinTimer < PREPARE_TIME + FAST_SPIN_TIME ? 1 : 2) {
|
||||
int speed = switch (blockEntity.getspinTimer() < PREPARE_TIME ? 0 : blockEntity.getspinTimer() < PREPARE_TIME + FAST_SPIN_TIME ? 1 : 2) {
|
||||
case 0 -> PREPARE_SPEED;
|
||||
case 1 -> FAST_SPEED;
|
||||
default -> FAST_SPEED;
|
||||
};
|
||||
|
||||
boolean lock0 = spinTimer >= PREPARE_TIME + FAST_SPIN_TIME + LOCK_INTERVAL;
|
||||
boolean lock1 = spinTimer >= PREPARE_TIME + FAST_SPIN_TIME + LOCK_INTERVAL * 2;
|
||||
boolean lock2 = spinTimer >= PREPARE_TIME + FAST_SPIN_TIME + LOCK_INTERVAL * 3;
|
||||
boolean lock0 = blockEntity.getspinTimer() >= PREPARE_TIME + FAST_SPIN_TIME + LOCK_INTERVAL;
|
||||
boolean lock1 = blockEntity.getspinTimer() >= PREPARE_TIME + FAST_SPIN_TIME + LOCK_INTERVAL * 2;
|
||||
boolean lock2 = blockEntity.getspinTimer() >= PREPARE_TIME + FAST_SPIN_TIME + LOCK_INTERVAL * 3;
|
||||
|
||||
int reel0 = lock0 ? final0.ordinal() : random.nextInt(7);
|
||||
int reel1 = lock1 ? final1.ordinal() : random.nextInt(7);
|
||||
int reel2 = lock2 ? final2.ordinal() : random.nextInt(7);
|
||||
int reel0 = lock0 ? blockEntity.getFinalSymbol(0) : random.nextInt(7);
|
||||
int reel1 = lock1 ? blockEntity.getFinalSymbol(1) : random.nextInt(7);
|
||||
int reel2 = lock2 ? blockEntity.getFinalSymbol(2) : random.nextInt(7);
|
||||
|
||||
if (spinTimer % speed == 0) {
|
||||
if (blockEntity.getspinTimer() % speed == 0) {
|
||||
blockEntity.setSymbols(reel0, reel1, reel2);
|
||||
}
|
||||
if (spinTimer >= (totalSpinDuration - RESULT_VIEW_TIME + 15)) {
|
||||
propertyDelegate.set(1, forceWin ? 1 : 0);
|
||||
if (blockEntity.getspinTimer() >= (totalSpinDuration - RESULT_VIEW_TIME + 15)) {
|
||||
propertyDelegate.set(1, blockEntity.getForceWin() ? 1 : 0);
|
||||
}
|
||||
if (spinTimer >= totalSpinDuration) {
|
||||
finishSpin(playerInventory.player);
|
||||
spinning = false;
|
||||
if (blockEntity.getspinTimer() >= totalSpinDuration) {
|
||||
blockEntity.finishSpin();
|
||||
blockEntity.setSpinning(false);
|
||||
propertyDelegate.set(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void finishSpin(PlayerEntity player) {
|
||||
lastSpinWon = forceWin;
|
||||
|
||||
if (lastSpinWon) {
|
||||
int payout = switch (winTier) {
|
||||
case 0 -> currentBetAmount * 2; // fruit 2x
|
||||
case 1 -> currentBetAmount * 16; // golden apple small
|
||||
case 2 -> currentBetAmount * 32; // jackpot
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
Direction facing = blockEntity.getCachedState().get(SlotMachineBlock.FACING);
|
||||
BlockPos drop = blockEntity.getPos().offset(facing);
|
||||
|
||||
ItemScatterer.spawn(
|
||||
player.getWorld(),
|
||||
drop.getX(),
|
||||
drop.getY(),
|
||||
drop.getZ(),
|
||||
new ItemStack(currentBetStack.getItem(), payout)
|
||||
);
|
||||
}
|
||||
currentBetAmount = 0;
|
||||
currentBetStack = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
return true;
|
||||
@@ -214,18 +162,38 @@ public class SlotMachineScreenHandler extends ScreenHandler {
|
||||
|
||||
@Override
|
||||
public ItemStack quickMove(PlayerEntity player, int index) {
|
||||
if (spinning) return ItemStack.EMPTY;
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
ItemStack newStack = ItemStack.EMPTY;
|
||||
Slot slot = this.slots.get(index);
|
||||
|
||||
if (slot.hasStack()) {
|
||||
ItemStack originalStack = slot.getStack();
|
||||
newStack = originalStack.copy();
|
||||
|
||||
// If clicking the bet slot → move to player inventory
|
||||
if (index == 0) {
|
||||
if (!this.insertItem(originalStack, 1, this.slots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
// If clicking player inventory → move to bet slot
|
||||
else {
|
||||
if (!this.insertItem(originalStack, 0, 1, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if (originalStack.isEmpty()) {
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
return newStack;
|
||||
}
|
||||
|
||||
public PropertyDelegate getPropertyDelegate() {
|
||||
return propertyDelegate;
|
||||
}
|
||||
public int getSpinTimer() {
|
||||
return spinTimer;
|
||||
}
|
||||
|
||||
public boolean didLastSpinWin() {
|
||||
return forceWin;
|
||||
}
|
||||
}
|
||||
@@ -32,13 +32,20 @@ public enum SlotSymbol {
|
||||
}
|
||||
|
||||
public static SlotSymbol rollFruit(Random random) {
|
||||
int fruitIndex = random.nextInt(5);
|
||||
switch (fruitIndex) {
|
||||
case 0: return APPLE;
|
||||
case 1: return SWEET_BERRIES;
|
||||
case 2: return GLOW_BERRIES;
|
||||
case 3: return MELON_SLICE;
|
||||
default: return CHORUS_FRUIT;
|
||||
}
|
||||
return switch (random.nextInt(5)) {
|
||||
case 0 -> APPLE;
|
||||
case 1 -> SWEET_BERRIES;
|
||||
case 2 -> GLOW_BERRIES;
|
||||
case 3 -> MELON_SLICE;
|
||||
default -> CHORUS_FRUIT;
|
||||
};
|
||||
}
|
||||
|
||||
public static SlotSymbol intToSymbol(int num) {
|
||||
return SlotSymbol.values()[num];
|
||||
};
|
||||
|
||||
public static int symbolToInt(SlotSymbol num) {
|
||||
return num.ordinal();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user