Skip to content

Commit

Permalink
Switch to Packet Tweaker for getting player
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed May 31, 2021
1 parent a9c1b53 commit 503f4ec
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 137 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modRuntime "com.github.SuperCoder7979:databreaker:0.2.6"
//modRuntime "com.github.SuperCoder7979:databreaker:0.2.6"

modCompileOnly "com.github.CaffeineMC.lithium-fabric:lithium:d2a5d9e"

modCompileOnly('com.github.TheEpicBlock:PolyMc:3.1.1') {
exclude module: 'artifice'
}

//modImplementation include("fr.catcore:server-translations-api:1.4.1")
modImplementation include("fr.catcore:server-translations-api:1.4.2+1.17")
modImplementation include("xyz.nucleoid:packet-tweaker:0.2.0-1.17-pre1")

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.11.3

# Mod Properties
mod_version = 0.1.0-pre0
mod_version = 0.1.0-pre0-1.17-pre1
maven_group = eu.pb4
archives_base_name = polymer

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.BitSet;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -47,6 +48,7 @@ public abstract class ServerChunkManagerMixin {
@Nullable
public abstract WorldChunk getWorldChunk(int chunkX, int chunkZ);

@Shadow @Final private ServerLightingProvider lightProvider;
@Unique
private final Object2LongArrayMap<ChunkPos> lastUpdates = new Object2LongArrayMap<>();

Expand Down Expand Up @@ -86,12 +88,14 @@ private void sendLightUpdates(LightType type, ChunkSectionPos pos, CallbackInfo
}

if (sendUpdate) {
//Packet<?> packet = new LightUpdateS2CPacket(pos.toChunkPos(), this.getLightingProvider(), true);
BitSet bitSet = new BitSet();
bitSet.set(pos.getSectionY() - this.lightProvider.getBottomY());
Packet<?> packet = new LightUpdateS2CPacket(pos.toChunkPos(), this.getLightingProvider(), new BitSet(this.world.getTopSectionCoord() + 2), bitSet, true);
Set<ServerPlayerEntity> players = this.threadedAnvilChunkStorage.getPlayersWatchingChunk(pos.toChunkPos(), false).collect(Collectors.toSet());
if (players.size() > 0) {
this.lastUpdates.put(pos.toChunkPos(), System.currentTimeMillis());
for (ServerPlayerEntity player : players) {
//player.networkHandler.sendPacket(packet);
player.networkHandler.sendPacket(packet);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ public abstract class ServerPlayNetworkHandlerMixin {
@Inject(method = "sendPacket(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("TAIL"))
private void catchBlockUpdates(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> listener, CallbackInfo cb) {
try {
if (packet instanceof BlockUpdateS2CPacket) {
BlockUpdateS2CPacketAccessor b = (BlockUpdateS2CPacketAccessor) packet;
BlockState blockState = b.getStateServer();
if (packet instanceof BlockUpdateS2CPacket blockUpdatePacket) {
BlockState blockState = blockUpdatePacket.getState();

if (blockState.getBlock() instanceof VirtualBlock) {
BlockPos pos = ((BlockUpdateS2CPacketAccessor) packet).getPosServer();
BlockPos pos = blockUpdatePacket.getPos();
((VirtualBlock) blockState.getBlock()).sendPacketsAfterCreation(this.player, pos, blockState);
}
} else if (packet instanceof ChunkDataS2CPacket) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package eu.pb4.polymer.mixin.item;

import eu.pb4.polymer.interfaces.PlayerContextInterface;
import eu.pb4.polymer.item.ItemHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
Expand All @@ -9,13 +8,13 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import xyz.nucleoid.packettweaker.PacketContext;

@Mixin(value = PacketByteBuf.class, priority = 500)
public class PacketByteBufMixin {

@ModifyVariable(method = "writeItemStack", at = @At("HEAD"), ordinal = 0)
private ItemStack replaceWithVanillaItem(ItemStack itemStack) {
return ItemHelper.getVirtualItemStack(itemStack, ((PlayerContextInterface) this).getPolymerPlayer());
return ItemHelper.getVirtualItemStack(itemStack, PacketContext.get().getTarget());
}

@Inject(method = "readItemStack", at = @At("RETURN"), cancellable = true)
Expand Down

This file was deleted.

44 changes: 0 additions & 44 deletions src/main/java/eu/pb4/polymer/mixin/other/PacketContextMixin.java

This file was deleted.

This file was deleted.

6 changes: 1 addition & 5 deletions src/main/resources/polymer.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"required": true,
"minVersion": "0.8",
"package": "eu.pb4.polymer.mixin",
"compatibilityLevel": "JAVA_8",
"compatibilityLevel": "JAVA_16",
"plugin": "eu.pb4.polymer.mixin.MixinPlugin",
"mixins": [
"block.AbstractBlockAccessor",
"block.AbstractBlockMixin",
"block.AbstractBlockSettingAccessor",
"block.BlockPaletteMixin",
"block.BlockUpdateS2CPacketAccessor",
"block.BlockUpdateS2CPacketMixin",
"block.ChunkDataS2CPacketMixin",
"block.ChunkDeltaUpdateS2CPacketAccessor",
Expand All @@ -30,9 +29,6 @@
"item.ServerPlayNetworkHandlerMixin",
"item.ItemStackContentMixin",
"other.DimensionTypeAccessor",
"other.PacketByteBufContextMixin",
"other.PacketContextMixin",
"other.ServerPlayNetworkHandlerContextMixin",
"other.SynchronizeRecipesS2CPacketMixin",
"other.RegistrySyncManagerMixin",
"polymc.BlockPolyGeneratorMixin"
Expand Down
2 changes: 1 addition & 1 deletion src/testmod/resources/test.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "eu.pb4.polymertest.mixin",
"compatibilityLevel": "JAVA_8",
"compatibilityLevel": "JAVA_16",
"mixins": [
"VillagerEntityAccessor",
"AECAccessor"
Expand Down

0 comments on commit 503f4ec

Please sign in to comment.