Skip to content

Commit

Permalink
Changed the way TESRs are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Sep 13, 2020
1 parent efae7f6 commit d6e4c6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.teammetallurgy.atum.blocks.base.tileentity.InventoryBaseTileEntity;
import com.teammetallurgy.atum.blocks.machines.QuernBlock;
import com.teammetallurgy.atum.init.AtumTileEntities;
import com.teammetallurgy.atum.misc.RenderUtils;
import com.teammetallurgy.atum.misc.StackHelper;
import com.teammetallurgy.atum.misc.recipe.RecipeHelper;
import net.minecraft.entity.player.PlayerInventory;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.IPacket;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.HopperTileEntity;
Expand Down Expand Up @@ -152,8 +154,9 @@ public CompoundNBT getUpdateTag() {
@Override
public void markDirty() {
super.markDirty();
if (this.world != null) {
this.world.notifyBlockUpdate(pos, this.world.getBlockState(pos), world.getBlockState(pos), 3);
if (this.world instanceof ServerWorld) {
final IPacket<?> packet = this.getUpdatePacket();
RenderUtils.sendToTracking((ServerWorld) this.world, this.pos, packet, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import com.teammetallurgy.atum.init.AtumEntities;
import com.teammetallurgy.atum.init.AtumSounds;
import com.teammetallurgy.atum.init.AtumTileEntities;
import net.minecraft.block.BlockState;
import com.teammetallurgy.atum.misc.RenderUtils;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.IPacket;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.util.Direction;
Expand Down Expand Up @@ -86,8 +87,10 @@ public boolean isUsableByPlayer(@Nonnull PlayerEntity player) {
public void setOpenable() {
this.isOpenable = true;
this.markDirty();
BlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
if (this.world instanceof ServerWorld) {
final IPacket<?> packet = this.getUpdatePacket();
RenderUtils.sendToTracking((ServerWorld) this.world, this.pos, packet, false);
}
}

public void spawn(PlayerEntity player, DifficultyInstance difficulty) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/teammetallurgy/atum/misc/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.IPacket;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.server.ServerWorld;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -52,4 +56,8 @@ public static void drawString(TileEntity te, String str, double xOffset, double
matrixStack.pop();
}
}

public static void sendToTracking(ServerWorld world, BlockPos blockPos, IPacket<?> packet, boolean boundaryOnly) {
world.getChunkProvider().chunkManager.getTrackingPlayers(new ChunkPos(blockPos), boundaryOnly).forEach(p -> p.connection.sendPacket(packet));
}
}

0 comments on commit d6e4c6d

Please sign in to comment.