Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
Bunch of patches + hopper fix (#352)
Browse files Browse the repository at this point in the history
* undo #74

* add SportPaper #207 Block#toLegacyData optimisation

* add SportPaper #206 Remove the world before nullifying chunkLoader & chunkProvider

* add SportPaper #204 dont divide d14 by 0

* add SportPaper #220 Use EnumMap in CraftPlayer#playEffect()

* add SportPaper #218 Update entity head yaw on teleport

* add SportPaper #130 fix CraftLivingEntity#damage not calling EntityDamageEvent

* add Migot #36 Check for lava only once per tick

* add optimize region cache - paper 1.13 backport

* update readme

* backport parts of light queue changes from 1.13

* Paper #178 Disable Vanilla Chunk GC in favor of Bukkits

* Paper #176 Auto fix bad Y levels on player login

* Paper #172 Incremental Auto Saving

* Paper Chunk registration fixes & Fix infinite loop when saving chunks

* Paper #163 MC-80966 - Always send chunk sections

* Paper Fix hopper suck in patch bug

* Update NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/CraftServer.java

Co-authored-by: Elier <[email protected]>

* third time to add dictionary.java...

* im very dump

* forth time to fix that... shall have more sleep

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/Entity.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/Entity.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/RegionFileCache.java

Co-authored-by: Elier <[email protected]>

* revert kigpaper optimize damage source

* get away because of revert

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/ChunkSection.java

Co-authored-by: Elier <[email protected]>

* Fix spaces

Co-authored-by: Elier <[email protected]>

* Fix spaces

Co-authored-by: Elier <[email protected]>

* Fix spaces

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/WorldServer.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/EntityPlayer.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/MinecraftServer.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/RegionFileCache.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/World.java

Co-authored-by: Elier <[email protected]>

* Update NachoSpigot-Server/src/main/java/net/minecraft/server/RegionFileCache.java

Co-authored-by: Elier <[email protected]>

Co-authored-by: Elier <[email protected]>
  • Loading branch information
crafter23456 and Elier authored Feb 26, 2022
1 parent db8d380 commit ec731d5
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 73 deletions.
2 changes: 1 addition & 1 deletion NachoSpigot-Server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.68.Final</version>
<version>4.1.74.Final</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.cobblesword.nachospigot.commons;

import net.minecraft.server.EnumParticle;
import org.bukkit.Effect;

import java.util.EnumMap;

public class Dictionary {
public static final EnumMap<Effect, EnumParticle> EFFECT_TO_PARTICLE = new EnumMap<>(Effect.class);

static {
String tmp;
for (EnumParticle p : EnumParticle.values()) {
tmp = p.b().replace("_", "");
for (Effect e : Effect.values()) {
// This is pretty much the original code, but we only call it once / effect & matching particle
if (e.getName() != null && e.getName().startsWith(tmp)) {
EFFECT_TO_PARTICLE.put(e, p);
break;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@ public IBlockData fromLegacyData(int i) {
}

public int toLegacyData(IBlockData iblockdata) {
if (iblockdata != null && !iblockdata.a().isEmpty()) {
throw new IllegalArgumentException("Don\'t know how to convert " + iblockdata + " back into data...");
} else {
return 0;
}
return 0; // Sportpaper - optimize toLegacyData removing unneeded sanity checks
}

public IBlockData updateState(IBlockData iblockdata, IBlockAccess iblockaccess, BlockPosition blockposition) {
Expand Down
33 changes: 14 additions & 19 deletions NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ private void d(int i, int j) {
this.g[i + j * 16] = true;
this.k = true;
}

private void recheckGaps(boolean flag) { h(flag); } // Paper

private void h(boolean flag) {
this.world.methodProfiler.a("recheckGaps");
Expand Down Expand Up @@ -1158,7 +1160,7 @@ public <T extends Entity> void a(Class<? extends T> oclass, AxisAlignedBB axisal

// PaperSpigot start
int[] counts;
if (ItemStack.class.isAssignableFrom(oclass)) {
if (EntityItem.class.isAssignableFrom(oclass)) {
counts = itemCounts;
} else if (IInventory.class.isAssignableFrom(oclass)) {
counts = inventoryEntityCounts;
Expand Down Expand Up @@ -1280,10 +1282,20 @@ public BlockPosition h(BlockPosition blockposition) {

return new BlockPosition(blockposition.getX(), this.f[k], blockposition.getZ());
}

// Paper start
private boolean shouldRecheckGaps = false;
public void doGapCheck() {
if (shouldRecheckGaps) {
this.recheckGaps(false);
shouldRecheckGaps = false;
}
}
// Paper end

public void b(boolean flag) {
if (this.k && !this.world.worldProvider.o() && !flag) {
this.recheckGaps(this.world.isClientSide); // PaperSpigot - Asynchronous lighting updates
shouldRecheckGaps = true; // Paper
}

this.p = true;
Expand All @@ -1304,23 +1316,6 @@ public void b(boolean flag) {

}

/**
* PaperSpigot - Recheck gaps asynchronously.
*/
public void recheckGaps(final boolean isClientSide) {
if (!world.paperSpigotConfig.useAsyncLighting) {
this.h(isClientSide);
return;
}

world.lightingExecutor.submit(new Runnable() {
@Override
public void run() {
Chunk.this.h(isClientSide);
}
});
}

public boolean isReady() {
// Spigot Start
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public void b() {
if (this.c()) {
continue;
}
break; // Paper - fix infinite loop when saving chunks
}
} finally {
this.e = false;
Expand Down Expand Up @@ -296,10 +297,6 @@ private void a(Chunk chunk, World world, NBTTagCompound nbttagcompound) {
nbttagcompound1 = new NBTTagCompound();
tileentity.b(nbttagcompound1);
nbttaglist2.add(nbttagcompound1);

if(tileentity instanceof TileEntityHopper) {
Arrays.fill(((TileEntityHopper) tileentity).items, null);
}
}

nbttagcompound.set("TileEntities", nbttaglist2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public int c(int i, int j, int k) {
}

public boolean a() {
return this.nonEmptyBlockCount == 0;
//return this.nonEmptyBlockCount == 0;
// Paper - MC-80966
// Even if there are no blocks, there may be other information associated with the chunk, always send it.
return false;
}

public boolean shouldTick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public synchronized void setSeed(long seed) {
public void inactiveTick() { }
// Spigot end

// Migot start
private boolean isInLava;
private int lastLavaCheck = Integer.MIN_VALUE;
// Migot end

public int getId() {
return this.id;
}
Expand Down Expand Up @@ -1070,7 +1075,15 @@ public boolean a(Material material) {
}

public boolean ab() {
return this.world.a(this.getBoundingBox().grow(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D), Material.LAVA);
// Migot start - Check for lava only once per tick
// return this.world.a(this.getBoundingBox().grow(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D), Material.LAVA);
int currentTick = MinecraftServer.currentTick;
if (this.lastLavaCheck != currentTick) {
this.lastLavaCheck = currentTick;
this.isInLava = this.world.a(this.getBoundingBox().grow(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D), Material.LAVA);
}
return this.isInLava;
// Migot end
}

public void a(float f, float f1, float f2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public void a(NBTTagCompound nbttagcompound) {
this.playerInteractManager.setGameMode(WorldSettings.EnumGamemode.getById(nbttagcompound.getInt("playerGameType")));
}
}


if (this.locY > 300) this.locY = 200;
this.getBukkitEntity().readExtraData(nbttagcompound); // CraftBukkit
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,11 @@ protected void A() throws ExceptionWorldConflict { // CraftBukkit - added throws
this.r.b().a(agameprofile);
}

if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
if (autosavePeriod > 0 /*&& this.ticks % autosavePeriod == 0*/) { // CraftBukkit // Paper - Incremental Auto Saving
SpigotTimings.worldSaveTimer.startTiming(); // Spigot
this.methodProfiler.a("save");
this.playerList.savePlayers(); // Nacho - deobfuscate playerList
//this.playerList.savePlayers();
if (this.ticks % autosavePeriod == 0) this.playerList.savePlayers(); // Paper - Incremental Auto Saving
// Spigot Start
// We replace this with saving each individual world as this.saveChunks(...) is broken,
// and causes the main thread to sleep for random amounts of time depending on chunk activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class RegionFileCache {
public static final Map<File, RegionFile> a = Maps.newHashMap(); // Spigot - private -> public

// PaperSpigot start
public static synchronized RegionFile a(File file, int i, int j) {
public static /*synchronized*/ RegionFile a(File file, int i, int j) { // Paper - remove synchronization
return a(file, i, j, true);
}
public static synchronized RegionFile a(File file, int i, int j, boolean create) {
public static /*synchronized*/ RegionFile a(File file, int i, int j, boolean create) { // Paper - remove synchronization
// PaperSpigot end
File file1 = new File(file, "region");
File file2 = new File(file1, "r." + (i >> 5) + "." + (j >> 5) + ".mca");
Expand All @@ -41,7 +41,7 @@ public static synchronized RegionFile a(File file, int i, int j, boolean create)
}
}

public static synchronized void a() {
public static /*synchronized*/ void a() { // Paper - remove synchronization
Iterator iterator = RegionFileCache.a.values().iterator();

while (iterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,8 @@ public void entityJoinedWorld(Entity entity, boolean flag) {
}

int k = MathHelper.floor(entity.locX / 16.0D);
int l = MathHelper.floor(entity.locY / 16.0D);
//int l = MathHelper.floor(entity.locY / 16.0D);
int l = Math.min(15, Math.max(0, MathHelper.floor(entity.locY / 16.0D))); // Paper - stay consistent with chunk add/remove behavior
int i1 = MathHelper.floor(entity.locZ / 16.0D);

// Nacho start - deobfuscate chunkX, chunkY, chunkZ removeEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,13 +962,13 @@ public void save(boolean flag, IProgressUpdate iprogressupdate) throws Exception

this.chunkProvider.saveChunks(flag, iprogressupdate);
// CraftBukkit - ArrayList -> Collection
Collection<Chunk> arraylist = this.chunkProviderServer.a();

/*Collection<Chunk> arraylist = this.chunkProviderServer.a(); // Paper start
for (Chunk value : arraylist) {
if (value != null && !this.manager.a(value.locX, value.locZ)) {
this.chunkProviderServer.queueUnload(value.locX, value.locZ);
}
}
*/ // Paper end

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,10 @@ public boolean unloadWorld(World world, boolean save) {
if (e.isCancelled()) {
return false;
}


worlds.remove(world.getName().toLowerCase());
console.worlds.remove(handle);

if (save) {
try {
handle.save(true, null);
Expand All @@ -1064,9 +1067,6 @@ public boolean unloadWorld(World world, boolean save) {
chunkProviderServer.chunks.clear();
}

worlds.remove(world.getName().toLowerCase());
console.worlds.remove(handle);

// KigPaper start - fix memory leak
CraftingManager craftingManager = CraftingManager.getInstance();
CraftInventoryView lastView = (CraftInventoryView) craftingManager.lastCraftView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.UUID;

import dev.cobblesword.nachospigot.commons.Constants;
import dev.cobblesword.nachospigot.commons.Dictionary;
import me.elier.nachospigot.config.NachoConfig;
import net.minecraft.server.*;

Expand Down Expand Up @@ -60,7 +61,6 @@
import org.bukkit.util.Vector;

import net.jafama.FastMath;
import me.elier.nachospigot.config.NachoConfig;

public class CraftWorld implements World {
public static final int CUSTOM_DIMENSION_OFFSET = 10;
Expand Down Expand Up @@ -1466,24 +1466,16 @@ public void playEffect( Location location, Effect effect, int id, int data, floa
{
net.minecraft.server.EnumParticle particle = null;
int[] extra = null;
for ( net.minecraft.server.EnumParticle p : net.minecraft.server.EnumParticle.values() )
{
if ( effect.getName().startsWith( p.b().replace("_", "") ) )
{
particle = p;
if ( effect.getData() != null )
{
if ( effect.getData().equals( org.bukkit.Material.class ) )
{
extra = new int[]{ id };
} else
{
extra = new int[]{ (data << 12) | (id & 0xFFF) };
}
if ((particle = Dictionary.EFFECT_TO_PARTICLE.get(effect)) != null) {
if (effect.getData() != null) {
if (effect.getData().equals( org.bukkit.Material.class)) {
extra = new int[]{id};
} else {
extra = new int[]{(data << 12) | (id & 0xFFF)};
}
break;
}
}

if ( extra == null )
{
extra = Constants.EMPTY_ARRAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public boolean teleport(Location location, TeleportCause cause) {
// entity.world = ((CraftWorld) location.getWorld()).getHandle();
// Spigot end
entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
entity.f(location.getYaw()); // KigPaper - update head yaw to keep consistency with /tp
entity.world.entityJoinedWorld(entity, false); // PaperSpigot - Fix issues with entities not being switched to their new chunk
// entity.setLocation() throws no event, and so cannot be cancelled
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import me.elier.nachospigot.config.NachoConfig;
import net.md_5.bungee.api.chat.BaseComponent;
import dev.cobblesword.nachospigot.commons.Dictionary;

import net.minecraft.server.*;
import net.minecraft.server.PacketPlayOutTitle.EnumTitleAction;
Expand Down Expand Up @@ -1532,22 +1533,16 @@ public void playEffect( Location location, Effect effect, int id, int data, floa
{
net.minecraft.server.EnumParticle particle = null;
int[] extra = null;
for ( net.minecraft.server.EnumParticle p : net.minecraft.server.EnumParticle.values() )
{
if ( effect.getName().startsWith( p.b().replace("_", "") ) )
if ((particle = Dictionary.EFFECT_TO_PARTICLE.get(effect)) != null) {
if (effect.getData() != null)
{
particle = p;
if ( effect.getData() != null )
if (effect.getData().equals(Material.class))
{
extra = new int[]{id};
} else
{
if ( effect.getData().equals( org.bukkit.Material.class ) )
{
extra = new int[]{ id };
} else
{
extra = new int[]{ (data << 12) | (id & 0xFFF) };
}
extra = new int[]{(data << 12) | (id & 0xFFF)};
}
break;
}
}
if ( extra == null )
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ See: [Contributors Page](https://github.com/CobbleSword/NachoSpigot/graphs/contr
[Paper-0249] Improve BlockPosition inlining by Techcable
[Paper-0254] Don't blindly send unlit chunks when lighting updates are allowed by Shane Freeder
[Paper-0266] [MC-99321] Dont check for blocked double chest for hoppers
[Paper-0301] Optimize Region File Cache
[Paper-0302] Don't load chunks for villager door checks by Aikar
[Paper-0313] Optimize World Time Updates by Aikar
[Paper-0321] Server Tick Events
Expand Down Expand Up @@ -170,7 +171,9 @@ See: [Contributors Page](https://github.com/CobbleSword/NachoSpigot/graphs/contr
[SportPaper-0171] Fix NPE in CraftChunk#getBlocks
[SportPaper-0197] Optimize head rotation patch
[SportPaper-0201] Cache block break animation packet
[SportPaper-0204] Optimize toLegacyData removing unneeded sanity checks
[SportPaper-0203] Fix Teleport Invisibility
[SportPaper-0206] Remove the world before nullifying chunkLoader & chunkProvider
[PaperBin-????] WorldServer#everyoneDeeplySleeping optimization
Expand All @@ -182,6 +185,7 @@ See: [Contributors Page](https://github.com/CobbleSword/NachoSpigot/graphs/contr
[KigPaper-0167] Add setType without lighting update API
[KigPaper-0172] NBT no-op for block place packet
[KigPaper-0191] Don't calculate initial light if not requested
[KigPaper-0220] Entity: Use EnumMap in CraftPlayer#playEffect()
[FlamePaper-0102] Fixed chunk memory leak
[FlamePaper-0103] Limit CraftChatMessage iterations
Expand All @@ -198,6 +202,7 @@ See: [Contributors Page](https://github.com/CobbleSword/NachoSpigot/graphs/contr
[MineTick-0017] Fix Insane Nether Portal Lag
[Migot-0009] Prevent Creature Spawning in Unloaded Chunks
[Migot-0036] Check for lava only once per tick
[Sugarcane-0022] Add YAML comments
```

0 comments on commit ec731d5

Please sign in to comment.