Skip to content

Commit

Permalink
Feature/research improvements (ldtteam#5869)
Browse files Browse the repository at this point in the history
Add Happiness Research effect into code actually.
Add xp research effect into code actually
Readjust research tree to move some researches into better positions.
  • Loading branch information
Raycoms authored Oct 4, 2020
1 parent a212076 commit 0012a22
Show file tree
Hide file tree
Showing 23 changed files with 203 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.reflect.TypeToken;
import com.minecolonies.api.colony.IColonyView;
import com.minecolonies.api.colony.requestsystem.manager.AssigningStrategy;
import com.minecolonies.api.colony.requestsystem.manager.IRequestManager;
import com.minecolonies.api.colony.requestsystem.requestable.IRequestable;
Expand Down Expand Up @@ -286,4 +287,11 @@ default AssigningStrategy getStrategy()
* @return an immutable copy of the set.
*/
Set<TypeToken<?>> getSuperClasses();

/**
* Get the resolver tooltip for a request.
* @param colony the colony view to obtain information if necessary.
* @return a list of strings or empty.
*/
List<String> getResolverToolTip(IColonyView colony);
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ public class CommonConfiguration extends AbstractConfiguration

public final ForgeConfigSpec.ConfigValue<List<? extends String>> hittingiron;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> stonecake;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> strong;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> hardened;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> reinforced;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> steelbracing;
Expand Down Expand Up @@ -1246,6 +1247,9 @@ protected CommonConfiguration(final ForgeConfigSpec.Builder builder)
this.stonecake = defineList(builder, "stonecake",
Collections.singletonList("minecraft:chiseled_stone_bricks*64"),
s -> s instanceof String);
this.strong = defineList(builder, "strong",
Collections.singletonList("minecraft:diamond*8"),
s -> s instanceof String);
this.hardened = defineList(builder, "hardened",
Collections.singletonList("minecraft:diamond*16"),
s -> s instanceof String);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.minecolonies.api.entity.citizen.citizenhandlers;

import com.minecolonies.api.colony.ICitizenData;
import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.entity.citizen.happiness.IHappinessModifier;
import net.minecraft.nbt.CompoundNBT;

Expand Down Expand Up @@ -36,9 +37,10 @@ public interface ICitizenHappinessHandler
/**
* Get the computed happiness of the citizen.
*
* @param colony the colony.
* @return the happiness.
*/
double getHappiness();
double getHappiness(IColony colony);

/**
* Read the handler from NBT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public final class ResearchConstants
public static final String CAP = "Citizen-Cap";
public static final String RAILS = "Rails";
public static final String WALKING = "Walking";
public static final String LEVELING = "Leveling";

public static final String HEALTH = "Health";
public static final String REGENERATION = "Regeneration";
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/com/minecolonies/api/util/SoundUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static void playRandomSound(@NotNull final World worldIn, @NotNull final
}
else if (v <= 0.2)
{
if (citizen.getCitizenHappinessHandler().getHappiness() < 5)
if (citizen.getCitizenHappinessHandler().getHappiness(citizen.getColony()) < 5)
{
playSoundAtCitizenWith(worldIn, pos, EventType.UNHAPPY, citizen);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,17 @@ public final class TranslationConstants
public static final String HUT_NEEDS_RESEARCH_TOOLTIP_1 = "com.minecolonies.coremod.research.item1";
@NonNls
public static final String HUT_NEEDS_RESEARCH_TOOLTIP_2 = "com.minecolonies.coremod.research.item2";
@NonNls
public static final String FROM = "com.minecolonies.coremod.from";
@NonNls
public static final String AT = "com.minecolonies.coremod.at";
@NonNls
public static final String IN_QUEUE = "com.minecolonies.coremod.listentry";
@NonNls
public static final String MISSING_DELIVERIES = "com.minecolonies.coremod.missingitems";
@NonNls
public static final String FINISHED = "com.minecolonies.coremod.finished";


private TranslationConstants()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ public final class WindowConstants
*/
public static final String BUTTON_RECALL = "recall";

/**
* Id of the hire Citizen button in the GUI.
*/
public static final String BUTTON_HIRE = "hire";

/**
* Id of the change specialization button in the GUI.
*/
Expand Down Expand Up @@ -145,11 +140,6 @@ public final class WindowConstants
*/
public static final String BUTTON_TP = "tp";

/**
* Id of the rally guards button in the GUI.
*/
public static final String BUTTON_RALLY_GUARDS = "rallyGuards";

/**
* Id of the up button in the GUI.
*/
Expand Down Expand Up @@ -455,26 +445,11 @@ public final class WindowConstants
*/
public static final String BUTTON_NEXT_COLOR_ID = "nextColor";

/**
* This button will send a packet to the server telling it to place this hut/decoration.
*/
public static final String BUTTON_CONFIRM = "confirm";

/**
* This button will remove the currently rendered structure.
*/
public static final String BUTTON_CANCEL = "cancel";

/**
* This button will rotateWithMirror the structure counterclockwise.
*/
public static final String BUTTON_ROTATE_LEFT = "rotateLeft";

/**
* This button will rotated the structure clockwise.
*/
public static final String BUTTON_ROTATE_RIGHT = "rotateRight";

/**
* Move the structure preview forward.
*/
Expand All @@ -485,26 +460,6 @@ public final class WindowConstants
*/
public static final String BUTTON_BACKWARD = "down";

/**
* Move the structure preview left.
*/
public static final String BUTTON_LEFT = "left";

/**
* Move the structure preview right.
*/
public static final String BUTTON_RIGHT = "right";

/**
* Mirror the structure.
*/
public static final String BUTTON_MIRROR = "mirror";

/**
* Resource suffix.
*/
public static final String MOVE_BUILDING_SOURCE_SUFFIX = ":gui/windowmovebuilding.xml";

/**
* The builders gui file.
*/
Expand Down Expand Up @@ -938,7 +893,7 @@ public final class WindowConstants
public static final String LIST_ELEMENT_ID_REQUEST_STACK = "requestStack";

/**
* Resolver string.
* Delivery image.
*/
public static final String DELIVERY_IMAGE = "deliveryImage";

Expand Down Expand Up @@ -982,21 +937,6 @@ public final class WindowConstants
*/
public static final String REQUESTER = "requester";

/**
* Delivery origin.
*/
public static final String FROM = "com.minecolonies.coremod.from";

/**
* Number in queue.
*/
public static final String IN_QUEUE = "com.minecolonies.coremod.listentry";

/**
* Id of the order label.
*/
public static final String ORDER = "order";

/**
* Id of the parent label.
*/
Expand All @@ -1007,11 +947,6 @@ public final class WindowConstants
*/
public static final int LIFE_COUNT_DIVIDER = 30;

/**
* ID for happiness modifier view
*/
public static final String HAPPINESS_MODIFIER_PANE = "happinessModifierView";

/**
* Warehouse constants
*/
Expand Down Expand Up @@ -1156,8 +1091,6 @@ public final class WindowConstants
public static final String RESPONSE_BOX_ID = "responseOptions";
public static final String MEDIUM_SIZED_BUTTON_RES = "textures/gui/builderhut/builder_button_medium_large.png";

public static final String SMALL_SIZED_BUTTON_RES = "textures/gui/builderhut/builder_button_mini.png";

/**
* The resource string.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.ldtteam.blockout.controls.*;
import com.ldtteam.blockout.views.Box;
import com.ldtteam.blockout.views.ScrollingList;
import com.ldtteam.structurize.util.LanguageHandler;
import com.minecolonies.api.colony.ICitizenDataView;
import com.minecolonies.api.colony.IColonyView;
import com.minecolonies.api.colony.buildings.views.IBuildingView;
import com.minecolonies.api.colony.requestsystem.manager.IRequestManager;
Expand All @@ -17,10 +15,7 @@
import com.minecolonies.api.colony.requestsystem.token.IToken;
import com.minecolonies.api.util.InventoryUtils;
import com.minecolonies.coremod.Network;
import com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingDeliveryman;
import com.minecolonies.coremod.colony.jobs.views.DmanJobView;
import com.minecolonies.coremod.colony.requestsystem.requesters.IBuildingBasedRequester;
import com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests;
import com.minecolonies.coremod.network.messages.server.colony.UpdateRequestStateMessage;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.player.PlayerInventory;
Expand Down Expand Up @@ -321,54 +316,17 @@ public void updateElement(final int index, final Pane rowPane)
logo.setVisible(false);
exampleStackDisplay.setVisible(true);
exampleStackDisplay.setItem(displayStacks.get((lifeCount / LIFE_COUNT_DIVIDER) % displayStacks.size()));
rowPane.findPaneOfTypeByID(REQUESTER, Label.class).setLabelText(request.getRequester().getRequesterDisplayName(colony.getRequestManager(), request).getFormattedText());
}
else
{
exampleStackDisplay.setVisible(false);
logo.setVisible(true);
logo.setImage(request.getDisplayIcon());
logo.setHoverToolTip(request.getResolverToolTip(colony));
}

final String requester = request.getRequester().getRequesterDisplayName(colony.getRequestManager(), request).getFormattedText();

if (request instanceof StandardRequests.DeliveryRequest)
{
final BlockPos resolver = colony.getRequestManager().getResolverForRequest(request.getId()).getLocation().getInDimensionLocation();
final IBuildingView view = colony.getBuilding(resolver);

int posInList = -1;
if (view instanceof BuildingDeliveryman.View)
{
for (int worker : ((BuildingDeliveryman.View) view).getWorkerId())
{
final ICitizenDataView citizen = colony.getCitizen(worker);
if (citizen != null)
{
if (citizen.getJobView() instanceof DmanJobView && ((DmanJobView) citizen.getJobView()).getDataStore().getQueue().contains(request.getId()))
{
posInList = ((DmanJobView) citizen.getJobView()).getDataStore().getQueue().indexOf(request.getId());
}
}
}
}

if (posInList >= 0)
{
logo.setHoverToolTip(ImmutableList.of(LanguageHandler.format(FROM, requester), LanguageHandler.format(IN_QUEUE, posInList)));
}
else
{
logo.setHoverToolTip(ImmutableList.of(LanguageHandler.format(FROM, requester)));
}
}
else
{
rowPane.findPaneOfTypeByID(REQUESTER, Label.class)
.setLabelText(requester);
}

rowPane.findPaneOfTypeByID(REQUEST_SHORT_DETAIL, Label.class)
.setLabelText(request.getShortDisplayString().getFormattedText().replace("§f", ""));
rowPane.findPaneOfTypeByID(REQUEST_SHORT_DETAIL, Label.class).setLabelText(request.getShortDisplayString().getFormattedText().replace("§f", ""));

if (!cancellable(request))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.List;

import static com.minecolonies.api.util.constant.Suppression.EXCEPTION_HANDLERS_SHOULD_PRESERVE_THE_ORIGINAL_EXCEPTIONS;
import static com.minecolonies.api.util.constant.TranslationConstants.FROM;
import static com.minecolonies.api.util.constant.TranslationConstants.IN_QUEUE;
import static com.minecolonies.api.util.constant.WindowConstants.*;

/**
Expand Down Expand Up @@ -172,6 +174,7 @@ public void onOpened()

final ItemIcon exampleStackDisplay = findPaneOfTypeByID(LIST_ELEMENT_ID_REQUEST_STACK, ItemIcon.class);
final List<ItemStack> displayStacks = request.getDisplayStacks();
final IColonyView colony = IColonyManager.getInstance().getColonyView(colonyId, Minecraft.getInstance().world.getDimension().getType().getId());

if (!displayStacks.isEmpty())
{
Expand All @@ -181,16 +184,15 @@ public void onOpened()
{
logo.setVisible(true);
logo.setImage(request.getDisplayIcon());
logo.setHoverToolTip(request.getResolverToolTip(colony));
}

final IColonyView view = IColonyManager.getInstance().getColonyView(colonyId, Minecraft.getInstance().world.getDimension().getType().getId());
final String requester = request.getRequester().getRequesterDisplayName(view.getRequestManager(), request).getFormattedText();
final String requester = request.getRequester().getRequesterDisplayName(colony.getRequestManager(), request).getFormattedText();

findPaneOfTypeByID(REQUESTER, Label.class).setLabelText(requester);
final Label targetLabel = findPaneOfTypeByID(LIST_ELEMENT_ID_REQUEST_LOCATION, Label.class);
targetLabel.setLabelText(request.getRequester().getLocation().toString());

final IColonyView colony = IColonyManager.getInstance().getColonyView(colonyId, Minecraft.getInstance().world.getDimension().getType().getId());
if (colony == null)
{
Log.getLogger().warn("---Colony Null in WindowRequestDetail---");
Expand All @@ -206,38 +208,7 @@ public void onOpened()
return;
}

if (request instanceof StandardRequests.DeliveryRequest)
{
final BlockPos resolverPos = colony.getRequestManager().getResolverForRequest(request.getId()).getLocation().getInDimensionLocation();
final IBuildingView buildingView = colony.getBuilding(resolverPos);

int posInList = -1;
if (buildingView instanceof BuildingDeliveryman.View)
{
for (int worker : ((BuildingDeliveryman.View) buildingView).getWorkerId())
{
final ICitizenDataView citizen = colony.getCitizen(worker);
if (citizen != null)
{
if (citizen.getJobView() instanceof DmanJobView && ((DmanJobView) citizen.getJobView()).getDataStore().getQueue().contains(request.getId()))
{
posInList = ((DmanJobView) citizen.getJobView()).getDataStore().getQueue().indexOf(request.getId());
}
}
}
}

if (posInList >= 0)
{
logo.setHoverToolTip(ImmutableList.of(LanguageHandler.format(FROM, requester), LanguageHandler.format(IN_QUEUE, posInList)));
}
else
{
logo.setHoverToolTip(ImmutableList.of(LanguageHandler.format(FROM, requester)));
}
}

findPaneOfTypeByID(RESOLVER, Label.class).setLabelText("Resolver: " + resolver.getRequesterDisplayName(view.getRequestManager(), request).getFormattedText());
findPaneOfTypeByID(RESOLVER, Label.class).setLabelText("Resolver: " + resolver.getRequesterDisplayName(colony.getRequestManager(), request).getFormattedText());
}
catch (@SuppressWarnings(EXCEPTION_HANDLERS_SHOULD_PRESERVE_THE_ORIGINAL_EXCEPTIONS) final IllegalArgumentException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ public void serializeViewNetworkData(@NotNull final PacketBuffer buf)
buf.writeFloat(getEntity().map(AbstractEntityCitizen::getMaxHealth).orElse(MAX_HEALTH));

buf.writeDouble(getSaturation());
buf.writeDouble(citizenHappinessHandler.getHappiness());
buf.writeDouble(citizenHappinessHandler.getHappiness(getColony()));

buf.writeCompoundTag(citizenSkillHandler.write());

Expand Down Expand Up @@ -977,7 +977,7 @@ public void deserializeNBT(final CompoundNBT nbtTagCompound)

if (nbtTagCompound.keySet().contains(TAG_LEVEL_MAP) && !nbtTagCompound.keySet().contains(TAG_NEW_SKILLS))
{
citizenSkillHandler.init((int) citizenHappinessHandler.getHappiness());
citizenSkillHandler.init((int) citizenHappinessHandler.getHappiness(getColony()));
final Map<String, Integer> levels = new HashMap<>();
final ListNBT levelTagList = nbtTagCompound.getList(TAG_LEVEL_MAP, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < levelTagList.size(); ++i)
Expand Down
Loading

0 comments on commit 0012a22

Please sign in to comment.