Search in sources :

Example 1 with INamedContainerProvider

use of net.minecraft.inventory.container.INamedContainerProvider in project AgriCraft by AgriCraft.

the class GuiPlugin method onSeedAnalyzerRightClick.

public void onSeedAnalyzerRightClick(PlayerInteractEvent.RightClickBlock event) {
    BlockPos pos = event.getPos();
    BlockState state = event.getWorld().getBlockState(pos);
    if (event.getPlayer().isSneaking()) {
        return;
    }
    if (state.getBlock() != AgriCraft.instance.getModBlockRegistry().seed_analyzer.getBlock()) {
        return;
    }
    event.setCancellationResult(ActionResultType.SUCCESS);
    event.setCanceled(true);
    if (event.getPlayer().world.isRemote) {
        return;
    }
    INamedContainerProvider containerProvider = new INamedContainerProvider() {

        @Nonnull
        @Override
        public ITextComponent getDisplayName() {
            return new TranslationTextComponent("screen.agricraft.seed_analyzer");
        }

        @Override
        public Container createMenu(int id, @Nonnull PlayerInventory playerInventory, @Nonnull PlayerEntity player) {
            return new SeedAnalyzerContainer(id, event.getWorld(), playerInventory, pos);
        }
    };
    NetworkHooks.openGui((ServerPlayerEntity) event.getPlayer(), containerProvider, pos);
}
Also used : BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) SeedAnalyzerContainer(com.infinityraider.agricraft.plugins.agrigui.analyzer.SeedAnalyzerContainer) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) PlayerInventory(net.minecraft.entity.player.PlayerInventory) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Aggregations

SeedAnalyzerContainer (com.infinityraider.agricraft.plugins.agrigui.analyzer.SeedAnalyzerContainer)1 Nonnull (javax.annotation.Nonnull)1 BlockState (net.minecraft.block.BlockState)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)1 BlockPos (net.minecraft.util.math.BlockPos)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1