Skip to content

Commit

Permalink
Filter custom block entity packet
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Jun 15, 2024
1 parent 07a0dc5 commit 65b7c9a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* OKTW Galaxy Project
* Copyright (C) 2018-2024
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package one.oktw.galaxy.mixin.tweak;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.network.packet.s2c.play.ChunkData;
import net.minecraft.util.math.BlockPos;
import one.oktw.galaxy.block.entity.CustomBlockEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

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

@Mixin(ChunkData.class)
public class MixinCustomBLockEntity_ChunkData {
@Redirect(method = "<init>(Lnet/minecraft/world/chunk/WorldChunk;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;entrySet()Ljava/util/Set;"))
private Set<Map.Entry<BlockPos, BlockEntity>> removeCustomBlock(Map<BlockPos, BlockEntity> instance) {
return instance.entrySet().stream().filter(e -> !(e.getValue() instanceof CustomBlockEntity)).collect(Collectors.toSet());
}
}
1 change: 1 addition & 0 deletions src/main/resources/tweak.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"MixinAsyncChunk_StorageIoWorker",
"MixinAsyncChunk_ThreadedAnvilChunkStorage",
"MixinCustomBlockEntity_BarrierBlock",
"MixinCustomBLockEntity_ChunkData",
"MixinCustomBlockEntity_Structure",
"MixinFixBeacon_BeaconBlockEntity",
"MixinGlobalDataPack_VanillaDataPackProvider",
Expand Down

0 comments on commit 65b7c9a

Please sign in to comment.