Skip to content

Commit

Permalink
Clear code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Jul 5, 2023
1 parent b2382c7 commit 6e39cd4
Show file tree
Hide file tree
Showing 56 changed files with 126 additions and 4,581 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
return 0;
} else {
- try {
+ try (co.aikar.timings.Timing timing = p_195447_1_.getTiming().startTiming()) { // Paper
+ try {
this.field_194021_h = true;
int j = 0;
FunctionObject.IEntry[] afunctionobject$ientry = p_195447_1_.func_193528_a();
16 changes: 0 additions & 16 deletions patches/minecraft/net/minecraft/block/Block.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@
private static final LoadingCache<VoxelShape, Boolean> field_223006_b = CacheBuilder.newBuilder().maximumSize(512L).weakKeys().build(new CacheLoader<VoxelShape, Boolean>() {
public Boolean load(VoxelShape p_load_1_) {
return !VoxelShapes.func_197879_c(VoxelShapes.func_197868_b(), p_load_1_, IBooleanFunction.field_223236_g_);
@@ -64,6 +_,15 @@
});
protected final StateContainer<Block, BlockState> field_176227_L;
private BlockState field_196275_y;
+ // Paper start
+ public co.aikar.timings.Timing timing;
+ public co.aikar.timings.Timing getTiming() {
+ if (timing == null) {
+ timing = co.aikar.timings.MinecraftTimings.getBlockTiming(this);
+ }
+ return timing;
+ }
+ // Paper end
@Nullable
private String field_149770_b;
@Nullable
@@ -151,6 +_,8 @@
super(p_i48440_1_);
StateContainer.Builder<Block, BlockState> builder = new StateContainer.Builder<>(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
--- a/net/minecraft/command/FunctionObject.java
+++ b/net/minecraft/command/FunctionObject.java
@@ -15,12 +_,22 @@
public class FunctionObject {
private final FunctionObject.IEntry[] field_193530_b;
private final ResourceLocation field_197002_b;
+ // Paper start
+ public co.aikar.timings.Timing timing;
+ public co.aikar.timings.Timing getTiming() {
+ if (timing == null) {
+ timing = co.aikar.timings.MinecraftTimings.getCommandFunctionTiming(this);
+ }
+ return timing;
+ }
+ // Paper end

public FunctionObject(ResourceLocation p_i47973_1_, FunctionObject.IEntry[] p_i47973_2_) {
this.field_197002_b = p_i47973_1_;
@@ -21,6 +_,7 @@
this.field_193530_b = p_i47973_2_;
}

Expand Down
23 changes: 3 additions & 20 deletions patches/minecraft/net/minecraft/entity/EntityType.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,9 @@
private static <T extends Entity> EntityType<T> func_200712_a(String p_200712_0_, EntityType.Builder<T> p_200712_1_) {
return Registry.func_218325_a(Registry.field_212629_r, p_200712_0_, p_200712_1_.func_206830_a(p_200712_0_));
}
@@ -282,7 +_,19 @@
return Registry.field_212629_r.func_241873_b(ResourceLocation.func_208304_a(p_220327_0_));
@@ -283,6 +_,10 @@
}

+ // Paper start - timings
+ public static String id = "custom"; // Mohist
+ public final co.aikar.timings.Timing tickTimer;
+ public final co.aikar.timings.Timing inactiveTickTimer;
+ public final co.aikar.timings.Timing passengerTickTimer;
+ public final co.aikar.timings.Timing passengerInactiveTickTimer;
+ // Paper end
+
public EntityType(EntityType.IFactory<T> p_i231489_1_, EntityClassification p_i231489_2_, boolean p_i231489_3_, boolean p_i231489_4_, boolean p_i231489_5_, boolean p_i231489_6_, ImmutableSet<Block> p_i231489_7_, EntitySize p_i231489_8_, int p_i231489_9_, int p_i231489_10_) {
+ this(p_i231489_1_, p_i231489_2_, p_i231489_3_, p_i231489_4_, p_i231489_5_, p_i231489_6_, p_i231489_7_, p_i231489_8_, p_i231489_9_, p_i231489_10_, EntityType::defaultVelocitySupplier, EntityType::defaultTrackingRangeSupplier, EntityType::defaultUpdateIntervalSupplier, null);
+ }
Expand All @@ -57,20 +48,14 @@
this.field_200732_aK = p_i231489_1_;
this.field_220355_ba = p_i231489_2_;
this.field_225438_be = p_i231489_6_;
@@ -293,6 +_,16 @@
@@ -293,6 +_,10 @@
this.field_220359_bi = p_i231489_8_;
this.field_233594_bl_ = p_i231489_9_;
this.field_233595_bm_ = p_i231489_10_;
+ this.velocityUpdateSupplier = velocityUpdateSupplier;
+ this.trackingRangeSupplier = trackingRangeSupplier;
+ this.updateIntervalSupplier = updateIntervalSupplier;
+ this.customClientFactory = customClientFactory;
+ // Paper start - timings
+ this.tickTimer = co.aikar.timings.MinecraftTimings.getEntityTimings(id, "tick");
+ this.inactiveTickTimer = co.aikar.timings.MinecraftTimings.getEntityTimings(id, "inactiveTick");
+ this.passengerTickTimer = co.aikar.timings.MinecraftTimings.getEntityTimings(id, "passengerTick");
+ this.passengerInactiveTickTimer = co.aikar.timings.MinecraftTimings.getEntityTimings(id, "passengerInactiveTick");
+ // Paper end
}

@Nullable
Expand Down Expand Up @@ -175,7 +160,7 @@
private Builder(EntityType.IFactory<T> p_i50479_1_, EntityClassification p_i50479_2_) {
this.field_200709_a = p_i50479_1_;
this.field_220324_b = p_i50479_2_;
@@ -587,16 +_,48 @@
@@ -587,16 +_,46 @@
return this;
}

Expand Down Expand Up @@ -209,8 +194,6 @@
}

- return new EntityType<>(this.field_200709_a, this.field_220324_b, this.field_200710_b, this.field_200711_c, this.field_220325_e, this.field_225436_f, this.field_233603_c_, this.field_220326_f, this.field_233604_h_, this.field_233605_i_);
+ id = p_206830_1_; // Mohist
+
+ return new EntityType<>(this.field_200709_a, this.field_220324_b, this.field_200710_b, this.field_200711_c, this.field_220325_e, this.field_225436_f, this.field_233603_c_, this.field_220326_f, this.field_233604_h_, this.field_233605_i_, velocityUpdateSupplier, trackingRangeSupplier, updateIntervalSupplier, customClientFactory);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,69 +56,6 @@
return this.field_194138_c;
}

@@ -47,17 +_,56 @@

public boolean func_77569_a(CraftingInventory p_77569_1_, World p_77569_2_) {
RecipeItemHelper recipeitemhelper = new RecipeItemHelper();
+ java.util.List<ItemStack> inputs = new java.util.ArrayList<>();
int i = 0;

+ // Paper start
+ java.util.List<ItemStack> providedItems = new java.util.ArrayList<>();
+ co.aikar.util.Counter<ItemStack> matchedProvided = new co.aikar.util.Counter<>();
+ co.aikar.util.Counter<Ingredient> matchedIngredients = new co.aikar.util.Counter<>();
+ // Paper end
for(int j = 0; j < p_77569_1_.func_70302_i_(); ++j) {
ItemStack itemstack = p_77569_1_.func_70301_a(j);
if (!itemstack.func_190926_b()) {
- ++i;
- recipeitemhelper.func_221264_a(itemstack, 1);
- }
- }
-
- return i == this.field_77579_b.size() && recipeitemhelper.func_194116_a(this, (IntList)null);
+ if (isSimple) {
+ // Paper start
+ itemstack = itemstack.func_77946_l();
+ providedItems.add(itemstack);
+ for (Ingredient ingredient : field_77579_b) {
+ if (ingredient.test(itemstack)) {
+ matchedProvided.increment(itemstack);
+ matchedIngredients.increment(ingredient);
+ }
+ }
+ // Paper end
+ } else {
+ inputs.add(itemstack);
+ }
+ }
+ }
+
+ //return i == this.recipeItems.size() && (isSimple ? recipeitemhelper.canCraft(this, (IntList)null) : net.minecraftforge.common.util.RecipeMatcher.findMatches(inputs, this.recipeItems) != null);
+ // Paper start
+ if (isSimple && (matchedProvided.isEmpty() || matchedIngredients.isEmpty())) {
+ return false;
+ }
+ java.util.List<Ingredient> ingredients = new java.util.ArrayList<>(this.field_77579_b);
+ providedItems.sort(java.util.Comparator.comparingInt((ItemStack c) -> (int) matchedProvided.getCount(c)).reversed());
+ ingredients.sort(java.util.Comparator.comparingInt((Ingredient c) -> (int) matchedIngredients.getCount(c)));
+
+ PROVIDED:
+ for (ItemStack provided : providedItems) {
+ for (Iterator<Ingredient> itIngredient = ingredients.iterator(); itIngredient.hasNext(); ) {
+ Ingredient ingredient = itIngredient.next();
+ if (ingredient.test(provided)) {
+ itIngredient.remove();
+ continue PROVIDED;
+ }
+ }
+ return false;
+ }
+ return isSimple ? ingredients.isEmpty() : net.minecraftforge.common.util.RecipeMatcher.findMatches(inputs, this.field_77579_b) != null;
+ // Paper end
}

public ItemStack func_77572_b(CraftingInventory p_77572_1_) {
@@ -68,14 +_,15 @@
return p_194133_1_ * p_194133_2_ >= this.field_77579_b.size();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
--- a/net/minecraft/network/PacketThreadUtil.java
+++ b/net/minecraft/network/PacketThreadUtil.java
@@ -1,5 +_,9 @@
@@ -1,5 +_,7 @@
package net.minecraft.network;

+import co.aikar.timings.MinecraftTimings;
+import co.aikar.timings.Timing;
+import net.minecraft.network.play.ServerPlayNetHandler;
+import net.minecraft.server.MinecraftServer;
import net.minecraft.util.concurrent.ThreadTaskExecutor;
import net.minecraft.world.server.ServerWorld;
import org.apache.logging.log4j.LogManager;
@@ -14,9 +_,13 @@

@@ -15,6 +_,7 @@
public static <T extends INetHandler> void func_218797_a(IPacket<T> p_218797_0_, T p_218797_1_, ThreadTaskExecutor<?> p_218797_2_) throws ThreadQuickExitException {
if (!p_218797_2_.func_213162_bc()) {
+ Timing timing = MinecraftTimings.getPacketTiming(p_218797_0_); // Paper - timings
p_218797_2_.execute(() -> {
+ if (MinecraftServer.getServer().hasStopped() || (p_218797_1_ instanceof ServerPlayNetHandler && ((ServerPlayNetHandler) p_218797_1_).isDisconnected())) return; // CraftBukkit, MC-142590
if (p_218797_1_.func_147298_b().func_150724_d()) {
+ try (Timing ignored = timing.startTiming()) { // Paper - timings
p_218797_0_.func_148833_a(p_218797_1_);
+ } // Paper - timings
} else {
field_225384_a.debug("Ignoring packet due to disconnection: " + p_218797_0_);
}
@@ -24,5 +_,10 @@
});
throw ThreadQuickExitException.field_179886_a;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
--- a/net/minecraft/network/play/ServerPlayNetHandler.java
+++ b/net/minecraft/network/play/ServerPlayNetHandler.java
@@ -1,8 +_,12 @@
@@ -1,8 +_,11 @@
package net.minecraft.network.play;

+import co.aikar.timings.MinecraftTimings;
+import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.primitives.Doubles;
Expand Down Expand Up @@ -1042,7 +1041,7 @@
if (this.field_147369_b.field_71071_by.field_70461_c != p_147355_1_.func_149614_c() && this.field_147369_b.func_184600_cs() == Hand.MAIN_HAND) {
this.field_147369_b.func_184602_cy();
}
@@ -1066,61 +_,298 @@
@@ -1066,61 +_,294 @@
this.field_147369_b.field_71071_by.field_70461_c = p_147355_1_.func_149614_c();
this.field_147369_b.func_143004_u();
} else {
Expand Down Expand Up @@ -1287,7 +1286,6 @@

private void func_147361_d(String p_147361_1_) {
- this.field_147367_d.func_195571_aL().func_197059_a(this.field_147369_b.func_195051_bN(), p_147361_1_);
+ MinecraftTimings.playerCommandTimer.startTiming(); // Paper
+ // CraftBukkit start - whole method
+ if ( org.spigotmc.SpigotConfig.logCommands ) { // Spigot
+ this.field_147370_c.info(this.field_147369_b.func_195047_I_() + " issued server command: " + p_147361_1_);
Expand All @@ -1297,7 +1295,6 @@
+ PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, p_147361_1_, new LazyPlayerSet(field_147367_d));
+ this.craftServer.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ MinecraftTimings.playerCommandTimer.stopTiming(); // Paper
+ return;
+ }
+
Expand All @@ -1309,8 +1306,6 @@
+ player.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
+ java.util.logging.Logger.getLogger(ServerPlayNetHandler.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ return;
+ } finally {
+ MinecraftTimings.playerCommandTimer.stopTiming(); // Paper
+ }
+ // CraftBukkit end
}
Expand Down
22 changes: 2 additions & 20 deletions patches/minecraft/net/minecraft/server/Main.java.patch
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -1,19 +_,23 @@
@@ -1,19 +_,22 @@
package net.minecraft.server;

+import com.destroystokyo.paper.config.PaperConfig;
import com.google.common.collect.ImmutableSet;
+import com.mohistmc.util.DatapackCodecUtils;
import com.mojang.authlib.GameProfileRepository;
Expand Down Expand Up @@ -41,7 +40,7 @@
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings;
@@ -71,31 +_,77 @@
@@ -71,31 +_,60 @@
OptionSpec<Integer> optionspec11 = optionparser.accepts("port").withRequiredArg().ofType(Integer.class).defaultsTo(-1);
OptionSpec<String> optionspec12 = optionparser.accepts("serverId").withRequiredArg();
OptionSpec<String> optionspec13 = optionparser.nonOptions();
Expand All @@ -68,14 +67,6 @@
+ .ofType(File.class)
+ .defaultsTo(new File("plugins"))
+ .describedAs("Plugin directory");
+
+ // Paper Start
+ optionparser.acceptsAll(Arrays.asList("paper", "paper-settings"), "File for paper settings")
+ .withRequiredArg()
+ .ofType(File.class)
+ .defaultsTo(new File("paper.yml"))
+ .describedAs("Yml file");
+ // Paper end
+
+

Expand All @@ -87,15 +78,6 @@
return;
}

+
+ // Paper start - load config files for access below if needed
+ org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = loadConfigFile((File) optionset.valueOf("bukkit-settings"));
+ org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = loadConfigFile((File) optionset.valueOf("spigot-settings"));
+ org.bukkit.configuration.file.YamlConfiguration paperConfiguration = loadConfigFile((File) optionset.valueOf("paper-settings"));
+
+ PaperConfig.init((File) optionset.valueOf("paper-settings")); // Paper
+ // Paper end
+
+ Path path1 = Paths.get("eula.txt");
+ ServerEula servereula = new ServerEula(path1);
+
Expand Down
Loading

0 comments on commit 6e39cd4

Please sign in to comment.