More research work
This commit is contained in:
parent
9e726e1779
commit
6769af52f5
@ -1,8 +1,14 @@
|
||||
package ru.dbotthepony.mc.otm.capability.android;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public record AndroidFeatureResearchCost(int experience, ItemStack ...items) {
|
||||
public boolean matches(Player ply) {
|
||||
if (ply.experienceLevel < experience)
|
||||
@ -34,6 +40,58 @@ public record AndroidFeatureResearchCost(int experience, ItemStack ...items) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Component> getTooltip() {
|
||||
var list = new ArrayList<Component>();
|
||||
|
||||
if (experience > 0)
|
||||
list.add(new TranslatableComponent("otm.android_station.research.xp_cost", experience));
|
||||
|
||||
for (var itemstack : items)
|
||||
list.add(new TranslatableComponent("otm.android_station.research.item", itemstack.getDisplayName(), itemstack.getCount()));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<Component> getTooltip(Player ply) {
|
||||
var list = new ArrayList<Component>();
|
||||
|
||||
if (experience > 0) {
|
||||
if (ply.experienceLevel >= experience) {
|
||||
list.add(new TranslatableComponent("otm.android_station.research.xp_cost", experience).withStyle(ChatFormatting.DARK_GREEN));
|
||||
} else {
|
||||
list.add(new TranslatableComponent("otm.android_station.research.xp_cost", experience).withStyle(ChatFormatting.DARK_RED));
|
||||
}
|
||||
}
|
||||
|
||||
for (var stack : items) {
|
||||
boolean hit = false;
|
||||
|
||||
if (stack.getTag() == null) {
|
||||
for (var inv_stack : ply.getInventory().items) {
|
||||
if (inv_stack.is(stack.getItem()) && inv_stack.getCount() >= stack.getCount()) {
|
||||
hit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var inv_stack : ply.getInventory().items) {
|
||||
if (inv_stack.is(stack.getItem()) && inv_stack.getCount() >= stack.getCount() && inv_stack.getTag() != null && inv_stack.getTag().equals(stack.getTag())) {
|
||||
hit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hit) {
|
||||
list.add(new TranslatableComponent("otm.android_station.research.item", stack.getDisplayName(), stack.getCount()).withStyle(ChatFormatting.DARK_GREEN));
|
||||
} else {
|
||||
list.add(new TranslatableComponent("otm.android_station.research.item", stack.getDisplayName(), stack.getCount()).withStyle(ChatFormatting.DARK_RED));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean research(Player ply) {
|
||||
if (!matches(ply))
|
||||
return false;
|
||||
|
@ -3,14 +3,13 @@ package ru.dbotthepony.mc.otm.capability.android;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.network.MatteryNetworking;
|
||||
import ru.dbotthepony.mc.otm.network.android.AndroidResearchRequestPacket;
|
||||
import ru.dbotthepony.mc.otm.screen.RenderHelper;
|
||||
import ru.dbotthepony.mc.otm.screen.SkinElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -21,7 +20,6 @@ public class AndroidFeatureResearchNode {
|
||||
|
||||
public final Set<AndroidFeatureType<?>> predecessors = new HashSet<>();
|
||||
|
||||
protected final Component name;
|
||||
protected final Component description;
|
||||
public boolean with_description = false;
|
||||
|
||||
@ -30,7 +28,6 @@ public class AndroidFeatureResearchNode {
|
||||
public AndroidFeatureResearchNode(AndroidFeatureType<?> type, AndroidFeatureResearchCost cost) {
|
||||
this.type = type;
|
||||
this.cost = cost;
|
||||
name = new TranslatableComponent("android_feature." + type.getRegistryName().getNamespace() + "." + type.getRegistryName().getPath());
|
||||
description = new TranslatableComponent("android_feature." + type.getRegistryName().getNamespace() + "." + type.getRegistryName().getPath() + ".description");
|
||||
}
|
||||
|
||||
@ -83,19 +80,41 @@ public class AndroidFeatureResearchNode {
|
||||
});
|
||||
}
|
||||
|
||||
public Component getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Component getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public List<Component> getTooltip() {
|
||||
var list = new ArrayList<Component>();
|
||||
list.add(type.getDisplayName());
|
||||
|
||||
if (with_description) {
|
||||
return List.of(getName(), getDescription());
|
||||
list.add(getDescription());
|
||||
}
|
||||
|
||||
return List.of(getName());
|
||||
list.addAll(cost.getTooltip());
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<Component> getTooltip(Player ply) {
|
||||
var list = new ArrayList<Component>();
|
||||
list.add(type.getDisplayName());
|
||||
|
||||
if (with_description) {
|
||||
list.add(getDescription());
|
||||
}
|
||||
|
||||
list.addAll(cost.getTooltip(ply));
|
||||
|
||||
ply.getCapability(MatteryCapability.ANDROID).ifPresent(cap -> {
|
||||
for (var prec : predecessors) {
|
||||
if (!cap.hasFeature(prec)) {
|
||||
list.add(new TranslatableComponent("otm.android_station.research.missing_predecessors", prec.getDisplayName()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package ru.dbotthepony.mc.otm.capability.android;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.registries.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -42,4 +44,11 @@ public class AndroidFeatureType<T extends AndroidFeature> extends ForgeRegistryE
|
||||
|
||||
return cache = getResearchNodeInner();
|
||||
}
|
||||
|
||||
public Component getDisplayName() {
|
||||
if (getRegistryName() == null)
|
||||
return new TranslatableComponent("android_feature.null.null");
|
||||
|
||||
return new TranslatableComponent("android_feature." + getRegistryName().getNamespace() + "." + getRegistryName().getPath());
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class AndroidStationScreen extends MatteryScreen<AndroidStationMenu> {
|
||||
@Override
|
||||
protected boolean innerRenderTooltips(PoseStack stack, float mouse_x, float mouse_y, float flag) {
|
||||
if (is_hovered) {
|
||||
var list = new ArrayList<>(node.getTooltip());
|
||||
var list = new ArrayList<>(node.getTooltip(Minecraft.getInstance().player));
|
||||
|
||||
Minecraft.getInstance().player.getCapability(MatteryCapability.ANDROID).ifPresent(_cap -> {
|
||||
if (_cap instanceof AndroidCapabilityPlayer cap) {
|
||||
@ -86,8 +86,6 @@ public class AndroidStationScreen extends MatteryScreen<AndroidStationMenu> {
|
||||
}
|
||||
}
|
||||
|
||||
private final Set<AndroidFeatureResearchNode> nodes = new HashSet<>();
|
||||
|
||||
public static final int FRAME_WIDTH = 210;
|
||||
public static final int GRID_WIDTH = 6;
|
||||
public static final int GRID_HEIGHT = 5;
|
||||
@ -95,14 +93,6 @@ public class AndroidStationScreen extends MatteryScreen<AndroidStationMenu> {
|
||||
|
||||
public AndroidStationScreen(AndroidStationMenu p_97741_, Inventory p_97742_, Component p_97743_) {
|
||||
super(p_97741_, p_97742_, p_97743_);
|
||||
|
||||
for (var feature : Registry.ANDROID_FEATURES().getValues()) {
|
||||
var node = feature.getResearchNode();
|
||||
|
||||
if (node != null) {
|
||||
nodes.add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -39,6 +39,9 @@
|
||||
"otm.android_station.research.researched": "Researched!",
|
||||
"otm.android_station.research.can_be_researched": "Ready to research!",
|
||||
"otm.android_station.research.can_not_be_researched": "Can not afford!",
|
||||
"otm.android_station.research.xp_cost": "Experience cost: %s levels",
|
||||
"otm.android_station.research.item": "Requires %s x%s",
|
||||
"otm.android_station.research.missing_predecessors": "%s needs to be researched first",
|
||||
|
||||
"android_feature.overdrive_that_matters.air_bags": "Air bags",
|
||||
"android_feature.overdrive_that_matters.air_bags.description": "Allows to swim in water",
|
||||
|
Loading…
Reference in New Issue
Block a user