1
0
Fork 0
mirror of https://github.com/TheClashFruit/CreatePissAndShit.git synced 2024-09-19 17:36:47 +00:00

feat: diarrhea and shit mechanics

This commit is contained in:
TheClashFruit 2024-07-29 14:46:28 +02:00
parent 55923b0119
commit 6deebf84de
Signed by: TheClashFruit
GPG key ID: 09BB24C34C2F3204
18 changed files with 271 additions and 32 deletions

View file

@ -5,10 +5,8 @@ import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import me.theclashfruit.pissnshit.config.MainConfig;
import me.theclashfruit.pissnshit.network.PissSyncPacket;
import me.theclashfruit.pissnshit.registry.Blocks;
import me.theclashfruit.pissnshit.registry.Fluids;
import me.theclashfruit.pissnshit.registry.Items;
import me.theclashfruit.pissnshit.registry.ItemGroups;
import me.theclashfruit.pissnshit.network.PissingPacket;
import me.theclashfruit.pissnshit.registry.*;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
@ -39,6 +37,9 @@ public class PissAndShit implements ModInitializer {
Items.init();
Blocks.init();
StatusEffects.init();
Potions.init();
ItemGroups.init();
AutoConfig.register(MainConfig.class, Toml4jConfigSerializer::new);
@ -61,5 +62,8 @@ public class PissAndShit implements ModInitializer {
);
}
});
// Register Packets
PissingPacket.register();
}
}

View file

@ -2,21 +2,31 @@ package me.theclashfruit.pissnshit.client;
import me.theclashfruit.pissnshit.client.gui.PissAndShitHudOverlay;
import me.theclashfruit.pissnshit.network.PissSyncPacket;
import me.theclashfruit.pissnshit.network.PissingPacket;
import me.theclashfruit.pissnshit.network.ShitSyncPacket;
import me.theclashfruit.pissnshit.registry.Fluids;
import me.theclashfruit.pissnshit.util.PissManager;
import me.theclashfruit.pissnshit.util.PlayerEntityUtil;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.client.render.fluid.v1.SimpleFluidRenderHandler;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.util.InputUtil;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;
public class PissAndShitClient implements ClientModInitializer {
private static KeyBinding keyBinding;
@Override
public void onInitializeClient() {
FluidRenderHandlerRegistry.INSTANCE.register(Fluids.STILL_PISS, Fluids.FLOWING_PISS, new SimpleFluidRenderHandler(
@ -39,5 +49,18 @@ public class PissAndShitClient implements ClientModInitializer {
// Register Packets
PissSyncPacket.register();
ShitSyncPacket.register();
keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.pissnshit.piss",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_Y,
"category.pissnshit.main"
));
ClientTickEvents.END_CLIENT_TICK.register(c -> {
while (keyBinding.wasPressed()) {
PissingPacket.sentToServer(1);
}
});
}
}

View file

@ -34,9 +34,9 @@ public class PissAndShitHudOverlay implements Drawable {
int fullPissIcons = pissLevel / 10;
int remainingPissLevel = pissLevel - (fullPissIcons * 10);
int shitLevel = ((PlayerEntityUtil) this.client.player).getShitManager().getShitLevel();
int fullShitIcons = shitLevel / 10;
int remainingShitLevel = shitLevel - (fullShitIcons * 10);
double shitLevel = ((PlayerEntityUtil) this.client.player).getShitManager().getShitLevel();
int fullShitIcons = (int) (shitLevel / 10);
int remainingShitLevel = (int) (shitLevel - (fullShitIcons * 10));
for (int i = 0; i < 10; i++) {
int iconX = x - (9 - i) * 8 - 9;

View file

@ -0,0 +1,15 @@
package me.theclashfruit.pissnshit.effects;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory;
public class DiarrheaStatusEffect extends StatusEffect {
public DiarrheaStatusEffect() {
super(StatusEffectCategory.HARMFUL, 0x361A0E);
}
@Override
public boolean canApplyUpdateEffect(int duration, int amplifier) {
return true;
}
}

View file

@ -4,6 +4,7 @@ import me.theclashfruit.pissnshit.PissAndShit;
import me.theclashfruit.pissnshit.registry.Blocks;
import me.theclashfruit.pissnshit.registry.Items;
import me.theclashfruit.pissnshit.registry.Fluids;
import me.theclashfruit.pissnshit.registry.Tags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
@ -64,7 +65,7 @@ public class PissFluid extends FlowableFluid {
@Override
protected boolean canBeReplacedWith(FluidState state, BlockView world, BlockPos pos, Fluid fluid, Direction direction) {
return direction == Direction.DOWN && !fluid.isIn(FluidTags.WATER);
return direction == Direction.DOWN && !fluid.isIn(Tags.PISS);
}
@Override

View file

@ -4,12 +4,15 @@ import me.theclashfruit.pissnshit.util.PissManager;
import me.theclashfruit.pissnshit.util.PlayerEntityUtil;
import me.theclashfruit.pissnshit.util.ShitManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(PlayerEntity.class)
public class PlayerEntityMixin implements PlayerEntityUtil {
@ -29,8 +32,13 @@ public class PlayerEntityMixin implements PlayerEntityUtil {
}
}
// Lnet/minecraft/entity/player/PlayerEntity;eatFood(Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;
@Inject(
at = @At("HEAD"),
method = "eatFood(Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;"
)
public void eatFood(World world, ItemStack stack, CallbackInfoReturnable<ItemStack> cir) {
shitManager.eat(stack, ((PlayerEntity) (Object) this));
}
@Inject(
at = @At("TAIL"),

View file

@ -16,7 +16,7 @@ public class PissSyncPacket {
public static void register() {
ClientPlayNetworking.registerGlobalReceiver(PissSyncPacket.ID, (c, handler, buf, responseSender) -> {
PissSyncPacket.SyncPacket packet = PissSyncPacket.SyncPacket.decode(buf);
Packet packet = Packet.decode(buf);
c.execute(() -> {
if (c.player != null) {
@ -31,17 +31,17 @@ public class PissSyncPacket {
public static void sendToClient(ServerPlayerEntity player, int pissLevel) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
new SyncPacket(pissLevel)
new Packet(pissLevel)
.encode(buf);
ServerPlayNetworking.send(player, ID, buf);
}
public record SyncPacket(int pissLevel) {
public static SyncPacket decode(PacketByteBuf buf) {
public record Packet(int pissLevel) {
public static Packet decode(PacketByteBuf buf) {
int pissLevel = buf.readInt();
return new SyncPacket(pissLevel);
return new Packet(pissLevel);
}
public void encode(PacketByteBuf buf) {

View file

@ -0,0 +1,46 @@
package me.theclashfruit.pissnshit.network;
import io.netty.buffer.Unpooled;
import me.theclashfruit.pissnshit.util.PlayerEntityUtil;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import static me.theclashfruit.pissnshit.PissAndShit.MOD_ID;
public class PissingPacket {
public static final Identifier ID = new Identifier(MOD_ID, "pissing");
public static void register() {
ServerPlayNetworking.registerGlobalReceiver(ID, (server, player, handler, buffer, responseSender) -> {
Packet packet = Packet.decode(buffer);
server.execute(() -> {
((PlayerEntityUtil) player).getPissManager().piss(packet.amount(), player);
});
});
}
public static void sentToServer(int amount) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
new Packet(1)
.encode(buf);
ClientPlayNetworking.send(ID, buf);
}
public record Packet(int amount) {
public static Packet decode(PacketByteBuf buf) {
int amount = buf.readInt();
return new Packet(amount);
}
public void encode(PacketByteBuf buf) {
buf.writeInt(amount);
}
}
}

View file

@ -1,7 +1,6 @@
package me.theclashfruit.pissnshit.network;
import io.netty.buffer.Unpooled;
import me.theclashfruit.pissnshit.util.PissManager;
import me.theclashfruit.pissnshit.util.PlayerEntityUtil;
import me.theclashfruit.pissnshit.util.ShitManager;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
@ -17,7 +16,7 @@ public class ShitSyncPacket {
public static void register() {
ClientPlayNetworking.registerGlobalReceiver(ShitSyncPacket.ID, (c, handler, buf, responseSender) -> {
ShitSyncPacket.SyncPacket packet = ShitSyncPacket.SyncPacket.decode(buf);
Packet packet = Packet.decode(buf);
c.execute(() -> {
if (c.player != null) {
@ -29,24 +28,24 @@ public class ShitSyncPacket {
});
}
public static void sendToClient(ServerPlayerEntity player, int shitLevel) {
public static void sendToClient(ServerPlayerEntity player, double shitLevel) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
new SyncPacket(shitLevel)
new Packet(shitLevel)
.encode(buf);
ServerPlayNetworking.send(player, ID, buf);
}
public record SyncPacket(int shitLevel) {
public static SyncPacket decode(PacketByteBuf buf) {
int shitLevel = buf.readInt();
public record Packet(double shitLevel) {
public static Packet decode(PacketByteBuf buf) {
double shitLevel = buf.readDouble();
return new SyncPacket(shitLevel);
return new Packet(shitLevel);
}
public void encode(PacketByteBuf buf) {
buf.writeInt(shitLevel);
buf.writeDouble(shitLevel);
}
}
}

View file

@ -0,0 +1,27 @@
package me.theclashfruit.pissnshit.registry;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.potion.Potion;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import static me.theclashfruit.pissnshit.PissAndShit.MOD_ID;
public class Potions {
public static final Potion DIARRHEA_POTION = Registry.register(
Registries.POTION,
new Identifier(MOD_ID, "diarrhea_potion"),
new Potion(
new StatusEffectInstance(
StatusEffects.DIARRHEA,
3600,
0
)
)
);
public static void init() {
}
}

View file

@ -0,0 +1,17 @@
package me.theclashfruit.pissnshit.registry;
import me.theclashfruit.pissnshit.effects.DiarrheaStatusEffect;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import static me.theclashfruit.pissnshit.PissAndShit.MOD_ID;
public class StatusEffects {
public static final StatusEffect DIARRHEA = new DiarrheaStatusEffect();
public static void init() {
Registry.register(Registries.STATUS_EFFECT, new Identifier(MOD_ID, "diarrhea"), DIARRHEA);
}
}

View file

@ -0,0 +1,15 @@
package me.theclashfruit.pissnshit.registry;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
import static me.theclashfruit.pissnshit.PissAndShit.MOD_ID;
public class Tags {
public static final TagKey<Item> GIVES_DIARRHEA = TagKey.of(RegistryKeys.ITEM, new Identifier(MOD_ID, "gives_diarrhea"));
public static final TagKey<Fluid> PISS = TagKey.of(RegistryKeys.FLUID, new Identifier(MOD_ID, "piss"));
}

View file

@ -6,6 +6,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import static me.theclashfruit.pissnshit.PissAndShit.CONFIG;
@ -15,6 +16,7 @@ public class PissManager {
private int pissTickTimer;
private long lastPissTick;
private long lastPissTime;
private final long maxInterval;
private final long minInterval;
@ -55,12 +57,34 @@ public class PissManager {
}
}
public void piss(int amount, PlayerEntity player) {
long currentWorldTicks = player.getWorld().getTime();
if ((currentWorldTicks - this.minInterval >= this.lastPissTime || currentWorldTicks - this.lastPissTime <= 10) && currentWorldTicks - this.lastPissTime >= 5) {
if (pissLevel >= 1) {
this.pissLevel -= amount;
} else {
player.sendMessage(Text.literal("You can't piss yet!"), true);
}
// Sync Piss Level
PissSyncPacket.sendToClient((ServerPlayerEntity) player, this.pissLevel);
this.lastPissTime = currentWorldTicks;
} else if (currentWorldTicks - this.lastPissTime <= 5) {
return;
} else {
player.sendMessage(Text.literal("You can't piss yet!"), true);
}
}
public void readNbt(NbtCompound nbt) {
if (nbt.contains("pissLevel", NbtElement.NUMBER_TYPE)) {
this.pissLevel = nbt.getInt("pissLevel");
this.pissTickTimer = nbt.getInt("pissTickTimer");
this.lastPissTick = nbt.getLong("lastPissTick");
this.lastPissTime = nbt.getLong("lastPissTime");
}
}
@ -69,6 +93,7 @@ public class PissManager {
nbt.putInt("pissTickTimer", this.pissTickTimer);
nbt.putLong("lastPissTick", this.lastPissTick);
nbt.putLong("lastPissTime", this.lastPissTime);
}
public int getPissLevel() {

View file

@ -2,15 +2,23 @@ package me.theclashfruit.pissnshit.util;
import me.theclashfruit.pissnshit.network.ShitSyncPacket;
import me.theclashfruit.pissnshit.registry.DamageTypes;
import me.theclashfruit.pissnshit.registry.StatusEffects;
import me.theclashfruit.pissnshit.registry.Tags;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.server.network.ServerPlayerEntity;
import static me.theclashfruit.pissnshit.PissAndShit.CONFIG;
import static me.theclashfruit.pissnshit.PissAndShit.LOGGER;
public class ShitManager {
private int shitLevel = 6;
private double shitLevel = 6;
private double foodBuffer = 0;
private int shitTickTimer;
@ -26,8 +34,15 @@ public class ShitManager {
public void update(PlayerEntity player) {
long currentWorldTicks = player.getWorld().getTime();
boolean hasDiarrhea = player.hasStatusEffect(StatusEffects.DIARRHEA);
if (currentWorldTicks - this.lastShitTick >= this.minInterval * 0.1) {
if (foodBuffer > 0) {
double food = hasDiarrhea ? foodBuffer * 0.5 : foodBuffer * 0.1;
shitLevel += food;
foodBuffer -= food;
}
// Sync Shit Level
ShitSyncPacket.sendToClient((ServerPlayerEntity) player, this.shitLevel);
@ -48,27 +63,45 @@ public class ShitManager {
}
}
public void eat(ItemStack stack, PlayerEntity player) {
Item item = stack.getItem();
FoodComponent foodComponent = item.getFoodComponent();
if (foodComponent != null)
foodBuffer += foodComponent.getHunger();
if (stack.isIn(Tags.GIVES_DIARRHEA)) {
player.addStatusEffect(
new StatusEffectInstance(StatusEffects.DIARRHEA, 1800)
);
}
}
public void readNbt(NbtCompound nbt) {
if (nbt.contains("pissLevel", NbtElement.NUMBER_TYPE)) {
this.shitLevel = nbt.getInt("shitLevel");
if (nbt.contains("shitLevel", NbtElement.NUMBER_TYPE)) {
this.shitTickTimer = nbt.getInt("shitTickTimer");
this.lastShitTick = nbt.getLong("lastShitTick");
this.shitLevel = nbt.getDouble("shitLevel");
this.foodBuffer = nbt.getDouble("shitBuffer");
}
}
public void writeNbt(NbtCompound nbt) {
nbt.putInt("shitLevel", this.shitLevel);
nbt.putInt("shitTickTimer", this.shitTickTimer);
nbt.putLong("lastShitTick", this.lastShitTick);
nbt.putDouble("shitLevel", this.shitLevel);
nbt.putDouble("shitBuffer", this.foodBuffer);
}
public int getShitLevel() {
public double getShitLevel() {
return this.shitLevel;
}
public void setShitLevel(int shitLevel) {
public void setShitLevel(double shitLevel) {
this.shitLevel = shitLevel;
}
}

View file

@ -13,6 +13,14 @@
"block.pissnshit.mechanical_sanctifier": "Mechanical Sanctifier",
"effect.pissnshit.diarrhea": "Diarrhea",
"item.minecraft.potion.effect.diarrhea_potion": "Potion of Diarrhea",
"item.minecraft.splash_potion.effect.diarrhea_potion": "Splash Potion of Diarrhea",
"item.minecraft.lingering_potion.effect.diarrhea_potion": "Lingering Potion of Diarrhea",
"item.minecraft.tipped_arrow.effect.diarrhea_potion": "Arrow of Diarrhea",
"death.attack.fullOfPiss": "%1$s got full of piss.",
"death.attack.fullOfShit": "%1$s got full of shit.",

View file

@ -1,5 +1,4 @@
{
"replace": false,
"values": [
"pissnshit:piss",
"pissnshit:flowing_piss"

View file

@ -0,0 +1,5 @@
{
"values": [
"minecraft:cookie"
]
}

View file

@ -0,0 +1,14 @@
{
"values": [
"minecraft:milk_bucket",
"minecraft:cake",
"minecraft:poisonous_potato",
"minecraft:rotten_flesh",
"minecraft:spider_eye",
"minecraft:beef",
"minecraft:porkchop",
"minecraft:mutton",
"minecraft:chicken",
"minecraft:rabbit"
]
}