mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 11:29:23 +01:00
Fix server crashes on boot
This commit is contained in:
parent
f32f7187cc
commit
844efe4260
6 changed files with 99 additions and 77 deletions
|
@ -35,7 +35,6 @@ import de.ellpeck.actuallyadditions.mod.misc.apiimpl.LaserRelayConnectionHandler
|
|||
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.MethodHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.particle.ActuallyParticles;
|
||||
import de.ellpeck.actuallyadditions.mod.update.UpdateChecker;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ResourceReloader;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -129,7 +128,7 @@ public class ActuallyAdditions {
|
|||
|
||||
commonCapsLoaded = false; // Loader.isModLoaded("commoncapabilities");
|
||||
|
||||
new UpdateChecker();
|
||||
// new UpdateChecker();
|
||||
}
|
||||
|
||||
private void onConfigReload(ModConfigEvent event) {
|
||||
|
|
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.event;
|
|||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import de.ellpeck.actuallyadditions.api.misc.IGoggles;
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay;
|
||||
import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
|
||||
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
||||
|
@ -23,6 +24,7 @@ import de.ellpeck.actuallyadditions.mod.tile.IEnergyDisplay;
|
|||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
import io.netty.util.internal.ConcurrentSet;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
|
@ -30,12 +32,14 @@ import net.minecraft.client.gui.GuiGraphics;
|
|||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
@ -47,6 +51,7 @@ import net.neoforged.neoforge.client.gui.VanillaGuiLayers;
|
|||
import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class ClientEvents {
|
||||
|
@ -64,6 +69,52 @@ public class ClientEvents {
|
|||
if (mc.level == null) {
|
||||
WorldData.clear();
|
||||
}
|
||||
|
||||
if (mc.player != null) {
|
||||
renderEngineerEffect(mc.player);
|
||||
}
|
||||
}
|
||||
|
||||
private final Set<Entity> cachedGlowingEntities = new ConcurrentSet<>();
|
||||
|
||||
/**
|
||||
* Renders a special visual effect for entities around the player if the player is wearing goggles that allow them to see spectral mobs.
|
||||
*
|
||||
* @param player The player wearing the goggles.
|
||||
*/
|
||||
private void renderEngineerEffect(Player player) {
|
||||
ItemStack face = player.getInventory().armor.get(3);
|
||||
if (player != null && !face.isEmpty() && face.getItem() instanceof IGoggles goggles && goggles.displaySpectralMobs()) {
|
||||
double range = 8;
|
||||
AABB aabb = new AABB(player.getX() - range, player.getY() - range, player.getZ() - range, player.getX() + range, player.getY() + range, player.getZ() + range);
|
||||
List<Entity> entities = player.level().getEntitiesOfClass(Entity.class, aabb);
|
||||
if (entities != null && !entities.isEmpty()) {
|
||||
this.cachedGlowingEntities.addAll(entities);
|
||||
}
|
||||
|
||||
if (!this.cachedGlowingEntities.isEmpty()) {
|
||||
for (Entity entity : this.cachedGlowingEntities) {
|
||||
if (!entity.isAlive() || entity.distanceToSqr(player.getX(), player.getY(), player.getZ()) > range * range) {
|
||||
entity.setGlowingTag(false);
|
||||
|
||||
this.cachedGlowingEntities.remove(entity);
|
||||
} else {
|
||||
entity.setGlowingTag(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.cachedGlowingEntities.isEmpty()) {
|
||||
for (Entity entity : this.cachedGlowingEntities) {
|
||||
if (entity.isAlive()) {
|
||||
entity.setGlowingTag(false);
|
||||
}
|
||||
}
|
||||
this.cachedGlowingEntities.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
@ -29,18 +29,11 @@ import java.util.Set;
|
|||
|
||||
public class ItemEngineerGoggles extends ItemArmorAA implements IGoggles {
|
||||
|
||||
private final Set<Entity> cachedGlowingEntities = new ConcurrentSet<>();
|
||||
|
||||
private final boolean displayMobs;
|
||||
|
||||
public ItemEngineerGoggles(boolean displayMobs) {
|
||||
super(ArmorMaterials.GOGGLES, Type.HELMET, ActuallyItems.defaultProps().setNoRepair().durability(0));
|
||||
this.displayMobs = displayMobs;
|
||||
|
||||
if (FMLEnvironment.dist.isClient()) {
|
||||
NeoForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean isWearing(Player player) {
|
||||
|
@ -48,46 +41,6 @@ public class ItemEngineerGoggles extends ItemArmorAA implements IGoggles {
|
|||
return !face.isEmpty() && face.getItem() instanceof IGoggles;
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientTick(ClientTickEvent.Post event) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player != null && isWearing(player)) {
|
||||
ItemStack face = player.getInventory().armor.get(3);
|
||||
if (((IGoggles) face.getItem()).displaySpectralMobs()) {
|
||||
double range = 8;
|
||||
AABB aabb = new AABB(player.getX() - range, player.getY() - range, player.getZ() - range, player.getX() + range, player.getY() + range, player.getZ() + range);
|
||||
List<Entity> entities = player.level().getEntitiesOfClass(Entity.class, aabb);
|
||||
if (entities != null && !entities.isEmpty()) {
|
||||
this.cachedGlowingEntities.addAll(entities);
|
||||
}
|
||||
|
||||
if (!this.cachedGlowingEntities.isEmpty()) {
|
||||
for (Entity entity : this.cachedGlowingEntities) {
|
||||
if (!entity.isAlive() || entity.distanceToSqr(player.getX(), player.getY(), player.getZ()) > range * range) {
|
||||
entity.setGlowingTag(false);
|
||||
|
||||
this.cachedGlowingEntities.remove(entity);
|
||||
} else {
|
||||
entity.setGlowingTag(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.cachedGlowingEntities.isEmpty()) {
|
||||
for (Entity entity : this.cachedGlowingEntities) {
|
||||
if (entity.isAlive()) {
|
||||
entity.setGlowingTag(false);
|
||||
}
|
||||
}
|
||||
this.cachedGlowingEntities.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean displaySpectralMobs() {
|
||||
return this.displayMobs;
|
||||
|
|
|
@ -16,10 +16,7 @@ import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
|||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
|
||||
import de.ellpeck.actuallyadditions.mod.network.gui.IStringReactor;
|
||||
import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -28,9 +25,9 @@ import net.minecraft.resources.ResourceLocation;
|
|||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.neoforged.fml.loading.FMLEnvironment;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||
|
@ -43,41 +40,24 @@ public final class PacketHandler {
|
|||
public static final List<IDataHandler> DATA_HANDLERS = new ArrayList<>();
|
||||
public static final IDataHandler LASER_HANDLER = new IDataHandler() {
|
||||
@Override
|
||||
|
||||
public void handleData(CompoundTag compound, IPayloadContext context) {
|
||||
AssetUtil.spawnLaserWithTimeClient(compound.getDouble("StartX"), compound.getDouble("StartY"), compound.getDouble("StartZ"), compound.getDouble("EndX"), compound.getDouble("EndY"), compound.getDouble("EndZ"), compound.getInt("Color"), compound.getInt("MaxAge"), compound.getDouble("RotationTime"), compound.getFloat("Size"), compound.getFloat("Alpha"));
|
||||
}
|
||||
};
|
||||
public static final IDataHandler TILE_ENTITY_HANDLER = new IDataHandler() {
|
||||
@Override
|
||||
|
||||
public void handleData(CompoundTag compound, IPayloadContext context) {
|
||||
Level world = Minecraft.getInstance().level;
|
||||
if (world != null) {
|
||||
BlockEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
||||
if (tile instanceof TileEntityBase) {
|
||||
((TileEntityBase) tile).readSyncableNBT(compound.getCompound("Data"), world.registryAccess(), TileEntityBase.NBTType.SYNC);
|
||||
}
|
||||
if (FMLEnvironment.dist.isClient()) {
|
||||
PacketHandlerClient.handleTileUpdate(compound, context);
|
||||
}
|
||||
}
|
||||
};
|
||||
public static final IDataHandler LASER_PARTICLE_HANDLER = new IDataHandler() {
|
||||
@Override
|
||||
|
||||
public void handleData(CompoundTag compound, IPayloadContext context) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
ItemStack stack = ItemStack.parseOptional(context.player().registryAccess(), compound);
|
||||
|
||||
double inX = compound.getDouble("InX") + 0.5;
|
||||
double inY = compound.getDouble("InY") + 0.78;
|
||||
double inZ = compound.getDouble("InZ") + 0.5;
|
||||
|
||||
double outX = compound.getDouble("OutX") + 0.5;
|
||||
double outY = compound.getDouble("OutY") + 0.525;
|
||||
double outZ = compound.getDouble("OutZ") + 0.5;
|
||||
|
||||
mc.level.addParticle(ParticleLaserItem.Factory.createData(stack, inX, inY, inZ),
|
||||
outX, outY, outZ, 0, 0.025, 0);
|
||||
if (FMLEnvironment.dist.isClient()) {
|
||||
PacketHandlerClient.handleLaserParticle(compound, context);
|
||||
}
|
||||
}
|
||||
};
|
||||
public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = (compound, context) -> {
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package de.ellpeck.actuallyadditions.mod.network;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
|
||||
public final class PacketHandlerClient {
|
||||
public static void handleTileUpdate(CompoundTag compound, IPayloadContext context) {
|
||||
Level world = Minecraft.getInstance().level;
|
||||
if (world != null) {
|
||||
BlockEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
||||
if (tile instanceof TileEntityBase tileBase) {
|
||||
tileBase.readSyncableNBT(compound.getCompound("Data"), world.registryAccess(), TileEntityBase.NBTType.SYNC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleLaserParticle(CompoundTag compound, IPayloadContext context) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
ItemStack stack = ItemStack.parseOptional(context.player().registryAccess(), compound);
|
||||
|
||||
double inX = compound.getDouble("InX") + 0.5;
|
||||
double inY = compound.getDouble("InY") + 0.78;
|
||||
double inZ = compound.getDouble("InZ") + 0.5;
|
||||
|
||||
double outX = compound.getDouble("OutX") + 0.5;
|
||||
double outY = compound.getDouble("OutY") + 0.525;
|
||||
double outZ = compound.getDouble("OutZ") + 0.5;
|
||||
|
||||
mc.level.addParticle(ParticleLaserItem.Factory.createData(stack, inX, inY, inZ),
|
||||
outX, outY, outZ, 0, 0.025, 0);
|
||||
}
|
||||
}
|
|
@ -62,7 +62,7 @@ public record PacketServerToClient(CompoundTag data, IDataHandler handler) imple
|
|||
if (message.data != null && message.handler != null) {
|
||||
message.handler.handleData(message.data, context);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue