mirror of
https://github.com/TeamMidnightDust/VisualOverhaul.git
synced 2025-12-16 14:05:08 +01:00
VisualOverhaul 3.3.0 - 1.17 and small Refactor
Update to 1.17-pre1 and Java 16 Upgrade to MidnightLib, making the config more clean and accessible without modmenu (Please ignore the commits before)
This commit is contained in:
35
src/main/java/eu/midnightdust/visualoverhaul/mixin/MixinBrewingStandBlockEntity.java
Normal file → Executable file
35
src/main/java/eu/midnightdust/visualoverhaul/mixin/MixinBrewingStandBlockEntity.java
Normal file → Executable file
@@ -4,15 +4,16 @@ import eu.midnightdust.visualoverhaul.VisualOverhaul;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.fabricmc.fabric.api.server.PlayerStream;
|
||||
import net.fabricmc.fabric.impl.networking.ServerSidePacketRegistryImpl;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.BrewingStandBlockEntity;
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
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;
|
||||
@@ -23,27 +24,25 @@ import java.util.stream.Stream;
|
||||
@Mixin(BrewingStandBlockEntity.class)
|
||||
public abstract class MixinBrewingStandBlockEntity extends LockableContainerBlockEntity {
|
||||
|
||||
@Shadow private DefaultedList<ItemStack> inventory;
|
||||
Boolean invUpdate = true;
|
||||
int playerUpdate = -1;
|
||||
private static boolean invUpdate = true;
|
||||
private static int playerUpdate = -1;
|
||||
|
||||
private MixinBrewingStandBlockEntity(BlockEntityType<?> blockEntityType) {
|
||||
super(blockEntityType);
|
||||
protected MixinBrewingStandBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
|
||||
super(blockEntityType, blockPos, blockState);
|
||||
}
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "tick")
|
||||
public void tick(CallbackInfo ci) {
|
||||
if (!this.world.isClient && (invUpdate || world.getPlayers().size() == playerUpdate)) {
|
||||
Stream<PlayerEntity> watchingPlayers = PlayerStream.watching(world, getPos());
|
||||
private static void tick(World world, BlockPos pos, BlockState state, BrewingStandBlockEntity blockEntity, CallbackInfo ci) {
|
||||
if (!world.isClient && (invUpdate || world.getPlayers().size() == playerUpdate)) {
|
||||
Stream<PlayerEntity> watchingPlayers = PlayerStream.watching(world, pos);
|
||||
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
|
||||
passedData.writeBlockPos(pos);
|
||||
passedData.writeItemStack(inventory.get(0));
|
||||
passedData.writeItemStack(inventory.get(1));
|
||||
passedData.writeItemStack(inventory.get(2));
|
||||
passedData.writeItemStack(inventory.get(3));
|
||||
passedData.writeItemStack(inventory.get(4));
|
||||
passedData.writeItemStack(blockEntity.getStack(0));
|
||||
passedData.writeItemStack(blockEntity.getStack(1));
|
||||
passedData.writeItemStack(blockEntity.getStack(2));
|
||||
passedData.writeItemStack(blockEntity.getStack(3));
|
||||
passedData.writeItemStack(blockEntity.getStack(4));
|
||||
|
||||
passedData.writeString(String.valueOf(inventory));
|
||||
watchingPlayers.forEach(player -> ServerSidePacketRegistryImpl.INSTANCE.sendToPlayer(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData));
|
||||
invUpdate = false;
|
||||
}
|
||||
@@ -51,7 +50,7 @@ public abstract class MixinBrewingStandBlockEntity extends LockableContainerBloc
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "getStack", cancellable = true)
|
||||
public void getStack(int slot, CallbackInfoReturnable cir) {
|
||||
this.invUpdate = true;
|
||||
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
|
||||
invUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user