This commit is contained in:
2026-01-22 09:16:59 +01:00
parent a5150e34fe
commit 49148454ac
16 changed files with 123 additions and 1133 deletions

View File

@@ -1,23 +1,28 @@
package dev.tggamesyt.szar;
import dev.tggamesyt.szar.Szar;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SpyglassItem;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.UseAction;
import net.minecraft.world.World;
import java.util.Random;
import static dev.tggamesyt.szar.Szar.MOD_ID;
public class Joint extends SpyglassItem {
public Joint(Settings settings) {
@@ -42,12 +47,35 @@ public class Joint extends SpyglassItem {
user.setCurrentHand(hand); // start using
return TypedActionResult.consume(user.getStackInHand(hand));
}
private static final Random RANDOM = new Random() {};
public static final RegistryKey<DamageType> HEART_ATTACK =
RegistryKey.of(RegistryKeys.DAMAGE_TYPE, new Identifier(MOD_ID, "heart_attack"));
public static final RegistryKey<DamageType> DROG_OVERDOSE =
RegistryKey.of(RegistryKeys.DAMAGE_TYPE, new Identifier(MOD_ID, "drog_overdose"));
@Override
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) {
// Only do server/client side durability and effect
//if (!world.isClient) return;
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()
.getRegistryManager()
.get(RegistryKeys.DAMAGE_TYPE)
.entryOf(DROG_OVERDOSE);
DamageSource source = new DamageSource(drogAttackType);
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()));
if (user instanceof PlayerEntity player && !world.isClient) {
@@ -105,6 +133,16 @@ public class Joint extends SpyglassItem {
true, // show particles
true // show icon
));
if (amplifier == 9 && RANDOM.nextInt(100) == 0) {
RegistryEntry<DamageType> heartAttackType =
user.getWorld()
.getRegistryManager()
.get(RegistryKeys.DAMAGE_TYPE)
.entryOf(HEART_ATTACK);
DamageSource source = new DamageSource(heartAttackType);
user.damage(source, Float.MAX_VALUE);
}
}
if (amplifier > 3) {
int nausealevel = amplifier - 3;

View File

@@ -0,0 +1,52 @@
package dev.tggamesyt.szar;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import java.util.UUID;
public class PlayerValueTimer {
// 20 ticks/sec * 60 sec * 3 min
private static final int INTERVAL_TICKS = 20 * 60 * 3;
private static final int ONE_MIN = 20 * 20;
private static int tickCounter = 0;
private static int tickCounterMin = 0;
static void onServerTick(MinecraftServer server) {
tickCounter++;
tickCounterMin++;
if (tickCounter >= INTERVAL_TICKS) {
tickCounter = 0;
runDecrease(server);
}
if (tickCounterMin >= ONE_MIN) {
tickCounterMin = 0;
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
if (Szar.PLAYER_ADDICTION_LEVEL.getOrDefault(player.getUuid(), false) && Szar.PLAYER_JOINT_LEVEL.getOrDefault(player.getUuid(), 0) < 10) {
if (!player.hasStatusEffect(Szar.DROG_EFFECT)) {
player.addStatusEffect(
new StatusEffectInstance(StatusEffects.WITHER, 10, 0)
);
};
}
}
}
}
private static void runDecrease(MinecraftServer server) {
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
UUID uuid = player.getUuid();
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);
}
}
}

View File

@@ -5,8 +5,6 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.message.v1.ServerMessageDecoratorEvent;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
@@ -19,28 +17,27 @@ import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern;
public class Szar implements ModInitializer {
public static final String MOD_ID = "szar";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
public static final Block SZAR_BLOCK =
new SzarBlock();
public static final Block NIGGERITEBLOCK =
@@ -112,14 +109,10 @@ public class Szar implements ModInitializer {
GYPSY_ENTITY_TYPE,
GypsyEntity.createAttributes()
);
ServerTickEvents.END_WORLD_TICK.register(world -> {
for (var entity : world.getPlayers()) {
if (entity.getHealth() <= 0f) {
tryDrugTotem(entity);
}
}
});
ServerTickEvents.END_SERVER_TICK.register(PlayerValueTimer::onServerTick);
}
public static final Map<UUID, Integer> PLAYER_JOINT_LEVEL = new HashMap<>();
public static final Map<UUID, Boolean> PLAYER_ADDICTION_LEVEL = new HashMap<>();
public static final StatusEffect DROG_EFFECT = Registry.register(
Registries.STATUS_EFFECT,
new Identifier(MOD_ID, "drog"),
@@ -359,50 +352,4 @@ public class Szar implements ModInitializer {
.getProgress(advancement)
.isDone();
}
public static boolean tryDrugTotem(PlayerEntity player) {
StatusEffectInstance effect = player.getStatusEffect(Szar.DROG_EFFECT);
if (effect == null || effect.getAmplifier() < 5) return false;
// Only trigger if holding Joint
ItemStack stack = player.getMainHandStack();
if (!(stack.getItem() instanceof Joint)) return false;
World world = player.getWorld();
// Prevent death
player.setHealth(1f);
// Clear negative effects
player.clearStatusEffects();
// Vanilla totem effects
player.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 900, 1));
player.addStatusEffect(new StatusEffectInstance(StatusEffects.ABSORPTION, 100, 1));
player.addStatusEffect(new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 800, 0));
// Sound
player.playSound(SoundEvents.ITEM_TOTEM_USE, 1f, 1f);
// Animation via packet
if (!world.isClient() && player instanceof ServerPlayerEntity serverPlayer) {
PacketByteBuf buf = PacketByteBufs.create();
buf.writeItemStack(stack);
ServerPlayNetworking.send(serverPlayer, Szar.TOTEMPACKET, buf);
}
// Reduce drug level safely
int duration = effect.getDuration();
int amplifier = effect.getAmplifier();
player.addStatusEffect(new StatusEffectInstance(
Szar.DROG_EFFECT,
duration,
Math.max(0, amplifier - 2),
false,
true,
true
));
return true;
}
}

View File

@@ -20,5 +20,7 @@
"item.szar.niggerite_chestplate": "Niggerite Chestplate",
"item.szar.niggerite_leggings": "Niggerite Leggings",
"item.szar.niggerite_boots": "Niggerite Boots",
"item.szar.niggerite_helmet": "Niggerite Helmet"
"item.szar.niggerite_helmet": "Niggerite Helmet",
"death.attack.heart_attack": "%1$s got a heart attack",
"death.attack.drog_overdose": "%1$s got a drog overdose"
}

View File

@@ -0,0 +1,6 @@
{
"message_id": "drog_overdose",
"scaling": "never",
"exhaustion": 0.0,
"death_message_type": "default"
}

View File

@@ -0,0 +1,6 @@
{
"message_id": "heart_attack",
"scaling": "never",
"exhaustion": 0.0,
"death_message_type": "default"
}