-
-
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.
- Loading branch information
Showing
10 changed files
with
153 additions
and
2 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
10 changes: 10 additions & 0 deletions
10
.../main/java/org/quiltmc/qsl/item/extension/api/trident/ProjectileModifyingTridentItem.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,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); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...extension/src/main/java/org/quiltmc/qsl/item/extension/api/trident/TridentExtensions.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,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(); | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...c/main/java/org/quiltmc/qsl/item/extension/api/trident/TridentThrownProjectileEvents.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,4 @@ | ||
package org.quiltmc.qsl.item.extension.api.trident; | ||
|
||
public class TridentThrownProjectileEvents { | ||
} |
24 changes: 24 additions & 0 deletions
24
...rc/main/java/org/quiltmc/qsl/item/extension/impl/trident/TridentClientModInitializer.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,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()); | ||
}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ion/src/main/java/org/quiltmc/qsl/item/extension/mixin/trident/TridentEntityAccessor.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,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); | ||
} |
33 changes: 33 additions & 0 deletions
33
...ension/src/main/java/org/quiltmc/qsl/item/extension/mixin/trident/TridentEntityMixin.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,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); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...va/org/quiltmc/qsl/item/extension/mixin/trident/client/ClientPlayNetworkHandlerMixin.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,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()); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../java/org/quiltmc/qsl/item/extension/mixin/trident/client/TridentEntityRendererMixin.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,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()); | ||
} | ||
} | ||
} |
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