package com.dairymoose.modernlife.core;

import com.dairymoose.modernlife.blocks.ModernBookshelfBlock;
import com.dairymoose.modernlife.blocks.OakPostBlock;
import com.dairymoose.modernlife.items.CameraItem;
import com.dairymoose.modernlife.items.FlashlightItem;
import com.dairymoose.modernlife.network.play.client.ClientboundBulletHolePacket;
import com.dairymoose.modernlife.network.play.client.ClientboundFlashlightUpdatePacket;
import com.dairymoose.modernlife.network.play.client.ClientboundMultipartCanvasPacket;
import com.dairymoose.modernlife.network.play.client.ClientboundWinchDummyPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundBikeDismountPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundBookCancelPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundCameraPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundCanvasChecksumPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundCanvasCopyRequestPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundCanvasPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundChainsawTargetPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundChessStatePacket;
import com.dairymoose.modernlife.network.play.client.ServerboundFuelLevelPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundGuitarPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundHitscanPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundMultipartCameraPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundMultipartEaselPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundPrintSizePacket;
import com.dairymoose.modernlife.network.play.client.ServerboundRadiatorPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundRequestCanvasPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundStopUsingCameraPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundTrashCanPacket;
import com.dairymoose.modernlife.network.play.client.ServerboundWirelessChannelPacket;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.PauseScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.NonNullList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.storage.LevelResource;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.item.ItemExpireEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/* loaded from: outputsrg.jar:com/dairymoose/modernlife/core/ModernLifeCommon.class */
public class ModernLifeCommon {
    public static final String MODID = "modernlife";
    private BlockItem itemOakPost;
    private OakPostBlock blockOakPost;
    private static ModernLifeCraftingFlags craftingFlags;
    public static int winchTickCounter = 0;
    public static int clientTickCounter = 0;
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "modernlife");
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "modernlife");
    public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, "modernlife");
    public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, "modernlife");
    public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, "modernlife");
    public static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, "modernlife");
    public static final Logger LOGGER = LogManager.getLogger();
    private static long nextUniqueCanvasId = 1;
    public static int FLASHLIGHT_DURATION_MINUTES = 25;
    public static String ServerLevelFolderName = null;
    private int flashlightTickCounter = 0;
    private int speedometerTickCounter = 0;
    private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    private final boolean shouldUseNotifyNeighborLogic = false;
    Queue<BlockEvent.NeighborNotifyEvent> snowEvents = new LinkedList();
    private boolean awaitingBookScreenCancel = false;
    AbstractContainerMenu lastContainer = null;
    public boolean isFloating = false;
    public Vec3 lastPos = null;

    public ModernLifeCommon() {
        LOGGER.debug(CustomBlocks.BLOCK_RADIATOR);
        ModernLifeConfigPrepopulator prepop = new ModernLifeConfigPrepopulator();
        prepop.parseFile("modernlife", "common", ModernLifeConfig.COMMON.flashlightLightLevel, ModernLifeConfig.COMMON.flashlightFullChargeDuration);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        MinecraftForge.EVENT_BUS.register(this);
        craftingFlags = new ModernLifeCraftingFlags();
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ModernLifeConfig.commonSpec);
        ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ModernLifeConfig.clientSpec);
        ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ModernLifeConfig.serverSpec);
        Integer durationConfig = ModernLifeConfig.COMMON.flashlightFullChargeDuration.getValue();
        if (durationConfig != null) {
            FLASHLIGHT_DURATION_MINUTES = durationConfig.intValue();
        }
        BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
        BLOCK_ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
        SOUND_EVENTS.register(FMLJavaModLoadingContext.get().getModEventBus());
        ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
        CONTAINERS.register(FMLJavaModLoadingContext.get().getModEventBus());
        int msgId = 0 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(0, ServerboundCanvasPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundCanvasPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId2 = msgId + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId, ServerboundGuitarPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundGuitarPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId3 = msgId2 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId2, ServerboundWirelessChannelPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundWirelessChannelPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId4 = msgId3 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId3, ServerboundBikeDismountPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundBikeDismountPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId5 = msgId4 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId4, ServerboundTrashCanPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundTrashCanPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId6 = msgId5 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId5, ServerboundChainsawTargetPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundChainsawTargetPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId7 = msgId6 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId6, ServerboundRadiatorPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundRadiatorPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId8 = msgId7 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId7, ClientboundFlashlightUpdatePacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ClientboundFlashlightUpdatePacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId9 = msgId8 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId8, ServerboundChessStatePacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundChessStatePacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId10 = msgId9 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId9, ServerboundCameraPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundCameraPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId11 = msgId10 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId10, ServerboundMultipartCameraPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundMultipartCameraPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId12 = msgId11 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId11, ServerboundMultipartEaselPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundMultipartEaselPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId13 = msgId12 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId12, ClientboundMultipartCanvasPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ClientboundMultipartCanvasPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId14 = msgId13 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId13, ServerboundRequestCanvasPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundRequestCanvasPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId15 = msgId14 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId14, ServerboundPrintSizePacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundPrintSizePacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId16 = msgId15 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId15, ServerboundStopUsingCameraPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundStopUsingCameraPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId17 = msgId16 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId16, ServerboundHitscanPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundHitscanPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId18 = msgId17 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId17, ClientboundBulletHolePacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ClientboundBulletHolePacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId19 = msgId18 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId18, ServerboundFuelLevelPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundFuelLevelPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId20 = msgId19 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId19, ClientboundWinchDummyPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ClientboundWinchDummyPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId21 = msgId20 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId20, ServerboundBookCancelPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundBookCancelPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int msgId22 = msgId21 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId21, ServerboundCanvasCopyRequestPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundCanvasCopyRequestPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
        int i = msgId22 + 1;
        ModernLifeNetwork.INSTANCE.registerMessage(msgId22, ServerboundCanvasChecksumPacket.class, (v0, v1) -> {
            v0.write(v1);
        }, ServerboundCanvasChecksumPacket::new, (v0, v1) -> {
            v0.handle(v1);
        });
    }

    private void setup(FMLCommonSetupEvent event) {
        ModernLifeConfig.reinit();
    }

    public int materialColorToTintColor(int materialColorRgb) {
        int r = materialColorRgb & 255;
        int g = (materialColorRgb & 65280) >> 8;
        int b = (materialColorRgb & 16711680) >> 16;
        return (materialColorRgb & (-16777216)) | (r << 16) | (g << 8) | b;
    }

    @SubscribeEvent
    public void onInteractEventServer(PlayerInteractEvent interactEvent) {
        ItemStack itemStack;
        if (!interactEvent.getWorld().isClientSide) {
            Boolean result = CameraItem.usingCameraServer.get(interactEvent.getPlayer());
            if (result != null && result.booleanValue() && !(interactEvent instanceof PlayerInteractEvent.RightClickItem) && interactEvent != null && interactEvent.isCancelable()) {
                interactEvent.setCanceled(true);
            }
            if (interactEvent.getPlayer() != null && (itemStack = interactEvent.getPlayer().getMainHandItem()) != null && itemStack.getItem() == CustomBlocks.ITEM_HANDGUN.get()) {
                if (((interactEvent instanceof PlayerInteractEvent.LeftClickBlock) || (interactEvent instanceof PlayerInteractEvent.LeftClickEmpty)) && interactEvent != null && interactEvent.isCancelable()) {
                    interactEvent.setCanceled(true);
                }
            }
        }
    }

    @SubscribeEvent
    public void onAttackEvent(AttackEntityEvent e) {
        ItemStack itemStack;
        if (e.getPlayer() != null && (itemStack = e.getPlayer().getMainHandItem()) != null && itemStack.getItem() == CustomBlocks.ITEM_HANDGUN.get() && e != null && e.isCancelable()) {
            e.setCanceled(true);
        }
    }

    @SubscribeEvent
    public void onServerTick(TickEvent.ServerTickEvent serverTick) {
        if (serverTick.phase == TickEvent.Phase.START && BlockVolume.dummy != null) {
            Vec3 dummyPos = BlockVolume.dummy.position();
            double newDummyY = dummyPos.y + 0.125d;
            BlockVolume.dummy.setPacketCoordinates(dummyPos.x, newDummyY, dummyPos.z);
        }
        if (serverTick.phase == TickEvent.Phase.END) {
            this.flashlightTickCounter++;
            winchTickCounter++;
        }
    }

    private void cleanupCanvasData(ItemStack itemStack) {
        if ((itemStack != null) & (itemStack.getItem() == CustomBlocks.ITEM_CANVAS.get())) {
            LOGGER.debug("cleanup canvas data");
            if (itemStack.getTag() != null && itemStack.getTag().contains("UniqueId")) {
                long uniqueId = itemStack.getTag().getLong("UniqueId");
                ServerboundMultipartCameraPacket.deletePng(uniqueId);
            }
        }
    }

    @SubscribeEvent
    public void onItemDestroyedEvent(PlayerDestroyItemEvent destroyEvent) {
        if (destroyEvent != null) {
            destroyEvent.getOriginal();
        }
    }

    @SubscribeEvent
    public void onItemExpiredEvent(ItemExpireEvent expireEvent) {
        if (expireEvent.getEntityItem() != null) {
            expireEvent.getEntityItem().getItem();
        }
    }

    @OnlyIn(Dist.CLIENT)
    @SubscribeEvent
    public void onClientTick(TickEvent.ClientTickEvent clientTick) {
        if (clientTick.phase == TickEvent.Phase.START) {
            clientTickCounter++;
        }
        if (clientTick.phase == TickEvent.Phase.END) {
            this.speedometerTickCounter++;
        }
    }

    private void awaitBookInHand(Player player) {
        if (player.level.isClientSide && ModernBookshelfBlock.clientAwaitingBook != null) {
            ItemStack pickedBook = ModernBookshelfBlock.clientAwaitingBook;
            if (ItemStack.isSameItemSameTags(pickedBook, player.getItemInHand(InteractionHand.MAIN_HAND))) {
                ModernBookshelfBlock.clientAwaitingBook = null;
                try {
                    pickedBook.use(player.level, player, InteractionHand.MAIN_HAND);
                } catch (Exception e) {
                    LOGGER.error("Use book error", e);
                }
            }
        }
    }

    private void awaitBookScreen(Player player) {
        if (player.level.isClientSide) {
            Screen screen = Minecraft.getInstance().screen;
            if (this.awaitingBookScreenCancel && screen == null) {
                this.awaitingBookScreenCancel = false;
                ServerboundBookCancelPacket bookCancelPacket = new ServerboundBookCancelPacket(ModernBookshelfBlock.oldItemSlot, ModernBookshelfBlock.lastBlockPos);
                ModernLifeNetwork.INSTANCE.sendToServer(bookCancelPacket);
                return;
            }
            long timestamp = System.currentTimeMillis();
            long timeDiff = timestamp - ModernBookshelfBlock.usedBookTimestamp;
            if (screen != null && timeDiff <= 1000 && !(screen instanceof PauseScreen)) {
                ModernBookshelfBlock.usedBookTimestamp = 0L;
                this.awaitingBookScreenCancel = true;
            }
        }
    }

    private void requestContainerImages(Player player) {
        AbstractContainerMenu menu;
        if (player.level.isClientSide && player == Minecraft.getInstance().player && (menu = player.containerMenu) != null && menu != this.lastContainer) {
            this.lastContainer = menu;
            LOGGER.debug("check container for images: " + menu);
            NonNullList<ItemStack> items = menu.getItems();
            if (items != null) {
                for (int i = 0; i < items.size(); i++) {
                    ItemStack itemStack = (ItemStack) items.get(i);
                    if (itemStack != null && itemStack.getItem() == CustomBlocks.ITEM_CANVAS.get() && itemStack.getTag() != null && itemStack.getTag().contains("UniqueId")) {
                        long uniqueId = itemStack.getTag().getLong("UniqueId");
                        ModernLifeClient.getCanvasData(uniqueId);
                    }
                }
            }
        }
    }

    @SubscribeEvent
    public void playerTickEvent(TickEvent.PlayerTickEvent pte) {
        if (pte.side == LogicalSide.SERVER && pte.phase == TickEvent.Phase.START && !pte.player.level.isClientSide) {
            LivingEntity livingEntity = pte.player;
            Boolean result = FlashlightItem.usingFlashlight.get(livingEntity);
            if (result != null && result.booleanValue()) {
                ItemStack flashlight = null;
                if (livingEntity.getMainHandItem().getItem().equals(CustomBlocks.ITEM_FLASHLIGHT.get())) {
                    flashlight = livingEntity.getMainHandItem();
                } else if (livingEntity.getOffhandItem().getItem().equals(CustomBlocks.ITEM_FLASHLIGHT.get())) {
                    flashlight = livingEntity.getOffhandItem();
                }
                if (flashlight != null) {
                    CustomBlocks.ITEM_FLASHLIGHT.get().onUsingTick(flashlight, livingEntity, this.flashlightTickCounter);
                } else {
                    CustomBlocks.ITEM_FLASHLIGHT.get().removePhoton(livingEntity);
                }
            }
        } else if (pte.side == LogicalSide.CLIENT && pte.phase == TickEvent.Phase.START && pte.player.level.isClientSide) {
            if (BlockVolume.shouldFloat) {
                Vec3 delta = pte.player.getDeltaMovement();
                if (!this.isFloating) {
                    this.isFloating = true;
                    pte.player.setDeltaMovement(delta.x, 0.125d, delta.z);
                } else {
                    pte.player.setDeltaMovement(delta.x, 0.125d, delta.z);
                }
            } else {
                this.isFloating = false;
            }
            awaitBookInHand(pte.player);
            requestContainerImages(pte.player);
            awaitBookScreen(pte.player);
            Player player = pte.player;
            ItemStack speedometer = null;
            if (player.getMainHandItem().getItem().equals(CustomBlocks.ITEM_SPEEDOMETER.get())) {
                speedometer = player.getMainHandItem();
            } else if (player.getOffhandItem().getItem().equals(CustomBlocks.ITEM_SPEEDOMETER.get())) {
                speedometer = player.getOffhandItem();
            }
            if (speedometer != null && pte.player.equals(Minecraft.getInstance().player)) {
                CustomBlocks.ITEM_SPEEDOMETER.get().onUsingTick(speedometer, player, this.speedometerTickCounter);
            }
        }
        if (pte.side == LogicalSide.CLIENT && pte.phase == TickEvent.Phase.START && pte.player.level.isClientSide && Minecraft.getInstance().player == pte.player && BlockVolume.dummy != null) {
            Vec3 dummyPos = BlockVolume.dummy.position();
            double newDummyY = dummyPos.y + 0.125d;
            BlockVolume.dummy.absMoveTo(dummyPos.x, newDummyY, dummyPos.z);
            Vec3 currentPos = pte.player.position();
            Vec3 solidGround = BlockVolume.dummy.getEntitySolidGround(pte.player);
            boolean didCollide = false;
            double posX = currentPos.x;
            double posY = currentPos.y;
            double posZ = currentPos.z;
            if (BlockVolume.dummy.isEntityColliding(pte.player)) {
                didCollide = true;
                if (this.lastPos != null) {
                    posX = this.lastPos.x;
                    posY = this.lastPos.y;
                    posZ = this.lastPos.z;
                }
            }
            if (solidGround != null) {
                pte.player.setOnGround(true);
                pte.player.absMoveTo(posX, solidGround.y, posZ);
                pte.player.resetFallDistance();
                Vec3 delta2 = pte.player.getDeltaMovement();
                pte.player.setDeltaMovement(delta2.x, 0.0d, delta2.z);
            } else if (didCollide) {
                pte.player.absMoveTo(posX, posY, posZ);
            }
            if (!didCollide) {
                this.lastPos = currentPos;
            }
        }
    }

    public static synchronized long getNextCanvasId() {
        long toReturn = nextUniqueCanvasId;
        nextUniqueCanvasId = toReturn + 1;
        String subFolder = ServerboundMultipartCameraPacket.getSubFolderPrepend();
        File canvasInfo = new File(subFolder + "canvasInfo.txt");
        try {
            FileWriter fw = new FileWriter(canvasInfo);
            String toWrite = String.valueOf(nextUniqueCanvasId);
            fw.write(toWrite);
            fw.close();
        } catch (IOException e) {
            LOGGER.debug("Error writing to canvasInfo.txt");
        }
        return toReturn;
    }

    public static void ensureDirectory(String directory) {
    }

    @SubscribeEvent
    public void onServerStarting(ServerStartingEvent event) {
        Path path;
        if (event != null && event.getServer() != null && (path = event.getServer().getWorldPath(LevelResource.ROOT)) != null) {
            ServerLevelFolderName = path.toString();
            if (!ServerLevelFolderName.isEmpty()) {
                ServerLevelFolderName = ServerLevelFolderName.replace('\\', '/');
                if (!ServerLevelFolderName.endsWith("/")) {
                    ServerLevelFolderName += "/";
                }
            }
        }
        String subFolder = ServerboundMultipartCameraPacket.getSubFolderPrepend();
        LOGGER.debug("use folder: " + subFolder);
        File canvasInfo = new File(subFolder + "canvasInfo.txt");
        if (canvasInfo.exists()) {
            try {
                FileReader fr = new FileReader(canvasInfo);
                BufferedReader br = new BufferedReader(fr);
                String line = br.readLine();
                nextUniqueCanvasId = Long.valueOf(line).longValue();
            } catch (IOException | NumberFormatException e) {
                LOGGER.error("canvasInfo.txt not found", e);
            }
        }
    }

    @SubscribeEvent
    public void onServerStopping(ServerStoppingEvent event) {
    }

    @SubscribeEvent
    public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
        ServerPlayer player = event.getPlayer();
        if (player instanceof ServerPlayer) {
            ServerPlayer serverPlayer = player;
            MinecraftServer server = serverPlayer.getServer();
            Collection<Recipe<?>> recipes = server.getRecipeManager().getRecipes();
            List<Recipe<?>> modRecipes = new ArrayList<>();
            for (Recipe<?> recipe : recipes) {
                if ("modernlife".equals(recipe.getId().getNamespace())) {
                    modRecipes.add(recipe);
                }
            }
            serverPlayer.awardRecipes(modRecipes);
        }
    }

    @SubscribeEvent
    public void onNotifyNeighbor(BlockEvent.NeighborNotifyEvent event) {
        try {
            Block updatedBlock = event.getWorld().getBlockState(event.getPos()).getBlock();
            if (updatedBlock != null) {
                updatedBlock.getRegistryName().getPath();
            }
        } catch (Exception e) {
            LOGGER.error("Error while checking block in onNotifyNeighbor");
        }
        if (event.getWorld() instanceof ServerLevel) {
            event.getWorld();
        }
    }

    public static int getHashCodeForBytes(byte[] data) {
        return Arrays.hashCode(data);
    }

    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/core/ModernLifeCommon$RegistryEvents.class */
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(RegistryEvent.Register<Block> blockRegistryEvent) {
            ModernLifeCommon.LOGGER.debug("HELLO from Register Block");
        }
    }
}
