Reimplement server entity load event (#1151)

This commit is contained in:
i509VCB 2020-11-05 14:02:40 -06:00 committed by GitHub
parent a927119a3e
commit c097c2c675
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 11 deletions

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.mixin.event.lifecycle;
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.entity.Entity;
import net.minecraft.server.world.ServerWorld;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
@Mixin(targets = "net/minecraft/server/world/ServerWorld$class_5526")
abstract class ServerWorldEntityLoaderMixin {
// final synthetic Lnet/minecraft/server/world/ServerWorld; field_26936
@SuppressWarnings("ShadowTarget")
@Shadow
@Final
private ServerWorld field_26936;
// onLoadEntity
@Inject(method = "method_31798(Lnet/minecraft/entity/Entity;)V", at = @At("TAIL"))
private void invokeEntityLoadEvent(Entity entity, CallbackInfo ci) {
ServerEntityEvents.ENTITY_LOAD.invoker().onLoad(entity, this.field_26936);
}
}

View file

@ -30,17 +30,6 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
@Mixin(ServerWorld.class)
public abstract class ServerWorldMixin {
/*@Shadow
private boolean inEntityTick;
// Call our load event after vanilla has loaded the entity
@Inject(method = "loadEntityUnchecked", at = @At("TAIL"))
private void onLoadEntity(Entity entity, CallbackInfo ci) {
if (!this.inEntityTick) { // Copy vanilla logic, we cannot load entities while the game is ticking entities
ServerEntityEvents.ENTITY_LOAD.invoker().onLoad(entity, (ServerWorld) (Object) this);
}
}*/
// Make sure "insideBlockTick" is true before we call the start tick, so inject after it is set
@Inject(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/server/world/ServerWorld;inBlockTick:Z", opcode = Opcodes.PUTFIELD, ordinal = 0, shift = At.Shift.AFTER))
private void startWorldTick(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {

View file

@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"MinecraftServerMixin",
"ServerWorldEntityLoaderMixin",
"ServerWorldMixin",
"ThreadedAnvilChunkStorageMixin",
"WorldMixin"