diff --git a/build.gradle b/build.gradle index 826bc55..66332a9 100644 --- a/build.gradle +++ b/build.gradle @@ -41,13 +41,15 @@ compileCommon compileClient compileServer - compile.extendsFrom compileCommon, compileClient, compileServer runtimeCommon - runtimeClient.extendsFrom runtimeCommon, compileCommon, compileClient - runtimeServer.extendsFrom runtimeCommon, compileCommon, compileServer - runtimeAll.extendsFrom runtimeCommon, compileCommon, compileClient, compileServer - runtime.setExtendsFrom([runtimeAll]) - //runtimeClient & runtimeServer is not linking to IDE and must not be used for adding dependencies + runtimeClient + runtimeServer + compile.extendsFrom compileCommon, compileClient, compileServer + packageClient.extendsFrom compileCommon, compileClient, runtimeCommon, runtimeClient + packageServer.extendsFrom compileCommon, compileServer, runtimeCommon, runtimeServer + packageAll.extendsFrom compileCommon, compileClient, compileServer, runtimeCommon, runtimeClient, runtimeServer + runtime.setExtendsFrom([packageAll]) + //packageClient, packageServer & packageAll is not linking to IDE and must not be used for adding dependencies } dependencies { @@ -102,7 +104,7 @@ compileServer 'jline:jline:2.13', {transitive = false} runtimeCommon 'net.openhft:koloboke-impl-jdk8:0.6.8' - runtime 'mysql:mysql-connector-java:5.1.31' + runtimeServer 'mysql:mysql-connector-java:5.1.31' testCompile "org.spockframework:spock-core:1.1-groovy-2.4-rc-1" } @@ -153,7 +155,7 @@ attributes( 'Main-Class': 'cpw.mods.fml.relauncher.ServerLaunchWrapper', 'TweakClass': 'cpw.mods.fml.common.launcher.FMLTweaker', - 'Class-Path': configurations.runtimeServer.collect { 'libraries/' + it.getName() }.join(' ') + 'Class-Path': configurations.packageServer.collect { 'libraries/' + it.getName() }.join(' ') ) } } @@ -209,26 +211,26 @@ publications { if(publish_jars.contains('dev')) mavenDevJar(MavenPublication) { - from new JavaLibrary(new ArchivePublishArtifact(tasks.jar), configurations.runtimeAll.getAllDependencies()) + from new JavaLibrary(new ArchivePublishArtifact(tasks.jar), configurations.packageAll.getAllDependencies()) artifacts.matching({it.classifier == "dev"}).all({it.classifier = null}) artifact tasks.jar_source artifact tasks.changelog.getProperty('changelogFile'), {classifier = 'changelog'} } if(publish_jars.contains('universal')) mavenUnivarsalJar(MavenPublication) { - from new JavaLibrary(new ArchivePublishArtifact(tasks.jar_universal), configurations.runtimeAll.getAllDependencies()) + from new JavaLibrary(new ArchivePublishArtifact(tasks.jar_universal), configurations.packageAll.getAllDependencies()) artifacts.matching({it.classifier == "universal"}).all({it.classifier = null}) artifactId = project.name + '-universal' } if(publish_jars.contains('server')) mavenServerJar(MavenPublication) { - from new JavaLibrary(new ArchivePublishArtifact(tasks.jar_server), configurations.runtimeServer.getAllDependencies()) + from new JavaLibrary(new ArchivePublishArtifact(tasks.jar_server), configurations.packageServer.getAllDependencies()) artifacts.matching({it.classifier == "server"}).all({it.classifier = null}) artifactId = project.name + '-server' } if(publish_jars.contains('client')) mavenClientJar(MavenPublication) { - from new JavaLibrary(new ArchivePublishArtifact(tasks.jar_client), configurations.runtimeClient.getAllDependencies()) + from new JavaLibrary(new ArchivePublishArtifact(tasks.jar_client), configurations.packageClient.getAllDependencies()) artifacts.matching({it.classifier == "client"}).all({it.classifier = null}) artifactId = project.name + '-client' } diff --git a/src/main/java/net/minecraft/block/BlockLeaves.java b/src/main/java/net/minecraft/block/BlockLeaves.java index 86d2a39..f432cf1 100644 --- a/src/main/java/net/minecraft/block/BlockLeaves.java +++ b/src/main/java/net/minecraft/block/BlockLeaves.java @@ -8,15 +8,14 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.stats.StatList; import net.minecraft.util.IIcon; import net.minecraft.world.ColorizerFoliage; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.IShearable; +import org.ultramine.server.util.MinecraftUtil; public abstract class BlockLeaves extends BlockLeavesBase implements IShearable { @@ -103,6 +102,7 @@ if ((l & 8) != 0 && (l & 4) == 0) { + /* byte b0 = 4; int i1 = b0 + 1; byte b1 = 32; @@ -197,6 +197,8 @@ l1 = this.field_150128_a[k1 * j1 + k1 * b1 + k1]; if (l1 >= 0) + */ + if(MinecraftUtil.canLeavesStay(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_, 4)) { p_149674_1_.setBlockMetadataWithNotify(p_149674_2_, p_149674_3_, p_149674_4_, l & -9, 4); } diff --git a/src/main/java/net/minecraft/entity/EntityTrackerEntry.java b/src/main/java/net/minecraft/entity/EntityTrackerEntry.java index 496c144..39ee8ee 100644 --- a/src/main/java/net/minecraft/entity/EntityTrackerEntry.java +++ b/src/main/java/net/minecraft/entity/EntityTrackerEntry.java @@ -114,7 +114,7 @@ public void sendLocationToAllClients(List p_73122_1_) { - this.playerEntitiesUpdated = false; + boolean playerEntitiesUpdated = false; if (!this.isDataInitialized || posX != this.myEntity.chunkCoordX || posZ != this.myEntity.chunkCoordZ) { @@ -122,9 +122,11 @@ this.posY = this.myEntity.posY; this.posZ = this.myEntity.chunkCoordZ; this.isDataInitialized = true; - this.playerEntitiesUpdated = true; - this.sendEventsToPlayers(p_73122_1_); + playerEntitiesUpdated = true; +// this.sendEventsToPlayers(p_73122_1_); + // Moved below to lastScaled(*)Position be calculated first (fixes bug with invisible players) } + this.playerEntitiesUpdated = playerEntitiesUpdated; if (this.field_85178_v != this.myEntity.ridingEntity || this.myEntity.ridingEntity != null && this.ticks % 60 == 0) { @@ -158,11 +160,11 @@ this.sendMetadataToAllAssociatedPlayers(); } - else if(trackingPlayers.size() == 0) + else if(trackingPlayers.size() == 0 && !playerEntitiesUpdated) { // No players - no tracking } - else if (this.ticks % this.updateFrequency == 0 || this.myEntity.isAirBorne || this.myEntity.getDataWatcher().hasChanges()) + else if (this.ticks % this.updateFrequency == 0 || this.myEntity.isAirBorne || this.myEntity.getDataWatcher().hasChanges() || playerEntitiesUpdated) { int i; int j; @@ -283,6 +285,9 @@ this.func_151261_b(new S12PacketEntityVelocity(this.myEntity)); this.myEntity.velocityChanged = false; } + + if(playerEntitiesUpdated) + this.sendEventsToPlayers(p_73122_1_); } private void sendMetadataToAllAssociatedPlayers() diff --git a/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java b/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java index 2a48196..5376b2d 100644 --- a/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java +++ b/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java @@ -847,6 +847,7 @@ this.lastHealth = -1.0F; this.lastFoodLevel = -1; this.destroyedItemsNetCache.addAll(((EntityPlayerMP)p_71049_1_).destroyedItemsNetCache); + this.translator = ((EntityPlayerMP)p_71049_1_).translator; } protected void onNewPotionEffect(PotionEffect p_70670_1_) diff --git a/src/main/java/net/minecraft/util/IntHashMap.java b/src/main/java/net/minecraft/util/IntHashMap.java index f91d4d8..ecc01ee 100644 --- a/src/main/java/net/minecraft/util/IntHashMap.java +++ b/src/main/java/net/minecraft/util/IntHashMap.java @@ -1,18 +1,26 @@ package net.minecraft.util; +import net.openhft.koloboke.collect.map.IntObjMap; +import net.openhft.koloboke.collect.map.hash.HashIntObjMaps; + import java.util.HashSet; import java.util.Set; public class IntHashMap { - private transient IntHashMap.Entry[] slots = new IntHashMap.Entry[16]; - private transient int count; - private int threshold = 12; - private final float growFactor = 0.75F; - private transient volatile int versionStamp; - private Set keySet = new HashSet(); + private final IntObjMap map; private static final String __OBFID = "CL_00001490"; + public IntHashMap(IntObjMap map) + { + this.map = map; + } + + public IntHashMap() + { + this(HashIntObjMaps.newMutableMap()); + } + private static int computeHash(int p_76044_0_) { p_76044_0_ ^= p_76044_0_ >>> 20 ^ p_76044_0_ >>> 12; @@ -26,167 +34,52 @@ public Object lookup(int p_76041_1_) { - int j = computeHash(p_76041_1_); - - for (IntHashMap.Entry entry = this.slots[getSlotIndex(j, this.slots.length)]; entry != null; entry = entry.nextEntry) - { - if (entry.hashEntry == p_76041_1_) - { - return entry.valueEntry; - } - } - - return null; + return map.get(p_76041_1_); } public boolean containsItem(int p_76037_1_) { - return this.lookupEntry(p_76037_1_) != null; + return map.containsKey(p_76037_1_); } final IntHashMap.Entry lookupEntry(int p_76045_1_) { - int j = computeHash(p_76045_1_); - - for (IntHashMap.Entry entry = this.slots[getSlotIndex(j, this.slots.length)]; entry != null; entry = entry.nextEntry) - { - if (entry.hashEntry == p_76045_1_) - { - return entry; - } - } - return null; } public void addKey(int p_76038_1_, Object p_76038_2_) { - this.keySet.add(Integer.valueOf(p_76038_1_)); - int j = computeHash(p_76038_1_); - int k = getSlotIndex(j, this.slots.length); - - for (IntHashMap.Entry entry = this.slots[k]; entry != null; entry = entry.nextEntry) - { - if (entry.hashEntry == p_76038_1_) - { - entry.valueEntry = p_76038_2_; - return; - } - } - - ++this.versionStamp; - this.insert(j, p_76038_1_, p_76038_2_, k); + map.put(p_76038_1_, p_76038_2_); } private void grow(int p_76047_1_) { - IntHashMap.Entry[] aentry = this.slots; - int j = aentry.length; - if (j == 1073741824) - { - this.threshold = Integer.MAX_VALUE; - } - else - { - IntHashMap.Entry[] aentry1 = new IntHashMap.Entry[p_76047_1_]; - this.copyTo(aentry1); - this.slots = aentry1; - this.threshold = (int)((float)p_76047_1_ * this.growFactor); - } } private void copyTo(IntHashMap.Entry[] p_76048_1_) { - IntHashMap.Entry[] aentry = this.slots; - int i = p_76048_1_.length; - for (int j = 0; j < aentry.length; ++j) - { - IntHashMap.Entry entry = aentry[j]; - - if (entry != null) - { - aentry[j] = null; - IntHashMap.Entry entry1; - - do - { - entry1 = entry.nextEntry; - int k = getSlotIndex(entry.slotHash, i); - entry.nextEntry = p_76048_1_[k]; - p_76048_1_[k] = entry; - entry = entry1; - } - while (entry1 != null); - } - } } public Object removeObject(int p_76049_1_) { - this.keySet.remove(Integer.valueOf(p_76049_1_)); - IntHashMap.Entry entry = this.removeEntry(p_76049_1_); - return entry == null ? null : entry.valueEntry; + return map.remove(p_76049_1_); } final IntHashMap.Entry removeEntry(int p_76036_1_) { - int j = computeHash(p_76036_1_); - int k = getSlotIndex(j, this.slots.length); - IntHashMap.Entry entry = this.slots[k]; - IntHashMap.Entry entry1; - IntHashMap.Entry entry2; - - for (entry1 = entry; entry1 != null; entry1 = entry2) - { - entry2 = entry1.nextEntry; - - if (entry1.hashEntry == p_76036_1_) - { - ++this.versionStamp; - --this.count; - - if (entry == entry1) - { - this.slots[k] = entry2; - } - else - { - entry.nextEntry = entry2; - } - - return entry1; - } - - entry = entry1; - } - - return entry1; + return null; } public void clearMap() { - ++this.versionStamp; - IntHashMap.Entry[] aentry = this.slots; - - for (int i = 0; i < aentry.length; ++i) - { - aentry[i] = null; - } - - this.count = 0; + map.clear(); } private void insert(int p_76040_1_, int p_76040_2_, Object p_76040_3_, int p_76040_4_) { - IntHashMap.Entry entry = this.slots[p_76040_4_]; - this.slots[p_76040_4_] = new IntHashMap.Entry(p_76040_1_, p_76040_2_, p_76040_3_, entry); - if (this.count++ >= this.threshold) - { - this.grow(2 * this.slots.length); - } } static class Entry diff --git a/src/main/java/net/minecraft/util/LongHashMap.java b/src/main/java/net/minecraft/util/LongHashMap.java index 3702385..5304814 100644 --- a/src/main/java/net/minecraft/util/LongHashMap.java +++ b/src/main/java/net/minecraft/util/LongHashMap.java @@ -1,14 +1,23 @@ package net.minecraft.util; +import net.openhft.koloboke.collect.map.LongObjMap; +import net.openhft.koloboke.collect.map.hash.HashLongObjMaps; + public class LongHashMap { - private transient LongHashMap.Entry[] hashArray = new LongHashMap.Entry[16]; - private transient int numHashElements; - private int capacity = 12; - private final float percentUseable = 0.75F; - private transient volatile int modCount; + private final LongObjMap map; private static final String __OBFID = "CL_00001492"; + public LongHashMap(LongObjMap map) + { + this.map = map; + } + + public LongHashMap() + { + this(HashLongObjMaps.newMutableMap()); + } + private static int getHashedKey(long p_76155_0_) { return hash((int)(p_76155_0_ ^ p_76155_0_ >>> 32)); @@ -27,157 +36,52 @@ public int getNumHashElements() { - return this.numHashElements; + return map.size(); } public Object getValueByKey(long p_76164_1_) { - int j = getHashedKey(p_76164_1_); - - for (LongHashMap.Entry entry = this.hashArray[getHashIndex(j, this.hashArray.length)]; entry != null; entry = entry.nextEntry) - { - if (entry.key == p_76164_1_) - { - return entry.value; - } - } - - return null; + return map.get(p_76164_1_); } public boolean containsItem(long p_76161_1_) { - return this.getEntry(p_76161_1_) != null; + return map.containsKey(p_76161_1_); } final LongHashMap.Entry getEntry(long p_76160_1_) { - int j = getHashedKey(p_76160_1_); - - for (LongHashMap.Entry entry = this.hashArray[getHashIndex(j, this.hashArray.length)]; entry != null; entry = entry.nextEntry) - { - if (entry.key == p_76160_1_) - { - return entry; - } - } - return null; } public void add(long p_76163_1_, Object p_76163_3_) { - int j = getHashedKey(p_76163_1_); - int k = getHashIndex(j, this.hashArray.length); - - for (LongHashMap.Entry entry = this.hashArray[k]; entry != null; entry = entry.nextEntry) - { - if (entry.key == p_76163_1_) - { - entry.value = p_76163_3_; - return; - } - } - - ++this.modCount; - this.createKey(j, p_76163_1_, p_76163_3_, k); + map.put(p_76163_1_, p_76163_3_); } private void resizeTable(int p_76153_1_) { - LongHashMap.Entry[] aentry = this.hashArray; - int j = aentry.length; - if (j == 1073741824) - { - this.capacity = Integer.MAX_VALUE; - } - else - { - LongHashMap.Entry[] aentry1 = new LongHashMap.Entry[p_76153_1_]; - this.copyHashTableTo(aentry1); - this.hashArray = aentry1; - this.capacity = (int)((float)p_76153_1_ * this.percentUseable); - } } private void copyHashTableTo(LongHashMap.Entry[] p_76154_1_) { - LongHashMap.Entry[] aentry = this.hashArray; - int i = p_76154_1_.length; - for (int j = 0; j < aentry.length; ++j) - { - LongHashMap.Entry entry = aentry[j]; - - if (entry != null) - { - aentry[j] = null; - LongHashMap.Entry entry1; - - do - { - entry1 = entry.nextEntry; - int k = getHashIndex(entry.hash, i); - entry.nextEntry = p_76154_1_[k]; - p_76154_1_[k] = entry; - entry = entry1; - } - while (entry1 != null); - } - } } public Object remove(long p_76159_1_) { - LongHashMap.Entry entry = this.removeKey(p_76159_1_); - return entry == null ? null : entry.value; + return map.remove(p_76159_1_); } final LongHashMap.Entry removeKey(long p_76152_1_) { - int j = getHashedKey(p_76152_1_); - int k = getHashIndex(j, this.hashArray.length); - LongHashMap.Entry entry = this.hashArray[k]; - LongHashMap.Entry entry1; - LongHashMap.Entry entry2; - - for (entry1 = entry; entry1 != null; entry1 = entry2) - { - entry2 = entry1.nextEntry; - - if (entry1.key == p_76152_1_) - { - ++this.modCount; - --this.numHashElements; - - if (entry == entry1) - { - this.hashArray[k] = entry2; - } - else - { - entry.nextEntry = entry2; - } - - return entry1; - } - - entry = entry1; - } - - return entry1; + return null; } private void createKey(int p_76156_1_, long p_76156_2_, Object p_76156_4_, int p_76156_5_) { - LongHashMap.Entry entry = this.hashArray[p_76156_5_]; - this.hashArray[p_76156_5_] = new LongHashMap.Entry(p_76156_1_, p_76156_2_, p_76156_4_, entry); - if (this.numHashElements++ >= this.capacity) - { - this.resizeTable(2 * this.hashArray.length); - } } static class Entry diff --git a/src/main/java/net/minecraft/world/World.java b/src/main/java/net/minecraft/world/World.java index ce28dc3..3868d15 100644 --- a/src/main/java/net/minecraft/world/World.java +++ b/src/main/java/net/minecraft/world/World.java @@ -1968,11 +1968,16 @@ { try { - long startT = System.nanoTime(); - this.updateEntity(entity); - long elapsed = System.nanoTime() - startT; - if(elapsed > 20000000) - FMLLog.warning("Possible lag source Entity %s %sms", entity, (elapsed/1000000)); + if(balancer.canUpdateEntity(entity)) + { + eventProxy.startEntity(entity); + chunkProfiler.startChunk(entity); + long startT = System.nanoTime(); + this.updateEntity(entity); + long elapsed = System.nanoTime() - startT; + if(elapsed > 20000000) + FMLLog.warning("Possible lag source Entity %s %sms", entity, (elapsed/1000000)); + } } catch (Throwable throwable1) { @@ -2162,7 +2167,7 @@ //boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(i >> 4, j >> 4)); //byte b0 = isForced ? (byte)0 : 32; //boolean canUpdate = !p_72866_2_ || this.checkChunksExist(i - b0, 0, j - b0, i + b0, 0, j + b0); - boolean canUpdate = balancer.canUpdateEntity(p_72866_1_); + boolean canUpdate = true; // checks moved up in call hierarchy //if (!canUpdate) //{ @@ -2171,10 +2176,9 @@ // canUpdate = event.canUpdate; //} + //noinspection ConstantConditions if (canUpdate) { - eventProxy.startEntity(p_72866_1_); - chunkProfiler.startChunk(p_72866_1_); p_72866_1_.lastTickPosX = p_72866_1_.posX; p_72866_1_.lastTickPosY = p_72866_1_.posY; p_72866_1_.lastTickPosZ = p_72866_1_.posZ; diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index f8d78fe..6e0e07b 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -1,6 +1,7 @@ package net.minecraftforge.common; import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -415,9 +416,14 @@ IChatComponent link = new ChatComponentText(url); // Add schema so client doesn't crash. - if (URI.create(url).getScheme() == null) - { - url = "http://" + url; + try { + if (new URI(url).getScheme() == null) + { + url = "http://" + url; + } + } catch (URISyntaxException e) { + ichat.appendSibling(link); + continue; } // Set the click event and append the link. diff --git a/src/main/java/org/ultramine/commands/CommandContext.java b/src/main/java/org/ultramine/commands/CommandContext.java index 9f4c236..86466eb 100644 --- a/src/main/java/org/ultramine/commands/CommandContext.java +++ b/src/main/java/org/ultramine/commands/CommandContext.java @@ -164,10 +164,15 @@ { sendMessage(EnumChatFormatting.YELLOW, msg, args); } + + public void broadcast(IChatComponent comp) + { + getServer().getConfigurationManager().sendChatMsg(comp); + } public void broadcast(EnumChatFormatting tplColor, EnumChatFormatting argsColor, String msg, Object... args) { - getServer().getConfigurationManager().sendChatMsg(BasicTypeFormatter.formatMessage(tplColor, argsColor, msg, args)); + broadcast(BasicTypeFormatter.formatMessage(tplColor, argsColor, msg, args)); } public void broadcast(EnumChatFormatting argsColor, String msg, Object... args) diff --git a/src/main/java/org/ultramine/commands/basic/BasicCommands.java b/src/main/java/org/ultramine/commands/basic/BasicCommands.java index 215df80..949e93c 100644 --- a/src/main/java/org/ultramine/commands/basic/BasicCommands.java +++ b/src/main/java/org/ultramine/commands/basic/BasicCommands.java @@ -364,7 +364,7 @@ { String msg = ctx.get("msg").asString().replace('&', '\u00a7'); if(ctx.getAction().equals("all")) - ctx.broadcast(WHITE, WHITE, msg); + ctx.broadcast(new ChatComponentText(msg)); else ctx.get("player").asPlayer().addChatMessage(new ChatComponentText(msg)); } @@ -440,14 +440,14 @@ if(player.isHidden()) { player.show(); - ctx.sendMessage("command.unmute.success.show"); - ctx.notifyOtherAdmins("command.unmute.notify.show"); + ctx.sendMessage("command.vanish.success.show"); + ctx.notifyOtherAdmins("command.vanish.notify.show"); } else { player.hide(); - ctx.sendMessage("command.unmute.success.hide"); - ctx.notifyOtherAdmins("command.unmute.notify.hide"); + ctx.sendMessage("command.vanish.success.hide"); + ctx.notifyOtherAdmins("command.vanish.notify.hide"); } } } diff --git a/src/main/java/org/ultramine/commands/basic/TechCommands.java b/src/main/java/org/ultramine/commands/basic/TechCommands.java index b612d03..417875e 100644 --- a/src/main/java/org/ultramine/commands/basic/TechCommands.java +++ b/src/main/java/org/ultramine/commands/basic/TechCommands.java @@ -727,6 +727,7 @@ { ent.attackEntityFrom(DamageSource.outOfWorld, 10000f); ent.setDead(); + break; } } } diff --git a/src/main/java/org/ultramine/server/ServerLoadBalancer.java b/src/main/java/org/ultramine/server/ServerLoadBalancer.java index af777f3..0a94195 100644 --- a/src/main/java/org/ultramine/server/ServerLoadBalancer.java +++ b/src/main/java/org/ultramine/server/ServerLoadBalancer.java @@ -69,6 +69,7 @@ int prior = activeChunkSet.get(ChunkHash.chunkToKey(cx, cz)); if(prior == Byte.MAX_VALUE) { + world.getEventProxy().startEntity(ent); ent.updateInactive(); return false; } diff --git a/src/main/java/org/ultramine/server/bootstrap/log4j/UMStripColorsRewritePolicy.java b/src/main/java/org/ultramine/server/bootstrap/log4j/UMStripColorsRewritePolicy.java index d1e7086..e4f1620 100644 --- a/src/main/java/org/ultramine/server/bootstrap/log4j/UMStripColorsRewritePolicy.java +++ b/src/main/java/org/ultramine/server/bootstrap/log4j/UMStripColorsRewritePolicy.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.core.impl.Log4jLogEvent; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.MessageFormatMessage; +import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.message.SimpleMessage; import org.apache.logging.log4j.message.StringFormattedMessage; @@ -23,7 +24,7 @@ { message = new SimpleMessage(((IUnformattedMessage) message).getUnformattedMessage()); } - else if(message instanceof SimpleMessage || message instanceof MessageFormatMessage || message instanceof StringFormattedMessage) + else if(message instanceof SimpleMessage || message instanceof ParameterizedMessage || message instanceof MessageFormatMessage || message instanceof StringFormattedMessage) { String text = message.getFormattedMessage(); StringBuilder sb = new StringBuilder(text.length()); diff --git a/src/main/java/org/ultramine/server/util/MinecraftUtil.java b/src/main/java/org/ultramine/server/util/MinecraftUtil.java index 7e05bd7..fbb8a38 100644 --- a/src/main/java/org/ultramine/server/util/MinecraftUtil.java +++ b/src/main/java/org/ultramine/server/util/MinecraftUtil.java @@ -1,9 +1,13 @@ package org.ultramine.server.util; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +import java.util.Arrays; public class MinecraftUtil { @@ -49,4 +53,88 @@ return cost; } } + + public static boolean canLeavesStay(World world, int bx, int by, int bz, int searchDistance) + { + return new LeavesPathFinder(world, bx, by, bz, searchDistance).canLeavesStay(); + } + + private static class LeavesPathFinder + { + private static final byte SIZE = 16; + private static final int SIZE_HALF = SIZE / 2; + private static final byte[] AREA = new byte[SIZE * SIZE * SIZE]; + private static final int EMPTY = 0; + private static final int WOOD = -1; + private static final int LEAVES = Byte.MAX_VALUE; + private static final int WALL = -2; + + private final World world; + private final int bx; + private final int by; + private final int bz; + private final int distance; + + public LeavesPathFinder(World world, int bx, int by, int bz, int distance) + { + this.world = world; + this.bx = bx; + this.by = by; + this.bz = bz; + this.distance = distance; + } + + public boolean canLeavesStay() + { + if(distance > 7) + throw new IllegalArgumentException("distance should be less then 8, given: " + distance); + if(!world.checkChunksExist(bx - distance - 1, by - distance - 1, bz - distance - 1, bx + distance + 1, by + distance + 1, bz + distance + 1)) + return true; + + Arrays.fill(AREA, (byte)EMPTY); + setVal(0, 0, 0, LEAVES); + return recursivePathFind(0, 0, 0, 0); + } + + private boolean recursivePathFind(int x, int y, int z, int depth) + { + int current = getVal(x, y, z); + + if(current == EMPTY) + { + Block block = world.getBlock(bx + x, by + y, bz + z); + current = block.canSustainLeaves(world, bx + x, by + y, bz + z) ? WOOD : block.isLeaves(world, bx + x, by + y, bz + z) ? LEAVES : WALL; + setVal(x, y, z, current); + } + + if(current == WOOD) + return true; + else if(current <= depth) + return false; + + setVal(x, y, z, depth); + + int newDepth = depth + 1; + if(newDepth > distance) + return false; + + if(recursivePathFind(x+1, y, z, newDepth)) return true; + if(recursivePathFind(x, y+1, z, newDepth)) return true; + if(recursivePathFind(x, y, z+1, newDepth)) return true; + if(recursivePathFind(x-1, y, z, newDepth)) return true; + if(recursivePathFind(x, y-1, z, newDepth)) return true; + if(recursivePathFind(x, y, z-1, newDepth)) return true; + return false; + } + + private static int getVal(int x, int y, int z) + { + return AREA[((x + SIZE_HALF) << 8) | ((y + SIZE_HALF) << 4) | (z + SIZE_HALF)]; + } + + private static void setVal(int x, int y, int z, int newVal) + { + AREA[((x + SIZE_HALF) << 8) | ((y + SIZE_HALF) << 4) | (z + SIZE_HALF)] = (byte)newVal; + } + } } diff --git a/src/main/java/org/ultramine/server/util/VanillaChunkHashMap.java b/src/main/java/org/ultramine/server/util/VanillaChunkHashMap.java index 09ed112..5028736 100644 --- a/src/main/java/org/ultramine/server/util/VanillaChunkHashMap.java +++ b/src/main/java/org/ultramine/server/util/VanillaChunkHashMap.java @@ -11,6 +11,7 @@ public VanillaChunkHashMap(ChunkMap chunkMap) { + super(null); this.chunkMap = chunkMap; }