generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 30
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
23 changed files
with
438 additions
and
18 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
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
2 changes: 1 addition & 1 deletion
2
...mixin/IMixinClientPlayNetworkHandler.java → ...lient/IMixinClientPlayNetworkHandler.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
34 changes: 34 additions & 0 deletions
34
src/main/java/io/github/plusls/MasaGadget/mixin/client/MixinClientPlayNetworkHandler.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,34 @@ | ||
package io.github.plusls.MasaGadget.mixin.client; | ||
|
||
import net.minecraft.block.entity.*; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayNetworkHandler; | ||
import net.minecraft.network.listener.ClientPlayPacketListener; | ||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; | ||
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; | ||
|
||
@Mixin(ClientPlayNetworkHandler.class) | ||
public abstract class MixinClientPlayNetworkHandler implements ClientPlayPacketListener { | ||
|
||
@Shadow | ||
private MinecraftClient client; | ||
|
||
@Inject(method = "onBlockEntityUpdate(Lnet/minecraft/network/packet/s2c/play/BlockEntityUpdateS2CPacket;)V", | ||
at = @At(value = "RETURN")) | ||
private void postOnBlockEntityUpdate(BlockEntityUpdateS2CPacket packet, CallbackInfo info) { | ||
int blockEntityType = packet.getBlockEntityType(); | ||
BlockEntity blockEntity = this.client.world.getBlockEntity(packet.getPos()); | ||
if (blockEntityType == 0 && ( | ||
blockEntity instanceof ShulkerBoxBlockEntity || | ||
blockEntity instanceof HopperBlockEntity || | ||
blockEntity instanceof AbstractFurnaceBlockEntity || | ||
blockEntity instanceof DispenserBlockEntity // 包括了投掷器 | ||
)) { | ||
blockEntity.fromTag(this.client.world.getBlockState(blockEntity.getPos()), packet.getCompoundTag()); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...et/mixin/MixinCustomPayloadS2CPacket.java → ...n/client/MixinCustomPayloadS2CPacket.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
20 changes: 20 additions & 0 deletions
20
src/main/java/io/github/plusls/MasaGadget/mixin/client/MixinMinecraftClient.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,20 @@ | ||
package io.github.plusls.MasaGadget.mixin.client; | ||
|
||
import io.github.plusls.MasaGadget.MasaGadgetMod; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
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; | ||
|
||
@Mixin({MinecraftClient.class}) | ||
public abstract class MixinMinecraftClient { | ||
@Inject( | ||
method = {"disconnect(Lnet/minecraft/client/gui/screen/Screen;)V"}, | ||
at = {@At("HEAD")} | ||
) | ||
private void onDisconnectPre(Screen screen, CallbackInfo ci) { | ||
MasaGadgetMod.masaGagdetInServer = false; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...et/mixin/MixinPlayerRespawnS2CPacket.java → ...n/client/MixinPlayerRespawnS2CPacket.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
2 changes: 1 addition & 1 deletion
2
...ls/MasaGadget/mixin/MixinDataStorage.java → ...ixin/client/malilib/MixinDataStorage.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
20 changes: 20 additions & 0 deletions
20
src/main/java/io/github/plusls/MasaGadget/mixin/client/malilib/MixinInventoryUtils.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,20 @@ | ||
package io.github.plusls.MasaGadget.mixin.client.malilib; | ||
|
||
import fi.dy.masa.malilib.util.InventoryUtils; | ||
import io.github.plusls.MasaGadget.network.DataAccessor; | ||
import net.minecraft.inventory.Inventory; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
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(value = InventoryUtils.class, remap = false) | ||
public abstract class MixinInventoryUtils { | ||
@Inject(method = "getInventory", | ||
at = @At(value = "HEAD")) | ||
private static void preGetInventory(World world, BlockPos pos, CallbackInfoReturnable<Inventory> info) { | ||
DataAccessor.requestBlockEntity(pos); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...t/mixin/MixinWidgetListConfigOptions.java → ...malilib/MixinWidgetListConfigOptions.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
37 changes: 37 additions & 0 deletions
37
src/main/java/io/github/plusls/MasaGadget/mixin/client/tweakeroo/MixinRenderHandler.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,37 @@ | ||
package io.github.plusls.MasaGadget.mixin.client.tweakeroo; | ||
|
||
import fi.dy.masa.malilib.hotkeys.IKeybind; | ||
import fi.dy.masa.malilib.interfaces.IRenderer; | ||
import fi.dy.masa.tweakeroo.event.RenderHandler; | ||
import io.github.plusls.MasaGadget.MasaGadgetMod; | ||
import io.github.plusls.MasaGadget.network.DataAccessor; | ||
import io.github.plusls.MasaGadget.network.ServerNetworkHandler; | ||
import io.netty.buffer.Unpooled; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
|
||
@Mixin(value = RenderHandler.class, remap = false) | ||
public abstract class MixinRenderHandler implements IRenderer { | ||
// 未按下按键时若是 lastBlockPos 不为空, 则告诉服务端不需要更新 block entity | ||
@Redirect(method = "onRenderGameOverlayPost", | ||
at = @At(value = "INVOKE", | ||
target = "Lfi/dy/masa/malilib/hotkeys/IKeybind;isKeybindHeld()Z", | ||
ordinal = 2)) | ||
private boolean redirectIsKeyBindHeld(IKeybind iKeybind) { | ||
boolean ret = iKeybind.isKeybindHeld(); | ||
|
||
if (!ret && DataAccessor.lastBlockPos != null) { | ||
DataAccessor.lastBlockPos = null; | ||
MasaGadgetMod.LOGGER.debug("cancel requestBlockEntity"); | ||
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); | ||
buf.writeBoolean(false); | ||
MinecraftClient.getInstance().getNetworkHandler().getConnection().send(new CustomPayloadC2SPacket(ServerNetworkHandler.REQUEST_BLOCK_ENTITY, buf)); | ||
} | ||
return ret; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/io/github/plusls/MasaGadget/mixin/server/MixinPlayerManager.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,31 @@ | ||
package io.github.plusls.MasaGadget.mixin.server; | ||
|
||
import io.github.plusls.MasaGadget.MasaGadgetMod; | ||
import io.github.plusls.MasaGadget.network.ClientNetworkHandler; | ||
import io.github.plusls.MasaGadget.network.ServerNetworkHandler; | ||
import io.netty.buffer.Unpooled; | ||
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry; | ||
import net.minecraft.network.ClientConnection; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.server.PlayerManager; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
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; | ||
|
||
@Mixin(PlayerManager.class) | ||
public abstract class MixinPlayerManager { | ||
|
||
@Inject(method = "onPlayerConnect(Lnet/minecraft/network/ClientConnection;Lnet/minecraft/server/network/ServerPlayerEntity;)V", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/network/packet/s2c/play/DifficultyS2CPacket;<init>(Lnet/minecraft/world/Difficulty;Z)V", | ||
ordinal = 0 | ||
) | ||
) | ||
private void onOnPlayerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { | ||
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); | ||
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, ClientNetworkHandler.HELLO, buf); | ||
MasaGadgetMod.LOGGER.debug("send hello!"); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...a/io/github/plusls/MasaGadget/mixin/server/inventory/MixinAbstractFurnaceBlockEntity.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,40 @@ | ||
package io.github.plusls.MasaGadget.mixin.server.inventory; | ||
|
||
import io.github.plusls.MasaGadget.MasaGadgetMod; | ||
import io.github.plusls.MasaGadget.network.ServerNetworkHandler; | ||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity; | ||
import net.minecraft.block.entity.LockableContainerBlockEntity; | ||
import net.minecraft.inventory.SidedInventory; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; | ||
import net.minecraft.recipe.RecipeInputProvider; | ||
import net.minecraft.recipe.RecipeUnlocker; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.Tickable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
@Mixin(AbstractFurnaceBlockEntity.class) | ||
public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerBlockEntity implements SidedInventory, RecipeUnlocker, RecipeInputProvider, Tickable { | ||
|
||
@Shadow | ||
public abstract CompoundTag toTag(CompoundTag tag); | ||
|
||
public MixinAbstractFurnaceBlockEntity() { | ||
super(null); | ||
} | ||
|
||
@Override | ||
public void markDirty() { | ||
super.markDirty(); | ||
if (ServerNetworkHandler.lastBlockPosMap.containsValue(this.pos)) { | ||
((ServerWorld) this.getWorld()).getChunkManager().markForUpdate(this.getPos()); | ||
MasaGadgetMod.LOGGER.debug("update AbstractFurnaceBlockEntity: {}", this.pos); | ||
} | ||
} | ||
|
||
@Override | ||
public BlockEntityUpdateS2CPacket toUpdatePacket() { | ||
return new BlockEntityUpdateS2CPacket(this.pos, 0, this.toTag(new CompoundTag())); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...in/java/io/github/plusls/MasaGadget/mixin/server/inventory/MixinDispenserBlockEntity.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,37 @@ | ||
package io.github.plusls.MasaGadget.mixin.server.inventory; | ||
|
||
import io.github.plusls.MasaGadget.MasaGadgetMod; | ||
import io.github.plusls.MasaGadget.network.ServerNetworkHandler; | ||
import net.minecraft.block.entity.DispenserBlockEntity; | ||
import net.minecraft.block.entity.LootableContainerBlockEntity; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; | ||
import net.minecraft.server.world.ServerWorld; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
|
||
@Mixin(DispenserBlockEntity.class) | ||
public abstract class MixinDispenserBlockEntity extends LootableContainerBlockEntity { | ||
|
||
@Shadow | ||
public abstract CompoundTag toTag(CompoundTag tag); | ||
|
||
public MixinDispenserBlockEntity() { | ||
super(null); | ||
} | ||
|
||
@Override | ||
public void markDirty() { | ||
super.markDirty(); | ||
if (ServerNetworkHandler.lastBlockPosMap.containsValue(this.pos)) { | ||
((ServerWorld) this.getWorld()).getChunkManager().markForUpdate(this.getPos()); | ||
MasaGadgetMod.LOGGER.debug("update DispenserBlockEntity: {}", this.pos); | ||
} | ||
} | ||
|
||
@Override | ||
public BlockEntityUpdateS2CPacket toUpdatePacket() { | ||
return new BlockEntityUpdateS2CPacket(this.pos, 0, this.toTag(new CompoundTag())); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/io/github/plusls/MasaGadget/mixin/server/inventory/MixinHopperBlockEntity.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,38 @@ | ||
package io.github.plusls.MasaGadget.mixin.server.inventory; | ||
|
||
import io.github.plusls.MasaGadget.MasaGadgetMod; | ||
import io.github.plusls.MasaGadget.network.ServerNetworkHandler; | ||
import net.minecraft.block.entity.Hopper; | ||
import net.minecraft.block.entity.HopperBlockEntity; | ||
import net.minecraft.block.entity.LootableContainerBlockEntity; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.Tickable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
@Mixin(HopperBlockEntity.class) | ||
public abstract class MixinHopperBlockEntity extends LootableContainerBlockEntity implements Hopper, Tickable { | ||
|
||
@Shadow | ||
public abstract CompoundTag toTag(CompoundTag tag); | ||
|
||
public MixinHopperBlockEntity() { | ||
super(null); | ||
} | ||
|
||
@Override | ||
public void markDirty() { | ||
super.markDirty(); | ||
if (ServerNetworkHandler.lastBlockPosMap.containsValue(this.pos)) { | ||
((ServerWorld) this.getWorld()).getChunkManager().markForUpdate(this.getPos()); | ||
MasaGadgetMod.LOGGER.debug("update HopperBlockEntity: {}", this.pos); | ||
} | ||
} | ||
|
||
@Override | ||
public BlockEntityUpdateS2CPacket toUpdatePacket() { | ||
return new BlockEntityUpdateS2CPacket(this.pos, 0, this.toTag(new CompoundTag())); | ||
} | ||
} |
Oops, something went wrong.