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

feat: implement shit

This commit is contained in:
TheClashFruit 2024-07-28 21:25:19 +02:00
parent 8fa0840784
commit 55923b0119
Signed by: TheClashFruit
GPG key ID: 09BB24C34C2F3204
6 changed files with 131 additions and 8 deletions

View file

@ -2,6 +2,7 @@ package me.theclashfruit.pissnshit.client;
import me.theclashfruit.pissnshit.client.gui.PissAndShitHudOverlay;
import me.theclashfruit.pissnshit.network.PissSyncPacket;
import me.theclashfruit.pissnshit.network.ShitSyncPacket;
import me.theclashfruit.pissnshit.registry.Fluids;
import me.theclashfruit.pissnshit.util.PissManager;
import me.theclashfruit.pissnshit.util.PlayerEntityUtil;
@ -37,5 +38,6 @@ public class PissAndShitClient implements ClientModInitializer {
// Register Packets
PissSyncPacket.register();
ShitSyncPacket.register();
}
}

View file

@ -14,14 +14,8 @@ public class PissAndShitHudOverlay implements Drawable {
private final MinecraftClient client;
private final int randFirst;
private final int randSecond;
public PissAndShitHudOverlay(MinecraftClient client) {
this.client = client;
this.randFirst = (int) (Math.random() * 100);
this.randSecond = (int) (Math.random() * 100);
}
@Override
@ -40,7 +34,7 @@ public class PissAndShitHudOverlay implements Drawable {
int fullPissIcons = pissLevel / 10;
int remainingPissLevel = pissLevel - (fullPissIcons * 10);
int shitLevel = this.randSecond;
int shitLevel = ((PlayerEntityUtil) this.client.player).getShitManager().getShitLevel();
int fullShitIcons = shitLevel / 10;
int remainingShitLevel = shitLevel - (fullShitIcons * 10);

View file

@ -25,6 +25,7 @@ public class PlayerEntityMixin implements PlayerEntityUtil {
public void tick(CallbackInfo ci) {
if (!((PlayerEntity) (Object) this).getWorld().isClient) {
pissManager.update(((PlayerEntity) (Object) this));
shitManager.update(((PlayerEntity) (Object) this));
}
}
@ -37,6 +38,7 @@ public class PlayerEntityMixin implements PlayerEntityUtil {
)
public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) {
pissManager.writeNbt(nbt);
shitManager.writeNbt(nbt);
}
@Inject(
@ -45,6 +47,7 @@ public class PlayerEntityMixin implements PlayerEntityUtil {
)
public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
pissManager.readNbt(nbt);
shitManager.readNbt(nbt);
}

View file

@ -0,0 +1,52 @@
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;
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 ShitSyncPacket {
public static final Identifier ID = new Identifier(MOD_ID, "shit_sync");
public static void register() {
ClientPlayNetworking.registerGlobalReceiver(ShitSyncPacket.ID, (c, handler, buf, responseSender) -> {
ShitSyncPacket.SyncPacket packet = ShitSyncPacket.SyncPacket.decode(buf);
c.execute(() -> {
if (c.player != null) {
ShitManager shitManager = ((PlayerEntityUtil) c.player).getShitManager();
shitManager.setShitLevel(packet.shitLevel());
}
});
});
}
public static void sendToClient(ServerPlayerEntity player, int shitLevel) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
new SyncPacket(shitLevel)
.encode(buf);
ServerPlayNetworking.send(player, ID, buf);
}
public record SyncPacket(int shitLevel) {
public static SyncPacket decode(PacketByteBuf buf) {
int shitLevel = buf.readInt();
return new SyncPacket(shitLevel);
}
public void encode(PacketByteBuf buf) {
buf.writeInt(shitLevel);
}
}
}

View file

@ -10,7 +10,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import static me.theclashfruit.pissnshit.PissAndShit.CONFIG;
public class PissManager {
private int pissLevel = 15;
private int pissLevel = 16;
private int pissTickTimer;
@ -59,6 +59,7 @@ public class PissManager {
if (nbt.contains("pissLevel", NbtElement.NUMBER_TYPE)) {
this.pissLevel = nbt.getInt("pissLevel");
this.pissTickTimer = nbt.getInt("pissTickTimer");
this.lastPissTick = nbt.getLong("lastPissTick");
}
}
@ -66,6 +67,7 @@ public class PissManager {
public void writeNbt(NbtCompound nbt) {
nbt.putInt("pissLevel", this.pissLevel);
nbt.putInt("pissTickTimer", this.pissTickTimer);
nbt.putLong("lastPissTick", this.lastPissTick);
}

View file

@ -1,4 +1,74 @@
package me.theclashfruit.pissnshit.util;
import me.theclashfruit.pissnshit.network.ShitSyncPacket;
import me.theclashfruit.pissnshit.registry.DamageTypes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.server.network.ServerPlayerEntity;
import static me.theclashfruit.pissnshit.PissAndShit.CONFIG;
public class ShitManager {
private int shitLevel = 6;
private int shitTickTimer;
private long lastShitTick;
private final long maxInterval;
private final long minInterval;
public ShitManager() {
this.maxInterval = CONFIG.shittingMechanics.maxIntervalTicks;
this.minInterval = CONFIG.shittingMechanics.minIntervalTicks;
}
public void update(PlayerEntity player) {
long currentWorldTicks = player.getWorld().getTime();
if (currentWorldTicks - this.lastShitTick >= this.minInterval * 0.1) {
// Sync Shit Level
ShitSyncPacket.sendToClient((ServerPlayerEntity) player, this.shitLevel);
this.lastShitTick = currentWorldTicks;
}
if (this.shitLevel >= 100) {
this.shitTickTimer++;
if (this.shitTickTimer >= 80) {
player.damage(DamageTypes.of(player.getWorld(), DamageTypes.FULL_OF_SHIT), 3f);
this.shitTickTimer = 0;
}
} else {
this.shitTickTimer = 0;
}
}
public void readNbt(NbtCompound nbt) {
if (nbt.contains("pissLevel", NbtElement.NUMBER_TYPE)) {
this.shitLevel = nbt.getInt("shitLevel");
this.shitTickTimer = nbt.getInt("shitTickTimer");
this.lastShitTick = nbt.getLong("lastShitTick");
}
}
public void writeNbt(NbtCompound nbt) {
nbt.putInt("shitLevel", this.shitLevel);
nbt.putInt("shitTickTimer", this.shitTickTimer);
nbt.putLong("lastShitTick", this.lastShitTick);
}
public int getShitLevel() {
return this.shitLevel;
}
public void setShitLevel(int shitLevel) {
this.shitLevel = shitLevel;
}
}