Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trident Api #159

Draft
wants to merge 1 commit into
base: 1.19
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/item/item_extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ qslModule {
moduleDependencies {
core {
api("qsl_base")
impl("networking")
}
}
injectedInterface("net/minecraft/class_1753") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.quiltmc.qsl.item.extension.api.trident;

import net.minecraft.item.Item;
import net.minecraft.item.TridentItem;

public class ProjectileModifyingTridentItem extends TridentItem {
public ProjectileModifyingTridentItem(Item.Settings settings) {
super(settings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.quiltmc.qsl.item.extension.api.trident;

import org.quiltmc.qsl.base.api.util.InjectedInterface;

import net.minecraft.item.TridentItem;
import net.minecraft.util.Identifier;

@InjectedInterface(TridentItem.class)
public interface TridentExtensions {
boolean useVanillaRenderer();
Identifier getRenderTexture();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.quiltmc.qsl.item.extension.api.trident;

public class TridentThrownProjectileEvents {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.quiltmc.qsl.item.extension.impl.trident;

import java.util.ArrayDeque;
import java.util.Deque;

import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer;
import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking;

import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

public class TridentClientModInitializer implements ClientModInitializer {
public static final Deque<ItemStack> TRIDENT_QUEUE = new ArrayDeque<>();

public static final Identifier TRIDENT_SPAWN_PACKET_ID = new Identifier("quilt_item_extensions", "trident_spawn_stack");

@Override
public void onInitializeClient(ModContainer mod) {
ClientPlayNetworking.registerGlobalReceiver(TRIDENT_SPAWN_PACKET_ID, (client, handler, buf, responseSender) -> {
TRIDENT_QUEUE.add(buf.readItemStack());
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.quiltmc.qsl.item.extension.mixin.trident;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import net.minecraft.entity.projectile.TridentEntity;
import net.minecraft.item.ItemStack;

@Mixin(TridentEntity.class)
public interface TridentEntityAccessor {
@Accessor("tridentStack")
ItemStack getTridentStack();

@Accessor("tridentStack")
void setTridentStack(ItemStack stack);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.quiltmc.qsl.item.extension.mixin.trident;

import org.quiltmc.qsl.item.extension.impl.trident.TridentClientModInitializer;
import org.quiltmc.qsl.networking.api.PacketByteBufs;
import org.quiltmc.qsl.networking.api.ServerPlayNetworking;
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.CallbackInfoReturnable;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.entity.projectile.TridentEntity;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.world.World;

@Mixin(ProjectileEntity.class)
public abstract class TridentEntityMixin extends Entity {
public TridentEntityMixin(EntityType<?> entityType, World world) {
super(entityType, world);
}

@Inject(method = "createSpawnPacket", at = @At("HEAD"))
public void sendTridentStackBeforeSpawnPacket(CallbackInfoReturnable<Packet<?>> cir) {
if ((Object) this instanceof TridentEntity trident) {
PacketByteBuf passedData = PacketByteBufs.create();
passedData.writeItemStack(((TridentEntityAccessor) trident).getTridentStack());
ServerPlayNetworking.send(this.world.getServer().getPlayerManager().getPlayerList(), TridentClientModInitializer.TRIDENT_SPAWN_PACKET_ID, passedData);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.quiltmc.qsl.item.extension.mixin.trident.client;

import org.quiltmc.qsl.item.extension.impl.trident.TridentClientModInitializer;
import org.quiltmc.qsl.item.extension.mixin.trident.TridentEntityAccessor;
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 org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;

@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin {
@Inject(method = "onEntitySpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;onSpawnPacket(Lnet/minecraft/network/packet/s2c/play/EntitySpawnS2CPacket;)V"), locals = LocalCapture.CAPTURE_FAILHARD)
public void onEntitySpawnMixin(EntitySpawnS2CPacket packet, CallbackInfo ci, EntityType<?> entityType, Entity entity) {
if (entityType == EntityType.TRIDENT) {
((TridentEntityAccessor) entity).setTridentStack(TridentClientModInitializer.TRIDENT_QUEUE.remove());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.quiltmc.qsl.item.extension.mixin.trident.client;

import org.quiltmc.qsl.item.extension.api.trident.TridentExtensions;
import org.quiltmc.qsl.item.extension.mixin.trident.TridentEntityAccessor;
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.CallbackInfoReturnable;

import net.minecraft.client.render.entity.TridentEntityRenderer;
import net.minecraft.entity.projectile.TridentEntity;
import net.minecraft.util.Identifier;

@Mixin(TridentEntityRenderer.class)
public class TridentEntityRendererMixin {
@Inject(method = "getTexture(Lnet/minecraft/entity/projectile/TridentEntity;)Lnet/minecraft/util/Identifier;", at = @At(value = "HEAD"), cancellable = true)
public void getTextureMixin(TridentEntity entity, CallbackInfoReturnable<Identifier> cir) {
if(((TridentEntityAccessor) entity).getTridentStack().getItem() instanceof TridentExtensions tridentItem) {
cir.setReturnValue(tridentItem.getRenderTexture());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
"bow.EntityUseBowMixin",
"crossbow.CrossbowItemAccessor",
"crossbow.CrossbowItemMixin",
"crossbow.EntityUseCrossbowMixin"
"crossbow.EntityUseCrossbowMixin",
"trident.TridentEntityAccessor",
"trident.TridentEntityMixin"
],
"client": [
"bow.client.SkeletonEntityModelMixin",
"client.HeldItemRendererMixin",
"crossbow.client.PlayerEntityRendererMixin"
"crossbow.client.PlayerEntityRendererMixin",
"trident.client.ClientPlayNetworkHandlerMixin",
"trident.client.TridentEntityRendererMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down