-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixed resource packs creation - It now works better on client
- Loading branch information
Showing
10 changed files
with
175 additions
and
5 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
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
47 changes: 47 additions & 0 deletions
47
src/main/java/eu/pb4/polymer/mixin/block/BlockEventS2CPacketMixin.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,47 @@ | ||
package eu.pb4.polymer.mixin.block; | ||
|
||
import eu.pb4.polymer.block.VirtualBlock; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.network.packet.s2c.play.BlockEventS2CPacket; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.spongepowered.asm.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.CallbackInfoReturnable; | ||
import xyz.nucleoid.packettweaker.PacketContext; | ||
|
||
@Mixin(BlockEventS2CPacket.class) | ||
public class BlockEventS2CPacketMixin { | ||
@Shadow @Mutable | ||
private Block block; | ||
|
||
@Shadow @Final private BlockPos pos; | ||
|
||
@Unique private Block oldBlock = null; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Inject(method = "getBlock", at = @At("TAIL"), cancellable = true) | ||
private void replaceBlockClient(CallbackInfoReturnable<Block> cir) { | ||
ServerPlayerEntity player = MinecraftClient.getInstance().getServer().getPlayerManager().getPlayer(MinecraftClient.getInstance().player.getUuid()); | ||
if (this.oldBlock instanceof VirtualBlock virtualBlock) { | ||
cir.setReturnValue(virtualBlock.getVirtualBlock(this.pos, player.getServerWorld())); | ||
} | ||
} | ||
|
||
@Inject(method = "write", at = @At("TAIL")) | ||
private void replaceBlock(PacketByteBuf byteBuf, CallbackInfo ci) { | ||
if (oldBlock == null) { | ||
this.oldBlock = block; | ||
} | ||
|
||
if (this.oldBlock instanceof VirtualBlock virtualBlock) { | ||
this.block = virtualBlock.getVirtualBlock(this.pos, PacketContext.get().getTarget().getServerWorld()); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/eu/pb4/polymer/mixin/block/PlayerActionResponseS2CPacketMixin.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 eu.pb4.polymer.mixin.block; | ||
|
||
import eu.pb4.polymer.block.VirtualBlock; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.network.packet.s2c.play.PlayerActionResponseS2CPacket; | ||
import org.spongepowered.asm.mixin.Final; | ||
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.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(PlayerActionResponseS2CPacket.class) | ||
public class PlayerActionResponseS2CPacketMixin { | ||
@Shadow @Final private BlockState state; | ||
|
||
@ModifyArg(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getRawIdFromState(Lnet/minecraft/block/BlockState;)I")) | ||
private BlockState replaceWithVirtualBlockState(BlockState state) { | ||
if (state.getBlock() instanceof VirtualBlock) { | ||
return ((VirtualBlock) state.getBlock()).getVirtualBlockState(state); | ||
} | ||
return state; | ||
} | ||
|
||
|
||
@Environment(EnvType.CLIENT) | ||
@Inject(method = "getBlockState", at = @At("HEAD"), cancellable = true) | ||
public void replaceWithVirtualState(CallbackInfoReturnable<BlockState> cir) { | ||
if (this.state.getBlock() instanceof VirtualBlock virtualBlock) { | ||
cir.setReturnValue(virtualBlock.getVirtualBlockState(this.state)); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/eu/pb4/polymer/mixin/item/ClickSlotC2SPacketMixin.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,30 @@ | ||
package eu.pb4.polymer.mixin.item; | ||
|
||
import eu.pb4.polymer.item.ItemHelper; | ||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; | ||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket; | ||
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; | ||
|
||
@Mixin(ClickSlotC2SPacket.class) | ||
public class ClickSlotC2SPacketMixin { | ||
@Inject(method = "getStack", at = @At("TAIL"), cancellable = true) | ||
private void replaceWithReal(CallbackInfoReturnable<ItemStack> cir) { | ||
cir.setReturnValue(ItemHelper.getRealItemStack(cir.getReturnValue())); | ||
} | ||
|
||
@Inject(method = "getModifiedStacks", at = @At("TAIL"), cancellable = true) | ||
private void replaceMultipleReal(CallbackInfoReturnable<Int2ObjectMap<ItemStack>> cir) { | ||
Int2ObjectMap map = new Int2ObjectArrayMap(); | ||
|
||
for (Int2ObjectMap.Entry<ItemStack> entry : cir.getReturnValue().int2ObjectEntrySet()) { | ||
map.put(entry.getIntKey(), ItemHelper.getRealItemStack(entry.getValue())); | ||
} | ||
|
||
cir.setReturnValue(map); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/eu/pb4/polymer/mixin/item/CreativeInventoryActionC2SPacketMixin.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,17 @@ | ||
package eu.pb4.polymer.mixin.item; | ||
|
||
import eu.pb4.polymer.item.ItemHelper; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket; | ||
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; | ||
|
||
@Mixin(CreativeInventoryActionC2SPacket.class) | ||
public class CreativeInventoryActionC2SPacketMixin { | ||
@Inject(method = "getItemStack", at = @At("TAIL"), cancellable = true) | ||
private void replaceWithReal(CallbackInfoReturnable<ItemStack> cir) { | ||
cir.setReturnValue(ItemHelper.getRealItemStack(cir.getReturnValue())); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/eu/pb4/polymer/mixin/item/ItemStackMixin.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 eu.pb4.polymer.mixin.item; | ||
|
||
import eu.pb4.polymer.item.ItemHelper; | ||
import net.minecraft.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
|
||
@Mixin(ItemStack.class) | ||
public class ItemStackMixin { | ||
@ModifyArg(method = "getTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/LiteralText;<init>(Ljava/lang/String;)V", ordinal = 3)) | ||
private String changeId(String id) { | ||
ItemStack stack = (ItemStack) (Object) this; | ||
return stack.hasTag() && stack.getTag().contains(ItemHelper.VIRTUAL_ITEM_ID) ? stack.getTag().getString(ItemHelper.VIRTUAL_ITEM_ID) : id; | ||
} | ||
} |
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