Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup and improve #1900

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.7.3'
id 'maven-publish'
}

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/carpet/api/settings/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class SettingsManager {
private MinecraftServer server;
private final List<RuleObserver> observers = new ArrayList<>();
private static final List<RuleObserver> staticObservers = new ArrayList<>();
static record ConfigReadResult(Map<String, String> ruleMap, boolean locked) {}
record ConfigReadResult(Map<String, String> ruleMap, boolean locked) {}

/**
* <p>Defines a class that can be notified about a {@link CarpetRule} changing.</p>
Expand All @@ -88,7 +88,7 @@ static record ConfigReadResult(Map<String, String> ruleMap, boolean locked) {}
* @see SettingsManager#registerGlobalRuleObserver(RuleObserver)
*/
@FunctionalInterface
public static interface RuleObserver {
public interface RuleObserver {
/**
* <p>Notifies this {@link RuleObserver} about the change of a {@link CarpetRule}.</p>
*
Expand Down Expand Up @@ -362,7 +362,7 @@ private void disableBooleanCommands()
if (rule.suggestions().contains("false"))
rule.set(server.createCommandSourceStack(), "false");
else
CarpetSettings.LOG.warn("Couldn't disable command rule "+ rule.name() + ": it doesn't suggest false as a valid option");
CarpetSettings.LOG.warn("Couldn't disable command rule {}: it doesn't suggest false as a valid option", rule.name());
} catch (InvalidRuleValueException e) {
throw new IllegalStateException(e); // contract of CarpetRule.suggestions()
}
Expand Down Expand Up @@ -569,7 +569,7 @@ static CompletableFuture<Suggestions> suggestMatchingContains(Stream<String> str
String query = suggestionsBuilder.getRemaining().toLowerCase(Locale.ROOT);
stream.forEach((listItem) -> {
// Regex camelCase Search
var words = Arrays.stream(listItem.split("(?<!^)(?=[A-Z])")).map(s -> s.toLowerCase(Locale.ROOT)).collect(Collectors.toList());
var words = Arrays.stream(listItem.split("(?<!^)(?=[A-Z])")).map(s -> s.toLowerCase(Locale.ROOT)).toList();
var prefixes = new ArrayList<String>(words.size());
for (int i = 0; i < words.size(); i++)
prefixes.add(String.join("", words.subList(i, words.size())));
Expand Down Expand Up @@ -658,8 +658,8 @@ private int displayRuleMenu(CommandSourceStack source, CarpetRule<?> rule) //TOD
tags.add(Messenger.c("c ["+ translated +"]", "^g "+ String.format(tr(TranslationKeys.LIST_ALL_CATEGORY), translated),"!/"+identifier+" list "+t));
tags.add(Messenger.c("w , "));
}
tags.remove(tags.size() - 1);
Messenger.m(source, tags.toArray(new Object[0]));
tags.removeLast();
Messenger.m(source, tags.toArray());

Messenger.m(source, "w "+ tr(TranslationKeys.CURRENT_VALUE)+": ", String.format("%s %s (%s value)", RuleHelper.getBooleanValue(rule) ? "lb" : "nb", RuleHelper.toRuleString(rule.value()), RuleHelper.isInDefaultValue(rule) ? "default" : "modified"));
List<Component> options = new ArrayList<>();
Expand All @@ -669,9 +669,9 @@ private int displayRuleMenu(CommandSourceStack source, CarpetRule<?> rule) //TOD
options.add(makeSetRuleButton(rule, o, false));
options.add(Messenger.c("w "));
}
options.remove(options.size()-1);
options.removeLast();
options.add(Messenger.c("y ]"));
Messenger.m(source, options.toArray(new Object[0]));
Messenger.m(source, options.toArray());

return 1;
}
Expand Down Expand Up @@ -736,8 +736,8 @@ private Component displayInteractiveSetting(CarpetRule<?> rule)
args.add(makeSetRuleButton(rule, RuleHelper.toRuleString(rule.value()), true));
args.add("w ");
}
args.remove(args.size()-1);
return Messenger.c(args.toArray(new Object[0]));
args.removeLast();
return Messenger.c(args.toArray());
}

private Component makeSetRuleButton(CarpetRule<?> rule, String option, boolean brackets)
Expand Down Expand Up @@ -780,8 +780,8 @@ private int listAllSettings(CommandSourceStack source)
tags.add("!/"+identifier+" list " + t);
tags.add("w ");
}
tags.remove(tags.size() - 1);
Messenger.m(source, tags.toArray(new Object[0]));
tags.removeLast();
Messenger.m(source, tags.toArray());

return count;
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/carpet/commands/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ public static void printBlock(List<Component> messages, CommandSourceStack sourc
{
Pattern p = Pattern.compile(grep);
Messenger.m(source, messages.get(0));
for (int i = 1; i<messages.size(); i++)
{
Component line = messages.get(i);
messages.forEach(line -> {
Matcher m = p.matcher(line.getString());
if (m.find())
{
Messenger.m(source, line);
}
}
});
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/commands/LogCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static int listLogs(CommandSourceStack source)
comp.add("^w Click to unsubscribe");
comp.add("!/log "+lname);
}
Messenger.m(player,comp.toArray(new Object[0]));
Messenger.m(player,comp.toArray());
}
return 1;
}
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/carpet/commands/SpawnCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package carpet.commands;

import carpet.CarpetSettings;
import carpet.fakes.SpawnGroupInterface;
import carpet.helpers.HopperCounter;
import carpet.utils.CommandHelper;
import carpet.utils.Messenger;
Expand Down Expand Up @@ -210,10 +209,7 @@ private static int generalMobcaps(CommandSourceStack source)

private static int resetSpawnRates(CommandSourceStack source)
{
for (MobCategory s: SpawnReporter.spawn_tries.keySet())
{
SpawnReporter.spawn_tries.put(s,1);
}
SpawnReporter.spawn_tries.replaceAll((s, v) -> 1);
Messenger.m(source, "gi Spawn rates brought to 1 round per tick for all groups.");

return 1;
Expand All @@ -229,7 +225,7 @@ private static int setSpawnRates(CommandSourceStack source, String mobtype, int

private static int setMobcaps(CommandSourceStack source, int hostile_cap)
{
double desired_ratio = (double)hostile_cap/ ((SpawnGroupInterface)(Object)MobCategory.MONSTER).getInitialSpawnCap();
double desired_ratio = (double)hostile_cap/ MobCategory.MONSTER.getMaxInstancesPerChunk();
SpawnReporter.mobcap_exponent = 4.0*Math.log(desired_ratio)/Math.log(2.0);
Messenger.m(source, String.format("gi Mobcaps for hostile mobs changed to %d, other groups will follow", hostile_cap));
return 1;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/carpet/fakes/ChunkTicketManagerInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.Ticket;
import net.minecraft.util.SortedArraySet;
import net.minecraft.world.level.ChunkPos;

public interface ChunkTicketManagerInterface
{
void changeSpawnChunks(ChunkPos pos, int distance);

Long2ObjectOpenHashMap<SortedArraySet<Ticket<?>>> getTicketsByPosition();

Expand Down
14 changes: 0 additions & 14 deletions src/main/java/carpet/fakes/IngredientInterface.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/carpet/fakes/RedstoneWireBlockInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
public interface RedstoneWireBlockInterface {
BlockState updateLogicPublic(Level world_1, BlockPos blockPos_1, BlockState blockState_1);
void setWiresGivePower(boolean wiresGivePower);
boolean getWiresGivePower();
}
6 changes: 0 additions & 6 deletions src/main/java/carpet/fakes/SpawnGroupInterface.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/carpet/helpers/EntityPlayerActionPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public EntityPlayerActionPack mount(boolean onlyRideables)
{
entities = player.level().getEntities(player, player.getBoundingBox().inflate(3.0D, 1.0D, 3.0D));
}
if (entities.size()==0)
if (entities.isEmpty())
return this;
Entity closest = null;
double distance = Double.POSITIVE_INFINITY;
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/carpet/helpers/HopperCounter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package carpet.helpers;

import carpet.CarpetServer;
import carpet.fakes.IngredientInterface;
import carpet.fakes.RecipeManagerInterface;
import carpet.utils.Messenger;
import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap;
Expand Down Expand Up @@ -32,13 +31,11 @@
import net.minecraft.world.level.material.MapColor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;

import static java.util.Map.entry;

Expand Down Expand Up @@ -177,7 +174,7 @@ public static List<Component> formatAll(MinecraftServer server, boolean realtime
public List<Component> format(MinecraftServer server, boolean realTime, boolean brief)
{
long ticks = Math.max(realTime ? (System.currentTimeMillis() - startMillis) / 50 : server.overworld().getGameTime() - startTick, 1);
if (startTick < 0 || ticks == 0)
if (startTick < 0)
{
if (brief)
{
Expand Down Expand Up @@ -222,7 +219,7 @@ public List<Component> format(MinecraftServer server, boolean realTime, boolean
"g : ","wb "+count,"g , ",
String.format("wb %.1f", count * (20.0 * 60.0 * 60.0) / ticks), "w /h"
);
}).collect(Collectors.toList()));
}).toList());
return items;
}

Expand Down Expand Up @@ -378,14 +375,11 @@ public static TextColor guessColor(Item item, RegistryAccess registryAccess)
{
for (Ingredient ingredient: r.getIngredients())
{
for (Collection<ItemStack> stacks : ((IngredientInterface) (Object) ingredient).getRecipeStacks())
for (ItemStack iStak : ingredient.getItems())
{
for (ItemStack iStak : stacks)
{
TextColor cand = fromItem(iStak.getItem(), registryAccess);
if (cand != null)
return cand;
}
TextColor cand = fromItem(iStak.getItem(), registryAccess);
if (cand != null)
return cand;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/helpers/RedstoneWireTurbo.java
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,6 @@ public void updateNeighborShapes(Level level, BlockPos pos, BlockState state) {
private static int getMaxCurrentStrength(final UpdateNode upd, final int strength) {
if (upd.type != UpdateNode.Type.REDSTONE) return strength;
final int i = upd.currentState.getValue(RedStoneWireBlock.POWER);
return i > strength ? i : strength;
return Math.max(i, strength);
}
}
2 changes: 1 addition & 1 deletion src/main/java/carpet/logging/HUDController.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void update_hud(MinecraftServer server, List<ServerPlayer> force)
{
ClientboundTabListPacket packet = new ClientboundTabListPacket(
scarpet_headers.getOrDefault(player.getScoreboardName(), Component.literal("")),
Messenger.c(player_huds.getOrDefault(player, List.of()).toArray(new Object[0]))
Messenger.c(player_huds.getOrDefault(player, List.of()).toArray())
);
player.connection.send(packet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void onEntityImpacted(Entity entity, Vec3 accel)
}


public static record EntityChangedStatusWithCount(Vec3 pos, EntityType<?> type, Vec3 accel)
public record EntityChangedStatusWithCount(Vec3 pos, EntityType<?> type, Vec3 accel)
{
public EntityChangedStatusWithCount(Entity e, Vec3 accel)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onFinish()
line.add(String.format("^w Tick: %d\nx: %f\ny: %f\nz: %f\n------------\nmx: %f\nmy: %f\nmz: %f",
i, pos.x, pos.y, pos.z, mot.x, mot.y, mot.z));
if ((((i + 1) % MAX_TICKS_PER_LINE) == 0) || i == positions.size() - 1) {
comp.add(Messenger.c(line.toArray(new Object[0])));
comp.add(Messenger.c(line.toArray()));
line.clear();
}
}
Expand Down
55 changes: 0 additions & 55 deletions src/main/java/carpet/mixins/DistanceManager_spawnChunksMixin.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;

@Mixin(value = Explosion.class)
@Mixin(Explosion.class)
public abstract class Explosion_optimizedTntMixin
{
@Shadow
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/carpet/mixins/Ingredient_scarpetMixin.java

This file was deleted.

Loading
Loading