This commit is contained in:
Eoghanmc22 2020-08-13 14:51:40 -04:00
commit 94279e2dbf
5 changed files with 32 additions and 23 deletions

View File

@ -112,7 +112,7 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.12' annotationProcessor 'org.projectlombok:lombok:1.18.12'
// Path finding // Path finding
api 'com.github.MadMartian:hydrazine-path-finding:1.3.0' api 'com.github.MadMartian:hydrazine-path-finding:1.3.1'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8" api "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
api 'com.github.jglrxavpok:Hephaistos:v1.0.5' api 'com.github.jglrxavpok:Hephaistos:v1.0.5'

View File

@ -339,8 +339,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
return; return;
} }
boolean chunkUnloaded = !ChunkUtils.isLoaded(instance, position.getX(), position.getZ()); if (!ChunkUtils.isLoaded(instance, position.getX(), position.getZ())) {
if (chunkUnloaded) {
// No update for entities in unloaded chunk // No update for entities in unloaded chunk
return; return;
} }
@ -392,6 +391,11 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
); );
onGround = CollisionUtils.handlePhysics(this, deltaPos, newPosition, newVelocityOut); onGround = CollisionUtils.handlePhysics(this, deltaPos, newPosition, newVelocityOut);
// Check chunk
if (!ChunkUtils.isLoaded(instance, newPosition.getX(), newPosition.getZ())) {
return;
}
// World border collision // World border collision
{ {
final WorldBorder worldBorder = instance.getWorldBorder(); final WorldBorder worldBorder = instance.getWorldBorder();
@ -461,10 +465,11 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
for (int y = minY; y <= maxY; y++) { for (int y = minY; y <= maxY; y++) {
for (int x = minX; x <= maxX; x++) { for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) { for (int z = minZ; z <= maxZ; z++) {
chunkUnloaded = !ChunkUtils.isLoaded(instance, x, z); final Chunk chunk = instance.getChunkAt(x, z);
if (chunkUnloaded) if (!ChunkUtils.isLoaded(chunk))
continue; continue;
final CustomBlock customBlock = instance.getCustomBlock(x, y, z);
final CustomBlock customBlock = chunk.getCustomBlock(x, y, z);
if (customBlock != null) { if (customBlock != null) {
tmpPosition.setX(x); tmpPosition.setX(x);
tmpPosition.setY(y); tmpPosition.setY(y);

View File

@ -650,7 +650,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param z the Z position * @param z the Z position
* @return the chunk at the given position, null if not loaded * @return the chunk at the given position, null if not loaded
*/ */
public Chunk getChunkAt(double x, double z) { public Chunk getChunkAt(float x, float z) {
final int chunkX = ChunkUtils.getChunkCoordinate((int) x); final int chunkX = ChunkUtils.getChunkCoordinate((int) x);
final int chunkZ = ChunkUtils.getChunkCoordinate((int) z); final int chunkZ = ChunkUtils.getChunkCoordinate((int) z);
return getChunk(chunkX, chunkZ); return getChunk(chunkX, chunkZ);

View File

@ -518,10 +518,8 @@ public class InventoryClickProcessor {
// Wait for inventory conditions + events to possibly close the inventory // Wait for inventory conditions + events to possibly close the inventory
player.UNSAFE_changeDidCloseInventory(false); player.UNSAFE_changeDidCloseInventory(false);
final List<InventoryCondition> inventoryConditions = isPlayerInventory ? // PreClickEvent
player.getInventory().getInventoryConditions() : inventory.getInventoryConditions(); {
if (!inventoryConditions.isEmpty()) {
InventoryPreClickEvent inventoryPreClickEvent = new InventoryPreClickEvent(player, inventory, slot, clickType, clicked, cursor); InventoryPreClickEvent inventoryPreClickEvent = new InventoryPreClickEvent(player, inventory, slot, clickType, clicked, cursor);
player.callEvent(InventoryPreClickEvent.class, inventoryPreClickEvent); player.callEvent(InventoryPreClickEvent.class, inventoryPreClickEvent);
cursor = inventoryPreClickEvent.getCursorItem(); cursor = inventoryPreClickEvent.getCursorItem();
@ -531,6 +529,12 @@ public class InventoryClickProcessor {
if (inventoryPreClickEvent.isCancelled()) { if (inventoryPreClickEvent.isCancelled()) {
clickResult.setRefresh(true); clickResult.setRefresh(true);
} }
}
// Inventory conditions
final List<InventoryCondition> inventoryConditions = isPlayerInventory ?
player.getInventory().getInventoryConditions() : inventory.getInventoryConditions();
if (!inventoryConditions.isEmpty()) {
for (InventoryCondition inventoryCondition : inventoryConditions) { for (InventoryCondition inventoryCondition : inventoryConditions) {
InventoryConditionResult result = new InventoryConditionResult(clicked, cursor); InventoryConditionResult result = new InventoryConditionResult(clicked, cursor);

View File

@ -623,8 +623,8 @@ public class ItemStack implements DataContainer {
/** /**
* Called when the player right clicks with this item * Called when the player right clicks with this item
* *
* @param player * @param player the player who used the item
* @param hand * @param hand the hand used
*/ */
public void onRightClick(Player player, Player.Hand hand) { public void onRightClick(Player player, Player.Hand hand) {
} }
@ -632,8 +632,8 @@ public class ItemStack implements DataContainer {
/** /**
* Called when the player left clicks with this item * Called when the player left clicks with this item
* *
* @param player * @param player the player who used the item
* @param hand * @param hand the hand used
*/ */
public void onLeftClick(Player player, Player.Hand hand) { public void onLeftClick(Player player, Player.Hand hand) {
} }
@ -641,10 +641,10 @@ public class ItemStack implements DataContainer {
/** /**
* Called when the player right clicks with this item on a block * Called when the player right clicks with this item on a block
* *
* @param player * @param player the player who used the item
* @param hand * @param hand the hand used
* @param position * @param position the position of the interacted block
* @param blockFace * @param blockFace the block face
* @return true if it prevents normal item use (placing blocks for instance) * @return true if it prevents normal item use (placing blocks for instance)
*/ */
public boolean onUseOnBlock(Player player, Player.Hand hand, BlockPosition position, Direction blockFace) { public boolean onUseOnBlock(Player player, Player.Hand hand, BlockPosition position, Direction blockFace) {
@ -656,10 +656,10 @@ public class ItemStack implements DataContainer {
* <p> * <p>
* Executed before any events * Executed before any events
* *
* @param player * @param player the player who clicked on the item
* @param clickType * @param clickType the click type
* @param slot * @param slot the slot clicked
* @param playerInventory * @param playerInventory true if the click is in the player inventory
*/ */
public void onInventoryClick(Player player, ClickType clickType, int slot, boolean playerInventory) { public void onInventoryClick(Player player, ClickType clickType, int slot, boolean playerInventory) {