-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
465 additions
and
11 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...on/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientBlockEntityEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package band.kessoku.lib.events.lifecycle.api.client; | ||
|
||
import band.kessoku.lib.event.api.Event; | ||
|
||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.client.world.ClientWorld; | ||
|
||
public class ClientBlockEntityEvent { | ||
|
||
/** | ||
* Called when a BlockEntity is loaded into a ClientWorld. | ||
* | ||
* <p>When this event is called, the block entity is already in the world. | ||
* However, its data might not be loaded yet, so don't rely on it. | ||
*/ | ||
public static final Event<Loaded> LOADED = Event.of(loadeds -> (blockEntity, world) -> { | ||
for (Loaded loaded : loadeds) { | ||
loaded.onLoaded(blockEntity, world); | ||
} | ||
}); | ||
|
||
/** | ||
* Called when a BlockEntity is about to be unloaded from a ClientWorld. | ||
* | ||
* <p>When this event is called, the block entity is still present on the world. | ||
*/ | ||
public static final Event<Unloaded> UNLOADED = Event.of(unloadeds -> (blockEntity, world) -> { | ||
for (Unloaded unloaded : unloadeds) { | ||
unloaded.onUnloaded(blockEntity, world); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface Loaded { | ||
void onLoaded(BlockEntity blockEntity, ClientWorld world); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface Unloaded { | ||
void onUnloaded(BlockEntity blockEntity, ClientWorld world); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...s-common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientChunkEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package band.kessoku.lib.events.lifecycle.api.client; | ||
|
||
import band.kessoku.lib.event.api.Event; | ||
|
||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.world.chunk.WorldChunk; | ||
|
||
public class ClientChunkEvent { | ||
|
||
/** | ||
* Called when a chunk is loaded into a ClientWorld. | ||
* | ||
* <p>When this event is called, the chunk is already in the world. | ||
*/ | ||
public static final Event<Loaded> LOADED = Event.of(loadeds -> (clientWorld, chunk) -> { | ||
for (Loaded callback : loadeds) { | ||
callback.onChunkLoaded(clientWorld, chunk); | ||
} | ||
}); | ||
|
||
/** | ||
* Called when a chunk is about to be unloaded from a ClientWorld. | ||
* | ||
* <p>When this event is called, the chunk is still present in the world. | ||
*/ | ||
public static final Event<Unloaded> UNLOADED = Event.of(unloadeds -> (clientWorld, chunk) -> { | ||
for (Unloaded unloaded : unloadeds) { | ||
unloaded.onChunkUnloaded(clientWorld, chunk); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface Loaded { | ||
void onChunkLoaded(ClientWorld world, WorldChunk chunk); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface Unloaded { | ||
void onChunkUnloaded(ClientWorld world, WorldChunk chunk); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...-common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientEntityEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package band.kessoku.lib.events.lifecycle.api.client; | ||
|
||
import band.kessoku.lib.event.api.Event; | ||
|
||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.Entity; | ||
|
||
public class ClientEntityEvent { | ||
|
||
/** | ||
* Called when an Entity is loaded into a ClientWorld. | ||
* | ||
* <p>When this event is called, the chunk is already in the world. | ||
*/ | ||
public static final Event<Loaded> LOADED = Event.of(loadeds -> (entity, world) -> { | ||
for (Loaded loaded : loadeds) { | ||
loaded.onLoaded(entity, world); | ||
} | ||
}); | ||
|
||
/** | ||
* Called when an Entity is about to be unloaded from a ClientWorld. | ||
* | ||
* <p>This event is called before the entity is unloaded from the world. | ||
*/ | ||
public static final Event<Unloaded> UNLOADED = Event.of(unloadeds -> (entity, world) -> { | ||
for (Unloaded unloaded : unloadeds) { | ||
unloaded.onUnloaded(entity, world); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface Loaded { | ||
void onLoaded(Entity entity, ClientWorld world); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface Unloaded { | ||
void onUnloaded(Entity entity, ClientWorld world); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,4 @@ interface End { | |
void onEndTick(ClientWorld world); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientChunkManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package band.kessoku.lib.events.lifecycle.mixin.neo.client; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import net.minecraft.client.world.ClientChunkManager; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.network.packet.s2c.play.ChunkData; | ||
import net.minecraft.util.math.ChunkPos; | ||
import net.minecraft.world.chunk.WorldChunk; | ||
|
||
import band.kessoku.lib.events.lifecycle.api.client.ClientChunkEvent; | ||
|
||
@Mixin(ClientChunkManager.class) | ||
public abstract class ClientChunkManagerMixin { | ||
@Final | ||
@Shadow | ||
private ClientWorld world; | ||
|
||
@Inject(method = "loadChunkFromPacket", at = @At(value = "NEW", target = "net/minecraft/world/chunk/WorldChunk", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD) | ||
private void onChunkUnload(int x, int z, PacketByteBuf buf, NbtCompound tag, Consumer<ChunkData.BlockEntityVisitor> consumer, CallbackInfoReturnable<WorldChunk> info, int index, WorldChunk worldChunk, ChunkPos chunkPos) { | ||
if (worldChunk != null) { | ||
ClientChunkEvent.UNLOADED.invoker().onChunkUnloaded(this.world, worldChunk); | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "updateLoadDistance", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "net/minecraft/client/world/ClientChunkManager$ClientChunkMap.isInRadius(II)Z" | ||
), | ||
locals = LocalCapture.CAPTURE_FAILHARD | ||
) | ||
private void onUpdateLoadDistance(int loadDistance, CallbackInfo ci, int oldRadius, int newRadius, ClientChunkManager.ClientChunkMap clientChunkMap, int k, WorldChunk oldChunk, ChunkPos chunkPos) { | ||
if (!clientChunkMap.isInRadius(chunkPos.x, chunkPos.z)) { | ||
ClientChunkEvent.UNLOADED.invoker().onChunkUnloaded(this.world, oldChunk); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ain/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientEntityHandlerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package band.kessoku.lib.events.lifecycle.mixin.neo.client; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.Entity; | ||
|
||
import band.kessoku.lib.events.lifecycle.api.client.ClientEntityEvent; | ||
|
||
@Mixin(targets = "net/minecraft/client/world/ClientWorld$ClientEntityHandler") | ||
public class ClientEntityHandlerMixin { | ||
// final synthetic Lnet/minecraft/client/world/ClientWorld; field_27735 | ||
@SuppressWarnings("ShadowTarget") | ||
@Shadow | ||
@Final | ||
private ClientWorld field_27735; | ||
|
||
// Call our load event after vanilla has loaded the entity | ||
@Inject(method = "startTracking(Lnet/minecraft/entity/Entity;)V", at = @At("TAIL")) | ||
private void invokeLoadEntity(Entity entity, CallbackInfo ci) { | ||
ClientEntityEvent.LOADED.invoker().onLoaded(entity, this.field_27735); | ||
} | ||
|
||
// Call our unload event before vanilla does. | ||
@Inject(method = "stopTracking(Lnet/minecraft/entity/Entity;)V", at = @At("HEAD")) | ||
private void invokeUnloadEntity(Entity entity, CallbackInfo ci) { | ||
ClientEntityEvent.UNLOADED.invoker().onUnloaded(entity, this.field_27735); | ||
} | ||
} |
Oops, something went wrong.