Skip to content

Commit

Permalink
Fixed issue with chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTroble committed Aug 6, 2021
1 parent f817071 commit 3ce5794
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 37 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [Fix] 1.14.4 - 08.06.2021 - 1
* Fixed issue with unneeded chunkloading

## [Fix] 1.13.2 - 08.05.2021 - 2
* Fixed issue with language keys not working

Expand Down
45 changes: 8 additions & 37 deletions src/main/java/eu/gir/gircredstone/tile/TileRedstoneEmitter.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package eu.gir.gircredstone.tile;

import java.util.concurrent.ExecutionException;

import eu.gir.gircredstone.block.BlockRedstoneAcceptor;
import eu.gir.gircredstone.init.GIRCInit;
import eu.gir.gircredstone.item.Linkingtool;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.server.ServerChunkProvider;

public class TileRedstoneEmitter extends TileEntity {

Expand All @@ -19,7 +15,7 @@ public TileRedstoneEmitter() {
}

private BlockPos linkedpos = null;

@Override
public CompoundNBT write(CompoundNBT compound) {
Linkingtool.writeBlockPosToNBT(linkedpos, compound);
Expand All @@ -33,54 +29,29 @@ public void read(CompoundNBT compound) {
}

public boolean link(final BlockPos pos) {
if(pos == null)
if (pos == null)
return false;
this.linkedpos = pos;
return true;
}

public boolean unlink() {
if(this.linkedpos == null)
if (this.linkedpos == null)
return false;
this.linkedpos = null;
return true;
}

public BlockPos getLinkedPos() {
return this.linkedpos;
}

public void accept(final boolean enabled) {
final BlockState state = world.getBlockState(linkedpos);
if (state.getBlock() instanceof BlockRedstoneAcceptor) {
world.setBlockState(linkedpos, state.with(BlockRedstoneAcceptor.POWER, enabled));
}
}

@SuppressWarnings("deprecation")
public void redstoneUpdate(final boolean enabled) {
if (linkedpos != null) {
final boolean flag = !world.isBlockLoaded(linkedpos);
if(flag) {
final Chunk chunk = world.getChunkAt(linkedpos);
final ServerChunkProvider provider = (ServerChunkProvider) world.getChunkProvider();
try {
provider.chunkManager.func_219188_b(chunk.getPos()).get().ifLeft(ch -> {
accept(enabled);
try {
provider.chunkManager.func_222973_a(chunk).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return;
final BlockState state = world.getBlockState(linkedpos);
if (state.getBlock() instanceof BlockRedstoneAcceptor) {
world.setBlockState(linkedpos, state.with(BlockRedstoneAcceptor.POWER, enabled));
}
accept(enabled);
}
}

Expand Down

0 comments on commit 3ce5794

Please sign in to comment.