-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create entity tick events * Apply licenses to entity tick events * Rename entity tick event Event fields * Fix javadocs / imports * Unfix some entity event javadoc * Change a comment in EntityEventsTestMod Co-authored-by: Ennui Langeweile <[email protected]> * Invert slime tick event test condition Co-authored-by: Ennui Langeweile <[email protected]>
- Loading branch information
Showing
8 changed files
with
219 additions
and
6 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
...tity_events/src/main/java/org/quiltmc/qsl/entity_events/api/ServerEntityTickCallback.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,48 @@ | ||
/* | ||
* Copyright 2022 QuiltMC | ||
* | ||
* 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 org.quiltmc.qsl.entity_events.api; | ||
|
||
import net.minecraft.entity.Entity; | ||
|
||
import org.quiltmc.qsl.base.api.event.Event; | ||
import org.quiltmc.qsl.base.api.event.EventAwareListener; | ||
|
||
/** | ||
* A callback that is invoked when an Entity is ticked on the logical server (nominally every 1/20 of a second). | ||
* <p> | ||
* There are two types of entity tick - standalone ({@link Entity#tick()}) and riding ({@link Entity#tickRiding()}). | ||
* This callback takes a parameter which specifies which type of tick it is. | ||
*/ | ||
@FunctionalInterface | ||
public interface ServerEntityTickCallback extends EventAwareListener { | ||
/** | ||
* Called when an entity is ticked. | ||
*/ | ||
Event<ServerEntityTickCallback> EVENT = Event.create(ServerEntityTickCallback.class, callbacks -> (entity, isPassengerTick) -> { | ||
for (ServerEntityTickCallback callback : callbacks) { | ||
callback.onServerEntityTick(entity, isPassengerTick); | ||
} | ||
}); | ||
|
||
/** | ||
* Called when an entity is ticked on the logical server. | ||
* | ||
* @param entity the entity | ||
* @param isPassengerTick whether the entity is being ticked as a passenger of another entity | ||
*/ | ||
void onServerEntityTick(Entity entity, boolean isPassengerTick); | ||
} |
52 changes: 52 additions & 0 deletions
52
...ents/src/main/java/org/quiltmc/qsl/entity_events/api/client/ClientEntityTickCallback.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,52 @@ | ||
/* | ||
* Copyright 2022 QuiltMC | ||
* | ||
* 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 org.quiltmc.qsl.entity_events.api.client; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
|
||
import net.minecraft.entity.Entity; | ||
|
||
import org.quiltmc.qsl.base.api.event.Event; | ||
import org.quiltmc.qsl.base.api.event.client.ClientEventAwareListener; | ||
|
||
/** | ||
* A callback that is invoked when an Entity is ticked on the logical client (nominally every 1/20 of a second). | ||
* <p> | ||
* There are two types of entity tick - standalone ({@link Entity#tick()}) and riding ({@link Entity#tickRiding()}). | ||
* This callback takes a parameter which specifies which type of tick it is. | ||
*/ | ||
@Environment(EnvType.CLIENT) | ||
@FunctionalInterface | ||
public interface ClientEntityTickCallback extends ClientEventAwareListener { | ||
/** | ||
* Called when an entity is ticked. | ||
*/ | ||
Event<ClientEntityTickCallback> EVENT = Event.create(ClientEntityTickCallback.class, callbacks -> (entity, isPassengerTick) -> { | ||
for (ClientEntityTickCallback callback : callbacks) { | ||
callback.onClientEntityTick(entity, isPassengerTick); | ||
} | ||
}); | ||
|
||
/** | ||
* Called when an entity is ticked on the logical client. | ||
* | ||
* @param entity the entity | ||
* @param isPassengerTick whether the entity is being ticked as a passenger of another entity | ||
*/ | ||
void onClientEntityTick(Entity entity, boolean isPassengerTick); | ||
} |
40 changes: 40 additions & 0 deletions
40
...ity/entity_events/src/main/java/org/quiltmc/qsl/entity_events/mixin/ServerWorldMixin.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,40 @@ | ||
/* | ||
* Copyright 2022 QuiltMC | ||
* | ||
* 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 org.quiltmc.qsl.entity_events.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
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 org.quiltmc.qsl.entity_events.api.ServerEntityTickCallback; | ||
|
||
@Mixin(ServerWorld.class) | ||
public abstract class ServerWorldMixin { | ||
@Inject(method = "tickEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;tick()V")) | ||
void invokeEntityTickEvent(Entity entity, CallbackInfo ci) { | ||
ServerEntityTickCallback.EVENT.invoker().onServerEntityTick(entity, false); | ||
} | ||
|
||
@Inject(method = "tickPassenger", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;tickRiding()V")) | ||
void invokePassengerEntityTickEvent(Entity vehicle, Entity passenger, CallbackInfo ci) { | ||
ServerEntityTickCallback.EVENT.invoker().onServerEntityTick(passenger, true); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ity_events/src/main/java/org/quiltmc/qsl/entity_events/mixin/client/ClientWorldMixin.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,40 @@ | ||
/* | ||
* Copyright 2022 QuiltMC | ||
* | ||
* 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 org.quiltmc.qsl.entity_events.mixin.client; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
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 org.quiltmc.qsl.entity_events.api.client.ClientEntityTickCallback; | ||
|
||
@Mixin(ClientWorld.class) | ||
public abstract class ClientWorldMixin { | ||
@Inject(method = "tickEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;tick()V")) | ||
void invokeEntityTickEvent(Entity entity, CallbackInfo ci) { | ||
ClientEntityTickCallback.EVENT.invoker().onClientEntityTick(entity, false); | ||
} | ||
|
||
@Inject(method = "tickPassenger", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;tickRiding()V")) | ||
void invokePassengerEntityTickEvent(Entity vehicle, Entity passenger, CallbackInfo ci) { | ||
ClientEntityTickCallback.EVENT.invoker().onClientEntityTick(passenger, true); | ||
} | ||
} |
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