Skip to content

Commit

Permalink
fix remaining issues with tridents, elytras, and another @shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
OroArmor committed Jan 8, 2021
1 parent 9762bab commit b09f7b9
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package com.oroarmor.netherite_plus.client;

import java.util.LinkedList;
import java.util.Queue;

import com.oroarmor.netherite_plus.NetheritePlusMod;
import com.oroarmor.netherite_plus.config.NetheritePlusConfig;
import com.oroarmor.netherite_plus.network.LavaVisionUpdatePacket;
import me.shedaniel.architectury.networking.NetworkManager;

public class NetheritePlusClientMod {
public static double LAVA_VISION_DISTANCE = NetheritePlusConfig.GRAPHICS.LAVA_VISION_DISTANCE.getValue();
public static final Queue<Integer> TRIDENT_QUEUE = new LinkedList<>();

public static void init() {
NetworkManager.registerReceiver(NetworkManager.Side.S2C, LavaVisionUpdatePacket.ID, (friendlyByteBuf, packetContext) -> {
NetheritePlusClientMod.LAVA_VISION_DISTANCE = friendlyByteBuf.readDouble();
});

NetworkManager.registerReceiver(NetworkManager.Side.S2C, NetheritePlusMod.id("netherite_trident"), (friendlyByteBuf, packetContext) -> {
System.out.println("received");
TRIDENT_QUEUE.add(friendlyByteBuf.readInt());
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public NetheriteElytraFeatureRenderer(RenderLayerParent<T, M> context) {
@Override
public void render(PoseStack matrixStack, MultiBufferSource vertexConsumerProvider, int i, T livingEntity, float f, float g, float h, float j, float k, float l) {
ItemStack itemStack = livingEntity.getItemBySlot(EquipmentSlot.CHEST);
if (itemStack.getItem() == NetheritePlusItems.NETHERITE_ELYTRA) {
if (itemStack.getItem() == NetheritePlusItems.NETHERITE_ELYTRA.get()) {
ResourceLocation identifier4;
if (livingEntity instanceof AbstractClientPlayer) {
AbstractClientPlayer abstractClientPlayerEntity = (AbstractClientPlayer) livingEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.oroarmor.netherite_plus.entity;

import com.oroarmor.netherite_plus.NetheritePlusMod;
import com.oroarmor.netherite_plus.config.NetheritePlusConfig;
import com.oroarmor.netherite_plus.item.NetheritePlusItems;
import io.netty.buffer.Unpooled;
import me.shedaniel.architectury.networking.NetworkManager;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
Expand Down Expand Up @@ -88,4 +94,8 @@ protected void onHitEntity(EntityHitResult entityHitResult) {
playSound(soundEvent, g, 1.0F);
}

@Override
public Packet<?> getAddEntityPacket() {
return super.getAddEntityPacket();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.oroarmor.netherite_plus.config.NetheritePlusConfig;
import com.oroarmor.netherite_plus.entity.NetheriteTridentEntity;

import net.minecraft.network.protocol.Packet;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.oroarmor.netherite_plus.mixin;

import java.util.Iterator;

import com.oroarmor.netherite_plus.client.NetheritePlusClientMod;
import com.oroarmor.netherite_plus.entity.NetheriteTridentEntity;
import com.oroarmor.netherite_plus.item.NetheritePlusItems;
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.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.Registry;
import net.minecraft.network.protocol.PacketUtils;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.world.entity.Entity;
Expand All @@ -23,9 +20,6 @@

@Mixin(ClientPacketListener.class)
public abstract class ClientPlayNetworkHandlerMixin {
@Shadow
public abstract ClientLevel getLevel();

@Inject(method = "handleAddEntity", at = @At("HEAD"), cancellable = true)
public void onEntitySpawnMixin(ClientboundAddEntityPacket packet, CallbackInfo info) {
PacketUtils.ensureRunningOnSameThread(packet, (ClientPacketListener) (Object) this, ((ClientPlayNetworkHandlerAccessor) this).getMinecraft());
Expand All @@ -42,17 +36,7 @@ public void onEntitySpawnMixin(ClientboundAddEntityPacket packet, CallbackInfo i
entity15 = new ThrownTrident(level, d, e, f);
entity16 = level.getEntity(packet.getData());

if (entity16 instanceof LocalPlayer) {

boolean hasNetheriteTrident = false;
Iterator<ItemStack> items = entity16.getHandSlots().iterator();
while (items.hasNext()) {
hasNetheriteTrident |= items.next().getItem() == NetheritePlusItems.NETHERITE_TRIDENT.get();
}
if (hasNetheriteTrident) {
entity15 = new NetheriteTridentEntity(level, d, e, f);
}
}
((ThrownTrident) entity15).tridentItem = new ItemStack(Registry.ITEM.byId(NetheritePlusClientMod.TRIDENT_QUEUE.remove()));

if (entity16 != null) {
((AbstractArrow) entity15).setOwner(entity16);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.oroarmor.netherite_plus.mixin;

import com.oroarmor.netherite_plus.NetheritePlusMod;
import io.netty.buffer.Unpooled;
import me.shedaniel.architectury.networking.NetworkManager;
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.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.ThrownTrident;

@Mixin(AbstractArrow.class)
public class TridentEntityMixin {
@Inject(method = "getAddEntityPacket()Lnet/minecraft/network/protocol/Packet;", at = @At("HEAD"))
public void sendTridentStackOnSpawn(CallbackInfoReturnable<Packet<?>> info){
if((Object) this instanceof ThrownTrident) {
FriendlyByteBuf passedData = new FriendlyByteBuf(Unpooled.buffer());
passedData.writeInt(Registry.ITEM.getId(((ThrownTrident)(Object)this).tridentItem.getItem()));
NetworkManager.sendToPlayers(((Entity) (Object) this).level.getServer().getPlayerList().getPlayers(), NetheritePlusMod.id("netherite_trident"), passedData);
}
}
}
3 changes: 2 additions & 1 deletion common/src/main/resources/netherite_plus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"CauldronBlockMixin",
"CrossbowItemMixin",
"PlayerEntityMixin",
"ServerPlayNetworkHandlerMixin"
"ServerPlayNetworkHandlerMixin",
"TridentEntityMixin"
],
"client": [
"ClientPlayNetworkHandlerAccessor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public void registerClient(FMLClientSetupEvent event) {
}
});

Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap().values()
.forEach(player -> player.addLayer(new NetheriteElytraFeatureRenderer(player)));

if (NetheritePlusConfig.ENABLED.ENABLED_BEACON.getValue()) {
RenderTypes.register(RenderType.cutout(), NetheritePlusBlocks.NETHERITE_BEACON.getOrNull());
Expand Down

0 comments on commit b09f7b9

Please sign in to comment.