Skip to content

Commit

Permalink
Add a few npe fixes and small adjustments to info commands (#10161)
Browse files Browse the repository at this point in the history
Add a few npe fixes and small adjustments to info commands
  • Loading branch information
someaddons authored Aug 25, 2024
1 parent a779517 commit 95bb1de
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CommandColonyInfo implements IMCColonyOfficerCommand
{
public static final String ID_TEXT = "ID: ";
public static final String NAME_TEXT = "Name: ";
private static final String MAYOR_TEXT = "Mayor: ";
public static final String MAYOR_TEXT = "Mayor: ";
private static final String COORDINATES_TEXT = "Coordinates: ";
private static final String COORDINATES_XYZ = "x=%s y=%s z=%s";
private static final String CITIZENS = "Citizens: ";
Expand Down Expand Up @@ -54,7 +54,7 @@ public int onExecute(final CommandContext<CommandSourceStack> context)
}

final BlockPos position = colony.getCenter();
context.getSource().sendSuccess(() -> Component.literal(ID_TEXT + colony.getID() + NAME_TEXT + colony.getName()), true);
context.getSource().sendSuccess(() -> Component.literal(ID_TEXT + colony.getID() + " " + NAME_TEXT + colony.getName()), true);
final String mayor = colony.getPermissions().getOwnerName();
context.getSource().sendSuccess(() -> Component.literal(MAYOR_TEXT + mayor), true);
context.getSource()
Expand All @@ -63,7 +63,6 @@ public int onExecute(final CommandContext<CommandSourceStack> context)
.sendSuccess(() -> Component.literal(COORDINATES_TEXT + String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())).setStyle(Style.EMPTY.withColor(
ChatFormatting.GREEN)), true);
context.getSource().sendSuccess(() -> Component.literal(String.format(LAST_CONTACT_TEXT, colony.getLastContactInHours())), true);
context.getSource().sendSuccess(() -> Component.literal(IS_DELETABLE + !colony.canBeAutoDeleted()), true);

if (!colony.getRaiderManager().canHaveRaiderEvents())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import static com.minecolonies.core.commands.colonycommands.CommandColonyInfo.MAYOR_TEXT;

public class CommandListColonies implements IMCCommand
{
Expand Down Expand Up @@ -98,7 +99,8 @@ private int executeCommand(final CommandContext<CommandSourceStack> context, fin
for (final IColony colony : coloniesPage)
{
context.getSource().sendSuccess(() -> Component.literal(String.format(
ID_AND_NAME_TEXT, colony.getID(), colony.getName())).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
ID_AND_NAME_TEXT, colony.getID(), colony.getName()) + " " + MAYOR_TEXT + colony.getPermissions().getOwnerName())
.setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
String.format(COMMAND_COLONY_INFO, colony.getID())))), true);
final BlockPos center = colony.getCenter();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static com.minecolonies.api.util.constant.translation.CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND;
import static com.minecolonies.core.commands.CommandArgumentNames.COLONYID_ARG;

// TODO: Unused, maybe drop or add an auto delete feature
public class CommandSetDeletable implements IMCOPCommand
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import com.minecolonies.api.entity.citizen.citizenhandlers.*;
import com.minecolonies.api.entity.citizen.happiness.ExpirationBasedHappinessModifier;
import com.minecolonies.api.entity.citizen.happiness.StaticHappinessSupplier;
import com.minecolonies.api.util.constant.TranslationConstants;
import com.minecolonies.core.entity.ai.minimal.EntityAIFloat;
import com.minecolonies.core.entity.pathfinding.pathresults.PathResult;
import com.minecolonies.api.entity.pathfinding.proxy.IWalkToProxy;
import com.minecolonies.api.inventory.InventoryCitizen;
import com.minecolonies.api.inventory.container.ContainerCitizenInventory;
Expand All @@ -39,6 +36,7 @@
import com.minecolonies.api.util.*;
import com.minecolonies.api.util.MessageUtils.MessagePriority;
import com.minecolonies.api.util.constant.HappinessConstants;
import com.minecolonies.api.util.constant.TranslationConstants;
import com.minecolonies.api.util.constant.TypeConstants;
import com.minecolonies.core.MineColonies;
import com.minecolonies.core.Network;
Expand All @@ -52,14 +50,16 @@
import com.minecolonies.core.colony.jobs.JobNetherWorker;
import com.minecolonies.core.colony.jobs.JobRanger;
import com.minecolonies.core.entity.ai.minimal.EntityAICitizenChild;
import com.minecolonies.core.entity.ai.minimal.EntityAIFloat;
import com.minecolonies.core.entity.ai.minimal.EntityAIInteractToggleAble;
import com.minecolonies.core.entity.ai.minimal.LookAtEntityGoal;
import com.minecolonies.core.entity.ai.workers.AbstractEntityAIBasic;
import com.minecolonies.core.entity.ai.workers.CitizenAI;
import com.minecolonies.core.entity.ai.workers.guard.AbstractEntityAIGuard;
import com.minecolonies.core.entity.citizen.citizenhandlers.*;
import com.minecolonies.core.entity.pathfinding.proxy.EntityCitizenWalkToProxy;
import com.minecolonies.core.entity.pathfinding.navigation.MovementHandler;
import com.minecolonies.core.entity.pathfinding.pathresults.PathResult;
import com.minecolonies.core.entity.pathfinding.proxy.EntityCitizenWalkToProxy;
import com.minecolonies.core.event.EventHandler;
import com.minecolonies.core.network.messages.client.ItemParticleEffectMessage;
import com.minecolonies.core.network.messages.client.VanillaParticleMessage;
Expand Down Expand Up @@ -92,7 +92,10 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.*;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ShieldItem;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
Expand All @@ -104,6 +107,7 @@
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -1930,13 +1934,23 @@ public void refreshDimensions()
@Override
public void queueSound(@NotNull final SoundEvent soundEvent, final BlockPos pos, final int length, final int repetitions)
{
if (soundEvent == null || !ForgeRegistries.SOUND_EVENTS.containsKey(soundEvent.getLocation()))
{
return;
}

Network.getNetwork().sendToPosition(new PlaySoundForCitizenMessage(this.getId(), soundEvent, this.getSoundSource(), pos, level, length, repetitions),
new PacketDistributor.TargetPoint(pos.getX(), pos.getY(), pos.getZ(), BLOCK_BREAK_SOUND_RANGE, level.dimension()));
}

@Override
public void queueSound(@NotNull final SoundEvent soundEvent, final BlockPos pos, final int length, final int repetitions, final float volume, final float pitch)
{
if (soundEvent == null || !ForgeRegistries.SOUND_EVENTS.containsKey(soundEvent.getLocation()))
{
return;
}

Network.getNetwork()
.sendToPosition(new PlaySoundForCitizenMessage(this.getId(), soundEvent, this.getSoundSource(), pos, level, volume, pitch, length, repetitions),
new PacketDistributor.TargetPoint(pos.getX(), pos.getY(), pos.getZ(), BLOCK_BREAK_SOUND_RANGE, level.dimension()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import com.minecolonies.api.colony.buildings.views.IBuildingView;
import com.minecolonies.api.colony.workorders.IWorkOrderView;
import com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding;
import com.minecolonies.core.client.gui.WindowResourceList;
import com.minecolonies.core.tileentities.TileEntityRack;
import com.minecolonies.api.util.BlockPosUtil;
import com.minecolonies.api.util.MessageUtils;
import com.minecolonies.api.util.constant.TranslationConstants;
import com.minecolonies.core.MineColonies;
import com.minecolonies.core.Network;
import com.minecolonies.core.client.gui.WindowResourceList;
import com.minecolonies.core.colony.buildings.moduleviews.BuildingResourcesModuleView;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingBuilder;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse;
import com.minecolonies.core.network.messages.server.ResourceScrollSaveWarehouseSnapshotMessage;
import com.minecolonies.core.tileentities.TileEntityRack;
import com.minecolonies.core.tileentities.TileEntityWareHouse;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -267,7 +266,7 @@ else if (buildingEntity.getBuilding() instanceof BuildingWareHouse)
{
MessageUtils.format(COM_MINECOLONIES_SCROLL_SNAPSHOT).sendTo(ctx.getPlayer());
}
else
else if (buildingEntity.getBuilding() != null)
{
final MutableComponent buildingTypeComponent = MessageUtils.format(buildingEntity.getBuilding().getBuildingType().getTranslationKey()).create();
MessageUtils.format(COM_MINECOLONIES_SCROLL_WRONG_BUILDING, buildingTypeComponent, buildingEntity.getColony().getName()).sendTo(ctx.getPlayer());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.minecolonies.core.network.messages.client.colony;

import com.minecolonies.api.colony.IColonyManager;
import com.minecolonies.api.entity.citizen.AbstractCivilianEntity;
import com.minecolonies.api.network.IMessage;
import com.minecolonies.api.sounds.SoundManager;
Expand Down Expand Up @@ -152,14 +151,14 @@ public PlaySoundForCitizenMessage(final int entityID, final SoundEvent event, fi
public void toBytes(final FriendlyByteBuf buf)
{
buf.writeResourceLocation(ForgeRegistries.SOUND_EVENTS.getKey(this.soundEvent));
buf.writeInt(this.soundSource.ordinal());
buf.writeBlockPos(this.pos);
buf.writeUtf(this.dimensionID.location().toString());
buf.writeFloat(this.volume);
buf.writeFloat(this.pitch);
buf.writeInt(this.length);
buf.writeInt(this.repetitions);
buf.writeInt(this.entityid);
buf.writeInt(soundSource.ordinal());
buf.writeBlockPos(pos);
buf.writeUtf(dimensionID.location().toString());
buf.writeFloat(volume);
buf.writeFloat(pitch);
buf.writeInt(length);
buf.writeInt(repetitions);
buf.writeInt(entityid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.jetbrains.annotations.Nullable;

import static com.minecolonies.api.util.constant.BuildingConstants.DEACTIVATED;
import static com.minecolonies.api.util.constant.TranslationConstants.*;
import static com.minecolonies.api.util.constant.TranslationConstants.HUT_BLOCK_MISSING_BUILDING;
import static com.minecolonies.core.MineColonies.getConfig;

/**
Expand Down Expand Up @@ -111,6 +111,11 @@ else if (world.getBlockEntity(pos) instanceof TileEntityColonyBuilding townhall
}
else
{
if (nextColony == null)
{
return;
}

final int blockRange = Math.max(MineColonies.getConfig().getServer().minColonyDistance.get(), getConfig().getServer().initialColonySize.get()) << 4;
final int distance = (int) BlockPosUtil.getDistance(pos, nextColony.getCenter());

Expand Down

0 comments on commit 95bb1de

Please sign in to comment.