reorganized finder types and profiles

This commit is contained in:
Unknown
2020-02-05 17:34:22 -05:00
parent a23b2bd9a9
commit 02a61a4a68
10 changed files with 140 additions and 100 deletions
@@ -15,8 +15,8 @@ public abstract class ClientCommand {
public abstract void build(LiteralArgumentBuilder<ServerCommandSource> builder);
protected final void sendFeedback(String message, boolean overlay) {
MinecraftClient.getInstance().player.addChatMessage(new LiteralText(message).formatted(Formatting.AQUA), overlay);
protected final void sendFeedback(String message, Formatting color, boolean overlay) {
MinecraftClient.getInstance().player.addChatMessage(new LiteralText(message).formatted(color), overlay);
}
public final void register(CommandDispatcher<ServerCommandSource> dispatcher) {
@@ -1,9 +1,10 @@
package kaptainwutax.seedcracker.command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import kaptainwutax.seedcracker.finder.FinderConfig;
import kaptainwutax.seedcracker.finder.Finder;
import kaptainwutax.seedcracker.finder.FinderQueue;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Formatting;
import static net.minecraft.server.command.CommandManager.literal;
@@ -16,7 +17,7 @@ public class FinderCommand extends ClientCommand {
@Override
public void build(LiteralArgumentBuilder<ServerCommandSource> builder) {
for(FinderConfig.Type finderType: FinderConfig.Type.values()) {
for(Finder.Type finderType: Finder.Type.values()) {
builder.then(literal("type")
.executes(context -> this.printFinderType(finderType))
.then(literal(finderType.toString())
@@ -25,7 +26,7 @@ public class FinderCommand extends ClientCommand {
);
}
for(FinderConfig.Category finderCategory: FinderConfig.Category.values()) {
for(Finder.Category finderCategory: Finder.Category.values()) {
builder.then(literal("category")
.executes(context -> this.printFinderCategory(finderCategory))
.then(literal(finderCategory.toString())
@@ -35,24 +36,28 @@ public class FinderCommand extends ClientCommand {
}
}
private int printFinderCategory(FinderConfig.Category finderCategory) {
FinderConfig.Type.getForCategory(finderCategory).forEach(this::printFinderType);
private int printFinderCategory(Finder.Category finderCategory) {
Finder.Type.getForCategory(finderCategory).forEach(this::printFinderType);
return 0;
}
private int printFinderType(FinderConfig.Type finderType) {
this.sendFeedback("Finder " + finderType + " is set to [" + String.valueOf(FinderQueue.get().finderProfile.getTypeState(finderType)).toUpperCase() + "].", false);
private int printFinderType(Finder.Type finderType) {
this.sendFeedback("Finder " + finderType + " is set to [" + String.valueOf(FinderQueue.get().finderProfile.getTypeState(finderType)).toUpperCase() + "].", Formatting.AQUA,false);
return 0;
}
private int setFinderCategory(FinderConfig.Category finderCategory, boolean flag) {
FinderConfig.Type.getForCategory(finderCategory).forEach(finderType -> this.setFinderType(finderType, flag));
private int setFinderCategory(Finder.Category finderCategory, boolean flag) {
Finder.Type.getForCategory(finderCategory).forEach(finderType -> this.setFinderType(finderType, flag));
return 0;
}
private int setFinderType(FinderConfig.Type finderType, boolean flag) {
FinderQueue.get().finderProfile.setTypeState(finderType, flag);
this.sendFeedback("Finder " + finderType + " has been set to [" + String.valueOf(flag).toUpperCase() + "].", false);
private int setFinderType(Finder.Type finderType, boolean flag) {
if(FinderQueue.get().finderProfile.setTypeState(finderType, flag)) {
this.sendFeedback("Finder " + finderType + " has been set to [" + String.valueOf(flag).toUpperCase() + "].", Formatting.AQUA, false);
} else {
this.sendFeedback("Your current finder profile is locked and cannot be modified. Please make a copy first.", Formatting.RED, false);
}
return 0;
}
@@ -3,6 +3,7 @@ package kaptainwutax.seedcracker.command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import kaptainwutax.seedcracker.finder.FinderQueue;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Formatting;
import static net.minecraft.server.command.CommandManager.literal;
@@ -27,13 +28,13 @@ public class RenderCommand extends ClientCommand {
}
private int printRenderMode() {
this.sendFeedback("Current render mode is set to [" + FinderQueue.get().renderType + "].", false);
this.sendFeedback("Current render mode is set to [" + FinderQueue.get().renderType + "].", Formatting.AQUA, false);
return 0;
}
private int setRenderMode(FinderQueue.RenderType renderType) {
FinderQueue.get().renderType = renderType;
this.sendFeedback("Set render mode to [" + FinderQueue.get().renderType + "].", false);
this.sendFeedback("Set render mode to [" + FinderQueue.get().renderType + "].", Formatting.AQUA, false);
return 0;
}
@@ -1,6 +1,13 @@
package kaptainwutax.seedcracker.finder;
import kaptainwutax.seedcracker.finder.population.DesertWellFinder;
import kaptainwutax.seedcracker.finder.population.DungeonFinder;
import kaptainwutax.seedcracker.finder.population.EndGatewayFinder;
import kaptainwutax.seedcracker.finder.population.EndPillarsFinder;
import kaptainwutax.seedcracker.finder.population.ore.EmeraldOreFinder;
import kaptainwutax.seedcracker.finder.structure.*;
import kaptainwutax.seedcracker.render.Renderer;
import kaptainwutax.seedcracker.util.FinderBuilder;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
@@ -9,8 +16,10 @@ import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public abstract class Finder {
@@ -89,4 +98,42 @@ public abstract class Finder {
return newList;
}
public enum Category {
STRUCTURES,
BIOMES,
ORES,
OTHERS
}
public enum Type {
BURIED_TREASURE(BuriedTreasureFinder::create, Category.STRUCTURES),
DESERT_TEMPLE(DesertTempleFinder::create, Category.STRUCTURES),
END_CITY(EndCityFinder::create, Category.STRUCTURES),
//IGLOO(IglooFinder::create, Category.STRUCTURES),
JUNGLE_TEMPLE(JungleTempleFinder::create, Category.STRUCTURES),
MONUMENT(OceanMonumentFinder::create, Category.STRUCTURES),
SWAMP_HUT(SwampHutFinder::create, Category.STRUCTURES),
//MANSION(MansionFinder::create, Category.STRUCTURES),
SHIPWRECK(ShipwreckFinder::create, Category.STRUCTURES),
END_PILLARS(EndPillarsFinder::create, Category.OTHERS),
END_GATEWAY(EndGatewayFinder::create, Category.OTHERS),
DUNGEON(DungeonFinder::create, Category.OTHERS),
EMERALD_ORE(EmeraldOreFinder::create, Category.ORES),
DESERT_WELL(DesertWellFinder::create, Category.OTHERS),
BIOME(BiomeFinder::create, Category.BIOMES);
public final FinderBuilder finderBuilder;
private final Category category;
Type(FinderBuilder finderBuilder, Category category) {
this.finderBuilder = finderBuilder;
this.category = category;
}
public static List<Type> getForCategory(Category category) {
return Arrays.stream(values()).filter(type -> type.category == category).collect(Collectors.toList());
}
}
}
@@ -1,31 +1,26 @@
package kaptainwutax.seedcracker.finder;
import kaptainwutax.seedcracker.finder.population.DesertWellFinder;
import kaptainwutax.seedcracker.finder.population.DungeonFinder;
import kaptainwutax.seedcracker.finder.population.EndGatewayFinder;
import kaptainwutax.seedcracker.finder.population.EndPillarsFinder;
import kaptainwutax.seedcracker.finder.population.ore.EmeraldOreFinder;
import kaptainwutax.seedcracker.finder.structure.*;
import kaptainwutax.seedcracker.util.FinderBuilder;
import kaptainwutax.seedcracker.finder.profile.FinderProfile;
import kaptainwutax.seedcracker.finder.profile.NopeProfile;
import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;
public class FinderConfig {
protected Map<Type, Boolean> typeStates = new HashMap<>();
protected Map<Type, ConcurrentLinkedQueue<Finder>> activeFinders = new ConcurrentHashMap<>();
protected FinderProfile finderProfile = new NopeProfile();
protected Map<Finder.Type, ConcurrentLinkedQueue<Finder>> activeFinders = new ConcurrentHashMap<>();
public FinderConfig() {
public FinderConfig(boolean defaultState) {
for(Type type: Type.values()) {
this.typeStates.put(type, defaultState);
}
}
public List<Type> getActiveFinderTypes() {
return this.typeStates.entrySet().stream()
public List<Finder.Type> getActiveFinderTypes() {
return this.finderProfile.typeStates.entrySet().stream()
.filter(Map.Entry::getValue)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
@@ -40,7 +35,7 @@ public class FinderConfig {
.flatMap(Queue::stream).collect(Collectors.toList());
}
public void addFinder(Type type, Finder finder) {
public void addFinder(Finder.Type type, Finder finder) {
if(finder.isUseless())return;
if(!this.activeFinders.containsKey(type)) {
@@ -50,50 +45,17 @@ public class FinderConfig {
this.activeFinders.get(type).add(finder);
}
public boolean getTypeState(Type type) {
return this.typeStates.get(type);
public boolean getTypeState(Finder.Type type) {
return this.finderProfile.typeStates.get(type);
}
public void setTypeState(Type type, boolean flag) {
this.typeStates.put(type, flag);
}
public enum Category {
STRUCTURES,
BIOMES,
ORES,
OTHERS
}
public enum Type {
BURIED_TREASURE(BuriedTreasureFinder::create, Category.STRUCTURES),
DESERT_TEMPLE(DesertTempleFinder::create, Category.STRUCTURES),
END_CITY(EndCityFinder::create, Category.STRUCTURES),
//IGLOO(IglooFinder::create, Category.STRUCTURES),
JUNGLE_TEMPLE(JungleTempleFinder::create, Category.STRUCTURES),
MONUMENT(OceanMonumentFinder::create, Category.STRUCTURES),
SWAMP_HUT(SwampHutFinder::create, Category.STRUCTURES),
//MANSION(MansionFinder::create, Category.STRUCTURES),
SHIPWRECK(ShipwreckFinder::create, Category.STRUCTURES),
END_PILLARS(EndPillarsFinder::create, Category.OTHERS),
END_GATEWAY(EndGatewayFinder::create, Category.OTHERS),
DUNGEON(DungeonFinder::create, Category.OTHERS),
EMERALD_ORE(EmeraldOreFinder::create, Category.ORES),
DESERT_WELL(DesertWellFinder::create, Category.OTHERS),
BIOME(BiomeFinder::create, Category.BIOMES);
public final FinderBuilder finderBuilder;
private final Category category;
Type(FinderBuilder finderBuilder, Category category) {
this.finderBuilder = finderBuilder;
this.category = category;
public boolean setTypeState(Finder.Type type, boolean flag) {
if(!this.finderProfile.getLocked()) {
this.finderProfile.typeStates.put(type, flag);
return true;
}
public static List<Type> getForCategory(Category category) {
return Arrays.stream(values()).filter(type -> type.category == category).collect(Collectors.toList());
}
return false;
}
}
@@ -17,7 +17,7 @@ public class FinderQueue {
public static ExecutorService SERVICE = Executors.newFixedThreadPool(5);
public RenderType renderType = RenderType.XRAY;
public FinderConfig finderProfile = new VanillaProfile();
public FinderConfig finderProfile = new FinderConfig();
private FinderQueue() {
this.clear();
@@ -70,7 +70,7 @@ public class FinderQueue {
public void clear() {
this.renderType = RenderType.XRAY;
this.finderProfile = new VanillaProfile();
this.finderProfile = new FinderConfig();
}
public enum RenderType {
@@ -0,0 +1,19 @@
package kaptainwutax.seedcracker.finder.profile;
public class CustomProfile extends FinderProfile {
public CustomProfile() {
super(false);
this.author = "";
this.locked = false;
}
public void setAuthor(String author) {
this.author = author;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
}
@@ -1,17 +1,28 @@
package kaptainwutax.seedcracker.finder.profile;
import kaptainwutax.seedcracker.finder.FinderConfig;
import kaptainwutax.seedcracker.finder.Finder;
public abstract class FinderProfile extends FinderConfig {
import java.util.HashMap;
public abstract class FinderProfile {
public final HashMap<Finder.Type, Boolean> typeStates = new HashMap<>();
protected String author;
protected boolean locked;
public FinderProfile(boolean defaultState) {
super(defaultState);
for(Finder.Type type: Finder.Type.values()) {
this.typeStates.put(type, defaultState);
}
}
public abstract String getAuthor();
public abstract boolean getLocked();
public String getAuthor() {
return this.author;
}
public abstract void setAuthor(String author);
public abstract void setLocked(boolean locked);
public boolean getLocked() {
return this.locked;
}
}
@@ -0,0 +1,11 @@
package kaptainwutax.seedcracker.finder.profile;
public class NopeProfile extends FinderProfile {
public NopeProfile() {
super(false);
this.author = "KaptainWutax";
this.locked = true;
}
}
@@ -4,24 +4,8 @@ public class VanillaProfile extends FinderProfile {
public VanillaProfile() {
super(true);
}
@Override
public String getAuthor() {
return "KaptainWutax";
}
@Override
public boolean getLocked() {
return true;
}
@Override
public void setAuthor(String author) {
}
@Override
public void setLocked(boolean locked) {
this.author = "KaptainWutax";
this.locked = true;
}
}