Search in sources :

Example 1 with IColonyEventDescription

use of com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription in project minecolonies by ldtteam.

the class EventDescriptionManager method deserializeNBT.

@Override
public void deserializeNBT(@NotNull final CompoundNBT eventManagerNBT) {
    final ListNBT eventDescListNBT = eventManagerNBT.getList(TAG_EVENT_DESC_LIST, Constants.NBT.TAG_COMPOUND);
    for (final INBT event : eventDescListNBT) {
        final CompoundNBT eventCompound = (CompoundNBT) event;
        final ResourceLocation eventTypeID = new ResourceLocation(MOD_ID, eventCompound.getString(TAG_NAME));
        final ColonyEventDescriptionTypeRegistryEntry registryEntry = MinecoloniesAPIProxy.getInstance().getColonyEventDescriptionRegistry().getValue(eventTypeID);
        if (registryEntry == null) {
            Log.getLogger().warn("Event is missing registryEntry!:" + eventTypeID.getPath());
            continue;
        }
        final IColonyEventDescription eventDescription = registryEntry.deserializeEventDescriptionFromNBT(eventCompound);
        eventDescs.add(eventDescription);
    }
}
Also used : ColonyEventDescriptionTypeRegistryEntry(com.minecolonies.api.colony.colonyEvents.registry.ColonyEventDescriptionTypeRegistryEntry) ListNBT(net.minecraft.nbt.ListNBT) IColonyEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription) CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 2 with IColonyEventDescription

use of com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription in project minecolonies by Minecolonies.

the class EventDescriptionManager method deserializeNBT.

@Override
public void deserializeNBT(@NotNull final CompoundNBT eventManagerNBT) {
    final ListNBT eventDescListNBT = eventManagerNBT.getList(TAG_EVENT_DESC_LIST, Constants.NBT.TAG_COMPOUND);
    for (final INBT event : eventDescListNBT) {
        final CompoundNBT eventCompound = (CompoundNBT) event;
        final ResourceLocation eventTypeID = new ResourceLocation(MOD_ID, eventCompound.getString(TAG_NAME));
        final ColonyEventDescriptionTypeRegistryEntry registryEntry = MinecoloniesAPIProxy.getInstance().getColonyEventDescriptionRegistry().getValue(eventTypeID);
        if (registryEntry == null) {
            Log.getLogger().warn("Event is missing registryEntry!:" + eventTypeID.getPath());
            continue;
        }
        final IColonyEventDescription eventDescription = registryEntry.deserializeEventDescriptionFromNBT(eventCompound);
        eventDescs.add(eventDescription);
    }
}
Also used : ColonyEventDescriptionTypeRegistryEntry(com.minecolonies.api.colony.colonyEvents.registry.ColonyEventDescriptionTypeRegistryEntry) ListNBT(net.minecraft.nbt.ListNBT) IColonyEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription) CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 3 with IColonyEventDescription

use of com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription in project minecolonies by Minecolonies.

the class WindowInfoPage method fillEventsList.

private void fillEventsList() {
    eventList = findPaneOfTypeByID(EVENTS_LIST, ScrollingList.class);
    eventList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return permissionEvents ? building.getPermissionEvents().size() : building.getColonyEvents().size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final Text nameLabel = rowPane.findPaneOfTypeByID(NAME_LABEL, Text.class);
            final Text actionLabel = rowPane.findPaneOfTypeByID(ACTION_LABEL, Text.class);
            if (permissionEvents) {
                final List<PermissionEvent> permissionEvents = building.getPermissionEvents();
                Collections.reverse(permissionEvents);
                final PermissionEvent event = permissionEvents.get(index);
                nameLabel.setText(event.getName() + (event.getId() == null ? " <fake>" : ""));
                rowPane.findPaneOfTypeByID(POS_LABEL, Text.class).setText(event.getPosition().getX() + " " + event.getPosition().getY() + " " + event.getPosition().getZ());
                if (event.getId() == null) {
                    rowPane.findPaneOfTypeByID(BUTTON_ADD_PLAYER_OR_FAKEPLAYER, Button.class).hide();
                }
                actionLabel.setText(new TranslationTextComponent(KEY_TO_PERMISSIONS + event.getAction().toString().toLowerCase(Locale.US)));
            } else {
                final List<IColonyEventDescription> colonyEvents = building.getColonyEvents();
                Collections.reverse(colonyEvents);
                final IColonyEventDescription event = colonyEvents.get(index);
                if (event instanceof CitizenDiedEvent) {
                    actionLabel.setText(((CitizenDiedEvent) event).getDeathCause());
                } else {
                    actionLabel.setText(event.getName());
                }
                if (event instanceof ICitizenEventDescription) {
                    nameLabel.setText(((ICitizenEventDescription) event).getCitizenName());
                } else if (event instanceof IBuildingEventDescription) {
                    IBuildingEventDescription buildEvent = (IBuildingEventDescription) event;
                    nameLabel.setText(MessageUtils.format(buildEvent.getBuildingName()).append(" " + buildEvent.getLevel()).create());
                }
                rowPane.findPaneOfTypeByID(POS_LABEL, Text.class).setText(event.getEventPos().getX() + " " + event.getEventPos().getY() + " " + event.getEventPos().getZ());
                rowPane.findPaneOfTypeByID(BUTTON_ADD_PLAYER_OR_FAKEPLAYER, Button.class).hide();
            }
        }
    });
}
Also used : IBuildingEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IBuildingEventDescription) Text(com.ldtteam.blockout.controls.Text) Pane(com.ldtteam.blockout.Pane) CitizenDiedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent) ICitizenEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.ICitizenEventDescription) IColonyEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription) PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ScrollingList(com.ldtteam.blockout.views.ScrollingList) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Example 4 with IColonyEventDescription

use of com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription in project minecolonies by Minecolonies.

the class EventDescriptionManager method serializeNBT.

@Override
public CompoundNBT serializeNBT() {
    final CompoundNBT eventManagerNBT = new CompoundNBT();
    final ListNBT eventDescsListNBT = new ListNBT();
    for (final IColonyEventDescription event : eventDescs) {
        final CompoundNBT eventNBT = event.serializeNBT();
        eventNBT.putString(TAG_NAME, event.getEventTypeId().getPath());
        eventDescsListNBT.add(eventNBT);
    }
    eventManagerNBT.put(TAG_EVENT_DESC_LIST, eventDescsListNBT);
    return eventManagerNBT;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) IColonyEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 5 with IColonyEventDescription

use of com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription in project minecolonies by Minecolonies.

the class BuildingTownHall method serializeToView.

@Override
public void serializeToView(@NotNull final PacketBuffer buf) {
    super.serializeToView(buf);
    buf.writeBoolean(MineColonies.getConfig().getServer().canPlayerUseAllyTHTeleport.get());
    buf.writeInt(permissionEvents.size());
    for (final PermissionEvent event : permissionEvents) {
        event.serialize(buf);
    }
    List<IColonyEventDescription> colonyEvents = colony.getEventDescriptionManager().getEventDescriptions();
    buf.writeInt(colonyEvents.size());
    for (final IColonyEventDescription event : colonyEvents) {
        buf.writeUtf(event.getEventTypeId().getPath());
        event.serialize(buf);
    }
}
Also used : IColonyEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription) PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent)

Aggregations

IColonyEventDescription (com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 ListNBT (net.minecraft.nbt.ListNBT)4 PermissionEvent (com.minecolonies.api.colony.permissions.PermissionEvent)3 Pane (com.ldtteam.blockout.Pane)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 IBuildingEventDescription (com.minecolonies.api.colony.colonyEvents.descriptions.IBuildingEventDescription)2 ICitizenEventDescription (com.minecolonies.api.colony.colonyEvents.descriptions.ICitizenEventDescription)2 ColonyEventDescriptionTypeRegistryEntry (com.minecolonies.api.colony.colonyEvents.registry.ColonyEventDescriptionTypeRegistryEntry)2 CitizenDiedEvent (com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent)2 INBT (net.minecraft.nbt.INBT)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Text (com.ldtteam.blockout.controls.Text)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1