Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
Expand Down Expand Up @@ -118,7 +119,6 @@ public Component getDisplayName() {
@Nullable
@Override
public AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new ActiveSilencerMenu(ModMenuTypes.ACTIVE_SILENCER.get(), i, inventory, this);
}

Expand Down Expand Up @@ -177,4 +177,9 @@ public void applyDiskData(ValueInput input) {
public AABB shape() {
return this.range;
}

@Override
public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) {
buffer.writeBlockPos(this.getBlockPos());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
Expand Down Expand Up @@ -151,7 +152,6 @@ public Component getDisplayName() {

@Override
public @Nullable AbstractContainerMenu createMenu(int containerId, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
if (player.level().getBlockEntity(this.getBlockPos()) instanceof AdvancedComparatorBlockEntity blockEntity) {
return new AdvancedComparatorMenu(ModMenuTypes.ADVANCED_COMPARATOR.get(), containerId, inventory, blockEntity);
}
Expand Down Expand Up @@ -182,4 +182,10 @@ public String getSerializedName() {
return this.name().toLowerCase();
}
}

@Override
public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) {
buffer.writeBlockPos(this.getBlockPos());
buffer.writeNbt(this.constructDataNbt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import lombok.Getter;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -21,4 +23,9 @@ protected BaseMachineBlockEntity(BlockEntityType<? extends BlockEntity> type, Bl
public abstract Direction getDirection();

public abstract void setDirection(Direction direction);

@Override
public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) {
buffer.writeBlockPos(this.getBlockPos());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.network.Connection;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
Expand Down Expand Up @@ -1419,4 +1420,9 @@ public void removePortal(Cube323PartHalf side) {
WormholeStabilizerHandler wh = this.megastructureManager.getWormholeHandler();
wh.removePortal(side, this);
}

@Override
public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) {
buffer.writeBlockPos(this.getBlockPos());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public Component getDisplayName() {
@Nullable
@Override
public AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new ChuteMenu(ModMenuTypes.CHUTE.get(), i, inventory, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.dubhe.anvilcraft.inventory.SliderMenu;
import lombok.Getter;
import net.minecraft.core.BlockPos;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.MenuProvider;
Expand Down Expand Up @@ -104,8 +105,7 @@ public Component getDisplayName() {
@Nullable
@Override
public AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new SliderMenu(i, this::setPower);
return new SliderMenu(i, this.getPower(), this::setPower);
}

public void setPower(int power) {
Expand Down Expand Up @@ -138,4 +138,9 @@ public Level getCurrentLevel() {
public int getRange() {
return 2;
}

@Override
public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) {
buffer.writeVarInt(this.getPower());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ public Component getDisplayName() {

@Override
public @Nullable AbstractContainerMenu createMenu(int containerId, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new ExpCollectorMenu(ModMenuTypes.EXP_COLLECTOR.get(), containerId, inventory, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
Expand Down Expand Up @@ -188,7 +189,6 @@ public void saveAdditional(ValueOutput output) {
@Nullable
@Override
public AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new ItemCollectorMenu(ModMenuTypes.ITEM_COLLECTOR.get(), i, inventory, this);
}

Expand Down Expand Up @@ -411,4 +411,9 @@ public static void poachItemEntity(ItemEntity itemEntity) {
}

}

@Override
public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) {
buffer.writeBlockPos(this.getBlockPos());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
Expand Down Expand Up @@ -345,7 +346,6 @@ public Component getDisplayName() {

@Override
public @Nullable AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new ItemDetectorMenu(ModMenuTypes.ITEM_DETECTOR.get(), id, inventory, this);
}

Expand Down Expand Up @@ -473,4 +473,9 @@ public Mode cycle() {
return this == Mode.ANY ? Mode.ALL : Mode.ANY;
}
}

@Override
public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) {
buffer.writeBlockPos(this.getBlockPos());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public static Vec3 getOutputSpeed(Direction direction) {
@Nullable
@Override
public AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new MagneticChuteMenu(ModMenuTypes.MAGNETIC_CHUTE.get(), i, inventory, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
Expand Down Expand Up @@ -285,7 +286,6 @@ public Component getDisplayName() {

@Override
public @Nullable AbstractContainerMenu createMenu(int containerId, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
if (player.level().getBlockEntity(this.getBlockPos()) instanceof PulseGeneratorBlockEntity blockEntity) {
return new PulseGeneratorMenu(ModMenuTypes.PULSE_GENERATOR.get(), containerId, inventory, blockEntity);
}
Expand Down Expand Up @@ -343,4 +343,10 @@ public static Mode fromIndex(int index) {
return Mode.values()[index];
}
}

@Override
public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) {
buffer.writeBlockPos(this.getBlockPos());
buffer.writeNbt(this.constructDataNbt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ public Component getDisplayName() {

@Override
public @Nullable AbstractContainerMenu createMenu(int containerId, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new StructureScannerMenu(ModMenuTypes.STRUCTURE_SCANNER.get(), containerId, inventory, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import dev.dubhe.anvilcraft.init.block.ModBlockTags;
import dev.dubhe.anvilcraft.init.block.ModBlocks;
import dev.dubhe.anvilcraft.inventory.TeslaTowerMenu;
import dev.dubhe.anvilcraft.network.TeslaFilterSyncPacket;
import dev.dubhe.anvilcraft.util.DistanceComparator;
import it.unimi.dsi.fastutil.Pair;
import lombok.Getter;
Expand All @@ -34,6 +35,7 @@
import net.minecraft.core.UUIDUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
Expand Down Expand Up @@ -420,7 +422,9 @@ public Component getDisplayName() {

@Override
public @Nullable AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
if (this.level == null || player.isSpectator()) return null;
if (this.level == null) {
return null;
}
BlockState blockState = this.level.getBlockState(this.getBlockPos());
int offsetY = blockState.getValue(TeslaTowerBlock.HALF).getOffsetY();
if (this.level.getBlockEntity(this.getBlockPos().above(-offsetY)) instanceof TeslaTowerBlockEntity teslaTowerBlockEntity) {
Expand Down Expand Up @@ -461,4 +465,10 @@ public void applyDiskData(ValueInput input) {
});
this.handleSync(filters);
}

@Override
public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) {
buffer.writeBlockPos(this.getBlockPos());
TeslaFilterSyncPacket.STREAM_CODEC.encode(buffer, TeslaFilterSyncPacket.create(this.getAllowList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public void preRemoveSideEffects(BlockPos pos, BlockState state) {
@Nullable
@Override
public AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new BatchCrafterMenu(ModMenuTypes.BATCH_CRAFTER.get(), i, inventory, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public SingleRecipeInput createDummyInput() {
@Nullable
@Override
public AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
if (player.isSpectator()) return null;
return new BatchCutterMenu(ModMenuTypes.BATCH_CUTTER.get(), i, inventory, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
Expand Down Expand Up @@ -181,6 +182,11 @@ public void onRemove(Level level, BlockPos pos, BlockState state) {
public void onPlace(Level level, BlockPos pos, BlockState state) {
}

@Override
protected @Nullable MenuProvider getMenuProvider(BlockState state, Level level, BlockPos pos) {
return level.getBlockEntity(this.getMainPartPos(pos, state)) instanceof TeslaTowerBlockEntity blockEntity ? blockEntity : null;
}

@Override
protected InteractionResult useWithoutItem(
BlockState state,
Expand All @@ -197,7 +203,7 @@ protected InteractionResult useWithoutItem(
BlockEntity blockEntity = level.getBlockEntity(mainPartPos);
if (blockEntity instanceof TeslaTowerBlockEntity teslaTowerBlockEntity && player instanceof ServerPlayer sp) {
if (sp.gameMode.getGameModeForPlayer() == GameType.SPECTATOR) return InteractionResult.PASS;
ModMenuTypes.open(sp, teslaTowerBlockEntity, mainPartPos);
ModMenuTypes.open(sp, teslaTowerBlockEntity);
PacketDistributor.sendToPlayer(sp, TeslaFilterSyncPacket.create(teslaTowerBlockEntity.getAllowList()));
return InteractionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public InteractionResult use(
}
if (level.getBlockEntity(pos) instanceof CreativeGeneratorBlockEntity entity
&& player instanceof ServerPlayer serverPlayer) {
ModMenuTypes.open(serverPlayer, entity, pos);
ModMenuTypes.open(serverPlayer, entity);
PacketDistributor.sendToPlayer(serverPlayer, new SliderInitPacket(entity.getPower()));
}
return InteractionResult.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -277,6 +278,11 @@ public static int getDelay() {
return 1;
}

@Override
protected @Nullable MenuProvider getMenuProvider(BlockState state, Level level, BlockPos pos) {
return level.getBlockEntity(pos) instanceof AdvancedComparatorBlockEntity blockEntity ? blockEntity : null;
}

@Override
protected InteractionResult useWithoutItem(
BlockState state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
Expand Down Expand Up @@ -310,6 +311,11 @@ public static int getInputSignal(Level level, BlockPos pos, BlockState state) {
}
}

@Override
protected @Nullable MenuProvider getMenuProvider(BlockState state, Level level, BlockPos pos) {
return level.getBlockEntity(pos) instanceof PulseGeneratorBlockEntity blockEntity ? blockEntity : null;
}

@Override
protected InteractionResult useWithoutItem(
BlockState state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ protected void init() {
this.value.setTextColorUneditable(-1);
this.value.setBordered(false);
this.value.setMaxLength(50);
this.sliderWidget.setValue(this.menu.getInitialValue());
this.value.setValue(Integer.toString(this.menu.getInitialValue()));
this.value.setResponder(this::onValueInput);
this.value.setValue("");
TexturedButton max = new TexturedButton(
152 + offsetX,
43 + offsetY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ protected void init() {
.toList()
);
this.filteredFilters.addAll(this.allFilter);
this.handleSync(List.copyOf(this.menu.getBlockEntity().getAllowList()));
}

private boolean mouseInLeft(double mouseX, double mouseY, int leftPos, int topPos) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/dubhe/anvilcraft/init/ModMenuTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class ModMenuTypes {
public static final MenuEntry<SliderMenu> SLIDER = REGISTRUM
.menu(
"slider",
(menuType, containerId, inventory) -> new SliderMenu(menuType, containerId),
(menuType, containerId, inventory, extraData) -> new SliderMenu(menuType, containerId, inventory, extraData),
() -> SliderScreen::new)
.register();
public static final MenuEntry<ItemCollectorMenu> ITEM_COLLECTOR = REGISTRUM
Expand Down
Loading
Loading