-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trying add crafting and water handling inside blockentity
- Loading branch information
Showing
8 changed files
with
354 additions
and
21 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BrewingKegBlock.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
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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/megatrex4/ukrainian_dlight/networking/ModMessages.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,15 @@ | ||
package com.megatrex4.ukrainian_dlight.networking; | ||
|
||
import com.megatrex4.ukrainian_dlight.UkrainianDelight; | ||
import com.megatrex4.ukrainian_dlight.networking.packet.FluidSyncS2CPacket; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class ModMessages { | ||
public static final Identifier FLUID_SYNC = new Identifier(UkrainianDelight.MOD_ID, "fluid_sync"); | ||
|
||
public static void registerS2CPackets() { | ||
ClientPlayNetworking.registerGlobalReceiver(FLUID_SYNC, FluidSyncS2CPacket::receive); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/megatrex4/ukrainian_dlight/networking/packet/FluidSyncS2CPacket.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 com.megatrex4.ukrainian_dlight.networking.packet; | ||
|
||
import com.megatrex4.ukrainian_dlight.block.entity.BrewingKegBlockEntity; | ||
import com.megatrex4.ukrainian_dlight.screen.BrewingKegScreenHandler; | ||
import com.megatrex4.ukrainian_dlight.util.FluidStack; | ||
import net.fabricmc.fabric.api.networking.v1.PacketSender; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayNetworkHandler; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class FluidSyncS2CPacket { | ||
public static void receive(MinecraftClient client, ClientPlayNetworkHandler handler, | ||
PacketByteBuf buf, PacketSender responseSender) { | ||
FluidVariant variant = FluidVariant.fromPacket(buf); | ||
long fluidLevel = buf.readLong(); | ||
BlockPos position = buf.readBlockPos(); | ||
|
||
if(client.world.getBlockEntity(position) instanceof BrewingKegBlockEntity blockEntity) { | ||
blockEntity.setFluidLevel(variant, fluidLevel); | ||
|
||
if(client.player.currentScreenHandler instanceof BrewingKegScreenHandler screenHandler && | ||
screenHandler.blockEntity.getPos().equals(position)) { | ||
blockEntity.setFluidLevel(variant, fluidLevel); | ||
screenHandler.setFluid(new FluidStack(variant, fluidLevel)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.