-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking Changes: Refactor Events Package
Add LivingEntityNetworkingEvents And ClientLivingEntityNetworkingEvents Add ServerStellarStatusNetworkingEvents And ClientStellarStatusNetworkingEvents Add MModdingTrackedDataHandlers Add TrackedDataHandlerUtils Add CommonOperations Add MModdingPackets#LIVING_ENTITY_STUCK_ARROW_TYPES Modify LivingEntityMixin
- Loading branch information
1 parent
e1a77a8
commit 5b11f80
Showing
25 changed files
with
497 additions
and
35 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
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/mmodding/mmodding_lib/ducks/LivingEntityDuckInterface.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,14 @@ | ||
package com.mmodding.mmodding_lib.ducks; | ||
|
||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.Map; | ||
|
||
public interface LivingEntityDuckInterface { | ||
|
||
Map<Integer, Identifier> mmodding_lib$getStuckArrowTypes(); | ||
|
||
void mmodding_lib$setStuckArrowTypes(Map<Integer, Identifier> stuckArrowTypes); | ||
|
||
void mmodding_lib$putStuckArrowType(int index, Identifier arrowEntityId); | ||
} |
21 changes: 21 additions & 0 deletions
21
...ain/java/com/mmodding/mmodding_lib/library/entities/data/MModdingTrackedDataHandlers.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,21 @@ | ||
package com.mmodding.mmodding_lib.library.entities.data; | ||
|
||
import com.mmodding.mmodding_lib.library.utils.MModdingIdentifier; | ||
import com.mmodding.mmodding_lib.library.utils.TrackedDataHandlerUtils; | ||
import net.minecraft.entity.data.TrackedDataHandler; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.util.Identifier; | ||
import org.quiltmc.qsl.entity.networking.api.tracked_data.QuiltTrackedDataHandlerRegistry; | ||
|
||
import java.util.List; | ||
|
||
public class MModdingTrackedDataHandlers { | ||
|
||
public static final TrackedDataHandler<List<String>> STRING_LIST = TrackedDataHandlerUtils.createTrackedDataListHandler(PacketByteBuf::writeString, PacketByteBuf::readString); | ||
public static final TrackedDataHandler<List<Identifier>> IDENTIFIER_LIST = TrackedDataHandlerUtils.createTrackedDataListHandler(PacketByteBuf::writeIdentifier, PacketByteBuf::readIdentifier); | ||
|
||
static { | ||
QuiltTrackedDataHandlerRegistry.register(new MModdingIdentifier("string_list"), MModdingTrackedDataHandlers.STRING_LIST); | ||
QuiltTrackedDataHandlerRegistry.register(new MModdingIdentifier("identifier_list"), MModdingTrackedDataHandlers.IDENTIFIER_LIST); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...t/MModdingClientInitializationEvents.java → ...t/MModdingClientInitializationEvents.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
2 changes: 1 addition & 1 deletion
2
...r/MModdingServerInitializationEvents.java → ...r/MModdingServerInitializationEvents.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
34 changes: 34 additions & 0 deletions
34
...ava/com/mmodding/mmodding_lib/library/events/networking/LivingEntityNetworkingEvents.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 com.mmodding.mmodding_lib.library.events.networking; | ||
|
||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.util.Identifier; | ||
import org.quiltmc.qsl.base.api.event.Event; | ||
|
||
import java.util.Map; | ||
|
||
public class LivingEntityNetworkingEvents { | ||
|
||
public static final Event<BeforeStuckArrowTypes> BEFORE_STUCK_ARROW_TYPES = Event.create(BeforeStuckArrowTypes.class, callbacks -> (livingEntity, stuckArrowTypes) -> { | ||
for (BeforeStuckArrowTypes callback : callbacks) { | ||
callback.beforeStuckArrowTypesSent(livingEntity, stuckArrowTypes); | ||
} | ||
}); | ||
|
||
public static final Event<AfterStuckArrowTypes> AFTER_STUCK_ARROW_TYPES = Event.create(AfterStuckArrowTypes.class, callbacks -> (livingEntity, stuckArrowTypes) -> { | ||
for (AfterStuckArrowTypes callback : callbacks) { | ||
callback.afterStuckArrowTypesSent(livingEntity, stuckArrowTypes); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface BeforeStuckArrowTypes { | ||
|
||
void beforeStuckArrowTypesSent(LivingEntity livingEntity, Map<Integer, Identifier> stuckArrowTypes); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface AfterStuckArrowTypes { | ||
|
||
void afterStuckArrowTypesSent(LivingEntity livingEntity, Map<Integer, Identifier> stuckArrowTypes); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../client/ClientConfigNetworkingEvents.java → .../client/ClientConfigNetworkingEvents.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
2 changes: 1 addition & 1 deletion
2
...ient/ClientGlintPackNetworkingEvents.java → ...ient/ClientGlintPackNetworkingEvents.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
36 changes: 36 additions & 0 deletions
36
...ing/mmodding_lib/library/events/networking/client/ClientLivingEntityNetworkingEvents.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,36 @@ | ||
package com.mmodding.mmodding_lib.library.events.networking.client; | ||
|
||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.util.Identifier; | ||
import org.quiltmc.loader.api.minecraft.ClientOnly; | ||
import org.quiltmc.qsl.base.api.event.Event; | ||
|
||
import java.util.Map; | ||
|
||
@ClientOnly | ||
public class ClientLivingEntityNetworkingEvents { | ||
|
||
public static final Event<BeforeStuckArrowTypes> BEFORE_STUCK_ARROW_TYPES = Event.create(BeforeStuckArrowTypes.class, callbacks -> (livingEntity, stuckArrowTypes) -> { | ||
for (BeforeStuckArrowTypes callback : callbacks) { | ||
callback.beforeStuckArrowTypesReceived(livingEntity, stuckArrowTypes); | ||
} | ||
}); | ||
|
||
public static final Event<AfterStuckArrowTypes> AFTER_STUCK_ARROW_TYPES = Event.create(AfterStuckArrowTypes.class, callbacks -> (livingEntity, stuckArrowTypes) -> { | ||
for (AfterStuckArrowTypes callback : callbacks) { | ||
callback.afterStuckArrowTypesReceived(livingEntity, stuckArrowTypes); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface BeforeStuckArrowTypes { | ||
|
||
void beforeStuckArrowTypesReceived(LivingEntity livingEntity, Map<Integer, Identifier> stuckArrowTypes); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface AfterStuckArrowTypes { | ||
|
||
void afterStuckArrowTypesReceived(LivingEntity livingEntity, Map<Integer, Identifier> stuckArrowTypes); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ng/mmodding_lib/library/events/networking/client/ClientStellarStatusNetworkingEvents.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,36 @@ | ||
package com.mmodding.mmodding_lib.library.events.networking.client; | ||
|
||
import com.mmodding.mmodding_lib.library.stellar.client.ClientStellarStatus; | ||
import net.minecraft.util.Identifier; | ||
import org.quiltmc.loader.api.minecraft.ClientOnly; | ||
import org.quiltmc.qsl.base.api.event.Event; | ||
|
||
@ClientOnly | ||
public class ClientStellarStatusNetworkingEvents { | ||
|
||
public static final Event<Before> BEFORE = Event.create(Before.class, callbacks -> (identifier, status) -> { | ||
for (Before callback : callbacks) { | ||
callback.beforeStellarStatusReceived(identifier, status); | ||
} | ||
}); | ||
|
||
public static final Event<After> AFTER = Event.create(After.class, callbacks -> (identifier, status) -> { | ||
for (After callback : callbacks) { | ||
callback.afterStellarStatusReceived(identifier, status); | ||
} | ||
}); | ||
|
||
@ClientOnly | ||
@FunctionalInterface | ||
public interface Before { | ||
|
||
void beforeStellarStatusReceived(Identifier identifier, ClientStellarStatus status); | ||
} | ||
|
||
@ClientOnly | ||
@FunctionalInterface | ||
public interface After { | ||
|
||
void afterStellarStatusReceived(Identifier identifier, ClientStellarStatus status); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../server/ServerConfigNetworkingEvents.java → .../server/ServerConfigNetworkingEvents.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
2 changes: 1 addition & 1 deletion
2
...rver/ServerGlintPackNetworkingEvents.java → ...rver/ServerGlintPackNetworkingEvents.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
64 changes: 64 additions & 0 deletions
64
...ng/mmodding_lib/library/events/networking/server/ServerStellarStatusNetworkingEvents.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,64 @@ | ||
package com.mmodding.mmodding_lib.library.events.networking.server; | ||
|
||
import com.mmodding.mmodding_lib.library.stellar.StellarStatus; | ||
import net.minecraft.util.Identifier; | ||
import org.quiltmc.loader.api.minecraft.DedicatedServerOnly; | ||
import org.quiltmc.qsl.base.api.event.Event; | ||
|
||
import java.util.Map; | ||
|
||
@DedicatedServerOnly | ||
public class ServerStellarStatusNetworkingEvents { | ||
|
||
public static final Event<Before> BEFORE = Event.create(Before.class, callbacks -> (identifier, status) -> { | ||
for (Before callback : callbacks) { | ||
callback.beforeStellarStatusSent(identifier, status); | ||
} | ||
}); | ||
|
||
public static final Event<After> AFTER = Event.create(After.class, callbacks -> (identifier, status) -> { | ||
for (After callback : callbacks) { | ||
callback.afterStellarStatusSent(identifier, status); | ||
} | ||
}); | ||
|
||
public static final Event<BeforeAll> BEFORE_ALL = Event.create(BeforeAll.class, callbacks -> stellarStatus -> { | ||
for (BeforeAll callback : callbacks) { | ||
callback.beforeAllStellarStatusSent(stellarStatus); | ||
} | ||
}); | ||
|
||
public static final Event<AfterAll> AFTER_ALL = Event.create(AfterAll.class, callbacks -> stellarStatus -> { | ||
for (AfterAll callback : callbacks) { | ||
callback.afterAllStellarStatusSent(stellarStatus); | ||
} | ||
}); | ||
|
||
@DedicatedServerOnly | ||
@FunctionalInterface | ||
public interface Before { | ||
|
||
void beforeStellarStatusSent(Identifier identifier, StellarStatus status); | ||
} | ||
|
||
@DedicatedServerOnly | ||
@FunctionalInterface | ||
public interface After { | ||
|
||
void afterStellarStatusSent(Identifier identifier, StellarStatus status); | ||
} | ||
|
||
@DedicatedServerOnly | ||
@FunctionalInterface | ||
public interface BeforeAll { | ||
|
||
void beforeAllStellarStatusSent(Map<Identifier, StellarStatus> stellarStatus); | ||
} | ||
|
||
@DedicatedServerOnly | ||
@FunctionalInterface | ||
public interface AfterAll { | ||
|
||
void afterAllStellarStatusSent(Map<Identifier, StellarStatus> stellarStatus); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/com/mmodding/mmodding_lib/library/utils/TrackedDataHandlerUtils.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,76 @@ | ||
package com.mmodding.mmodding_lib.library.utils; | ||
|
||
import net.minecraft.entity.data.TrackedDataHandler; | ||
import net.minecraft.network.PacketByteBuf; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TrackedDataHandlerUtils { | ||
|
||
public static <T> TrackedDataHandler<List<T>> createTrackedDataListHandler(WriteAction<T> writeAction, ReadAction<T> readAction) { | ||
|
||
return new TrackedDataHandler<>() { | ||
|
||
@Override | ||
public void write(PacketByteBuf buf, List<T> value) { | ||
buf.writeVarInt(value.size()); | ||
value.forEach(element -> writeAction.write(buf, element)); | ||
} | ||
|
||
@Override | ||
public List<T> read(PacketByteBuf buf) { | ||
int size = buf.readVarInt(); | ||
List<T> value = new ArrayList<>(size); | ||
for (int i = 0; i < size; i++) { | ||
value.add(readAction.read(buf)); | ||
} | ||
return value; | ||
} | ||
|
||
@Override | ||
public List<T> copy(List<T> value) { | ||
return new ArrayList<>(value); | ||
} | ||
}; | ||
} | ||
|
||
public static <T> TrackedDataHandler<T> createTrackedDataHandler(WriteAction<T> writeAction, ReadAction<T> readAction, CopyAction<T> copyAction) { | ||
|
||
return new TrackedDataHandler<>() { | ||
|
||
@Override | ||
public void write(PacketByteBuf buf, T value) { | ||
writeAction.write(buf, value); | ||
} | ||
|
||
@Override | ||
public T read(PacketByteBuf buf) { | ||
return readAction.read(buf); | ||
} | ||
|
||
@Override | ||
public T copy(T value) { | ||
return copyAction.copy(value); | ||
} | ||
}; | ||
} | ||
|
||
@FunctionalInterface | ||
public interface WriteAction<T> { | ||
|
||
void write(PacketByteBuf buf, T value); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface ReadAction<T> { | ||
|
||
T read(PacketByteBuf buf); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface CopyAction<T> { | ||
|
||
T copy(T value); | ||
} | ||
} |
Oops, something went wrong.